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.



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

def initialize(width, height, options); 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

#captionString

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

Returns:

  • (String)

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



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

def caption
  @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

#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.



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

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.



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

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.



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_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.



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

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.



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

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.



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.

Returns:

  • (true, false)

    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.

Parameters:

  • id (Integer)

    the button’s platform-defined id.

See Also:



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

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:



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

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)


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

#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:



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

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.



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

def drop(filename); end

#fullscreen?true, false

Returns whether this is a fullscreen window.

Returns:

  • (true, false)

    whether this is a fullscreen window.



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

def fullscreen?; end

#gain_focusObject

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.

Parameters:

  • index (integer)

    index for looking up gamepad.

See Also:



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

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:



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

def gamepad_disconnected(index); end

#lose_focusObject

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.

Returns:

  • (true, false)

    whether the system cursor should be shown.



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.

Returns:

  • (true, false)

    whether the window needs to be redrawn.

See Also:



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

def needs_redraw?; end

#resizable?true, false

Returns whether this window is resizable.

Returns:

  • (true, false)

    whether this window is resizable.



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

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.



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

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



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

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.



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

def update; end