Mercurial > vba-clojure
comparison src/win32/Joypad.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // Joypad.cpp : implementation file | |
2 // | |
3 | |
4 #include "stdafx.h" | |
5 #include "resource.h" | |
6 #include "Joypad.h" | |
7 #include "Input.h" | |
8 #include "VBA.h" | |
9 | |
10 extern USHORT joypad[4][13]; | |
11 extern USHORT motion[4]; | |
12 | |
13 ///////////////////////////////////////////////////////////////////////////// | |
14 // JoypadEditControl | |
15 | |
16 JoypadEditControl::JoypadEditControl() | |
17 {} | |
18 | |
19 JoypadEditControl::~JoypadEditControl() | |
20 {} | |
21 | |
22 BEGIN_MESSAGE_MAP(JoypadEditControl, CEdit) | |
23 //{{AFX_MSG_MAP(JoypadEditControl) | |
24 ON_WM_CHAR() | |
25 //}}AFX_MSG_MAP | |
26 ON_MESSAGE(JOYCONFIG_MESSAGE, OnJoyConfig) | |
27 END_MESSAGE_MAP() | |
28 | |
29 ///////////////////////////////////////////////////////////////////////////// | |
30 // JoypadEditControl message handlers | |
31 | |
32 void JoypadEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) | |
33 {} | |
34 | |
35 LRESULT JoypadEditControl::OnJoyConfig(WPARAM wParam, LPARAM lParam) | |
36 { | |
37 SetWindowLong(GetSafeHwnd(), GWL_USERDATA, ((wParam<<8)|lParam)); | |
38 SetWindowText(theApp.input->getKeyName((wParam<<8)|lParam)); | |
39 GetParent()->GetNextDlgTabItem(this, FALSE)->SetFocus(); | |
40 return TRUE; | |
41 } | |
42 | |
43 BOOL JoypadEditControl::PreTranslateMessage(MSG *pMsg) | |
44 { | |
45 if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN)) | |
46 return TRUE; | |
47 | |
48 return CEdit::PreTranslateMessage(pMsg); | |
49 } | |
50 | |
51 ///////////////////////////////////////////////////////////////////////////// | |
52 // JoypadConfig dialog | |
53 | |
54 JoypadConfig::JoypadConfig(int w, CWnd*pParent /*=NULL*/) | |
55 : CDialog(JoypadConfig::IDD, pParent) | |
56 { | |
57 //{{AFX_DATA_INIT(JoypadConfig) | |
58 //}}AFX_DATA_INIT | |
59 timerId = 0; | |
60 which = w; | |
61 if (which < 0 || which > 3) | |
62 which = 0; | |
63 } | |
64 | |
65 void JoypadConfig::DoDataExchange(CDataExchange*pDX) | |
66 { | |
67 CDialog::DoDataExchange(pDX); | |
68 //{{AFX_DATA_MAP(JoypadConfig) | |
69 DDX_Control(pDX, IDC_EDIT_UP, up); | |
70 DDX_Control(pDX, IDC_EDIT_SPEED, speed); | |
71 DDX_Control(pDX, IDC_EDIT_RIGHT, right); | |
72 DDX_Control(pDX, IDC_EDIT_LEFT, left); | |
73 DDX_Control(pDX, IDC_EDIT_DOWN, down); | |
74 DDX_Control(pDX, IDC_EDIT_CAPTURE, capture); | |
75 DDX_Control(pDX, IDC_EDIT_BUTTON_START, buttonStart); | |
76 DDX_Control(pDX, IDC_EDIT_BUTTON_SELECT, buttonSelect); | |
77 DDX_Control(pDX, IDC_EDIT_BUTTON_R, buttonR); | |
78 DDX_Control(pDX, IDC_EDIT_BUTTON_L, buttonL); | |
79 DDX_Control(pDX, IDC_EDIT_BUTTON_GS, buttonGS); | |
80 DDX_Control(pDX, IDC_EDIT_BUTTON_B, buttonB); | |
81 DDX_Control(pDX, IDC_EDIT_BUTTON_A, buttonA); | |
82 //}}AFX_DATA_MAP | |
83 } | |
84 | |
85 BEGIN_MESSAGE_MAP(JoypadConfig, CDialog) | |
86 //{{AFX_MSG_MAP(JoypadConfig) | |
87 ON_BN_CLICKED(ID_CANCEL, OnCancel) | |
88 ON_BN_CLICKED(ID_OK, OnOk) | |
89 ON_WM_CHAR() | |
90 ON_WM_DESTROY() | |
91 ON_WM_TIMER() | |
92 ON_WM_KEYDOWN() | |
93 //}}AFX_MSG_MAP | |
94 END_MESSAGE_MAP() | |
95 | |
96 ///////////////////////////////////////////////////////////////////////////// | |
97 // JoypadConfig message handlers | |
98 | |
99 void JoypadConfig::OnCancel() | |
100 { | |
101 EndDialog(FALSE); | |
102 } | |
103 | |
104 void JoypadConfig::OnOk() | |
105 { | |
106 assignKeys(); | |
107 theApp.input->checkKeys(); | |
108 EndDialog(TRUE); | |
109 } | |
110 | |
111 void JoypadConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) | |
112 {} | |
113 | |
114 void JoypadConfig::OnDestroy() | |
115 { | |
116 CDialog::OnDestroy(); | |
117 | |
118 KillTimer(timerId); | |
119 } | |
120 | |
121 void JoypadConfig::OnTimer(UINT nIDEvent) | |
122 { | |
123 theApp.input->checkDevices(); | |
124 | |
125 CDialog::OnTimer(nIDEvent); | |
126 } | |
127 | |
128 void JoypadConfig::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) | |
129 {} | |
130 | |
131 BOOL JoypadConfig::OnInitDialog() | |
132 { | |
133 CDialog::OnInitDialog(); | |
134 | |
135 timerId = SetTimer(0, 200, NULL); | |
136 | |
137 SetWindowLong(up, GWL_USERDATA, joypad[which][KEY_UP]); | |
138 up.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_UP])); | |
139 | |
140 SetWindowLong(down, GWL_USERDATA, joypad[which][KEY_DOWN]); | |
141 down.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_DOWN])); | |
142 | |
143 SetWindowLong(left, GWL_USERDATA, joypad[which][KEY_LEFT]); | |
144 left.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_LEFT])); | |
145 | |
146 SetWindowLong(right, GWL_USERDATA, joypad[which][KEY_RIGHT]); | |
147 right.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_RIGHT])); | |
148 | |
149 SetWindowLong(buttonA, GWL_USERDATA, joypad[which][KEY_BUTTON_A]); | |
150 buttonA.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_A])); | |
151 | |
152 SetWindowLong(buttonB, GWL_USERDATA, joypad[which][KEY_BUTTON_B]); | |
153 buttonB.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_B])); | |
154 | |
155 SetWindowLong(buttonL, GWL_USERDATA, joypad[which][KEY_BUTTON_L]); | |
156 buttonL.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_L])); | |
157 | |
158 SetWindowLong(buttonR, GWL_USERDATA, joypad[which][KEY_BUTTON_R]); | |
159 buttonR.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_R])); | |
160 | |
161 SetWindowLong(buttonSelect, GWL_USERDATA, joypad[which][KEY_BUTTON_SELECT]); | |
162 buttonSelect.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SELECT])); | |
163 | |
164 SetWindowLong(buttonStart, GWL_USERDATA, joypad[which][KEY_BUTTON_START]); | |
165 buttonStart.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_START])); | |
166 | |
167 SetWindowLong(speed, GWL_USERDATA, joypad[which][KEY_BUTTON_SPEED]); | |
168 speed.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SPEED])); | |
169 | |
170 SetWindowLong(capture, GWL_USERDATA, joypad[which][KEY_BUTTON_CAPTURE]); | |
171 capture.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_CAPTURE])); | |
172 | |
173 SetWindowLong(buttonGS, GWL_USERDATA, joypad[which][KEY_BUTTON_GS]); | |
174 buttonGS.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_GS])); | |
175 | |
176 CenterWindow(); | |
177 | |
178 return TRUE; // return TRUE unless you set the focus to a control | |
179 // EXCEPTION: OCX Property Pages should return FALSE | |
180 } | |
181 | |
182 void JoypadConfig::assignKey(int id, int key) | |
183 { | |
184 switch (id) | |
185 { | |
186 case IDC_EDIT_LEFT: | |
187 joypad[which][KEY_LEFT] = key; | |
188 break; | |
189 case IDC_EDIT_RIGHT: | |
190 joypad[which][KEY_RIGHT] = key; | |
191 break; | |
192 case IDC_EDIT_UP: | |
193 joypad[which][KEY_UP] = key; | |
194 break; | |
195 case IDC_EDIT_SPEED: | |
196 joypad[which][KEY_BUTTON_SPEED] = key; | |
197 break; | |
198 case IDC_EDIT_CAPTURE: | |
199 joypad[which][KEY_BUTTON_CAPTURE] = key; | |
200 break; | |
201 case IDC_EDIT_DOWN: | |
202 joypad[which][KEY_DOWN] = key; | |
203 break; | |
204 case IDC_EDIT_BUTTON_A: | |
205 joypad[which][KEY_BUTTON_A] = key; | |
206 break; | |
207 case IDC_EDIT_BUTTON_B: | |
208 joypad[which][KEY_BUTTON_B] = key; | |
209 break; | |
210 case IDC_EDIT_BUTTON_L: | |
211 joypad[which][KEY_BUTTON_L] = key; | |
212 break; | |
213 case IDC_EDIT_BUTTON_R: | |
214 joypad[which][KEY_BUTTON_R] = key; | |
215 break; | |
216 case IDC_EDIT_BUTTON_START: | |
217 joypad[which][KEY_BUTTON_START] = key; | |
218 break; | |
219 case IDC_EDIT_BUTTON_SELECT: | |
220 joypad[which][KEY_BUTTON_SELECT] = key; | |
221 break; | |
222 case IDC_EDIT_BUTTON_GS: | |
223 joypad[which][KEY_BUTTON_GS] = key; | |
224 break; | |
225 } | |
226 } | |
227 | |
228 void JoypadConfig::assignKeys() | |
229 { | |
230 int id; | |
231 | |
232 id = IDC_EDIT_UP; | |
233 assignKey(id, GetWindowLong(up, GWL_USERDATA)); | |
234 | |
235 id = IDC_EDIT_DOWN; | |
236 assignKey(id, GetWindowLong(down, GWL_USERDATA)); | |
237 | |
238 id = IDC_EDIT_LEFT; | |
239 assignKey(id, GetWindowLong(left, GWL_USERDATA)); | |
240 | |
241 id = IDC_EDIT_RIGHT; | |
242 assignKey(id, GetWindowLong(right, GWL_USERDATA)); | |
243 | |
244 id = IDC_EDIT_BUTTON_A; | |
245 assignKey(id, GetWindowLong(buttonA, GWL_USERDATA)); | |
246 | |
247 id = IDC_EDIT_BUTTON_B; | |
248 assignKey(id, GetWindowLong(buttonB, GWL_USERDATA)); | |
249 | |
250 id = IDC_EDIT_BUTTON_L; | |
251 assignKey(id, GetWindowLong(buttonL, GWL_USERDATA)); | |
252 | |
253 id = IDC_EDIT_BUTTON_R; | |
254 assignKey(id, GetWindowLong(buttonR, GWL_USERDATA)); | |
255 | |
256 id = IDC_EDIT_BUTTON_SELECT; | |
257 assignKey(id, GetWindowLong(buttonSelect, GWL_USERDATA)); | |
258 | |
259 id = IDC_EDIT_BUTTON_START; | |
260 assignKey(id, GetWindowLong(buttonStart, GWL_USERDATA)); | |
261 | |
262 id = IDC_EDIT_SPEED; | |
263 assignKey(id, GetWindowLong(speed, GWL_USERDATA)); | |
264 | |
265 id = IDC_EDIT_CAPTURE; | |
266 assignKey(id, GetWindowLong(capture, GWL_USERDATA)); | |
267 | |
268 id = IDC_EDIT_BUTTON_GS; | |
269 assignKey(id, GetWindowLong(buttonGS, GWL_USERDATA)); | |
270 | |
271 // winSaveKeys(); | |
272 } | |
273 | |
274 ///////////////////////////////////////////////////////////////////////////// | |
275 // MotionConfig dialog | |
276 | |
277 MotionConfig::MotionConfig(CWnd*pParent /*=NULL*/) | |
278 : CDialog(MotionConfig::IDD, pParent) | |
279 { | |
280 //{{AFX_DATA_INIT(MotionConfig) | |
281 // NOTE: the ClassWizard will add member initialization here | |
282 //}}AFX_DATA_INIT | |
283 timerId = 0; | |
284 } | |
285 | |
286 void MotionConfig::DoDataExchange(CDataExchange*pDX) | |
287 { | |
288 CDialog::DoDataExchange(pDX); | |
289 //{{AFX_DATA_MAP(MotionConfig) | |
290 DDX_Control(pDX, IDC_EDIT_UP, up); | |
291 DDX_Control(pDX, IDC_EDIT_RIGHT, right); | |
292 DDX_Control(pDX, IDC_EDIT_LEFT, left); | |
293 DDX_Control(pDX, IDC_EDIT_DOWN, down); | |
294 //}}AFX_DATA_MAP | |
295 } | |
296 | |
297 BEGIN_MESSAGE_MAP(MotionConfig, CDialog) | |
298 //{{AFX_MSG_MAP(MotionConfig) | |
299 ON_BN_CLICKED(ID_CANCEL, OnCancel) | |
300 ON_BN_CLICKED(ID_OK, OnOk) | |
301 ON_WM_CHAR() | |
302 ON_WM_DESTROY() | |
303 ON_WM_KEYDOWN() | |
304 ON_WM_TIMER() | |
305 //}}AFX_MSG_MAP | |
306 END_MESSAGE_MAP() | |
307 | |
308 ///////////////////////////////////////////////////////////////////////////// | |
309 // MotionConfig message handlers | |
310 | |
311 void MotionConfig::OnCancel() | |
312 { | |
313 EndDialog(FALSE); | |
314 } | |
315 | |
316 void MotionConfig::OnOk() | |
317 { | |
318 assignKeys(); | |
319 theApp.input->checkKeys(); | |
320 EndDialog(TRUE); | |
321 } | |
322 | |
323 void MotionConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) | |
324 {} | |
325 | |
326 void MotionConfig::OnDestroy() | |
327 { | |
328 CDialog::OnDestroy(); | |
329 | |
330 KillTimer(timerId); | |
331 } | |
332 | |
333 BOOL MotionConfig::OnInitDialog() | |
334 { | |
335 CDialog::OnInitDialog(); | |
336 | |
337 timerId = SetTimer(0, 200, NULL); | |
338 | |
339 SetWindowLong(up, GWL_USERDATA, motion[KEY_UP]); | |
340 up.SetWindowText(theApp.input->getKeyName(motion[KEY_UP])); | |
341 | |
342 SetWindowLong(down, GWL_USERDATA, motion[KEY_DOWN]); | |
343 down.SetWindowText(theApp.input->getKeyName(motion[KEY_DOWN])); | |
344 | |
345 SetWindowLong(left, GWL_USERDATA, motion[KEY_LEFT]); | |
346 left.SetWindowText(theApp.input->getKeyName(motion[KEY_LEFT])); | |
347 | |
348 SetWindowLong(right, GWL_USERDATA, motion[KEY_RIGHT]); | |
349 right.SetWindowText(theApp.input->getKeyName(motion[KEY_RIGHT])); | |
350 | |
351 CenterWindow(); | |
352 | |
353 return TRUE; // return TRUE unless you set the focus to a control | |
354 // EXCEPTION: OCX Property Pages should return FALSE | |
355 } | |
356 | |
357 void MotionConfig::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) | |
358 {} | |
359 | |
360 void MotionConfig::OnTimer(UINT nIDEvent) | |
361 { | |
362 theApp.input->checkDevices(); | |
363 | |
364 CDialog::OnTimer(nIDEvent); | |
365 } | |
366 | |
367 void MotionConfig::assignKey(int id, int key) | |
368 { | |
369 switch (id) | |
370 { | |
371 case IDC_EDIT_LEFT: | |
372 motion[KEY_LEFT] = key; | |
373 break; | |
374 case IDC_EDIT_RIGHT: | |
375 motion[KEY_RIGHT] = key; | |
376 break; | |
377 case IDC_EDIT_UP: | |
378 motion[KEY_UP] = key; | |
379 break; | |
380 case IDC_EDIT_DOWN: | |
381 motion[KEY_DOWN] = key; | |
382 break; | |
383 } | |
384 } | |
385 | |
386 void MotionConfig::assignKeys() | |
387 { | |
388 int id; | |
389 | |
390 id = IDC_EDIT_UP; | |
391 assignKey(id, GetWindowLong(up, GWL_USERDATA)); | |
392 | |
393 id = IDC_EDIT_DOWN; | |
394 assignKey(id, GetWindowLong(down, GWL_USERDATA)); | |
395 | |
396 id = IDC_EDIT_LEFT; | |
397 assignKey(id, GetWindowLong(left, GWL_USERDATA)); | |
398 | |
399 id = IDC_EDIT_RIGHT; | |
400 assignKey(id, GetWindowLong(right, GWL_USERDATA)); | |
401 } | |
402 |