Window.hpp
Go to the documentation of this file.
1 
2 
3 
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 std::auto_ptr<Impl> pimpl;
32 
33  public:
37  Window(unsigned width, unsigned height, bool fullscreen,
38  double updateInterval = 16.666666);
39  virtual ~Window();
40 
41  std::wstring caption() const;
42  void setCaption(const std::wstring& caption);
43 
44  double updateInterval() const;
45 
48  void show();
50  void close();
51 
54  virtual void update() {}
57  virtual void draw() {}
58 
63  virtual bool needsRedraw() const { return true; }
64 
67  virtual bool needsCursor() const { return false; }
68 
72  virtual void loseFocus() {}
73 
76  virtual void releaseMemory() {}
77 
80  virtual void buttonDown(Gosu::Button) {}
82  virtual void buttonUp(Gosu::Button) {}
83 
84  // Ignore when SWIG is wrapping this class for Ruby/Gosu.
85  #ifndef SWIG
86 
87  const Graphics& graphics() const;
88  Graphics& graphics();
89 
90  const Input& input() const;
91  Input& input();
92 
93  #ifdef GOSU_IS_WIN
94  // Only on Windows, used for integrating with GUI toolkits.
95  HWND handle() const;
96  virtual LRESULT handleMessage(UINT message, WPARAM wparam,
97  LPARAM lparam);
98  #endif
99 
100  #ifdef GOSU_IS_UNIX
101  // Context for creating shared contexts.
102  // Only on Unices (so far).
103  typedef std::tr1::shared_ptr<std::tr1::function<void()> > SharedContext;
104  SharedContext createSharedContext();
105  #endif
106 
107  #ifdef GOSU_IS_IPHONE
108  void* rootViewController() const;
109  // iPhone-only callbacks for touch events.
110  // Note that it does not hurt to override them even if you compile
111  // for another platform; if you don't specify "virtual" the code
112  // should even be stripped away cleanly.
113  virtual void touchBegan(Touch touch) {}
114  virtual void touchMoved(Touch touch) {}
115  virtual void touchEnded(Touch touch) {}
116  #endif
117 
118  const Audio& audio() const;
119  Audio& audio();
120 
121  #endif
122  };
123 }
124 
125 #ifdef GOSU_IS_IPHONE
126 Gosu::Window& windowInstance();
127 #endif
128 
129 #endif