annotate src/win32/Joypad.cpp @ 2:3549bbe597ed

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