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 #ifndef NOMINMAX 00013 #define NOMINMAX 00014 #endif 00015 #include <windows.h> 00016 #endif 00017 00018 #ifdef GOSU_IS_MAC 00019 #include <Gosu/ButtonsMac.hpp> 00020 #endif 00021 00022 #ifdef GOSU_IS_X 00023 #include <X11/Xlib.h> 00024 #include <X11/Xutil.h> 00025 #include <X11/keysym.h> 00026 #include <Gosu/ButtonsX.hpp> 00027 #endif 00028 00029 #include <Gosu/Platform.hpp> 00030 #include <Gosu/Fwd.hpp> 00031 #include <boost/function.hpp> 00032 #include <boost/scoped_ptr.hpp> 00033 #include <vector> 00034 00035 namespace Gosu 00036 { 00038 class Button 00039 { 00040 unsigned id_; 00041 00042 public: 00044 explicit Button(unsigned id) : id_(id) {} 00046 unsigned id() const { return id_; } 00047 00049 Button() : id_(noButton) {} 00050 00052 Button(ButtonName name) : id_(name) {} 00053 }; 00054 00056 inline bool operator==(Button lhs, Button rhs) 00057 { 00058 return lhs.id() == rhs.id(); 00059 } 00060 inline bool operator!=(Button lhs, Button rhs) 00061 { 00062 return !(lhs == rhs); 00063 } 00064 inline bool operator<(Button lhs, Button rhs) 00065 { 00066 return lhs.id() < rhs.id(); 00067 } 00068 00073 struct Touch 00074 { 00076 void* id; 00078 float x, y; 00079 }; 00080 typedef std::vector<Touch> Touches; 00081 00084 class Input 00085 { 00086 struct Impl; 00087 boost::scoped_ptr<Impl> pimpl; 00088 00089 public: 00090 #ifdef GOSU_IS_WIN 00091 Input(HWND window); 00092 #endif 00093 00094 #ifdef GOSU_IS_MAC 00095 #ifdef GOSU_IS_IPHONE 00096 Input(void* view, float updateInterval); 00097 void feedTouchEvent(int type, void* touches); 00098 #else 00099 Input(void* window); 00100 bool feedNSEvent(void* event); 00101 #endif 00102 #endif 00103 00104 #ifdef GOSU_IS_X 00105 Input(::Display* display, ::Window window); 00106 bool feedXEvent(::XEvent& event); 00107 #endif 00108 00109 ~Input(); 00110 00112 static wchar_t idToChar(Button btn); 00115 static Button charToId(wchar_t ch); 00116 00119 bool down(Button btn) const; 00120 00123 double mouseX() const; 00125 double mouseY() const; 00126 00130 void setMousePosition(double x, double y); 00131 00132 // Undocumented for the moment. Also applies to currentTouches(). 00133 void setMouseFactors(double factorX, double factorY); 00134 00136 const Touches& currentTouches() const; 00137 00139 double accelerometerX() const; 00140 double accelerometerY() const; 00141 double accelerometerZ() const; 00142 00145 void update(); 00146 00149 boost::function<void (Button)> onButtonDown, onButtonUp; 00150 00153 boost::function<void (Touch)> onTouchBegan, onTouchMoved, onTouchEnded; 00154 00156 TextInput* textInput() const; 00158 void setTextInput(TextInput* input); 00159 }; 00160 } 00161 00162 #endif
Documentation not clear enough? Please go to one of the places listed on http://www.libgosu.org/ and leave feedback. Thanks!