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