SDXFrameWork 0.10 SDXFrameWork

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Joypad.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/Key.h>
7 #include <Utility/EnumArray.h>
8
9 namespace SDX
10 {
12 enum class PadType
13 {
14 KeyAndPad1,
15 Pad1,
16 Pad2,
17 Pad3,
18 Pad4,
19 KeyBord
20 };
21
23 enum class PadCode :unsigned int
24 {
25 Button1,
26 Button2,
27 Button3,
28 Button4,
29 Button5,
30 Button6,
31 Button7,
32 Button8,
33 Button9,
34 Button10,
35 Button11,
36 Button12,
37 Button13,
38 Button14,
39 Button15,
40 Button16,
41 Button17,
42 Button18,
43 Button19,
44 Button20,
45 Button21,
46 Button22,
47 Button23,
48 Button24,
49 Button25,
50 Button26,
51 Button27,
52 Button28,
53 Down,
54 Left,
55 Right,
56 Up,
57 COUNT,
58 };
59
63 class Joypad
64 {
65 friend class Input;
66 private:
67 PadType inputType = PadType::KeyAndPad1;
68 SDL_Joystick* handle;
69
70 EnumArray<bool, PadCode> press;
71
72 Joypad(const Joypad &joypad){};
73 Joypad operator =(const Joypad &joypad) = delete;
74 public:
75 int StickX = 0;
76 int StickY = 0;
77
78 Key Down;
79 Key Left;
80 Key Right;
81 Key Up;
82 Key Button1;
83 Key Button2;
84 Key Button3;
85 Key Button4;
86 Key Button5;
87 Key Button6;
88 Key Button7;
89 Key Button8;
90 Key Button9;
91 Key Button10;
92 Key Button11;
93 Key Button12;
94 Key Button13;
95 Key Button14;
96 Key Button15;
97 Key Button16;
98 Key Button17;
99 Key Button18;
100 Key Button19;
101 Key Button20;
102 Key Button21;
103 Key Button22;
104 Key Button23;
105 Key Button24;
106 Key Button25;
107 Key Button26;
108 Key Button27;
109 Key Button28;
110
111 Joypad(){}
112
114 void Open()
115 {
116 handle = SDL_JoystickOpen(0);
117 }
118
120 void Make(PadType パッドタイプ)
121 {
122 inputType = パッドタイプ;
123 }
124
126 void Reset()
127 {
128 Up.Reset();
129 Down.Reset();
130 Left.Reset();
131 Right.Reset();
132 Button1.Reset();
133 Button2.Reset();
134 Button3.Reset();
135 Button4.Reset();
136 Button5.Reset();
137 Button6.Reset();
138 Button7.Reset();
139 Button8.Reset();
140 Button9.Reset();
141 Button10.Reset();
142 Button11.Reset();
143 Button12.Reset();
144 Button13.Reset();
145 Button14.Reset();
146 Button15.Reset();
147 Button16.Reset();
148 Button17.Reset();
149 Button18.Reset();
150 Button19.Reset();
151 Button20.Reset();
152 Button21.Reset();
153 Button22.Reset();
154 Button23.Reset();
155 Button24.Reset();
156 Button25.Reset();
157 Button26.Reset();
158 Button27.Reset();
159 Button28.Reset();
160
161 StickX = 0;
162 StickY = 0;
163 }
164
166 void Update()
167 {
168 Down.Update(press[PadCode::Down]);
169 Left.Update(press[PadCode::Left]);
170 Right.Update(press[PadCode::Right]);
171 Up.Update(press[PadCode::Up]);
172 Button1.Update(press[PadCode::Button1]);
173 Button2.Update(press[PadCode::Button2]);
174 Button3.Update(press[PadCode::Button3]);
175 Button4.Update(press[PadCode::Button4]);
176 Button5.Update(press[PadCode::Button5]);
177 Button6.Update(press[PadCode::Button6]);
178 Button7.Update(press[PadCode::Button7]);
179 Button8.Update(press[PadCode::Button8]);
180 Button9.Update(press[PadCode::Button9]);
181 Button10.Update(press[PadCode::Button10]);
182 Button11.Update(press[PadCode::Button11]);
183 Button12.Update(press[PadCode::Button12]);
184 Button13.Update(press[PadCode::Button13]);
185 Button14.Update(press[PadCode::Button14]);
186 Button15.Update(press[PadCode::Button15]);
187 Button16.Update(press[PadCode::Button16]);
188 Button17.Update(press[PadCode::Button17]);
189 Button18.Update(press[PadCode::Button18]);
190 Button19.Update(press[PadCode::Button19]);
191 Button20.Update(press[PadCode::Button20]);
192 Button21.Update(press[PadCode::Button21]);
193 Button22.Update(press[PadCode::Button22]);
194 Button23.Update(press[PadCode::Button23]);
195 Button24.Update(press[PadCode::Button24]);
196 Button25.Update(press[PadCode::Button25]);
197 Button26.Update(press[PadCode::Button26]);
198 Button27.Update(press[PadCode::Button27]);
199 Button28.Update(press[PadCode::Button28]);
200 }
201
203 PadType GetInputType()
204 {
205 return inputType;
206 }
207
209 void SetInputType(PadType 入力タイプ)
210 {
211 inputType = 入力タイプ;
212 }
213
215 static int GetCount()
216 {
217 return SDL_NumJoysticks();
218 }
219
222 Key& operator[](PadCode index)
223 {
224 switch (index)
225 {
226 case PadCode::Button1:return Button1;
227 case PadCode::Button2: return Button2;
228 case PadCode::Button3: return Button3;
229 case PadCode::Button4: return Button4;
230 case PadCode::Button5: return Button5;
231 case PadCode::Button6: return Button6;
232 case PadCode::Button7: return Button7;
233 case PadCode::Button8: return Button8;
234 case PadCode::Button9: return Button9;
235 case PadCode::Button10: return Button10;
236 case PadCode::Button11: return Button11;
237 case PadCode::Button12: return Button12;
238 case PadCode::Button13: return Button13;
239 case PadCode::Button14: return Button14;
240 case PadCode::Button15: return Button15;
241 case PadCode::Button16: return Button16;
242 case PadCode::Button17: return Button17;
243 case PadCode::Button18: return Button18;
244 case PadCode::Button19: return Button19;
245 case PadCode::Button20: return Button20;
246 case PadCode::Button21: return Button21;
247 case PadCode::Button22: return Button22;
248 case PadCode::Button23: return Button23;
249 case PadCode::Button24: return Button24;
250 case PadCode::Button25: return Button25;
251 case PadCode::Button26: return Button26;
252 case PadCode::Button27: return Button27;
253 case PadCode::Button28: return Button28;
254 case PadCode::Down: return Down;
255 case PadCode::Left: return Left;
256 case PadCode::Right: return Right;
257 case PadCode::Up: return Up;
258 default: return Button1;
259 }
260 }
261 };
262 }
SDX::Joypad::GetCount
static int GetCount()
接続中のパッド数を取得.
Definition: Joypad.h:215
SDX::Joypad::Button4
Key Button4
キー
Definition: Joypad.h:85
SDX::Joypad::Button26
Key Button26
キー
Definition: Joypad.h:107
SDX::Joypad::Button16
Key Button16
キー
Definition: Joypad.h:97
SDX::Joypad::Button17
Key Button17
キー
Definition: Joypad.h:98
SDX::Joypad::Button22
Key Button22
キー
Definition: Joypad.h:103
SDX::Joypad::Down
Key Down
キー
Definition: Joypad.h:78
SDX::Joypad::Left
Key Left
キー
Definition: Joypad.h:79
SDX::Joypad::Button25
Key Button25
キー
Definition: Joypad.h:106
SDX::Joypad::Button6
Key Button6
キー
Definition: Joypad.h:87
SDX::Joypad::StickY
int StickY
ジョイスティックの縦方向入力
Definition: Joypad.h:76
SDX::Joypad::Button12
Key Button12
キー
Definition: Joypad.h:93
SDX::Joypad::Button13
Key Button13
キー
Definition: Joypad.h:94
SDX::Joypad::Button21
Key Button21
キー
Definition: Joypad.h:102
SDX::Joypad::Button3
Key Button3
キー
Definition: Joypad.h:84
SDX::PadType
PadType
ゲームパッドの種類.
Definition: Joypad.h:12
SDX::Joypad::Button27
Key Button27
キー
Definition: Joypad.h:108
SDX::Joypad
ジョイパッドの状態を表すクラス.
Definition: Joypad.h:63
SDX::PadCode
PadCode
ゲームパッドコード.
Definition: Joypad.h:23
SDX::Joypad::Up
Key Up
キー
Definition: Joypad.h:81
SDX::Key::Reset
void Reset()
キーのリセット.
Definition: Key.h:20
SDX::Joypad::Button23
Key Button23
キー
Definition: Joypad.h:104
SDX::Joypad::Button18
Key Button18
キー
Definition: Joypad.h:99
SDX::Joypad::Button1
Key Button1
キー
Definition: Joypad.h:82
SDX::Joypad::Button9
Key Button9
キー
Definition: Joypad.h:90
SDX::Joypad::Button8
Key Button8
キー
Definition: Joypad.h:89
SDX::Joypad::GetInputType
PadType GetInputType()
パッドタイプの取得.
Definition: Joypad.h:203
SDX::Joypad::Right
Key Right
キー
Definition: Joypad.h:80
SDX::EnumArray< bool, PadCode >
SDX::Joypad::Button11
Key Button11
キー
Definition: Joypad.h:92
SDX::Joypad::Button24
Key Button24
キー
Definition: Joypad.h:105
SDX::Joypad::Button15
Key Button15
キー
Definition: Joypad.h:96
SDX::Joypad::Reset
void Reset()
状態のリセット.
Definition: Joypad.h:126
SDX::Input
キーやマウスによる入力をまとめて管理するクラス.
Definition: Input.h:17
SDX::Joypad::Button2
Key Button2
キー
Definition: Joypad.h:83
SDX::Joypad::Button7
Key Button7
キー
Definition: Joypad.h:88
SDX::Joypad::Button19
Key Button19
キー
Definition: Joypad.h:100
SDX::Key::Update
void Update(bool 押下フラグ)
押下状態の更新.
Definition: Key.h:29
SDX::Joypad::Open
void Open()
ジョイパッドを起動.
Definition: Joypad.h:114
SDX::Joypad::Button14
Key Button14
キー
Definition: Joypad.h:95
SDX::Joypad::Button5
Key Button5
キー
Definition: Joypad.h:86
SDX::Joypad::Make
void Make(PadType パッドタイプ)
パッドの作成.
Definition: Joypad.h:120
SDX::Joypad::operator[]
Key & operator[](PadCode index)
PadCodeでアクセス.
Definition: Joypad.h:222
SDX::Joypad::Button10
Key Button10
キー
Definition: Joypad.h:91
SDX::Key
各ボタンとキーを表すクラス.
Definition: Key.h:11
SDX::Joypad::StickX
int StickX
ジョイスティックの横方向入力
Definition: Joypad.h:75
SDX::Joypad::Button20
Key Button20
キー
Definition: Joypad.h:101
SDX::Joypad::Update
void Update()
状態の更新.
Definition: Joypad.h:166
SDX::Joypad::Button28
Key Button28
キー
Definition: Joypad.h:109
SDX::Joypad::SetInputType
void SetInputType(PadType 入力タイプ)
パッドタイプの設定.
Definition: Joypad.h:209