Window.hpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 #ifndef GOSU_WINDOW_HPP
00005 #define GOSU_WINDOW_HPP
00006 
00007 #include <Gosu/Fwd.hpp>
00008 #include <Gosu/Platform.hpp>
00009 #include <Gosu/Input.hpp>
00010 #include <Gosu/TR1.hpp>
00011 #include <memory>
00012 #include <string>
00013 
00014 #ifdef GOSU_IS_WIN
00015 #ifndef NOMINMAX
00016 #define NOMINMAX
00017 #endif
00018 #include <windows.h>
00019 #endif
00020 
00021 namespace Gosu
00022 {
00028     class Window
00029     {
00030         struct Impl;
00031         const std::auto_ptr<Impl> pimpl;
00032     
00033     public:
00037         Window(unsigned width, unsigned height, bool fullscreen,
00038             double updateInterval = 16.666666);
00039         virtual ~Window();
00040 
00041         std::wstring caption() const;
00042         void setCaption(const std::wstring& caption);
00043         
00044         double updateInterval() const;
00045 
00048         void show();
00050         void close();
00051 
00054         virtual void update() {}
00057         virtual void draw() {}
00058         
00063         virtual bool needsRedraw() const { return true; }
00064 
00067         virtual bool needsCursor() const { return false; }
00068         
00072         virtual void loseFocus() {}
00073         
00076         virtual void releaseMemory() {}
00077 
00080         virtual void buttonDown(Gosu::Button) {}
00082         virtual void buttonUp(Gosu::Button) {}
00083         
00084         // Ignore when SWIG is wrapping this class for Ruby/Gosu.
00085         #ifndef SWIG
00086         
00087         const Graphics& graphics() const;
00088         Graphics& graphics();
00089         
00090         const Input& input() const;
00091         Input& input();
00092         
00093         #ifdef GOSU_IS_WIN
00094         // Only on Windows, used for integrating with GUI toolkits.
00095         HWND handle() const;
00096         virtual LRESULT handleMessage(UINT message, WPARAM wparam,
00097             LPARAM lparam);
00098         #endif
00099         
00100         #ifdef GOSU_IS_UNIX
00101         // Context for creating shared contexts.
00102         // Only on Unices (so far).
00103         typedef std::tr1::shared_ptr<std::tr1::function<void()> > SharedContext;
00104         SharedContext createSharedContext();
00105         #endif
00106         
00107         #ifdef GOSU_IS_IPHONE
00108         void* rootViewController() const;
00109         // iPhone-only callbacks for touch events.
00110         // Note that it does not hurt to override them even if you compile
00111         // for another platform; if you don't specify "virtual" the code
00112         // should even be stripped away cleanly.
00113         virtual void touchBegan(Touch touch) {}
00114         virtual void touchMoved(Touch touch) {}
00115         virtual void touchEnded(Touch touch) {}
00116         #endif        
00117         
00118         const Audio& audio() const;
00119         Audio& audio();
00120 
00121         #endif
00122     };
00123 }
00124 
00125 #ifdef GOSU_IS_IPHONE
00126 Gosu::Window& windowInstance();
00127 #endif
00128 
00129 #endif