Window.hpp
Go to the documentation of this file.
1 
4 #ifndef GOSU_WINDOW_HPP
5 #define GOSU_WINDOW_HPP
6 
7 #include <Gosu/Fwd.hpp>
8 #include <Gosu/Platform.hpp>
9 #include <Gosu/Input.hpp>
10 #include <Gosu/TR1.hpp>
11 #include <memory>
12 #include <string>
13 
14 #ifdef GOSU_IS_WIN
15 #ifndef NOMINMAX
16 #define NOMINMAX
17 #endif
18 #include <windows.h>
19 #endif
20 
21 namespace Gosu
22 {
28  class Window
29  {
30  struct Impl;
31  const GOSU_UNIQUE_PTR<Impl> pimpl;
32 #if defined(GOSU_CPP11_ENABLED)
33  Window(Window&&) = delete;
34  Window& operator=(Window&&) = delete;
35  Window(const Window&) = delete;
36  Window& operator=(const Window&) = delete;
37 #endif
38 
39  public:
43  Window(unsigned width, unsigned height, bool fullscreen,
44  double updateInterval = 16.666666);
45  virtual ~Window();
46 
47  std::wstring caption() const;
48  void setCaption(const std::wstring& caption);
49 
50  double updateInterval() const;
51 
54  void show();
56  void close();
57 
60  virtual void update() {}
63  virtual void draw() {}
64 
69  virtual bool needsRedraw() const { return true; }
70 
73  virtual bool needsCursor() const { return false; }
74 
78  virtual void loseFocus() {}
79 
82  virtual void releaseMemory() {}
83 
86  virtual void buttonDown(Gosu::Button) {}
88  virtual void buttonUp(Gosu::Button) {}
89 
90  // Ignore when SWIG is wrapping this class for Ruby/Gosu.
91  #ifndef SWIG
92 
93  const Graphics& graphics() const;
94  Graphics& graphics();
95 
96  const Input& input() const;
97  Input& input();
98 
99  #ifdef GOSU_IS_WIN
100  // Only on Windows, used for integrating with GUI toolkits.
101  HWND handle() const;
102  virtual LRESULT handleMessage(UINT message, WPARAM wparam,
103  LPARAM lparam);
104  #endif
105 
106  #ifdef GOSU_IS_UNIX
107  // Context for creating shared contexts.
108  // Only on Unices (so far).
109  typedef std::tr1::shared_ptr<std::tr1::function<void()> > SharedContext;
110  SharedContext createSharedContext();
111  #endif
112 
113  #ifdef GOSU_IS_IPHONE
114  void* rootViewController() const;
115  // iPhone-only callbacks for touch events.
116  // Note that it does not hurt to override them even if you compile
117  // for another platform; if you don't specify "virtual" the code
118  // should even be stripped away cleanly.
119  virtual void touchBegan(Touch touch) {}
120  virtual void touchMoved(Touch touch) {}
121  virtual void touchEnded(Touch touch) {}
122  #endif
123 
124  const Audio& audio() const;
125  Audio& audio();
126 
127  #endif
128  };
129 }
130 
131 #ifdef GOSU_IS_IPHONE
132 Gosu::Window& windowInstance();
133 #endif
134 
135 #endif
Includes all parts of C++03 (TR1) that are relevant for Gosu.
Convenient all-in-one class that serves as the foundation of a standard Gosu application.
Definition: Window.hpp:28
virtual void loseFocus()
This function is called when the window loses focus on some platforms.
Definition: Window.hpp:78
Manages initialization and shutdown of the input system.
Definition: Input.hpp:75
void close()
Closes the window if it is currently shown.
Contains declarations of all of Gosu&#39;s available classes.
void setCaption(const std::wstring &caption)
virtual void buttonUp(Gosu::Button)
Same as buttonDown. Called then the user released a button.
Definition: Window.hpp:88
Struct that saves information about a touch on the surface of a multi- touch device.
Definition: Input.hpp:64
virtual ~Window()
Window(unsigned width, unsigned height, bool fullscreen, double updateInterval=16.666666)
Constructs a Window.
const Audio & audio() const
const Graphics & graphics() const
virtual void buttonDown(Gosu::Button)
Called before update when the user pressed a button while the window had the focus.
Definition: Window.hpp:86
Very lightweight class that identifies a button (keyboard, mouse or other device).
Definition: Input.hpp:29
void show()
Enters a modal loop where the Window is visible on screen and receives calls to draw, update etc.
Interface of the Input class.
class GOSU_DEPRECATED Audio
Definition: Audio.hpp:24
const Input & input() const
virtual void releaseMemory()
This function is called when the operating system&#39;s memory is low.
Definition: Window.hpp:82
Macros and utility functions to facilitate programming on all of Gosu&#39;s supported platforms...
Serves as the target of all drawing and provides primitive drawing functionality. ...
Definition: Graphics.hpp:49
virtual void draw()
Called after every update and when the OS wants the window to repaint itself.
Definition: Window.hpp:63
virtual bool needsRedraw() const
Gives the game a chance to say no to being redrawn.
Definition: Window.hpp:69
std::wstring caption() const
virtual void update()
Called every updateInterval milliseconds while the window is being shown.
Definition: Window.hpp:60
void handleMessage()
Blocking function which waits for the next message, processes it, then returns.
double updateInterval() const
virtual bool needsCursor() const
If this function returns true, the system arrow cursor is drawn while over the window.
Definition: Window.hpp:73