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 #include <windows.h>
00013 #endif
00014
00015 #ifdef GOSU_IS_MAC
00016 #include <Gosu/ButtonsMac.hpp>
00017 #endif
00018
00019 #ifdef GOSU_IS_X
00020 #include <X11/Xlib.h>
00021 #include <X11/Xutil.h>
00022 #include <X11/keysym.h>
00023 #include <Gosu/ButtonsX.hpp>
00024 #endif
00025
00026 #include <Gosu/Platform.hpp>
00027 #include <Gosu/Fwd.hpp>
00028 #include <boost/function.hpp>
00029 #include <boost/scoped_ptr.hpp>
00030
00031 namespace Gosu
00032 {
00034 class Button
00035 {
00036 unsigned id;
00037
00038 public:
00040 explicit Button(unsigned id) : id(id) {}
00042 unsigned getId() const { return id; }
00043
00045 Button() : id(noButton) {}
00046
00048 Button(ButtonName name) : id(name) {}
00049 };
00050
00052 inline bool operator==(Button lhs, Button rhs)
00053 {
00054 return lhs.getId() == rhs.getId();
00055 }
00056 inline bool operator!=(Button lhs, Button rhs)
00057 {
00058 return !(lhs == rhs);
00059 }
00060
00064 class Input
00065 {
00066 struct Impl;
00067 boost::scoped_ptr<Impl> pimpl;
00068
00069 public:
00070 #ifdef GOSU_IS_WIN
00071 Input(HWND window);
00072 #endif
00073
00074 #ifdef GOSU_IS_MAC
00075 Input(void* nswindow);
00076 bool feedNSEvent(void* event);
00077 #endif
00078
00079 #ifdef GOSU_IS_X
00080 Input(::Display* dpy);
00081 bool feedXEvent(::XEvent& event, Window* window);
00082 #endif
00083
00084 ~Input();
00085
00087 static wchar_t idToChar(Button btn);
00090 static Button charToId(wchar_t ch);
00091
00093 bool down(Button btn) const;
00094
00097 double mouseX() const;
00099 double mouseY() const;
00100
00101 void setMouseFactors(double factorX, double factorY);
00102
00105 void update();
00106
00109 boost::function<void (Button)> onButtonDown, onButtonUp;
00110
00111 TextInput* textInput() const;
00112 void setTextInput(TextInput* input);
00113 };
00114 }
00115
00116 #endif