Cxbx-Reloaded/Source/Win32/Cxbx/DlgControllerConfig.cpp

248 lines
9.1 KiB
C++
Raw Normal View History

2003-03-30 06:30:19 +00:00
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * Cxbx->Win32->Cxbx->DlgControllerConfig.cpp
// *
// * This file is part of the Cxbx project.
// *
// * Cxbx and Cxbe are free software; you can redistribute them
// * and/or modify them under the terms of the GNU General Public
// * License as published by the Free Software Foundation; either
// * version 2 of the license, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have recieved a copy of the GNU General Public License
// * along with this program; see the file COPYING.
// * If not, write to the Free Software Foundation, Inc.,
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
// *
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
// *
// * All rights reserved
// *
// ******************************************************************
#include "DlgControllerConfig.h"
2003-04-02 02:23:30 +00:00
#include "ResCxbx.h"
#include "EmuShared.h"
2003-03-30 06:30:19 +00:00
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
2003-04-01 23:11:03 +00:00
#include <stdio.h>
2003-03-30 06:30:19 +00:00
// ******************************************************************
2003-04-02 22:57:26 +00:00
// * Static Function(s)
2003-03-30 06:30:19 +00:00
// ******************************************************************
2003-04-15 08:08:53 +00:00
INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
VOID ConfigureInput(HWND hWndDlg, HWND hWndButton, XBCtrlObject object);
2003-03-30 06:30:19 +00:00
2003-04-01 23:11:03 +00:00
// ******************************************************************
2003-04-02 22:57:26 +00:00
// * Static Variable(s)
2003-04-01 23:11:03 +00:00
// ******************************************************************
2003-04-15 08:08:53 +00:00
XBController g_XBController;
2003-04-01 23:11:03 +00:00
2003-03-30 06:30:19 +00:00
// ******************************************************************
2003-04-02 22:57:26 +00:00
// * Show Controller Configuration Dialog Window
2003-03-30 06:30:19 +00:00
// ******************************************************************
void ShowControllerConfig(HWND hwnd)
{
2003-04-15 08:08:53 +00:00
g_EmuShared->GetXBController(&g_XBController);
2003-04-04 03:31:43 +00:00
2003-03-30 06:30:19 +00:00
DialogBox
(
GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_CONTROLLER_CFG),
hwnd,
DlgControllerConfigProc
);
}
// ******************************************************************
2003-04-02 22:57:26 +00:00
// * Controller Configuration Dialog Procedure
// ******************************************************************
INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2003-04-04 03:31:43 +00:00
{
switch(uMsg)
{
case WM_INITDIALOG:
SetClassLong(hWndDlg, GCL_HICON, (LONG)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CXBX)));
2003-04-02 20:01:37 +00:00
SetFocus(GetDlgItem(hWndDlg, IDC_SET_X));
break;
case WM_CLOSE:
EndDialog(hWndDlg, wParam);
break;
case WM_COMMAND:
{
HWND hWndButton = GetDlgItem(hWndDlg, LOWORD(wParam));
switch(LOWORD(wParam))
{
case IDC_INPUT_CONFIG_CANCEL:
EndDialog(hWndDlg, wParam);
break;
case IDC_INPUT_CONFIG_ACCEPT:
2003-04-15 08:08:53 +00:00
g_EmuShared->SetXBController(&g_XBController);
2003-04-01 08:16:06 +00:00
EndDialog(hWndDlg, wParam);
break;
2003-04-13 02:39:16 +00:00
case IDC_SET_LEFT_POSY:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_LTHUMBPOSY);
break;
2003-04-13 02:39:16 +00:00
case IDC_SET_LEFT_NEGY:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_LTHUMBNEGY);
break;
2003-04-13 02:39:16 +00:00
case IDC_SET_LEFT_POSX:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_LTHUMBPOSX);
break;
2003-04-13 02:39:16 +00:00
case IDC_SET_LEFT_NEGX:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_LTHUMBNEGX);
2003-04-13 02:39:16 +00:00
break;
case IDC_SET_RIGHT_POSY:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_RTHUMBPOSY);
2003-04-13 02:39:16 +00:00
break;
case IDC_SET_RIGHT_NEGY:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_RTHUMBNEGY);
2003-04-13 02:39:16 +00:00
break;
case IDC_SET_RIGHT_POSX:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_RTHUMBPOSX);
2003-04-13 02:39:16 +00:00
break;
case IDC_SET_RIGHT_NEGX:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_RTHUMBNEGX);
break;
case IDC_SET_X:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_X);
break;
case IDC_SET_Y:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_Y);
break;
case IDC_SET_A:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_A);
break;
case IDC_SET_B:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_B);
break;
case IDC_SET_WHITE:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_WHITE);
break;
case IDC_SET_BLACK:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_BLACK);
break;
case IDC_SET_LTRIGGER:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_LTRIGGER);
break;
case IDC_SET_RTRIGGER:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_RTRIGGER);
break;
case IDC_SET_DPAD_UP:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_DPADUP);
break;
case IDC_SET_DPAD_DOWN:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_DPADDOWN);
break;
case IDC_SET_DPAD_LEFT:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_DPADLEFT);
break;
case IDC_SET_DPAD_RIGHT:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_DPADRIGHT);
break;
case IDC_SET_BACK:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_BACK);
break;
case IDC_SET_START:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_START);
break;
case IDC_SET_LTHUMB:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_LTHUMB);
break;
case IDC_SET_RTHUMB:
2003-04-15 08:08:53 +00:00
ConfigureInput(hWndDlg, hWndButton, XBCTRL_OBJECT_RTHUMB);
break;
}
}
break;
}
return FALSE;
}
2003-03-30 06:30:19 +00:00
// ******************************************************************
// * ConfigureInput
// ******************************************************************
2003-04-15 08:08:53 +00:00
VOID ConfigureInput(HWND hWndDlg, HWND hWndButton, XBCtrlObject object)
2003-03-30 06:30:19 +00:00
{
2003-04-15 08:08:53 +00:00
static bConfigDone = true;
if(!bConfigDone)
2003-03-30 06:30:19 +00:00
return;
2003-04-04 03:31:43 +00:00
2003-04-15 08:08:53 +00:00
bConfigDone = false;
2003-03-30 06:30:19 +00:00
char szOrgText[32];
char szNewText[255] = "Recieved no user input, try again...";
SetWindowText(GetDlgItem(hWndDlg, IDC_CONFIG_STATUS), "Waiting for your input...");
GetWindowText(hWndButton, szOrgText, 32);
2003-04-15 08:08:53 +00:00
g_XBController.ConfigBegin(hWndDlg, object);
2003-04-04 03:31:43 +00:00
2003-03-30 06:30:19 +00:00
// ******************************************************************
// * Wait for input, or 5 second timeout
// ******************************************************************
2003-04-15 08:08:53 +00:00
for(int v=100;v>0;v--)
2003-03-30 06:30:19 +00:00
{
2003-04-15 08:08:53 +00:00
// ******************************************************************
// * Update the button text every second
// ******************************************************************
if(v%20 == 0)
2003-03-30 06:30:19 +00:00
{
2003-04-15 08:08:53 +00:00
char szBuffer[255];
2003-04-04 03:31:43 +00:00
2003-04-15 08:08:53 +00:00
sprintf(szBuffer, "%d", (v+19)/20);
2003-04-04 03:31:43 +00:00
2003-04-15 08:08:53 +00:00
SetWindowText(hWndButton, szBuffer);
}
2003-04-04 03:31:43 +00:00
2003-04-15 08:08:53 +00:00
if(g_XBController.GetError())
goto cleanup;
2003-04-04 03:31:43 +00:00
2003-04-15 08:08:53 +00:00
if(g_XBController.ConfigPoll(szNewText))
break;
2003-03-30 06:30:19 +00:00
2003-04-15 08:08:53 +00:00
Sleep(50);
2003-03-30 06:30:19 +00:00
}
2003-04-15 08:08:53 +00:00
if(g_XBController.GetError())
goto cleanup;
else
g_XBController.ConfigEnd();
2003-03-30 06:30:19 +00:00
2003-04-15 08:08:53 +00:00
cleanup:
2003-04-04 03:31:43 +00:00
// ******************************************************************
// * Update Window
// ******************************************************************
{
2003-04-15 08:08:53 +00:00
if(g_XBController.GetError())
2003-04-16 19:06:20 +00:00
sprintf(szNewText, "%s", g_XBController.GetError());
2003-04-15 08:08:53 +00:00
SetWindowText(hWndButton, szOrgText);
2003-04-04 03:31:43 +00:00
SetWindowText(GetDlgItem(hWndDlg, IDC_CONFIG_STATUS), szNewText);
MSG Msg;
while(PeekMessage(&Msg, hWndDlg, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE));
while(PeekMessage(&Msg, hWndDlg, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
}
2003-03-30 06:30:19 +00:00
2003-04-15 08:08:53 +00:00
bConfigDone = true;
2003-03-30 06:30:19 +00:00
}