Class: Gosu::Window
- Inherits:
-
Object
- Object
- Gosu::Window
- Defined in:
- rdoc/gosu.rb
Overview
There should really only be one instance of this class at a time. This may or may not change later.
Main class that serves as the foundation of a standard Gosu application. Manages initialization of all of Gosu's core components and provides timing functionality.
Note that all coordinates, even the mouse position, are in client coordinates, relative to the window’s top left corner. This means that the mouse position can be negative or larger than the window size.
Instance Attribute Summary collapse
-
#caption ⇒ String
The window's caption, usually displayed in the title bar.
-
#fullscreen ⇒ Object
writeonly
Toggles between windowed mode and fullscreen.
-
#height ⇒ Integer
The window's height, in pixels.
-
#mouse_x ⇒ Float
The mouse pointer's window-based X coordinate.
-
#mouse_y ⇒ Float
The mouse pointer's window-based Y coordinate.
-
#text_input ⇒ TextInput?
The currently active TextInput.
-
#update_interval ⇒ Float
The interval between calls to #update, in milliseconds.
-
#width ⇒ Integer
The window's width, in pixels.
Callbacks collapse
-
#button_down(id) ⇒ void
This method is called before #update if a button is pressed while the window has focus.
-
#button_up(id) ⇒ void
This method is called before #update if a button is released while the window has focus.
-
#close ⇒ bool
This method is called whenever the user tries to close the window, e.g.
-
#draw ⇒ void
This method is called after every update and whenever the OS wants the window to repaint itself.
-
#drop(filename) ⇒ Object
Called when a file is dropped onto the window.
-
#needs_cursor? ⇒ true, false
This method can be overriden to control the visibility of the system cursor over your window, e.g., for level editors or other situations where introducing a custom cursor or hiding the default one is not desired.
-
#needs_redraw? ⇒ true, false
This method can be overriden to give the game a chance to opt out of a call to #draw; however, the operating system can still force a redraw for any reason.
-
#update ⇒ void
This method is called once every #update_interval milliseconds while the window is being shown.
Instance Method Summary collapse
-
#close! ⇒ void
Tells the window to end the current run loop as soon as possible.
-
#fullscreen? ⇒ true, false
Whether this is a fullscreen window.
-
#initialize(width, height, options) ⇒ Window
constructor
Creates a new window with the requested size.
-
#resizable? ⇒ true, false
Whether this window is resizable.
-
#show ⇒ void
Enters a modal loop where the Window is visible on screen and receives calls to draw, update etc.
-
#tick ⇒ true, false
EXPERIMENTAL - MAY DISAPPEAR WITHOUT WARNING.
Constructor Details
#initialize(width, height, options = {}) ⇒ Window #initialize(width, height, fullscreen, update_interval = 16.666666) ⇒ Window
Creates a new window with the requested size.
Resizable fullscreen windows always use the full desktop resolution. Windows that are larger than the desktop resolution will be shrunk.
791 |
# File 'rdoc/gosu.rb', line 791 def initialize(width, height, ); end |
Instance Attribute Details
#caption ⇒ String
Returns the window's caption, usually displayed in the title bar.
732 733 734 |
# File 'rdoc/gosu.rb', line 732 def caption @caption end |
#fullscreen=(value) ⇒ Object (writeonly)
Toggles between windowed mode and fullscreen.
766 767 768 |
# File 'rdoc/gosu.rb', line 766 def fullscreen=(value) @fullscreen = value end |
#height ⇒ Integer
The window's height, in pixels. This only counts the drawable area and does not include any borders or decorations added by the window manager.
758 759 760 |
# File 'rdoc/gosu.rb', line 758 def height @height end |
#mouse_x ⇒ Float
Returns the mouse pointer's window-based X coordinate.
736 737 738 |
# File 'rdoc/gosu.rb', line 736 def mouse_x @mouse_x end |
#mouse_y ⇒ Float
Returns the mouse pointer's window-based Y coordinate.
740 741 742 |
# File 'rdoc/gosu.rb', line 740 def mouse_y @mouse_y end |
#text_input ⇒ TextInput?
The currently active TextInput. If not nil, all keyboard input will be handled by this object.
746 747 748 |
# File 'rdoc/gosu.rb', line 746 def text_input @text_input end |
#update_interval ⇒ Float
Returns the interval between calls to #update, in milliseconds.
774 775 776 |
# File 'rdoc/gosu.rb', line 774 def update_interval @update_interval end |
#width ⇒ Integer
The window's width, in pixels. This only counts the drawable area and does not include any borders or decorations added by the window manager.
752 753 754 |
# File 'rdoc/gosu.rb', line 752 def width @width end |
Instance Method Details
#button_down(id) ⇒ void
This method returns an undefined value.
This method is called before #update if a button is pressed while the window has focus.
By default, this will toggle fullscreen mode if the user presses Alt+Enter (Windows, Linux), cmd+F (macOS), or F11 (on all operating systems). To support these shortcuts in your application, make sure to call super in your implementation.
871 |
# File 'rdoc/gosu.rb', line 871 def (id); end |
#button_up(id) ⇒ void
This method returns an undefined value.
This method is called before #update if a button is released while the window has focus.
881 |
# File 'rdoc/gosu.rb', line 881 def (id); end |
#close ⇒ bool
This method is called whenever the user tries to close the window, e.g. by clicking the [x] button in the window's title bar. If you do not want the window to close immediately, you should override this method and call the #close! when needed.
856 |
# File 'rdoc/gosu.rb', line 856 def close; end |
#close! ⇒ void
This method returns an undefined value.
Tells the window to end the current run loop as soon as possible.
817 |
# File 'rdoc/gosu.rb', line 817 def close!; end |
#draw ⇒ void
This method returns an undefined value.
This method is called after every update and whenever the OS wants the window to repaint itself. Your application's rendering code should go here.
833 |
# File 'rdoc/gosu.rb', line 833 def draw; end |
#drop(filename) ⇒ Object
Called when a file is dropped onto the window.
887 |
# File 'rdoc/gosu.rb', line 887 def drop(filename); end |
#fullscreen? ⇒ true, false
Returns whether this is a fullscreen window.
762 |
# File 'rdoc/gosu.rb', line 762 def fullscreen?; end |
#needs_cursor? ⇒ true, false
This method can be overriden to control the visibility of the system cursor over your window, e.g., for level editors or other situations where introducing a custom cursor or hiding the default one is not desired.
847 |
# File 'rdoc/gosu.rb', line 847 def needs_cursor?; end |
#needs_redraw? ⇒ true, false
This method can be overriden to give the game a chance to opt out of a call to #draw; however, the operating system can still force a redraw for any reason.
841 |
# File 'rdoc/gosu.rb', line 841 def needs_redraw?; end |
#resizable? ⇒ true, false
Returns whether this window is resizable.
770 |
# File 'rdoc/gosu.rb', line 770 def resizable?; end |
#show ⇒ void
This method returns an undefined value.
Enters a modal loop where the Window is visible on screen and receives calls to draw, update etc.
797 |
# File 'rdoc/gosu.rb', line 797 def show; end |
#tick ⇒ true, false
EXPERIMENTAL - MAY DISAPPEAR WITHOUT WARNING.
Performs a single step in the main loop. This can be useful for integrating Gosu with other libraries that have their own main loop, e.g. Ruby/Tk.
See: www.libgosu.org/cgi-bin/mwf/topic_show.pl?tid=1218
If you find a good way to use #tick, please let us know on the forum and we can make this a part of Gosu's stable interface. Thank you!
811 |
# File 'rdoc/gosu.rb', line 811 def tick; end |
#update ⇒ void
This method returns an undefined value.
This method is called once every #update_interval milliseconds while the window is being shown. Your application's main logic should go here.
825 |
# File 'rdoc/gosu.rb', line 825 def update; end |