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.

Parameters:

  • width (Integer)

    the desired window width.

  • height (Integer)

    the desired window height.

  • options (Hash)

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. Not useful if the window is either fullscreen or borderless.

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

    whether the window should hide all its window chrome. Does not affect fullscreen windows.

  • :update_interval (Float) — default: 16.666666

    the interval between frames, in milliseconds.


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

def initialize(width, height, options); end

Instance Attribute Details

#borderless=(value) ⇒ Object (writeonly)

Toggles between borderless mode and having window chrome.


824
825
826
# File 'rdoc/gosu.rb', line 824

def borderless=(value)
  @borderless = value
end

#captionString

Returns the window's caption, usually displayed in the title bar.

Returns:

  • (String)

    the window's caption, usually displayed in the title bar.


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

def caption
  @caption
end

#fullscreen=(value) ⇒ Object (writeonly)

Toggles between windowed mode and fullscreen.


808
809
810
# File 'rdoc/gosu.rb', line 808

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.

Returns:

  • (Integer)

    the window's height, in pixels.


800
801
802
# File 'rdoc/gosu.rb', line 800

def height
  @height
end

#mouse_xFloat

Returns the mouse pointer's window-based X coordinate.

Returns:

  • (Float)

    the mouse pointer's window-based X coordinate.


778
779
780
# File 'rdoc/gosu.rb', line 778

def mouse_x
  @mouse_x
end

#mouse_yFloat

Returns the mouse pointer's window-based Y coordinate.

Returns:

  • (Float)

    the mouse pointer's window-based Y coordinate.


782
783
784
# File 'rdoc/gosu.rb', line 782

def mouse_y
  @mouse_y
end

#resizable=(value) ⇒ Object (writeonly)

Toggles between resizable and fixed modes.


816
817
818
# File 'rdoc/gosu.rb', line 816

def resizable=(value)
  @resizable = value
end

#text_inputTextInput?

The currently active TextInput. If not nil, all keyboard input will be handled by this object.

Returns:

  • (TextInput?)

    the currently active text input, if any.


788
789
790
# File 'rdoc/gosu.rb', line 788

def text_input
  @text_input
end

#update_intervalFloat

Returns the interval between calls to #update, in milliseconds.

Returns:

  • (Float)

    the interval between calls to #update, in milliseconds.


828
829
830
# File 'rdoc/gosu.rb', line 828

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.

Returns:

  • (Integer)

    the window's width, in pixels.


794
795
796
# File 'rdoc/gosu.rb', line 794

def width
  @width
end

Instance Method Details

#borderless?true, false

Returns whether this window is borderless.

Returns:

  • (true, false)

    whether this window is borderless.


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

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.

Parameters:

  • id (Integer)

    the button's platform-defined id.

See Also:


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

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.

Parameters:

  • id (Integer)

    the button's platform-defined id.

See Also:


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

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.

Returns:

  • (bool)

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

def close; end

#close!void

This method returns an undefined value.

Tells the window to end the current run loop as soon as possible.


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

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:


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

def draw; end

#drop(filename) ⇒ Object

Called when a file is dropped onto the window.

Parameters:

  • filename (String)

    the filename of the dropped file. When multiple files are dropped, this method will be called several times.


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

def drop(filename); end

#fullscreen?true, false

Returns whether this is a fullscreen window.

Returns:

  • (true, false)

    whether this is a fullscreen window.


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

def fullscreen?; 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.

Parameters:

  • index (integer)

    index for looking up gamepad.

See Also:


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

def gamepad_connected(index); end

#gamepad_disconnected(index) ⇒ Object

Called when a gamepad is disconnected.

Parameters:

  • index (integer)

    index for looking up gamepad.

See Also:


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

def gamepad_disconnected(index); 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.

Returns:

  • (true, false)

    whether the system cursor should be shown.


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

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.

Returns:

  • (true, false)

    whether the window needs to be redrawn.

See Also:


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

def needs_redraw?; end

#resizable?true, false

Returns whether this window is resizable.

Returns:

  • (true, false)

    whether this window is resizable.


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

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.


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

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!

Returns:

  • (true, false)

    whether the Gosu::Window should still be shown after this tick


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

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.


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

def update; end