diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/Joypad.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,402 @@
     1.4 +// Joypad.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "Joypad.h"
    1.10 +#include "Input.h"
    1.11 +#include "VBA.h"
    1.12 +
    1.13 +extern USHORT joypad[4][13];
    1.14 +extern USHORT motion[4];
    1.15 +
    1.16 +/////////////////////////////////////////////////////////////////////////////
    1.17 +// JoypadEditControl
    1.18 +
    1.19 +JoypadEditControl::JoypadEditControl()
    1.20 +{}
    1.21 +
    1.22 +JoypadEditControl::~JoypadEditControl()
    1.23 +{}
    1.24 +
    1.25 +BEGIN_MESSAGE_MAP(JoypadEditControl, CEdit)
    1.26 +//{{AFX_MSG_MAP(JoypadEditControl)
    1.27 +ON_WM_CHAR()
    1.28 +//}}AFX_MSG_MAP
    1.29 +ON_MESSAGE(JOYCONFIG_MESSAGE, OnJoyConfig)
    1.30 +END_MESSAGE_MAP()
    1.31 +
    1.32 +/////////////////////////////////////////////////////////////////////////////
    1.33 +// JoypadEditControl message handlers
    1.34 +
    1.35 +void JoypadEditControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    1.36 +{}
    1.37 +
    1.38 +LRESULT JoypadEditControl::OnJoyConfig(WPARAM wParam, LPARAM lParam)
    1.39 +{
    1.40 +	SetWindowLong(GetSafeHwnd(), GWL_USERDATA, ((wParam<<8)|lParam));
    1.41 +	SetWindowText(theApp.input->getKeyName((wParam<<8)|lParam));
    1.42 +	GetParent()->GetNextDlgTabItem(this, FALSE)->SetFocus();
    1.43 +	return TRUE;
    1.44 +}
    1.45 +
    1.46 +BOOL JoypadEditControl::PreTranslateMessage(MSG *pMsg)
    1.47 +{
    1.48 +	if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN))
    1.49 +		return TRUE;
    1.50 +
    1.51 +	return CEdit::PreTranslateMessage(pMsg);
    1.52 +}
    1.53 +
    1.54 +/////////////////////////////////////////////////////////////////////////////
    1.55 +// JoypadConfig dialog
    1.56 +
    1.57 +JoypadConfig::JoypadConfig(int w, CWnd*pParent /*=NULL*/)
    1.58 +	: CDialog(JoypadConfig::IDD, pParent)
    1.59 +{
    1.60 +	//{{AFX_DATA_INIT(JoypadConfig)
    1.61 +	//}}AFX_DATA_INIT
    1.62 +	timerId = 0;
    1.63 +	which   = w;
    1.64 +	if (which < 0 || which > 3)
    1.65 +		which = 0;
    1.66 +}
    1.67 +
    1.68 +void JoypadConfig::DoDataExchange(CDataExchange*pDX)
    1.69 +{
    1.70 +	CDialog::DoDataExchange(pDX);
    1.71 +	//{{AFX_DATA_MAP(JoypadConfig)
    1.72 +	DDX_Control(pDX, IDC_EDIT_UP, up);
    1.73 +	DDX_Control(pDX, IDC_EDIT_SPEED, speed);
    1.74 +	DDX_Control(pDX, IDC_EDIT_RIGHT, right);
    1.75 +	DDX_Control(pDX, IDC_EDIT_LEFT, left);
    1.76 +	DDX_Control(pDX, IDC_EDIT_DOWN, down);
    1.77 +	DDX_Control(pDX, IDC_EDIT_CAPTURE, capture);
    1.78 +	DDX_Control(pDX, IDC_EDIT_BUTTON_START, buttonStart);
    1.79 +	DDX_Control(pDX, IDC_EDIT_BUTTON_SELECT, buttonSelect);
    1.80 +	DDX_Control(pDX, IDC_EDIT_BUTTON_R, buttonR);
    1.81 +	DDX_Control(pDX, IDC_EDIT_BUTTON_L, buttonL);
    1.82 +	DDX_Control(pDX, IDC_EDIT_BUTTON_GS, buttonGS);
    1.83 +	DDX_Control(pDX, IDC_EDIT_BUTTON_B, buttonB);
    1.84 +	DDX_Control(pDX, IDC_EDIT_BUTTON_A, buttonA);
    1.85 +	//}}AFX_DATA_MAP
    1.86 +}
    1.87 +
    1.88 +BEGIN_MESSAGE_MAP(JoypadConfig, CDialog)
    1.89 +//{{AFX_MSG_MAP(JoypadConfig)
    1.90 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
    1.91 +ON_BN_CLICKED(ID_OK, OnOk)
    1.92 +ON_WM_CHAR()
    1.93 +ON_WM_DESTROY()
    1.94 +ON_WM_TIMER()
    1.95 +ON_WM_KEYDOWN()
    1.96 +//}}AFX_MSG_MAP
    1.97 +END_MESSAGE_MAP()
    1.98 +
    1.99 +/////////////////////////////////////////////////////////////////////////////
   1.100 +// JoypadConfig message handlers
   1.101 +
   1.102 +void JoypadConfig::OnCancel()
   1.103 +{
   1.104 +	EndDialog(FALSE);
   1.105 +}
   1.106 +
   1.107 +void JoypadConfig::OnOk()
   1.108 +{
   1.109 +	assignKeys();
   1.110 +	theApp.input->checkKeys();
   1.111 +	EndDialog(TRUE);
   1.112 +}
   1.113 +
   1.114 +void JoypadConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
   1.115 +{}
   1.116 +
   1.117 +void JoypadConfig::OnDestroy()
   1.118 +{
   1.119 +	CDialog::OnDestroy();
   1.120 +
   1.121 +	KillTimer(timerId);
   1.122 +}
   1.123 +
   1.124 +void JoypadConfig::OnTimer(UINT nIDEvent)
   1.125 +{
   1.126 +	theApp.input->checkDevices();
   1.127 +
   1.128 +	CDialog::OnTimer(nIDEvent);
   1.129 +}
   1.130 +
   1.131 +void JoypadConfig::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
   1.132 +{}
   1.133 +
   1.134 +BOOL JoypadConfig::OnInitDialog()
   1.135 +{
   1.136 +	CDialog::OnInitDialog();
   1.137 +
   1.138 +	timerId = SetTimer(0, 200, NULL);
   1.139 +
   1.140 +	SetWindowLong(up, GWL_USERDATA, joypad[which][KEY_UP]);
   1.141 +	up.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_UP]));
   1.142 +
   1.143 +	SetWindowLong(down, GWL_USERDATA, joypad[which][KEY_DOWN]);
   1.144 +	down.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_DOWN]));
   1.145 +
   1.146 +	SetWindowLong(left, GWL_USERDATA, joypad[which][KEY_LEFT]);
   1.147 +	left.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_LEFT]));
   1.148 +
   1.149 +	SetWindowLong(right, GWL_USERDATA, joypad[which][KEY_RIGHT]);
   1.150 +	right.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_RIGHT]));
   1.151 +
   1.152 +	SetWindowLong(buttonA, GWL_USERDATA, joypad[which][KEY_BUTTON_A]);
   1.153 +	buttonA.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_A]));
   1.154 +
   1.155 +	SetWindowLong(buttonB, GWL_USERDATA, joypad[which][KEY_BUTTON_B]);
   1.156 +	buttonB.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_B]));
   1.157 +
   1.158 +	SetWindowLong(buttonL, GWL_USERDATA, joypad[which][KEY_BUTTON_L]);
   1.159 +	buttonL.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_L]));
   1.160 +
   1.161 +	SetWindowLong(buttonR, GWL_USERDATA, joypad[which][KEY_BUTTON_R]);
   1.162 +	buttonR.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_R]));
   1.163 +
   1.164 +	SetWindowLong(buttonSelect, GWL_USERDATA, joypad[which][KEY_BUTTON_SELECT]);
   1.165 +	buttonSelect.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SELECT]));
   1.166 +
   1.167 +	SetWindowLong(buttonStart, GWL_USERDATA, joypad[which][KEY_BUTTON_START]);
   1.168 +	buttonStart.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_START]));
   1.169 +
   1.170 +	SetWindowLong(speed, GWL_USERDATA, joypad[which][KEY_BUTTON_SPEED]);
   1.171 +	speed.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_SPEED]));
   1.172 +
   1.173 +	SetWindowLong(capture, GWL_USERDATA, joypad[which][KEY_BUTTON_CAPTURE]);
   1.174 +	capture.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_CAPTURE]));
   1.175 +
   1.176 +	SetWindowLong(buttonGS, GWL_USERDATA, joypad[which][KEY_BUTTON_GS]);
   1.177 +	buttonGS.SetWindowText(theApp.input->getKeyName(joypad[which][KEY_BUTTON_GS]));
   1.178 +
   1.179 +	CenterWindow();
   1.180 +
   1.181 +	return TRUE; // return TRUE unless you set the focus to a control
   1.182 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.183 +}
   1.184 +
   1.185 +void JoypadConfig::assignKey(int id, int key)
   1.186 +{
   1.187 +	switch (id)
   1.188 +	{
   1.189 +	case IDC_EDIT_LEFT:
   1.190 +		joypad[which][KEY_LEFT] = key;
   1.191 +		break;
   1.192 +	case IDC_EDIT_RIGHT:
   1.193 +		joypad[which][KEY_RIGHT] = key;
   1.194 +		break;
   1.195 +	case IDC_EDIT_UP:
   1.196 +		joypad[which][KEY_UP] = key;
   1.197 +		break;
   1.198 +	case IDC_EDIT_SPEED:
   1.199 +		joypad[which][KEY_BUTTON_SPEED] = key;
   1.200 +		break;
   1.201 +	case IDC_EDIT_CAPTURE:
   1.202 +		joypad[which][KEY_BUTTON_CAPTURE] = key;
   1.203 +		break;
   1.204 +	case IDC_EDIT_DOWN:
   1.205 +		joypad[which][KEY_DOWN] = key;
   1.206 +		break;
   1.207 +	case IDC_EDIT_BUTTON_A:
   1.208 +		joypad[which][KEY_BUTTON_A] = key;
   1.209 +		break;
   1.210 +	case IDC_EDIT_BUTTON_B:
   1.211 +		joypad[which][KEY_BUTTON_B] = key;
   1.212 +		break;
   1.213 +	case IDC_EDIT_BUTTON_L:
   1.214 +		joypad[which][KEY_BUTTON_L] = key;
   1.215 +		break;
   1.216 +	case IDC_EDIT_BUTTON_R:
   1.217 +		joypad[which][KEY_BUTTON_R] = key;
   1.218 +		break;
   1.219 +	case IDC_EDIT_BUTTON_START:
   1.220 +		joypad[which][KEY_BUTTON_START] = key;
   1.221 +		break;
   1.222 +	case IDC_EDIT_BUTTON_SELECT:
   1.223 +		joypad[which][KEY_BUTTON_SELECT] = key;
   1.224 +		break;
   1.225 +	case IDC_EDIT_BUTTON_GS:
   1.226 +		joypad[which][KEY_BUTTON_GS] = key;
   1.227 +		break;
   1.228 +	}
   1.229 +}
   1.230 +
   1.231 +void JoypadConfig::assignKeys()
   1.232 +{
   1.233 +	int id;
   1.234 +
   1.235 +	id = IDC_EDIT_UP;
   1.236 +	assignKey(id, GetWindowLong(up, GWL_USERDATA));
   1.237 +
   1.238 +	id = IDC_EDIT_DOWN;
   1.239 +	assignKey(id, GetWindowLong(down, GWL_USERDATA));
   1.240 +
   1.241 +	id = IDC_EDIT_LEFT;
   1.242 +	assignKey(id, GetWindowLong(left, GWL_USERDATA));
   1.243 +
   1.244 +	id = IDC_EDIT_RIGHT;
   1.245 +	assignKey(id, GetWindowLong(right, GWL_USERDATA));
   1.246 +
   1.247 +	id = IDC_EDIT_BUTTON_A;
   1.248 +	assignKey(id, GetWindowLong(buttonA, GWL_USERDATA));
   1.249 +
   1.250 +	id = IDC_EDIT_BUTTON_B;
   1.251 +	assignKey(id, GetWindowLong(buttonB, GWL_USERDATA));
   1.252 +
   1.253 +	id = IDC_EDIT_BUTTON_L;
   1.254 +	assignKey(id, GetWindowLong(buttonL, GWL_USERDATA));
   1.255 +
   1.256 +	id = IDC_EDIT_BUTTON_R;
   1.257 +	assignKey(id, GetWindowLong(buttonR, GWL_USERDATA));
   1.258 +
   1.259 +	id = IDC_EDIT_BUTTON_SELECT;
   1.260 +	assignKey(id, GetWindowLong(buttonSelect, GWL_USERDATA));
   1.261 +
   1.262 +	id = IDC_EDIT_BUTTON_START;
   1.263 +	assignKey(id, GetWindowLong(buttonStart, GWL_USERDATA));
   1.264 +
   1.265 +	id = IDC_EDIT_SPEED;
   1.266 +	assignKey(id, GetWindowLong(speed, GWL_USERDATA));
   1.267 +
   1.268 +	id = IDC_EDIT_CAPTURE;
   1.269 +	assignKey(id, GetWindowLong(capture, GWL_USERDATA));
   1.270 +
   1.271 +	id = IDC_EDIT_BUTTON_GS;
   1.272 +	assignKey(id, GetWindowLong(buttonGS, GWL_USERDATA));
   1.273 +
   1.274 +	//  winSaveKeys();
   1.275 +}
   1.276 +
   1.277 +/////////////////////////////////////////////////////////////////////////////
   1.278 +// MotionConfig dialog
   1.279 +
   1.280 +MotionConfig::MotionConfig(CWnd*pParent /*=NULL*/)
   1.281 +	: CDialog(MotionConfig::IDD, pParent)
   1.282 +{
   1.283 +	//{{AFX_DATA_INIT(MotionConfig)
   1.284 +	// NOTE: the ClassWizard will add member initialization here
   1.285 +	//}}AFX_DATA_INIT
   1.286 +	timerId = 0;
   1.287 +}
   1.288 +
   1.289 +void MotionConfig::DoDataExchange(CDataExchange*pDX)
   1.290 +{
   1.291 +	CDialog::DoDataExchange(pDX);
   1.292 +	//{{AFX_DATA_MAP(MotionConfig)
   1.293 +	DDX_Control(pDX, IDC_EDIT_UP, up);
   1.294 +	DDX_Control(pDX, IDC_EDIT_RIGHT, right);
   1.295 +	DDX_Control(pDX, IDC_EDIT_LEFT, left);
   1.296 +	DDX_Control(pDX, IDC_EDIT_DOWN, down);
   1.297 +	//}}AFX_DATA_MAP
   1.298 +}
   1.299 +
   1.300 +BEGIN_MESSAGE_MAP(MotionConfig, CDialog)
   1.301 +//{{AFX_MSG_MAP(MotionConfig)
   1.302 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
   1.303 +ON_BN_CLICKED(ID_OK, OnOk)
   1.304 +ON_WM_CHAR()
   1.305 +ON_WM_DESTROY()
   1.306 +ON_WM_KEYDOWN()
   1.307 +ON_WM_TIMER()
   1.308 +//}}AFX_MSG_MAP
   1.309 +END_MESSAGE_MAP()
   1.310 +
   1.311 +/////////////////////////////////////////////////////////////////////////////
   1.312 +// MotionConfig message handlers
   1.313 +
   1.314 +void MotionConfig::OnCancel()
   1.315 +{
   1.316 +	EndDialog(FALSE);
   1.317 +}
   1.318 +
   1.319 +void MotionConfig::OnOk()
   1.320 +{
   1.321 +	assignKeys();
   1.322 +	theApp.input->checkKeys();
   1.323 +	EndDialog(TRUE);
   1.324 +}
   1.325 +
   1.326 +void MotionConfig::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
   1.327 +{}
   1.328 +
   1.329 +void MotionConfig::OnDestroy()
   1.330 +{
   1.331 +	CDialog::OnDestroy();
   1.332 +
   1.333 +	KillTimer(timerId);
   1.334 +}
   1.335 +
   1.336 +BOOL MotionConfig::OnInitDialog()
   1.337 +{
   1.338 +	CDialog::OnInitDialog();
   1.339 +
   1.340 +	timerId = SetTimer(0, 200, NULL);
   1.341 +
   1.342 +	SetWindowLong(up, GWL_USERDATA, motion[KEY_UP]);
   1.343 +	up.SetWindowText(theApp.input->getKeyName(motion[KEY_UP]));
   1.344 +
   1.345 +	SetWindowLong(down, GWL_USERDATA, motion[KEY_DOWN]);
   1.346 +	down.SetWindowText(theApp.input->getKeyName(motion[KEY_DOWN]));
   1.347 +
   1.348 +	SetWindowLong(left, GWL_USERDATA, motion[KEY_LEFT]);
   1.349 +	left.SetWindowText(theApp.input->getKeyName(motion[KEY_LEFT]));
   1.350 +
   1.351 +	SetWindowLong(right, GWL_USERDATA, motion[KEY_RIGHT]);
   1.352 +	right.SetWindowText(theApp.input->getKeyName(motion[KEY_RIGHT]));
   1.353 +
   1.354 +	CenterWindow();
   1.355 +
   1.356 +	return TRUE; // return TRUE unless you set the focus to a control
   1.357 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.358 +}
   1.359 +
   1.360 +void MotionConfig::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
   1.361 +{}
   1.362 +
   1.363 +void MotionConfig::OnTimer(UINT nIDEvent)
   1.364 +{
   1.365 +	theApp.input->checkDevices();
   1.366 +
   1.367 +	CDialog::OnTimer(nIDEvent);
   1.368 +}
   1.369 +
   1.370 +void MotionConfig::assignKey(int id, int key)
   1.371 +{
   1.372 +	switch (id)
   1.373 +	{
   1.374 +	case IDC_EDIT_LEFT:
   1.375 +		motion[KEY_LEFT] = key;
   1.376 +		break;
   1.377 +	case IDC_EDIT_RIGHT:
   1.378 +		motion[KEY_RIGHT] = key;
   1.379 +		break;
   1.380 +	case IDC_EDIT_UP:
   1.381 +		motion[KEY_UP] = key;
   1.382 +		break;
   1.383 +	case IDC_EDIT_DOWN:
   1.384 +		motion[KEY_DOWN] = key;
   1.385 +		break;
   1.386 +	}
   1.387 +}
   1.388 +
   1.389 +void MotionConfig::assignKeys()
   1.390 +{
   1.391 +	int id;
   1.392 +
   1.393 +	id = IDC_EDIT_UP;
   1.394 +	assignKey(id, GetWindowLong(up, GWL_USERDATA));
   1.395 +
   1.396 +	id = IDC_EDIT_DOWN;
   1.397 +	assignKey(id, GetWindowLong(down, GWL_USERDATA));
   1.398 +
   1.399 +	id = IDC_EDIT_LEFT;
   1.400 +	assignKey(id, GetWindowLong(left, GWL_USERDATA));
   1.401 +
   1.402 +	id = IDC_EDIT_RIGHT;
   1.403 +	assignKey(id, GetWindowLong(right, GWL_USERDATA));
   1.404 +}
   1.405 +