Mercurial > vba-clojure
view src/win32/Joypad.cpp @ 8:08a8e09ca414
add files required by automake
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:54:39 -0600 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 // Joypad.cpp : implementation file2 //4 #include "stdafx.h"5 #include "resource.h"6 #include "Joypad.h"7 #include "Input.h"8 #include "VBA.h"10 extern USHORT joypad[4][13];11 extern USHORT motion[4];13 /////////////////////////////////////////////////////////////////////////////14 // JoypadEditControl16 JoypadEditControl::JoypadEditControl()17 {}19 JoypadEditControl::~JoypadEditControl()20 {}22 BEGIN_MESSAGE_MAP(JoypadEditControl, CEdit)23 //{{AFX_MSG_MAP(JoypadEditControl)24 ON_WM_CHAR()25 //}}AFX_MSG_MAP26 ON_MESSAGE(JOYCONFIG_MESSAGE, OnJoyConfig)27 END_MESSAGE_MAP()29 /////////////////////////////////////////////////////////////////////////////30 // JoypadEditControl message handlers32 void JoypadEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)33 {}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 }43 BOOL JoypadEditControl::PreTranslateMessage(MSG *pMsg)44 {45 if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN))46 return TRUE;48 return CEdit::PreTranslateMessage(pMsg);49 }51 /////////////////////////////////////////////////////////////////////////////52 // JoypadConfig dialog54 JoypadConfig::JoypadConfig(int w, CWnd*pParent /*=NULL*/)55 : CDialog(JoypadConfig::IDD, pParent)56 {57 //{{AFX_DATA_INIT(JoypadConfig)58 //}}AFX_DATA_INIT59 timerId = 0;60 which = w;61 if (which < 0 || which > 3)62 which = 0;63 }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_MAP83 }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_MAP94 END_MESSAGE_MAP()96 /////////////////////////////////////////////////////////////////////////////97 // JoypadConfig message handlers99 void JoypadConfig::OnCancel()100 {101 EndDialog(FALSE);102 }104 void JoypadConfig::OnOk()105 {106 assignKeys();107 theApp.input->checkKeys();108 EndDialog(TRUE);109 }111 void JoypadConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)112 {}114 void JoypadConfig::OnDestroy()115 {116 CDialog::OnDestroy();118 KillTimer(timerId);119 }121 void JoypadConfig::OnTimer(UINT nIDEvent)122 {123 theApp.input->checkDevices();125 CDialog::OnTimer(nIDEvent);126 }128 void JoypadConfig::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)129 {}131 BOOL JoypadConfig::OnInitDialog()132 {133 CDialog::OnInitDialog();135 timerId = SetTimer(0, 200, NULL);137 SetWindowLong(up, GWL_USERDATA, joypad[which][KEY_UP]);138 up.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_UP]));140 SetWindowLong(down, GWL_USERDATA, joypad[which][KEY_DOWN]);141 down.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_DOWN]));143 SetWindowLong(left, GWL_USERDATA, joypad[which][KEY_LEFT]);144 left.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_LEFT]));146 SetWindowLong(right, GWL_USERDATA, joypad[which][KEY_RIGHT]);147 right.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_RIGHT]));149 SetWindowLong(buttonA, GWL_USERDATA, joypad[which][KEY_BUTTON_A]);150 buttonA.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_A]));152 SetWindowLong(buttonB, GWL_USERDATA, joypad[which][KEY_BUTTON_B]);153 buttonB.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_B]));155 SetWindowLong(buttonL, GWL_USERDATA, joypad[which][KEY_BUTTON_L]);156 buttonL.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_L]));158 SetWindowLong(buttonR, GWL_USERDATA, joypad[which][KEY_BUTTON_R]);159 buttonR.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_R]));161 SetWindowLong(buttonSelect, GWL_USERDATA, joypad[which][KEY_BUTTON_SELECT]);162 buttonSelect.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SELECT]));164 SetWindowLong(buttonStart, GWL_USERDATA, joypad[which][KEY_BUTTON_START]);165 buttonStart.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_START]));167 SetWindowLong(speed, GWL_USERDATA, joypad[which][KEY_BUTTON_SPEED]);168 speed.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SPEED]));170 SetWindowLong(capture, GWL_USERDATA, joypad[which][KEY_BUTTON_CAPTURE]);171 capture.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_CAPTURE]));173 SetWindowLong(buttonGS, GWL_USERDATA, joypad[which][KEY_BUTTON_GS]);174 buttonGS.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_GS]));176 CenterWindow();178 return TRUE; // return TRUE unless you set the focus to a control179 // EXCEPTION: OCX Property Pages should return FALSE180 }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 }228 void JoypadConfig::assignKeys()229 {230 int id;232 id = IDC_EDIT_UP;233 assignKey(id, GetWindowLong(up, GWL_USERDATA));235 id = IDC_EDIT_DOWN;236 assignKey(id, GetWindowLong(down, GWL_USERDATA));238 id = IDC_EDIT_LEFT;239 assignKey(id, GetWindowLong(left, GWL_USERDATA));241 id = IDC_EDIT_RIGHT;242 assignKey(id, GetWindowLong(right, GWL_USERDATA));244 id = IDC_EDIT_BUTTON_A;245 assignKey(id, GetWindowLong(buttonA, GWL_USERDATA));247 id = IDC_EDIT_BUTTON_B;248 assignKey(id, GetWindowLong(buttonB, GWL_USERDATA));250 id = IDC_EDIT_BUTTON_L;251 assignKey(id, GetWindowLong(buttonL, GWL_USERDATA));253 id = IDC_EDIT_BUTTON_R;254 assignKey(id, GetWindowLong(buttonR, GWL_USERDATA));256 id = IDC_EDIT_BUTTON_SELECT;257 assignKey(id, GetWindowLong(buttonSelect, GWL_USERDATA));259 id = IDC_EDIT_BUTTON_START;260 assignKey(id, GetWindowLong(buttonStart, GWL_USERDATA));262 id = IDC_EDIT_SPEED;263 assignKey(id, GetWindowLong(speed, GWL_USERDATA));265 id = IDC_EDIT_CAPTURE;266 assignKey(id, GetWindowLong(capture, GWL_USERDATA));268 id = IDC_EDIT_BUTTON_GS;269 assignKey(id, GetWindowLong(buttonGS, GWL_USERDATA));271 // winSaveKeys();272 }274 /////////////////////////////////////////////////////////////////////////////275 // MotionConfig dialog277 MotionConfig::MotionConfig(CWnd*pParent /*=NULL*/)278 : CDialog(MotionConfig::IDD, pParent)279 {280 //{{AFX_DATA_INIT(MotionConfig)281 // NOTE: the ClassWizard will add member initialization here282 //}}AFX_DATA_INIT283 timerId = 0;284 }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_MAP295 }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_MAP306 END_MESSAGE_MAP()308 /////////////////////////////////////////////////////////////////////////////309 // MotionConfig message handlers311 void MotionConfig::OnCancel()312 {313 EndDialog(FALSE);314 }316 void MotionConfig::OnOk()317 {318 assignKeys();319 theApp.input->checkKeys();320 EndDialog(TRUE);321 }323 void MotionConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)324 {}326 void MotionConfig::OnDestroy()327 {328 CDialog::OnDestroy();330 KillTimer(timerId);331 }333 BOOL MotionConfig::OnInitDialog()334 {335 CDialog::OnInitDialog();337 timerId = SetTimer(0, 200, NULL);339 SetWindowLong(up, GWL_USERDATA, motion[KEY_UP]);340 up.SetWindowText(theApp.input->getKeyName(motion[KEY_UP]));342 SetWindowLong(down, GWL_USERDATA, motion[KEY_DOWN]);343 down.SetWindowText(theApp.input->getKeyName(motion[KEY_DOWN]));345 SetWindowLong(left, GWL_USERDATA, motion[KEY_LEFT]);346 left.SetWindowText(theApp.input->getKeyName(motion[KEY_LEFT]));348 SetWindowLong(right, GWL_USERDATA, motion[KEY_RIGHT]);349 right.SetWindowText(theApp.input->getKeyName(motion[KEY_RIGHT]));351 CenterWindow();353 return TRUE; // return TRUE unless you set the focus to a control354 // EXCEPTION: OCX Property Pages should return FALSE355 }357 void MotionConfig::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)358 {}360 void MotionConfig::OnTimer(UINT nIDEvent)361 {362 theApp.input->checkDevices();364 CDialog::OnTimer(nIDEvent);365 }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 }386 void MotionConfig::assignKeys()387 {388 int id;390 id = IDC_EDIT_UP;391 assignKey(id, GetWindowLong(up, GWL_USERDATA));393 id = IDC_EDIT_DOWN;394 assignKey(id, GetWindowLong(down, GWL_USERDATA));396 id = IDC_EDIT_LEFT;397 assignKey(id, GetWindowLong(left, GWL_USERDATA));399 id = IDC_EDIT_RIGHT;400 assignKey(id, GetWindowLong(right, GWL_USERDATA));401 }