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
-
#borderless ⇒ Object
writeonly
Toggles between borderless mode and having window chrome.
-
#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.
-
#resizable ⇒ Object
writeonly
Toggles between resizable and fixed modes.
-
#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.
-
#gain_focus ⇒ Object
Called when the window gains focus.
-
#gamepad_connected(index) ⇒ Object
Called when a gamepad is connected.
-
#gamepad_disconnected(index) ⇒ Object
Called when a gamepad is disconnected.
-
#lose_focus ⇒ Object
Called when the windows loses focus.
-
#needs_cursor? ⇒ true, false
This method can be overridden to control the visibility of the system cursor over your window.
-
#needs_redraw? ⇒ true, false
This method can be overridden 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
-
#borderless? ⇒ true, false
Whether this window is borderless.
-
#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.
847 |
# File 'rdoc/gosu.rb', line 847 def initialize(width, height, ); end |
Instance Attribute Details
#borderless=(value) ⇒ Object (writeonly)
Toggles between borderless mode and having window chrome.
825 826 827 |
# File 'rdoc/gosu.rb', line 825 def borderless=(value) @borderless = value end |
#caption ⇒ String
Returns the window’s caption, usually displayed in the title bar.
775 776 777 |
# File 'rdoc/gosu.rb', line 775 def @caption end |
#fullscreen=(value) ⇒ Object (writeonly)
Toggles between windowed mode and fullscreen.
809 810 811 |
# File 'rdoc/gosu.rb', line 809 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.
801 802 803 |
# File 'rdoc/gosu.rb', line 801 def height @height end |
#mouse_x ⇒ Float
Returns the mouse pointer’s window-based X coordinate.
779 780 781 |
# File 'rdoc/gosu.rb', line 779 def mouse_x @mouse_x end |
#mouse_y ⇒ Float
Returns the mouse pointer’s window-based Y coordinate.
783 784 785 |
# File 'rdoc/gosu.rb', line 783 def mouse_y @mouse_y end |
#resizable=(value) ⇒ Object (writeonly)
Toggles between resizable and fixed modes.
817 818 819 |
# File 'rdoc/gosu.rb', line 817 def resizable=(value) @resizable = value end |
#text_input ⇒ TextInput?
The currently active TextInput. If not nil, all keyboard input will be handled by this object.
789 790 791 |
# File 'rdoc/gosu.rb', line 789 def text_input @text_input end |
#update_interval ⇒ Float
Returns the interval between calls to #update, in milliseconds.
829 830 831 |
# File 'rdoc/gosu.rb', line 829 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.
795 796 797 |
# File 'rdoc/gosu.rb', line 795 def width @width end |
Instance Method Details
#borderless? ⇒ true, false
Returns whether this window is borderless.
821 |
# File 'rdoc/gosu.rb', line 821 def borderless?; end |
#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.
928 |
# File 'rdoc/gosu.rb', line 928 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.
938 |
# File 'rdoc/gosu.rb', line 938 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.
913 |
# File 'rdoc/gosu.rb', line 913 def close; end |
#close! ⇒ void
This method returns an undefined value.
Tells the window to end the current run loop as soon as possible.
873 |
# File 'rdoc/gosu.rb', line 873 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.
889 |
# File 'rdoc/gosu.rb', line 889 def draw; end |
#drop(filename) ⇒ Object
Called when a file is dropped onto the window.
944 |
# File 'rdoc/gosu.rb', line 944 def drop(filename); end |
#fullscreen? ⇒ true, false
Returns whether this is a fullscreen window.
805 |
# File 'rdoc/gosu.rb', line 805 def fullscreen?; end |
#gain_focus ⇒ Object
Called when the window gains focus
966 |
# File 'rdoc/gosu.rb', line 966 def gain_focus; end |
#gamepad_connected(index) ⇒ Object
Called when a gamepad is connected. If a gamepad is momentarily disconnected and then reconnected, before another gamepad, it will have the same index.
953 |
# File 'rdoc/gosu.rb', line 953 def gamepad_connected(index); end |
#gamepad_disconnected(index) ⇒ Object
Called when a gamepad is disconnected.
962 |
# File 'rdoc/gosu.rb', line 962 def gamepad_disconnected(index); end |
#lose_focus ⇒ Object
Called when the windows loses focus
970 |
# File 'rdoc/gosu.rb', line 970 def lose_focus; end |
#needs_cursor? ⇒ true, false
This method can be overridden to control the visibility of the system cursor over your window. The base class implementation returns true.
904 |
# File 'rdoc/gosu.rb', line 904 def needs_cursor?; end |
#needs_redraw? ⇒ true, false
This method can be overridden 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.
897 |
# File 'rdoc/gosu.rb', line 897 def needs_redraw?; end |
#resizable? ⇒ true, false
Returns whether this window is resizable.
813 |
# File 'rdoc/gosu.rb', line 813 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.
853 |
# File 'rdoc/gosu.rb', line 853 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!
867 |
# File 'rdoc/gosu.rb', line 867 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.
881 |
# File 'rdoc/gosu.rb', line 881 def update; end |