• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Input.hpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 #ifndef GOSU_INPUT_HPP
00005 #define GOSU_INPUT_HPP
00006 
00007 #include <Gosu/Fwd.hpp>
00008 #include <Gosu/Platform.hpp>
00009 
00010 #ifdef GOSU_IS_WIN
00011 #include <Gosu/ButtonsWin.hpp>
00012 #define NOMINMAX
00013 #include <windows.h>
00014 #endif
00015 
00016 #ifdef GOSU_IS_MAC
00017 #include <Gosu/ButtonsMac.hpp>
00018 #endif
00019 
00020 #ifdef GOSU_IS_X
00021 #include <X11/Xlib.h>
00022 #include <X11/Xutil.h>
00023 #include <X11/keysym.h>
00024 #include <Gosu/ButtonsX.hpp>
00025 #endif
00026 
00027 #include <Gosu/Platform.hpp>
00028 #include <Gosu/Fwd.hpp>
00029 #include <boost/function.hpp>
00030 #include <boost/scoped_ptr.hpp>
00031 #include <vector>
00032 
00033 namespace Gosu
00034 {
00036     class Button
00037     {
00038         unsigned id_;
00039         
00040     public:
00042         explicit Button(unsigned id) : id_(id) {}
00044         unsigned id() const { return id_; }
00045 
00047         Button() : id_(noButton) {}
00048 
00050         Button(ButtonName name) : id_(name) {}
00051     };
00052     
00053     // Available even on non-iPhone platforms to make it easier to compile the
00054     // same source for multiple platforms.
00055     
00058     struct Touch
00059     {
00061         void* id;
00063         double x, y;
00064     };
00065     typedef std::vector<Touch> Touches;
00066     
00068     inline bool operator==(Button lhs, Button rhs)
00069     {
00070         return lhs.id() == rhs.id();
00071     }
00072     inline bool operator!=(Button lhs, Button rhs)
00073     {
00074         return !(lhs == rhs);
00075     }
00076     inline bool operator<(Button lhs, Button rhs)
00077     {
00078         return lhs.id() < rhs.id();
00079     }
00080     
00083     class Input
00084     {
00085         struct Impl;
00086         boost::scoped_ptr<Impl> pimpl;
00087 
00088     public:
00089         #ifdef GOSU_IS_WIN
00090         Input(HWND window);
00091         #endif
00092         
00093         #ifdef GOSU_IS_MAC
00094         #ifdef GOSU_IS_IPHONE
00095         Input();
00096         #else
00097         Input(void* nswindow);
00098         bool feedNSEvent(void* event);
00099         #endif
00100         #endif
00101         
00102         #ifdef GOSU_IS_X
00103         Input(::Display* display, ::Window window);
00104         bool feedXEvent(::XEvent& event);
00105         #endif
00106         
00107         ~Input();
00108         
00110         static wchar_t idToChar(Button btn);
00113         static Button charToId(wchar_t ch);
00114         
00117         bool down(Button btn) const;
00118         
00121         double mouseX() const;
00123         double mouseY() const;
00124 
00128         void setMousePosition(double x, double y);
00129 
00130         // Undocumented for the moment.
00131         void setMouseFactors(double factorX, double factorY);
00132         
00135         void update();
00136         
00139         boost::function<void (Button)> onButtonDown, onButtonUp;
00140         
00142         TextInput* textInput() const;
00144         void setTextInput(TextInput* input);
00145     };
00146 }
00147 
00148 #endif

Documentation not clear enough? Please go to one of the places listed on http://www.libgosu.org/ and leave feedback. Thanks!