SDXFrameWork 0.10 SDXFrameWork

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Input.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5 #include <Multimedia/SDX.h>
6 #include <Multimedia/Keyboard.h>
7 #include <Multimedia/Mouse.h>
8 #include <Multimedia/Joypad.h>
9 #include <Multimedia/Touch.h>
10 #include <Multimedia/Gesture.h>
11 #include <Multimedia/Window.h>
12
13 namespace SDX
14 {
17 class Input
18 {
19 private:
20 MONO_STATE(Input)
21 public:
22 static Joypad pad;
23 static Mouse mouse;
24 static Keyboard key;
25 static Touch touch[10];
26 static Gesture gesture;
27
29 static void Reset()
30 {
31 pad.Reset();
32 mouse.Reset();
33 key.Reset();
34 for (auto && it : touch) it.Reset();
35 gesture.Reset();
36 }
37
39 static void Update()
40 {
41 //押下状態が変化無い場合Update出来ないので必要な処理
42 SDL_JoystickUpdate();
43 pad.Update();
44 mouse.Update();
45 key.Update();
46
47 for (auto && it : touch)
48 {
49 it.Update();
50 }
51
52 gesture.Update();
53 }
54
56 static void GetState(SDL_Event &event)
57 {
58 bool isPush = true;
59
60 switch (event.type)
61 {
62 case SDL_KEYUP:
63 isPush = false;
64 case SDL_KEYDOWN:
65 switch (event.key.keysym.sym)
66 {
67 case SDLK_BACKSPACE: key.press[KeyCode::Back] = isPush; break;
68 case SDLK_TAB: key.press[KeyCode::Tab] = isPush; break;
69 case SDLK_RETURN: key.press[KeyCode::Return] = isPush; break;
70 case SDLK_LSHIFT: key.press[KeyCode::LShift] = isPush; break;
71 case SDLK_RSHIFT: key.press[KeyCode::RShift] = isPush; break;
72 case SDLK_LCTRL: key.press[KeyCode::LControl] = isPush; break;
73 case SDLK_RCTRL: key.press[KeyCode::RControl] = isPush; break;
74 case SDLK_ESCAPE: key.press[KeyCode::Escape] = isPush; break;
75 case SDLK_SPACE: key.press[KeyCode::Space] = isPush; break;
76 case SDLK_PAGEUP: key.press[KeyCode::PageUp] = isPush; break;
77 case SDLK_PAGEDOWN: key.press[KeyCode::PageDown] = isPush; break;
78 case SDLK_END: key.press[KeyCode::End] = isPush; break;
79 case SDLK_HOME: key.press[KeyCode::Home] = isPush; break;
80 case SDLK_LEFT:
81 key.press[KeyCode::Left] = isPush;
82 pad.press[PadCode::Left] = isPush;
83 break;
84 case SDLK_UP:
85 key.press[KeyCode::Up] = isPush;
86 pad.press[PadCode::Up] = isPush;
87 break;
88 case SDLK_RIGHT:
89 key.press[KeyCode::Right] = isPush;
90 pad.press[PadCode::Right] = isPush;
91 break;
92 case SDLK_DOWN:
93 key.press[KeyCode::Down] = isPush;
94 pad.press[PadCode::Down] = isPush;
95 break;
96 case SDLK_INSERT: key.press[KeyCode::Insert] = isPush; break;
97 case SDLK_DELETE: key.press[KeyCode::Delete] = isPush; break;
98
99 case SDLK_MINUS: key.press[KeyCode::Minus] = isPush; break;
100 //case Yen = SDLK_YEN,
101 //case PrevTrack = SDLK_PREVTRACK,
102 case SDLK_PERIOD: key.press[KeyCode::Period] = isPush; break;
103 case SDLK_SLASH: key.press[KeyCode::Slash] = isPush; break;
104 case SDLK_LALT: key.press[KeyCode::LAlt] = isPush; break;
105 case SDLK_RALT: key.press[KeyCode::RAlt] = isPush; break;
106 case SDLK_SCROLLLOCK: key.press[KeyCode::Scroll] = isPush; break;
107 case SDLK_SEMICOLON: key.press[KeyCode::Semicolon] = isPush; break;
108 case SDLK_COLON: key.press[KeyCode::Colon] = isPush; break;
109 case SDLK_LEFTBRACKET: key.press[KeyCode::LBracket] = isPush; break;
110 case SDLK_RIGHTBRACKET: key.press[KeyCode::RBracket] = isPush; break;
111 case SDLK_AT: key.press[KeyCode::At] = isPush; break;
112 case SDLK_BACKSLASH: key.press[KeyCode::Backslash] = isPush; break;
113 case SDLK_COMMA: key.press[KeyCode::Comma] = isPush; break;
114 case SDLK_CAPSLOCK: key.press[KeyCode::Capslock] = isPush; break;
115 case SDLK_PAUSE: key.press[KeyCode::Pause] = isPush; break;
116
117 case SDLK_KP_0: key.press[KeyCode::Numpad0] = isPush; break;
118 case SDLK_KP_1: key.press[KeyCode::Numpad1] = isPush; break;
119 case SDLK_KP_2: key.press[KeyCode::Numpad2] = isPush; break;
120 case SDLK_KP_3: key.press[KeyCode::Numpad3] = isPush; break;
121 case SDLK_KP_4: key.press[KeyCode::Numpad4] = isPush; break;
122 case SDLK_KP_5: key.press[KeyCode::Numpad5] = isPush; break;
123 case SDLK_KP_6: key.press[KeyCode::Numpad6] = isPush; break;
124 case SDLK_KP_7: key.press[KeyCode::Numpad7] = isPush; break;
125 case SDLK_KP_8: key.press[KeyCode::Numpad8] = isPush; break;
126 case SDLK_KP_9: key.press[KeyCode::Numpad9] = isPush; break;
127 case SDLK_ASTERISK: key.press[KeyCode::Multiply] = isPush; break;
128 case SDLK_KP_PLUS: key.press[KeyCode::Add] = isPush; break;
129 case SDLK_KP_MINUS: key.press[KeyCode::Subtract] = isPush; break;
130 case SDLK_KP_PERIOD: key.press[KeyCode::Decimal] = isPush; break;
131 case SDLK_KP_DIVIDE: key.press[KeyCode::Divide] = isPush; break;
132 case SDLK_KP_ENTER: key.press[KeyCode::NUMPADEnter] = isPush; break;
133
134 case SDLK_F1: key.press[KeyCode::F1] = isPush; break;
135 case SDLK_F2: key.press[KeyCode::F2] = isPush; break;
136 case SDLK_F3: key.press[KeyCode::F3] = isPush; break;
137 case SDLK_F4: key.press[KeyCode::F4] = isPush; break;
138 case SDLK_F5: key.press[KeyCode::F5] = isPush; break;
139 case SDLK_F6: key.press[KeyCode::F6] = isPush; break;
140 case SDLK_F7: key.press[KeyCode::F7] = isPush; break;
141 case SDLK_F8: key.press[KeyCode::F8] = isPush; break;
142 case SDLK_F9: key.press[KeyCode::F9] = isPush; break;
143 case SDLK_F10: key.press[KeyCode::F10] = isPush; break;
144 case SDLK_F11: key.press[KeyCode::F11] = isPush; break;
145 case SDLK_F12: key.press[KeyCode::F12] = isPush; break;
146
147 case SDLK_a:
148 key.press[KeyCode::A] = isPush;
149 pad.press[PadCode::Button5] = isPush;
150 break;
151 case SDLK_b: key.press[KeyCode::B] = isPush; break;
152 case SDLK_c:
153 key.press[KeyCode::C] = isPush;
154 pad.press[PadCode::Button3] = isPush;
155 break;
156 case SDLK_d:
157 key.press[KeyCode::D] = isPush;
158 pad.press[PadCode::Button7] = isPush;
159 break;
160 case SDLK_e: key.press[KeyCode::E] = isPush; break;
161 case SDLK_f:
162 key.press[KeyCode::F] = isPush;
163 pad.press[PadCode::Button8] = isPush;
164 break;
165 case SDLK_g: key.press[KeyCode::G] = isPush; break;
166 case SDLK_h: key.press[KeyCode::H] = isPush; break;
167 case SDLK_i: key.press[KeyCode::I] = isPush; break;
168 case SDLK_j: key.press[KeyCode::J] = isPush; break;
169 case SDLK_k: key.press[KeyCode::K] = isPush; break;
170 case SDLK_l: key.press[KeyCode::L] = isPush; break;
171 case SDLK_m: key.press[KeyCode::M] = isPush; break;
172 case SDLK_n:
173 key.press[KeyCode::N] = isPush;
174 break;
175 case SDLK_o: key.press[KeyCode::O] = isPush; break;
176 case SDLK_p: key.press[KeyCode::P] = isPush; break;
177 case SDLK_q: key.press[KeyCode::Q] = isPush; break;
178 case SDLK_r: key.press[KeyCode::R] = isPush; break;
179 case SDLK_s:
180 key.press[KeyCode::S] = isPush;
181 pad.press[PadCode::Button6] = isPush;
182 break;
183 case SDLK_t: key.press[KeyCode::T] = isPush; break;
184 case SDLK_u: key.press[KeyCode::U] = isPush; break;
185 case SDLK_v:
186 key.press[KeyCode::V] = isPush;
187 pad.press[PadCode::Button4] = isPush;
188 break;
189 case SDLK_w: key.press[KeyCode::W] = isPush; break;
190 case SDLK_x:
191 key.press[KeyCode::X] = isPush;
192 pad.press[PadCode::Button2] = isPush;
193 break;
194 case SDLK_y: key.press[KeyCode::Y] = isPush; break;
195 case SDLK_z:
196 key.press[KeyCode::Z] = isPush;
197 pad.press[PadCode::Button1] = isPush;
198 break;
199 case SDLK_0: key.press[KeyCode::_0] = isPush; break;
200 case SDLK_1: key.press[KeyCode::_1] = isPush; break;
201 case SDLK_2: key.press[KeyCode::_2] = isPush; break;
202 case SDLK_3: key.press[KeyCode::_3] = isPush; break;
203 case SDLK_4: key.press[KeyCode::_4] = isPush; break;
204 case SDLK_5: key.press[KeyCode::_5] = isPush; break;
205 case SDLK_6: key.press[KeyCode::_6] = isPush; break;
206 case SDLK_7: key.press[KeyCode::_7] = isPush; break;
207 case SDLK_8: key.press[KeyCode::_8] = isPush; break;
208 case SDLK_9: key.press[KeyCode::_9] = isPush; break;
209 }
210 break;
211 case SDL_JOYAXISMOTION:
212 //左右の動き
213 if (event.jaxis.axis == 0)
214 {
215 pad.StickX = event.jaxis.value;
216 //pad.press[PadCode::Left] = (event.jaxis.value < -0x7000);//左右ボタンは兼ねない
217 //pad.press[PadCode::Right] = (event.jaxis.value > 0x7000);
218 }
219 //上下の動き
220 if (event.jaxis.axis == 1)
221 {
222 pad.StickY = event.jaxis.value;
223 //if (event.jaxis.value < -0x7000) pad.press[PadCode::Up] = true;//上下ボタンは兼ねない
224 //if (event.jaxis.value > 0x7000) pad.press[PadCode::Down] = true;
225 }
226 break;
227 case SDL_JOYHATMOTION:
228 pad.press[PadCode::Up] = false;
229 pad.press[PadCode::Left] = false;
230 pad.press[PadCode::Down] = false;
231 pad.press[PadCode::Right] = false;
232
233 switch (event.jhat.value)
234 {
235 case SDL_HAT_UP:pad.press[PadCode::Up] = true; break;
236 case SDL_HAT_LEFT:pad.press[PadCode::Left] = true; break;
237 case SDL_HAT_DOWN:pad.press[PadCode::Down] = true; break;
238 case SDL_HAT_RIGHT:pad.press[PadCode::Right] = true; break;
239 case SDL_HAT_LEFTUP:pad.press[PadCode::Up] = true; pad.press[PadCode::Left] = true; break;
240 case SDL_HAT_RIGHTUP:pad.press[PadCode::Up] = true; pad.press[PadCode::Right] = true; break;
241 case SDL_HAT_RIGHTDOWN:pad.press[PadCode::Down] = true; pad.press[PadCode::Right] = true; break;
242 case SDL_HAT_LEFTDOWN:pad.press[PadCode::Down] = true; pad.press[PadCode::Left] = true; break;
243 }
244 break;
245 case SDL_JOYBUTTONUP:
246 isPush = false;
247 case SDL_JOYBUTTONDOWN:
248 pad.press[(PadCode)event.jbutton.button] = isPush;
249 break;
250 case SDL_MOUSEMOTION:
251 mouse.xBuffer = event.motion.x;
252 mouse.yBuffer = event.motion.y;
253 break;
254 case SDL_MOUSEBUTTONUP:
255 isPush = false;
256 case SDL_MOUSEBUTTONDOWN:
257 switch (event.button.button)
258 {
259 case SDL_BUTTON_LEFT:mouse.press[MouseCode::Left] = isPush; break;
260 case SDL_BUTTON_RIGHT:mouse.press[MouseCode::Right] = isPush; break;
261 case SDL_BUTTON_MIDDLE:mouse.press[MouseCode::Middle] = isPush; break;
262 case SDL_BUTTON_X1:mouse.press[MouseCode::_4] = isPush; break;
263 case SDL_BUTTON_X2:mouse.press[MouseCode::_5] = isPush; break;
264 }
265 break;
266 case SDL_MOUSEWHEEL:
267 mouse.Whell = event.button.x;
268 break;
269 case SDL_FINGERUP:
270 isPush = false;
271 case SDL_FINGERDOWN:
272 if (event.tfinger.fingerId >= 10) break;
273 touch[(int)event.tfinger.fingerId].press = isPush;
274 if (event.tfinger.fingerId == 0) mouse.press[MouseCode::Left] = isPush;
275 if (event.tfinger.fingerId == 1) mouse.press[MouseCode::Right] = isPush;
276 case SDL_FINGERMOTION:
277 if (event.tfinger.fingerId >= 10) break;
278 touch[(int)event.tfinger.fingerId].Position(event.tfinger.x, event.tfinger.y);
279 mouse.xBuffer = (int)touch[(int)event.tfinger.fingerId].xBuffer;
280 mouse.yBuffer = (int)touch[(int)event.tfinger.fingerId].yBuffer;
281 break;
282 case SDL_MULTIGESTURE:
283 gesture.press = true;
284 gesture.fingerCount = event.mgesture.numFingers;
285 gesture.pinche = event.mgesture.dDist;
286 gesture.rotate = event.mgesture.dTheta;
287 gesture.Position(event.mgesture.x, event.mgesture.y);
288 break;
289 }
290 }
291
292
293 };
294 }
SDX::Keyboard::Reset
void Reset()
状態のリセット.
Definition: Keyboard.h:236
SDX::Mouse
マウスの状態を表すクラス.
Definition: Mouse.h:30
SDX::Input::Update
static void Update()
入力状態を更新.
Definition: Input.h:39
SDX::Gesture::fingerCount
int fingerCount
ジェスチャーに使った指の本数
Definition: Gesture.h:56
SDX::Keyboard
キーボードの状態を表すクラス.
Definition: Keyboard.h:121
SDX::Gesture::Update
void Update()
状態の更新.
Definition: Gesture.h:59
SDX::Input::mouse
static Mouse mouse
マウス
Definition: Input.h:23
SDX::Keyboard::Update
void Update()
状態の更新.
Definition: Keyboard.h:345
SDX::Joypad::StickY
int StickY
ジョイスティックの縦方向入力
Definition: Joypad.h:76
SDX::Joypad
ジョイパッドの状態を表すクラス.
Definition: Joypad.h:63
SDX::Gesture
タッチ操作の各種ジェスチャー.
Definition: Gesture.h:12
SDX::PadCode
PadCode
ゲームパッドコード.
Definition: Joypad.h:23
SDX::Gesture::pinche
double pinche
ピンチ操作
Definition: Gesture.h:51
SDX::Input::gesture
static Gesture gesture
タッチジェスチャー
Definition: Input.h:26
SDX::Input::pad
static Joypad pad
ジョイパッド
Definition: Input.h:22
SDX::Mouse::Reset
void Reset()
状態のリセット.
Definition: Mouse.h:61
SDX::Gesture::rotate
double rotate
回転ジェスチャー
Definition: Gesture.h:50
SDX::Gesture::Reset
void Reset()
状態をリセット.
Definition: Gesture.h:66
SDX::Input::key
static Keyboard key
キーボード
Definition: Input.h:24
SDX::Input::touch
static Touch touch[10]
タッチ
Definition: Input.h:25
SDX::Joypad::Reset
void Reset()
状態のリセット.
Definition: Joypad.h:126
SDX::Input
キーやマウスによる入力をまとめて管理するクラス.
Definition: Input.h:17
SDX::Mouse::Update
void Update()
状態の更新.
Definition: Mouse.h:79
SDX::Joypad::StickX
int StickX
ジョイスティックの横方向入力
Definition: Joypad.h:75
SDX::Touch
タッチ操作.
Definition: Touch.h:12
SDX::Input::Reset
static void Reset()
入力状態をリセット.
Definition: Input.h:29
SDX::Joypad::Update
void Update()
状態の更新.
Definition: Joypad.h:166
SDX::Input::GetState
static void GetState(SDL_Event &event)
入力の状態変化を取得.
Definition: Input.h:56
SDX::Mouse::Whell
int Whell
マウスの回転量
Definition: Mouse.h:48