Class: Gosu::Window

Inherits:
Object
  • Object
show all
Defined in:
rdoc/gosu.rb

Overview

Note:

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

Callbacks collapse

Instance Method Summary collapse

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.

Options Hash (options):

  • :fullscreen (true, false) — default: false

    whether to present the window in fullscreen mode.

  • :resizable (true, false) — default: false

    whether the window can be resized by the user.

  • :update_interval (Float) — default: 16.666666

    the interval between frames, in milliseconds.


791
# File 'rdoc/gosu.rb', line 791

def initialize(width, height, options); end

Instance Attribute Details

#captionString


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

#heightInteger

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_xFloat


736
737
738
# File 'rdoc/gosu.rb', line 736

def mouse_x
  @mouse_x
end

#mouse_yFloat


740
741
742
# File 'rdoc/gosu.rb', line 740

def mouse_y
  @mouse_y
end

#text_inputTextInput?

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_intervalFloat


774
775
776
# File 'rdoc/gosu.rb', line 774

def update_interval
  @update_interval
end

#widthInteger

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 button_down(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 button_up(id); end

#closebool

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

#drawvoid

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.

See Also:


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


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.

See Also:


841
# File 'rdoc/gosu.rb', line 841

def needs_redraw?; end

#resizable?true, false


770
# File 'rdoc/gosu.rb', line 770

def resizable?; end

#showvoid

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

#ticktrue, 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

#updatevoid

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