OSDN Git Service

first
[psychlops/cpp.git] / psychlops / core / devices / psychlops_io_hid.h
1 /*
2  *  psychlops_io_keyboard.h
3  *  Psychlops Standard Library (Universal)
4  *
5  *  Last Modified 2006/01/04 by Kenchi HOSOKAWA
6  *  (C) 2006 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
7  */
8
9 #ifndef HEADER_PSYCHLOPS_INPUT_HID
10 #define HEADER_PSYCHLOPS_INPUT_HID
11
12 #include "../graphic/psychlops_g_fundamental.h"
13
14
15 namespace Psychlops {
16
17         class Keyboard;
18         class Mouse;
19         class HumanInterfaceDevice;
20         class APIHIDProperties;
21         typedef HumanInterfaceDevice Input;
22
23
24
25         class Keyboard {
26                 friend class HumanInterfaceDevice;
27                 friend class APIHIDProperties;
28
29                 public:
30                 enum KeyState{
31                         pressed=0, pushed=1, released=2, hadpressed=3
32                 };
33                 struct Key {
34                         const int code;
35                         Key(const int code_);
36                         bool pressed() const;
37                         bool pushed() const;
38                         bool released() const;
39                         bool get(KeyState state) const;
40                 };
41                 static const Key
42 //              enum KeyCode{
43                         one,two,three,four,five,six,seven,eight,nine,zero,
44                         a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,
45                         comma,period,slash,
46                         pad0,pad1,pad2,pad3,pad4,pad5,pad6,pad7,pad8,pad9,
47                         rtn,spc,esc,tab,up,down,left,right,
48                         //      key modulator
49                         shift, shift_r, ctrl, alt,
50                         //  not recommended
51                         hyphen,equal,backslash,caret,
52                         underscore,semicolon,colon,leftbracket,rightbracket,at,   // because these keys laid on different location in differnt keyboard-lacalization.
53                         padcomma,padperiod,padenter,padplus,padminus,padasterisk,padslash,padequal,padclear,    //  because these keys are OS-specific.
54                         nfer,xfer   // because these keys exist only on Japanese keyboard
55                 ;//};
56
57
58                 static void update();
59                 static void refresh();
60
61                 static bool get(Key key, KeyState state = pushed);
62
63                 //  obsolete
64                         static bool getKey(Key key, KeyState state = pushed);
65                         static void wait(Key key, bool needrelease=true);
66                         static void allReleased();
67
68                 protected:
69                 static void refresh_internal();
70         };
71
72
73         class Mouse {
74                 friend class HumanInterfaceDevice;
75                 friend class APIHIDProperties;
76                 static ::Psychlops::Point pointerPos, wheelDelta, lastPoint;
77
78                 public:
79                 enum ButtonState{
80                         pressed=0, pushed=1, released=2, hadpressed=3
81                 };
82                 struct Button {
83                         const int code;
84                         Button(const int code_);
85                         bool pressed() const;
86                         bool pushed() const;
87                         bool released() const;
88                         bool get(ButtonState state) const;
89                 };
90                 static const Button left, right, middle, any;
91
92                 class POSITION;
93                 struct POSITIONVAL {
94                         friend class POSITION;
95                         friend class Mouse;
96                         friend class APIHIDProperties;
97                         protected:
98                         int val_;
99
100                         public:
101                         POSITIONVAL();
102                         operator int();
103                         int operator =(int val);
104                 };
105                 static POSITIONVAL uniX, uniY;
106                 struct POSITION { public: operator Psychlops::Point(); Psychlops::Point operator =(Point val); };
107                 static POSITION uniPosition;
108
109                 struct DEFPOSITIONVALX { operator int(); int operator =(int val); };
110                 static DEFPOSITIONVALX x;
111                 struct DEFPOSITIONVALY { operator int(); int operator =(int val); };
112                 static DEFPOSITIONVALY y;
113                 struct DEFPOSITION { operator ::Psychlops::Point(); ::Psychlops::Point operator =(::Psychlops::Point val); };
114                 static DEFPOSITION position;
115
116                 static bool show_local_pointer_;
117                 static bool showLocalPointer();
118
119                 static void initialize();
120
121                 static void update();
122                 static void refresh();
123
124                 static bool get(Button code, ButtonState state = pushed);
125                 static ::Psychlops::Point getWheelDelta();
126
127                 static void show();
128                 static void hide();
129                 static void drawPointer(Point p, Drawable &target);
130                 static void setPointer(int size);
131                 static void setPointer(Figure &fig);
132                 static Figure* pointer_figure;
133
134                 protected:
135                 static void refresh_internal();
136         };
137
138         class APIMouseProperties;
139         class HumanInterfaceDevice {
140                 friend class Keyboard;
141                 friend class Mouse;
142                 friend class APIHIDProperties;
143                 friend class APIMouseProperties;
144
145         public:
146                 enum ButtonState {
147                         pressed=0, pushed=1, released=2, hadpressed=3
148                 };
149                 struct ButtonStateHolder {
150                 private:
151                         Mouse::Button *target;
152                         bool pressed_, pushed_, released_, hadpressed_;
153                         void ask();
154                 public:
155                         ButtonStateHolder(const Mouse::Button &);
156                         bool pressed();
157                         bool pushed();
158                         bool released();
159                 };
160         private:
161                 static bool runningHIDListner;
162                 struct States {
163                         bool key[128];
164                         bool button[8];
165                         bool gamepad[32];
166                 };
167                 static States state[3];
168
169         public:
170                 static int pushRepeatFrames, pushRepeatInterval;
171                 
172                 static void initialize();
173                 static void finalize();
174
175                 static void startListener();
176                 static void stopListener();
177
178                 static void refresh();
179
180                 static bool get(Keyboard::Key code, Keyboard::KeyState state = Keyboard::pushed);
181                 static bool get(Mouse::Button code, Mouse::ButtonState state = Mouse::pushed);
182                 static void wait(Keyboard::Key code, Keyboard::KeyState state = Keyboard::pushed);
183         };
184
185
186
187
188 }       /*      <- namespace Psycholops         */
189
190 #endif