SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
Input.h
1 #pragma once
2 #include <Multimedia/SDX.h>
3 #include <Multimedia/Keyboard.h>
4 #include <Multimedia/Mouse.h>
5 #include <Multimedia/Joypad.h>
6 
7 namespace SDX
8 {
10 class Input
12 {
13 private:
14  Input(){}
15  ~Input();
16  static int handle;
17 
18 public:
19 
20  static Joypad pad;
21  static Mouse mouse;
22  static Keyboard key;
23 
25  static void Reset()
26  {
27  Input::pad.Reset();
28  Input::mouse.Reset();
29  Input::key.Reset();
30  }
31 
33  static void Update()
34  {
35  Input::pad.Update();
36  Input::mouse.Update();
37  Input::key.Update();
38  }
39 
40  #ifdef SDL
41  static void GetState(SDL_Event &event)
42  {
43  bool upState = true;
44 
45  switch (event.type)
46  {
47  case SDL_KEYUP:
48  upState = false;
49  case SDL_KEYDOWN:
50  switch (event.key.keysym.sym)
51  {
52  case SDLK_BACKSPACE: key.press[(int)KeyCode::Back] = upState; break;
53  case SDLK_TAB: key.press[(int)KeyCode::Tab] = upState; break;
54  case SDLK_RETURN: key.press[(int)KeyCode::Return] = upState; break;
55  case SDLK_LSHIFT: key.press[(int)KeyCode::LShift] = upState; break;
56  case SDLK_RSHIFT: key.press[(int)KeyCode::RShift] = upState; break;
57  case SDLK_LCTRL: key.press[(int)KeyCode::LControl] = upState; break;
58  case SDLK_RCTRL: key.press[(int)KeyCode::RControl] = upState; break;
59  case SDLK_ESCAPE: key.press[(int)KeyCode::Escape] = upState; break;
60  case SDLK_SPACE: key.press[(int)KeyCode::Space] = upState; break;
61  case SDLK_PAGEUP: key.press[(int)KeyCode::PageUp] = upState; break;
62  case SDLK_PAGEDOWN: key.press[(int)KeyCode::PageDown] = upState; break;
63  case SDLK_END: key.press[(int)KeyCode::End] = upState; break;
64  case SDLK_HOME: key.press[(int)KeyCode::Home] = upState; break;
65  case SDLK_LEFT:
66  key.press[(int)KeyCode::Left] = upState;
67  pad.press[(int)PadCode::Left] = upState;
68  break;
69  case SDLK_UP:
70  key.press[(int)KeyCode::Up] = upState;
71  pad.press[(int)PadCode::Up] = upState;
72  break;
73  case SDLK_RIGHT:
74  key.press[(int)KeyCode::Right] = upState;
75  pad.press[(int)PadCode::Right] = upState;
76  break;
77  case SDLK_DOWN:
78  key.press[(int)KeyCode::Down] = upState;
79  pad.press[(int)PadCode::Down] = upState;
80  break;
81  case SDLK_INSERT: key.press[(int)KeyCode::Insert] = upState; break;
82  case SDLK_DELETE: key.press[(int)KeyCode::Delete] = upState; break;
83 
84  case SDLK_MINUS: key.press[(int)KeyCode::Minus] = upState; break;
85  //case Yen = SDLK_YEN,
86  //case PrevTrack = SDLK_PREVTRACK,
87  case SDLK_PERIOD: key.press[(int)KeyCode::Period] = upState; break;
88  case SDLK_SLASH: key.press[(int)KeyCode::Slash] = upState; break;
89  case SDLK_LALT: key.press[(int)KeyCode::LAlt] = upState; break;
90  case SDLK_RALT: key.press[(int)KeyCode::RAlt] = upState; break;
91  case SDLK_SCROLLLOCK: key.press[(int)KeyCode::Scroll] = upState; break;
92  case SDLK_SEMICOLON: key.press[(int)KeyCode::Semicolon] = upState; break;
93  case SDLK_COLON: key.press[(int)KeyCode::Colon] = upState; break;
94  case SDLK_LEFTBRACKET: key.press[(int)KeyCode::LBracket] = upState; break;
95  case SDLK_RIGHTBRACKET: key.press[(int)KeyCode::RBracket] = upState; break;
96  case SDLK_AT: key.press[(int)KeyCode::At] = upState; break;
97  case SDLK_BACKSLASH: key.press[(int)KeyCode::Backslash] = upState; break;
98  case SDLK_COMMA: key.press[(int)KeyCode::Comma] = upState; break;
99  case SDLK_CAPSLOCK: key.press[(int)KeyCode::Capslock] = upState; break;
100  case SDLK_PAUSE: key.press[(int)KeyCode::Pause] = upState; break;
101 
102  case SDLK_KP_0: key.press[(int)KeyCode::Numpad0] = upState; break;
103  case SDLK_KP_1: key.press[(int)KeyCode::Numpad1] = upState; break;
104  case SDLK_KP_2: key.press[(int)KeyCode::Numpad2] = upState; break;
105  case SDLK_KP_3: key.press[(int)KeyCode::Numpad3] = upState; break;
106  case SDLK_KP_4: key.press[(int)KeyCode::Numpad4] = upState; break;
107  case SDLK_KP_5: key.press[(int)KeyCode::Numpad5] = upState; break;
108  case SDLK_KP_6: key.press[(int)KeyCode::Numpad6] = upState; break;
109  case SDLK_KP_7: key.press[(int)KeyCode::Numpad7] = upState; break;
110  case SDLK_KP_8: key.press[(int)KeyCode::Numpad8] = upState; break;
111  case SDLK_KP_9: key.press[(int)KeyCode::Numpad9] = upState; break;
112  case SDLK_ASTERISK: key.press[(int)KeyCode::Multiply] = upState; break;
113  case SDLK_KP_PLUS: key.press[(int)KeyCode::Add] = upState; break;
114  case SDLK_KP_MINUS: key.press[(int)KeyCode::Subtract] = upState; break;
115  case SDLK_KP_PERIOD: key.press[(int)KeyCode::Decimal] = upState; break;
116  case SDLK_KP_DIVIDE: key.press[(int)KeyCode::Divide] = upState; break;
117  case SDLK_KP_ENTER: key.press[(int)KeyCode::NUMPADEnter] = upState; break;
118 
119  case SDLK_F1: key.press[(int)KeyCode::F1] = upState; break;
120  case SDLK_F2: key.press[(int)KeyCode::F2] = upState; break;
121  case SDLK_F3: key.press[(int)KeyCode::F3] = upState; break;
122  case SDLK_F4: key.press[(int)KeyCode::F4] = upState; break;
123  case SDLK_F5: key.press[(int)KeyCode::F5] = upState; break;
124  case SDLK_F6: key.press[(int)KeyCode::F6] = upState; break;
125  case SDLK_F7: key.press[(int)KeyCode::F7] = upState; break;
126  case SDLK_F8: key.press[(int)KeyCode::F8] = upState; break;
127  case SDLK_F9: key.press[(int)KeyCode::F9] = upState; break;
128  case SDLK_F10: key.press[(int)KeyCode::F10] = upState; break;
129  case SDLK_F11: key.press[(int)KeyCode::F11] = upState; break;
130  case SDLK_F12: key.press[(int)KeyCode::F12] = upState; break;
131 
132  case SDLK_a:
133  key.press[(int)KeyCode::A] = upState;
134  pad.press[(int)PadCode::Button5] = upState;
135  break;
136  case SDLK_b: key.press[(int)KeyCode::B] = upState; break;
137  case SDLK_c:
138  key.press[(int)KeyCode::C] = upState;
139  pad.press[(int)PadCode::Button3] = upState;
140  break;
141  case SDLK_d:
142  key.press[(int)KeyCode::D] = upState;
143  pad.press[(int)PadCode::Button7] = upState;
144  break;
145  case SDLK_e: key.press[(int)KeyCode::E] = upState; break;
146  case SDLK_f:
147  key.press[(int)KeyCode::F] = upState;
148  pad.press[(int)PadCode::Button8] = upState;
149  break;
150  case SDLK_g: key.press[(int)KeyCode::G] = upState; break;
151  case SDLK_h: key.press[(int)KeyCode::H] = upState; break;
152  case SDLK_i: key.press[(int)KeyCode::I] = upState; break;
153  case SDLK_j: key.press[(int)KeyCode::J] = upState; break;
154  case SDLK_k: key.press[(int)KeyCode::K] = upState; break;
155  case SDLK_l: key.press[(int)KeyCode::L] = upState; break;
156  case SDLK_m: key.press[(int)KeyCode::M] = upState; break;
157  case SDLK_n: key.press[(int)KeyCode::N] = upState; break;
158  case SDLK_o: key.press[(int)KeyCode::O] = upState; break;
159  case SDLK_p: key.press[(int)KeyCode::P] = upState; break;
160  case SDLK_q: key.press[(int)KeyCode::Q] = upState; break;
161  case SDLK_r: key.press[(int)KeyCode::R] = upState; break;
162  case SDLK_s:
163  key.press[(int)KeyCode::S] = upState;
164  pad.press[(int)PadCode::Button6] = upState;
165  break;
166  case SDLK_t: key.press[(int)KeyCode::T] = upState; break;
167  case SDLK_u: key.press[(int)KeyCode::U] = upState; break;
168  case SDLK_v:
169  key.press[(int)KeyCode::V] = upState;
170  pad.press[(int)PadCode::Button4] = upState;
171  break;
172  case SDLK_w: key.press[(int)KeyCode::W] = upState; break;
173  case SDLK_x:
174  key.press[(int)KeyCode::X] = upState;
175  pad.press[(int)PadCode::Button2] = upState;
176  break;
177  case SDLK_y: key.press[(int)KeyCode::Y] = upState; break;
178  case SDLK_z:
179  key.press[(int)KeyCode::Z] = upState;
180  pad.press[(int)PadCode::Button1] = upState;
181  break;
182  case SDLK_0: key.press[(int)KeyCode::_0] = upState; break;
183  case SDLK_1: key.press[(int)KeyCode::_1] = upState; break;
184  case SDLK_2: key.press[(int)KeyCode::_2] = upState; break;
185  case SDLK_3: key.press[(int)KeyCode::_3] = upState; break;
186  case SDLK_4: key.press[(int)KeyCode::_4] = upState; break;
187  case SDLK_5: key.press[(int)KeyCode::_5] = upState; break;
188  case SDLK_6: key.press[(int)KeyCode::_6] = upState; break;
189  case SDLK_7: key.press[(int)KeyCode::_7] = upState; break;
190  case SDLK_8: key.press[(int)KeyCode::_8] = upState; break;
191  case SDLK_9: key.press[(int)KeyCode::_9] = upState; break;
192  }
193  break;
194  case SDL_MOUSEBUTTONUP:
195  upState = false;
196  case SDL_MOUSEBUTTONDOWN:
197  switch (event.button.button)
198  {
199  case SDL_BUTTON_LEFT:mouse.press[(int)MouseCode::Left] = upState; break;
200  case SDL_BUTTON_RIGHT:mouse.press[(int)MouseCode::Right] = upState; break;
201  case SDL_BUTTON_MIDDLE:mouse.press[(int)MouseCode::Middle] = upState; break;
202  case SDL_BUTTON_X1:mouse.press[(int)MouseCode::_4] = upState; break;
203  case SDL_BUTTON_X2:mouse.press[(int)MouseCode::_5] = upState; break;
204  }
205  break;
206  case SDL_JOYAXISMOTION:
207  //左右の動き
208  if (event.jaxis.axis == 0)
209  {
210  pad.StickX = event.jaxis.value;
211  if (event.jaxis.value < -0x7000) pad.press[(int)PadCode::Left] = true;
212  if (event.jaxis.value > 0x7000) pad.press[(int)PadCode::Right] = true;
213  }
214  //上下の動き
215  if (event.jaxis.axis == 1)
216  {
217  pad.StickY = event.jaxis.value;
218  if (event.jaxis.value < -0x7000) pad.press[(int)PadCode::Up] = true;
219  if (event.jaxis.value > 0x7000) pad.press[(int)PadCode::Down] = true;
220  }
221  break;
222  case SDL_JOYHATMOTION:
223  switch (event.jhat.value)
224  {
225  case SDL_HAT_UP:pad.press[(int)PadCode::Up] = true;break;
226  case SDL_HAT_LEFT:pad.press[(int)PadCode::Left] = true; break;
227  case SDL_HAT_DOWN:pad.press[(int)PadCode::Down] = true; break;
228  case SDL_HAT_RIGHT:pad.press[(int)PadCode::Right] = true;break;
229  }
230  break;
231  case SDL_JOYBUTTONUP:
232  upState = false;
233  case SDL_JOYBUTTONDOWN:
234  pad.press[event.jbutton.button] = upState;
235  break;
236  }
237  }
238  #endif
239 
241  static bool Text(int x,int y,int maxLength, char *str ,int isEscCancel ,bool isSingleOnly = false)
243  {
244  #ifdef DXLIB
245  if (isSingleOnly)
246  {
247  return (DxLib::KeyInputString(x, y, maxLength, str, isEscCancel) == 1);
248  }
249  else{
250  return ( DxLib::KeyInputSingleCharString( x , y ,maxLength , str , isEscCancel ) == 1 );
251  }
252  #elif defined(SDL)
253  return false;
254  #endif
255  }
256 
258  static int Number(int x,int y,int min,int max,int isEscCancel)
262  {
263  #ifdef DXLIB
264  return DxLib::KeyInputNumber(x, y, max, min, isEscCancel);
265  #elif defined(SDL)
266  return false;
267  #endif
268  }
269 
271  static bool StartTextMode( int 最大文字数 , bool ESCキャンセル可能フラグ , bool 半角文字限定フラグ , bool 数値入力限定フラグ )
273  {
274  #ifdef DXLIB
275  if (handle != NULL_HANDLE)
276  {
277  handle = DxLib::MakeKeyInput(最大文字数, ESCキャンセル可能フラグ, 半角文字限定フラグ, 数値入力限定フラグ);
278  }
279  DxLib::SetActiveKeyInput( handle );
280  #elif defined(SDL)
281  return false;
282  #endif
283  }
284 
286  static int CheckText()
287  {
288  #ifdef DXLIB
289  return DxLib::CheckKeyInput( handle );
290  #elif defined(SDL)
291  return false;
292  #endif
293  }
294 
296  static bool DrawText(int X座標 , int Y座標 )
297  {
298  #ifdef DXLIB
299  DxLib::DrawKeyInputString( X座標 , Y座標 , handle );
300  #elif defined(SDL)
301  return false;
302  #endif
303  }
304 
306  static bool SetText( const char* 文字列 )
307  {
308  #ifdef DXLIB
309  DxLib::SetKeyInputString(文字列, handle);
310  #elif defined(SDL)
311  return false;
312  #endif
313  }
314  static bool SetText( int 数値 )
315  {
316  #ifdef DXLIB
317  DxLib::SetKeyInputNumber(数値, handle);
318  #elif defined(SDL)
319  return false;
320  #endif
321  }
322 
324  static bool GetText( char* 出力バッファ )
325  {
326  #ifdef DXLIB
327  return !GetKeyInputString(出力バッファ, handle);
328  #elif defined(SDL)
329  return false;
330  #endif
331  }
332 
333 
335  static int SetKeyColor(
336  int 入力文字色 ,
337  int IME非使用時カーソル色 ,
338  int IME使用時文字色 ,
339  int IME使用時カーソル色 ,
340  int 変換時下線色 ,
341  int IME使用時変換候補色 ,
342  int 入力モード名色 ,
343  int 入力文字縁色 ,
344  int 変換候補縁色 ,
345  int 入力モード名縁色 ,
346  int 変換候補ウィンドウ縁色 ,
347  int 変換候補ウィンドウ色 )
348  {
349  #ifdef DXLIB
350  return DxLib::SetKeyInputStringColor
351  (
352  入力文字色,
353  IME非使用時カーソル色,
354  IME使用時文字色,
355  IME使用時カーソル色,
356  変換時下線色,
357  IME使用時変換候補色,
358  入力モード名色,
359  入力文字縁色,
360  変換候補縁色,
361  入力モード名縁色,
362  変換候補ウィンドウ縁色,
363  変換候補ウィンドウ色
364  );
365  #elif defined(SDL)
366  return false;
367  #endif
368  }
369 
370 };
371 
372 }
static void Update()
状態を更新.
Definition: Input.h:33
static int Number(int x, int y, int min, int max, int isEscCancel)
キーボードから数字を入力.
Definition: Input.h:261
static bool DrawText(int X座標, int Y座標)
テキストの描画.
Definition: Input.h:296
static int SetKeyColor(int 入力文字色, int IME非使用時カーソル色, int IME使用時文字色, int IME使用時カーソル色, int 変換時下線色, int IME使用時変換候補色, int 入力モード名色, int 入力文字縁色, int 変換候補縁色, int 入力モード名縁色, int 変換候補ウィンドウ縁色, int 変換候補ウィンドウ色)
キーボード入力時の表示色設定.
Definition: Input.h:335
static int CheckText()
テキスト入力モードの確認.
Definition: Input.h:286
static bool Text(int x, int y, int maxLength, char *str, int isEscCancel, bool isSingleOnly=false)
キーボードから文字を入力.
Definition: Input.h:242
static bool GetText(char *出力バッファ)
テキストの取得.
Definition: Input.h:324
static bool SetText(const char *文字列)
テキストの設定.
Definition: Input.h:306
static bool StartTextMode(int 最大文字数, bool ESCキャンセル可能フラグ, bool 半角文字限定フラグ, bool 数値入力限定フラグ)
テキスト入力モードの開始.
Definition: Input.h:272
static void Reset()
状態をリセット.
Definition: Input.h:25