Gosu
Public Member Functions | List of all members
Gosu::Window Class Reference

Convenient all-in-one class that serves as the foundation of a standard Gosu application. More...

Public Member Functions

 Window (unsigned width, unsigned height, bool fullscreen=false, double update_interval=16.666666)
 Constructs a Window. More...
 
virtual ~Window ()
 
unsigned width () const
 
unsigned height () const
 
bool fullscreen () const
 
void resize (unsigned width, unsigned height, bool fullscreen)
 
double update_interval () const
 
void set_update_interval (double update_interval)
 
std::string caption () const
 
void set_caption (const std::string &caption)
 
virtual void show ()
 Enters a modal loop where the Window is visible on screen and receives calls to draw, update etc. More...
 
virtual bool tick ()
 EXPERIMENTAL - MAY DISAPPEAR WITHOUT WARNING. More...
 
virtual void close ()
 Closes the window if it is currently shown. More...
 
virtual void update ()
 Called every update_interval milliseconds while the window is being shown. More...
 
virtual void draw ()
 Called after every update and when the OS wants the window to repaint itself. More...
 
virtual bool needs_redraw () const
 Gives the game a chance to say no to being redrawn. More...
 
virtual bool needs_cursor () const
 If this function returns true, the system arrow cursor is drawn while over the window. More...
 
virtual void lose_focus ()
 This function is called when the window loses focus on some platforms. More...
 
virtual void release_memory ()
 This function is called when the operating system's memory is low. More...
 
virtual void button_down (Gosu::Button)
 Called before update when the user presses a button while the window has the focus. More...
 
virtual void button_up (Gosu::Button)
 Same as button_down. Called when the user releases a button. More...
 
virtual void drop (const std::string &filename)
 Called when a file is dropped onto the window. More...
 
virtual void touch_began (Touch touch)
 
virtual void touch_moved (Touch touch)
 
virtual void touch_ended (Touch touch)
 
virtual void touch_cancelled (Touch touch)
 
const Graphicsgraphics () const
 
Graphicsgraphics ()
 
const Inputinput () const
 
Inputinput ()
 

Detailed Description

Convenient all-in-one 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 you should really only use one instance of this class at the same time.

Definition at line 38 of file Window.hpp.

Constructor & Destructor Documentation

◆ Window()

Gosu::Window::Window ( unsigned  width,
unsigned  height,
bool  fullscreen = false,
double  update_interval = 16.666666 
)

Constructs a Window.

Parameters
widthWidth of the window in points; that is, pixels on a normal display, and 'points' on a high-resolution display.
heightSee width.
update_intervalInterval in milliseconds between two calls to the update member function.

◆ ~Window()

virtual Gosu::Window::~Window ( )
virtual

Member Function Documentation

◆ button_down()

virtual void Gosu::Window::button_down ( Gosu::Button  )
virtual

Called before update when the user presses a button while the window has the focus.

By default, this will toggle fullscreen mode if the user presses Alt+Enter (Windows, Linux) or cmd+F (macOS). To support these shortcuts in your application, make sure to call Window::button_down in your implementation.

Referenced by release_memory().

◆ button_up()

virtual void Gosu::Window::button_up ( Gosu::Button  )
virtual

Same as button_down. Called when the user releases a button.

Definition at line 118 of file Window.hpp.

◆ caption()

std::string Gosu::Window::caption ( ) const

◆ close()

virtual void Gosu::Window::close ( )
virtual

Closes the window if it is currently shown.

If you do not want the window to close immediately, you should override this method and only call the base implementation (Window::close) when needed.

◆ draw()

virtual void Gosu::Window::draw ( )
virtual

Called after every update and when the OS wants the window to repaint itself.

Your application's rendering code goes here.

Definition at line 91 of file Window.hpp.

◆ drop()

virtual void Gosu::Window::drop ( const std::string &  filename)
virtual

Called when a file is dropped onto the window.

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

Definition at line 123 of file Window.hpp.

◆ fullscreen()

bool Gosu::Window::fullscreen ( ) const

◆ graphics() [1/2]

const Graphics& Gosu::Window::graphics ( ) const

Referenced by touch_cancelled().

◆ graphics() [2/2]

Graphics& Gosu::Window::graphics ( )

◆ height()

unsigned Gosu::Window::height ( ) const

◆ input() [1/2]

const Input& Gosu::Window::input ( ) const

Referenced by touch_cancelled().

◆ input() [2/2]

Input& Gosu::Window::input ( )

◆ lose_focus()

virtual void Gosu::Window::lose_focus ( )
virtual

This function is called when the window loses focus on some platforms.

Most importantly, it is called on the iPhone or iPad when the user locks the screen.

Definition at line 104 of file Window.hpp.

◆ needs_cursor()

virtual bool Gosu::Window::needs_cursor ( ) const
virtual

If this function returns true, the system arrow cursor is drawn while over the window.

Definition at line 100 of file Window.hpp.

◆ needs_redraw()

virtual bool Gosu::Window::needs_redraw ( ) const
virtual

Gives the game a chance to say no to being redrawn.

This is not a definitive answer. The operating system can still force the window to redraw itself. By default, the window is redrawn all the time.

Definition at line 97 of file Window.hpp.

◆ release_memory()

virtual void Gosu::Window::release_memory ( )
virtual

This function is called when the operating system's memory is low.

So far, it is only called in iOS applications.

Definition at line 108 of file Window.hpp.

References button_down().

◆ resize()

void Gosu::Window::resize ( unsigned  width,
unsigned  height,
bool  fullscreen 
)

◆ set_caption()

void Gosu::Window::set_caption ( const std::string &  caption)

◆ set_update_interval()

void Gosu::Window::set_update_interval ( double  update_interval)

◆ show()

virtual void Gosu::Window::show ( )
virtual

Enters a modal loop where the Window is visible on screen and receives calls to draw, update etc.

◆ tick()

virtual bool Gosu::Window::tick ( )
virtual

EXPERIMENTAL - MAY DISAPPEAR WITHOUT WARNING.

Performs a single mainloop step. This method is only useful if you want to integrate Gosu with another library that has its own main loop. This method implicitly shows the window if it was hidden before, and returns false when the window has been closed. If you discard the return value and keep calling tick(), the window will be shown again, or keep being shown.

◆ touch_began()

virtual void Gosu::Window::touch_began ( Touch  touch)
virtual

Definition at line 128 of file Window.hpp.

◆ touch_cancelled()

virtual void Gosu::Window::touch_cancelled ( Touch  touch)
virtual

Definition at line 131 of file Window.hpp.

References graphics(), and input().

◆ touch_ended()

virtual void Gosu::Window::touch_ended ( Touch  touch)
virtual

Definition at line 130 of file Window.hpp.

◆ touch_moved()

virtual void Gosu::Window::touch_moved ( Touch  touch)
virtual

Definition at line 129 of file Window.hpp.

◆ update()

virtual void Gosu::Window::update ( )
virtual

Called every update_interval milliseconds while the window is being shown.

Your application's main game logic goes here.

Definition at line 87 of file Window.hpp.

◆ update_interval()

double Gosu::Window::update_interval ( ) const

◆ width()

unsigned Gosu::Window::width ( ) const

The documentation for this class was generated from the following file: