FineKernelToolKit  2.9.0
 全て クラス ネームスペース ファイル 関数 変数 型定義 列挙型 列挙型の値 フレンド マクロ定義 ページ
Input.h
説明を見る。
1 /****************************************************************************
2  *
3  * Copyright (c) 1999-2014, Fine Kernel Project, All rights reserved.
4  *
5  * Redistribution and use in source and binary forms,
6  * with or without modification, are permitted provided that the
7  * following conditions are met:
8  *
9  * - Redistributions of source code must retain the above
10  * copyright notice, this list of conditions and the
11  * following disclaimer.
12  *
13  * - Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the
15  * following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * - Neither the name of the copyright holders nor the names
19  * of its contributors may be used to endorse or promote
20  * products derived from this software without specific
21  * prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  ****************************************************************************/
37 /****************************************************************************
38  *
39  * Copyright (c) 1999-2014, Fine Kernel Project, All rights reserved.
40  *
41  * 本ソフトウェアおよびソースコードのライセンスは、基本的に
42  * 「修正 BSD ライセンス」に従います。以下にその詳細を記します。
43  *
44  * ソースコード形式かバイナリ形式か、変更するかしないかを問わず、
45  * 以下の条件を満たす場合に限り、再頒布および使用が許可されます。
46  *
47  * - ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、
48  * および下記免責条項を含めること。
49  *
50  * - バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の
51  * 資料に、上記の著作権表示、本条件一覧、および下記免責条項を
52  * 含めること。
53  *
54  * - 書面による特別の許可なしに、本ソフトウェアから派生した製品の
55  * 宣伝または販売促進に、本ソフトウェアの著作権者の名前または
56  * コントリビューターの名前を使用してはならない。
57  *
58  * 本ソフトウェアは、著作権者およびコントリビューターによって「現
59  * 状のまま」提供されており、明示黙示を問わず、商業的な使用可能性、
60  * および特定の目的に対する適合性に関す暗黙の保証も含め、またそれ
61  * に限定されない、いかなる保証もないものとします。著作権者もコン
62  * トリビューターも、事由のいかんを問わず、損害発生の原因いかんを
63  * 問わず、かつ責任の根拠が契約であるか厳格責任であるか(過失その
64  * 他の)不法行為であるかを問わず、仮にそのような損害が発生する可
65  * 能性を知らされていたとしても、本ソフトウェアの使用によって発生
66  * した(代替品または代用サービスの調達、使用の喪失、データの喪失、
67  * 利益の喪失、業務の中断も含め、またそれに限定されない)直接損害、
68  * 間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害に
69  * ついて、一切責任を負わないものとします。
70  *
71  ****************************************************************************/
72 
73 #ifndef __FK_INPUT_HEADER__
74 #define __FK_INPUT_HEADER__
75 
76 #if defined(WIN32) && !defined(_MINGW_)
77 #define DIRECTINPUT_VERSION DIRECTINPUT_HEADER_VERSION
78 
79 #include <DX/dinput.h>
80 #pragma comment(lib,"dxguid.lib")
81 #pragma comment(lib,"dinput8.lib")
82 #else
83 
84 #ifndef FK_DOXYGEN_USER_PROCESS
85 #ifndef _MINGW_
86 
87 struct POINT
88 {
89  long x;
90  long y;
91 };
92 typedef unsigned long DWORD;
93 typedef long HRESULT;
94 typedef int* HINSTANCE;
95 typedef int* HWND;
96 
97 #else
98 
99 #include <Fl/x.h>
100 
101 #endif // !_MINGW_
102 #endif // !FK_DOXYGEN_USER_PROCESS
103 #endif // WIN32 && !_MINGW_
104 
105 #include <map>
106 #include <vector>
107 #include "Misc.h"
108 
110 
117 struct fk_InputInfo {
119 
124  bool button[32];
125 
127 
134  bool up;
135 
137 
140  bool down;
141 
143 
146  bool left;
147 
149 
152  bool right;
153 
155 
163  short x[3];
164 
166 
169  short y[3];
170 
172 
178  int pov;
179 };
180 
189 };
190 
205 };
206 
207 #ifdef FKUT_INPUT
208 
209 #define AXIS1_X FK_AXIS1_X
210 #define AXIS1_Y FK_AXIS1_Y
211 #define AXIS2_X FK_AXIS2_X
212 #define AXIS2_Y FK_AXIS2_Y
213 #define AXIS3_X FK_AXIS3_X
214 #define AXIS3_Y FK_AXIS3_Y
215 #define AXIS_X_POS FK_AXIS_X_POS
216 #define AXIS_X_NEG FK_AXIS_X_NEG
217 #define AXIS_Y_POS FK_AXIS_Y_POS
218 #define AXIS_Y_NEG FK_AXIS_Y_NEG
219 #define AXIS_Z_POS FK_AXIS_Z_POS
220 #define AXIS_Z_NEG FK_AXIS_Z_NEG
221 #define AXIS_RX_POS FK_AXIS_RX_POS
222 #define AXIS_RX_NEG FK_AXIS_RX_NEG
223 #define AXIS_RY_POS FK_AXIS_RY_POS
224 #define AXIS_RY_NEG FK_AXIS_RY_NEG
225 #define AXIS_RZ_POS FK_AXIS_RZ_POS
226 #define AXIS_RZ_NEG FK_AXIS_RZ_NEG
227 
228 #endif
229 
230 
231 #include <stdio.h>
232 
234 
257 class fk_Input : public Noncopyable {
258 private:
259 
260 #if defined(WIN32) && !defined(_MINGW_)
261  static const int BUTTON_NUM = 32;
262  static const int DIMGR_BUFFER_SIZE = 256;
263  static const int INPUT_DEVICE_NUM = 16;
264  static const int MOUSE_BUTTON_MAX = 8;
265  static const int KEY_NUM = 256;
266 
267  int buttonSwap[INPUT_DEVICE_NUM][BUTTON_NUM], axisSwap[INPUT_DEVICE_NUM][2*3];
268  unsigned long axisMap[4*3], povMap[8], keyMap[BUTTON_NUM];
269 
270  struct AxisParam {
271  int pos, neg, border;
272  };
273  std::map<int, AxisParam> axisParams[INPUT_DEVICE_NUM];
274 
275  //キーボードのメンバー変数
276  bool m_Key[KEY_NUM];
277 
278  //マウスのメンバー変数
279  POINT m_MouseWorldPos; //マウスの絶対座標
280  int m_MouseWheel;
281  POINT m_MouseLocalPos; //マウスのローカル座標
282  bool m_Button[MOUSE_BUTTON_MAX];
283  bool m_LastButton[MOUSE_BUTTON_MAX];
284 
285  //Joyのメンバー変数
286  DWORD m_JoyCount;
287  DWORD m_JoyMaxCount;
288  fk_InputInfo* m_JoyButton;
289 
290  //X座標の遊び 0〜1000の値です。低いほど敏感
291  int m_AllowX[INPUT_DEVICE_NUM];
292 
293  //Y座標の遊び 0〜1000の値です。低いほど敏感
294  int m_AllowY[INPUT_DEVICE_NUM];
295 
296  // アナログスティックの値で有効とする範囲を指定します
297  int m_AllowMin[INPUT_DEVICE_NUM];
298 
299  // アナログスティックの値で有効とする範囲を指定します
300  int m_AllowMax[INPUT_DEVICE_NUM];
301 
302  //デバイス関連のメンバー変数
303  HWND m_hwnd;
304  LPDIRECTINPUT8 m_Input;
305  LPDIRECTINPUTDEVICE8 m_KeyBoardDevice;
306  LPDIRECTINPUTDEVICE8 m_MouseDevice;
307  LPDIRECTINPUTDEVICE8 m_JoyStciDevice[INPUT_DEVICE_NUM];
308  DIDEVCAPS m_DevCaps;
309  DIDEVICEOBJECTDATA m_DeviceObject[DIMGR_BUFFER_SIZE]; // Receives buffered data
310 
311  //=====================
312  //Update関連
313  //=====================
314  HRESULT UpdateJoy(void);
315  HRESULT UpdateMouse(void);
316  HRESULT UpdateKey(void);
317 
318  //===========================
319  //Joyのコールバック関数
320  //===========================
321  static BOOL CALLBACK EnumSizesCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID lpvRef);
322  static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* lpddi, LPVOID lpContext);
323 
324  short AdjustParam(int, short);
325  void SetAxisParam(int, int, short);
326 
327 #endif // WIN32 && !_MINGW_
328 
329 public:
331  fk_Input(void);
333  ~fk_Input(void);
334 
335 #ifndef FK_DOXYGEN_USER_PROCESS
336  // Obsolute Functions
337  // マウス関連
338  POINT& GetMouseLocalPos(void);
339  POINT& GetMouseWorldPos(void);
340  bool GetMouseButton(DWORD keycode);
341  bool GetLastMouseButton(DWORD keycode);
342  int GetMouseWheel(void);
343  // キー関連
344  bool GetKey(const DWORD keycode);
345 
346 #endif
347 
349 
351 
367  HRESULT init(HINSTANCE hinst, HWND hwnd);
368 
370 
377  HRESULT uninit(void);
378 
380 
387  HRESULT update(void);
389 
391 
392 
394 
401  DWORD getJoyCount(void);
402 
404 
431  fk_InputInfo* getJoyStick(DWORD index);
432 
434 
468  fk_InputInfo getInputStatus(int index = 0);
469 
471 
473 
474 
476 
487  void setBorder(int index, int borderX, int borderY);
488 
490 
502  void setBorder(int borderX, int borderY);
503 
505 
530  void setMinMax(int index, int min, int max);
531 
533 
558  void setMinMax(int min, int max);
559 
561 
563 
564 
566 
577  void setButtonSwap(int dev, int id, int raw);
578 
579 
581 
604  void setAxisSwap(int dev, fk_AxisDirection id, fk_RawAxis raw);
605 
607 
639  void setAxisToButton(int dev, fk_AxisDirection axisID,
640  int posBtn, int negBtn, int border);
641 
643 
650  void clearAxisToButton(int dev);
651 
653 
655 
656 
658 
676  void setKeyAssign(int id, DWORD keycode);
677 
679 
701  void setAxisAssign(int axis_id, DWORD up, DWORD dn, DWORD lt, DWORD rt);
702 
704 
725  void setPOVAssign(DWORD ul, DWORD u, DWORD ur, DWORD l,
726  DWORD r, DWORD dl, DWORD d, DWORD dr);
727 
729 };
730 
731 #endif
bool left
左スティック左方向状況変数
Definition: Input.h:146
fk_Input(void)
コンストラクタ
void setAxisToButton(int dev, fk_AxisDirection axisID, int posBtn, int negBtn, int border)
軸ボタン割り当て設定関数
fk_InputInfo::y[1] に対応
Definition: Input.h:186
fk_InputInfo::x[0] に対応
Definition: Input.h:183
fk_InputInfo::x[1] に対応
Definition: Input.h:185
short x[3]
アナログスティック状況変数 (x 座標値)
Definition: Input.h:163
ゲームパッドの入力を受け取るための構造体
Definition: Input.h:117
ゲームパッド・ジョイスティック系デバイス制御クラス
Definition: Input.h:257
void setMinMax(int index, int min, int max)
スティッククリッピング設定関数1
short y[3]
アナログスティック状況変数 (y 座標値)
Definition: Input.h:169
bool up
左スティック上方向状況変数
Definition: Input.h:134
左スティック z 軸正方向
Definition: Input.h:197
fk_InputInfo::y[0] に対応
Definition: Input.h:184
右スティック y 軸正方向
Definition: Input.h:201
~fk_Input(void)
デストラクタ
HRESULT init(HINSTANCE hinst, HWND hwnd)
初期化関数
void setBorder(int index, int borderX, int borderY)
アナログデバイス調整関数
右スティック z 軸正方向
Definition: Input.h:203
右スティック y 軸逆方向
Definition: Input.h:202
fk_InputInfo * getJoyStick(DWORD index)
デバイス情報取得関数
fk_InputInfo::x[2] に対応
Definition: Input.h:187
左スティック x 軸逆方向
Definition: Input.h:194
左スティック x 軸正方向
Definition: Input.h:193
左スティック z 軸逆方向
Definition: Input.h:198
void clearAxisToButton(int dev)
軸ボタン割り当て解除関数
fk_InputInfo::y[2] に対応
Definition: Input.h:188
左スティック y 軸正方向
Definition: Input.h:195
bool down
左スティック下方向状況変数
Definition: Input.h:140
HRESULT uninit(void)
完了処理関数
void setKeyAssign(int id, DWORD keycode)
ボタン機能キーボード代替設定関数
右スティック x 軸逆方向
Definition: Input.h:200
DWORD getJoyCount(void)
デバイス個数取得関数
右スティック z 軸逆方向
Definition: Input.h:204
右スティック x 軸正方向
Definition: Input.h:199
void setAxisSwap(int dev, fk_AxisDirection id, fk_RawAxis raw)
軸入れ替え設定関数
fk_AxisDirection
ゲームデバイスでの仮想空間軸方向を表す列挙型
Definition: Input.h:182
HRESULT update(void)
更新処理
void setAxisAssign(int axis_id, DWORD up, DWORD dn, DWORD lt, DWORD rt)
スティック機能キーボード代替設定関数
fk_RawAxis
ゲームデバイスでのスティックデバイス軸方向を表す列挙型
Definition: Input.h:192
bool button[32]
各ボタン押下状況配列
Definition: Input.h:124
fk_InputInfo getInputStatus(int index=0)
キーボード考慮デバイス情報取得関数
bool right
左スティック上方向状況変数
Definition: Input.h:152
左スティック y 軸逆方向
Definition: Input.h:196
void setPOVAssign(DWORD ul, DWORD u, DWORD ur, DWORD l, DWORD r, DWORD dl, DWORD d, DWORD dr)
ハットスイッチ(POVボタン)機能キーボード代替設定関数
void setButtonSwap(int dev, int id, int raw)
ボタン入れ替え設定関数
int pov
ハットスイッチ状況変数
Definition: Input.h:178