Gosu
Window.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Gosu/Fwd.hpp>
4 #include <Gosu/Input.hpp>
5 #include <Gosu/Platform.hpp>
6 #include <memory>
7 #include <string>
8 
9 namespace Gosu
10 {
14  class Window
15  {
16  struct Impl;
17  const std::unique_ptr<Impl> pimpl;
18 
19  public:
26  Window(unsigned width, unsigned height, bool fullscreen = false,
27  double update_interval = 16.666666, bool resizable = false);
28  virtual ~Window();
29 
30  unsigned width() const;
31  unsigned height() const;
32  bool fullscreen() const;
33  bool resizable() const;
34  void resize(unsigned width, unsigned height, bool fullscreen);
35 
36  double update_interval() const;
37  void set_update_interval(double update_interval);
38 
39  std::string caption() const;
40  void set_caption(const std::string& caption);
41 
44  virtual void show();
45 
54  virtual bool tick();
55 
59  virtual void close();
60 
63  virtual void update() {}
64 
67  virtual void draw() {}
68 
73  virtual bool needs_redraw() const { return true; }
74 
76  virtual bool needs_cursor() const { return true; }
77 
80  virtual void lose_focus() {}
81 
84  virtual void release_memory() {}
85 
91  virtual void button_down(Gosu::Button);
92 
94  virtual void button_up(Gosu::Button) {}
95 
98  virtual void gamepad_connected(int index) {}
99 
102  virtual void gamepad_disconnected(int index) {}
103 
107  virtual void drop(const std::string& filename) {}
108 
109  // Ignore when SWIG is wrapping this class for Ruby/Gosu.
110  #ifndef SWIG
111  // Callbacks for touch events. So far these are only used on iOS.
112  virtual void touch_began(Touch touch) {}
113  virtual void touch_moved(Touch touch) {}
114  virtual void touch_ended(Touch touch) {}
115  virtual void touch_cancelled(Touch touch) {}
116 
117  const Graphics& graphics() const;
118  Graphics& graphics();
119 
120  const Input& input() const;
121  Input& input();
122  #endif
123 
124  #ifdef GOSU_IS_IPHONE
125  void* uikit_window() const;
126  #endif
127  };
128 
132  unsigned screen_width(Window* window = nullptr);
133 
137  unsigned screen_height(Window* window = nullptr);
138 
143  unsigned available_width(Window* window = nullptr);
144 
149  unsigned available_height(Window* window = nullptr);
150 }
virtual bool tick()
EXPERIMENTAL - MAY DISAPPEAR WITHOUT WARNING.
double update_interval() const
Convenient all-in-one class that serves as the foundation of a standard Gosu application.
Definition: Window.hpp:14
Definition: Audio.hpp:12
virtual void release_memory()
This function is called when the operating system&#39;s memory is low.
Definition: Window.hpp:84
virtual bool needs_cursor() const
If this function returns true, the system cursor will be visible while over the window.
Definition: Window.hpp:76
Manages initialization and shutdown of the input system.
Definition: Input.hpp:27
virtual void lose_focus()
This function is called when the window loses focus on some platforms.
Definition: Window.hpp:80
Window(unsigned width, unsigned height, bool fullscreen=false, double update_interval=16.666666, bool resizable=false)
Constructs a Window.
Struct that saves information about a touch on the surface of a multi-touch device.
Definition: Input.hpp:16
virtual ~Window()
unsigned height() const
const Input & input() const
virtual void drop(const std::string &filename)
Called when a file is dropped onto the window.
Definition: Window.hpp:107
bool fullscreen() const
unsigned screen_width(Window *window=nullptr)
Returns the width (in pixels) of a screen.
unsigned width() const
virtual void touch_ended(Touch touch)
Definition: Window.hpp:114
virtual void touch_moved(Touch touch)
Definition: Window.hpp:113
virtual void button_up(Gosu::Button)
Same as button_down. Called when the user releases a button.
Definition: Window.hpp:94
virtual void touch_cancelled(Touch touch)
Definition: Window.hpp:115
bool resizable() const
virtual void button_down(Gosu::Button)
Called before update when the user presses a button while the window has the focus.
const Graphics & graphics() const
void set_update_interval(double update_interval)
virtual void gamepad_connected(int index)
Called when a gamepad is connected.
Definition: Window.hpp:98
Macros and utility functions to facilitate programming on all of Gosu&#39;s supported platforms...
virtual void close()
Closes the window if it is currently shown.
Serves as the target of all drawing and provides primitive drawing functionality. ...
Definition: Graphics.hpp:24
virtual void draw()
Called after every update and when the OS wants the window to repaint itself.
Definition: Window.hpp:67
unsigned available_height(Window *window=nullptr)
Returns the maximum height (in &#39;points&#39;) that is available for a non-fullscreen Window.
Button
List of button IDs that can be used with Gosu::Input.
Definition: Buttons.hpp:8
void set_caption(const std::string &caption)
unsigned available_width(Window *window=nullptr)
Returns the maximum width (in &#39;points&#39;) that is available for a non-fullscreen Window.
void resize(unsigned width, unsigned height, bool fullscreen)
virtual void update()
Called every update_interval milliseconds while the window is being shown.
Definition: Window.hpp:63
virtual bool needs_redraw() const
Gives the game a chance to say no to being redrawn.
Definition: Window.hpp:73
unsigned screen_height(Window *window=nullptr)
Returns the height (in pixels) of the user&#39;s primary screen.
std::string caption() const
virtual void touch_began(Touch touch)
Definition: Window.hpp:112
virtual void show()
Enters a modal loop where the Window is visible on screen and receives calls to draw, update etc.
virtual void gamepad_disconnected(int index)
Called when a gamepad is disconnected.
Definition: Window.hpp:102