summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon
diff options
context:
space:
mode:
authorJohn Peterson <jpeterson57@gmail.com>2009-02-15 18:23:42 +0000
committerJohn Peterson <jpeterson57@gmail.com>2009-02-15 18:23:42 +0000
commita8e35e976acddc06eb316821d41d695d81421828 (patch)
tree2b5da453b223c7c8d21d684100f3ddadd65d0310 /Source/Core/InputCommon
parentc49f9695635fa4f947eb8f5082553ed2c07e89d6 (diff)
Emulated Wiimote: Added customizable controls for the Wiimote and the Nunchuck
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2259 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/InputCommon')
-rw-r--r--Source/Core/InputCommon/InputCommon.vcproj12
-rw-r--r--Source/Core/InputCommon/Src/Configuration.cpp42
-rw-r--r--Source/Core/InputCommon/Src/DirectInputBase.cpp194
-rw-r--r--Source/Core/InputCommon/Src/DirectInputBase.h58
-rw-r--r--Source/Core/InputCommon/Src/SDL.h31
5 files changed, 331 insertions, 6 deletions
diff --git a/Source/Core/InputCommon/InputCommon.vcproj b/Source/Core/InputCommon/InputCommon.vcproj
index 9693fa9d25..5449fac12d 100644
--- a/Source/Core/InputCommon/InputCommon.vcproj
+++ b/Source/Core/InputCommon/InputCommon.vcproj
@@ -153,7 +153,7 @@
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="4"
- CharacterSet="1"
+ CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
@@ -287,7 +287,7 @@
OutputDirectory="$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
ConfigurationType="4"
- CharacterSet="1"
+ CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
@@ -416,6 +416,14 @@
>
</File>
<File
+ RelativePath=".\Src\DirectInputBase.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Src\DirectInputBase.h"
+ >
+ </File>
+ <File
RelativePath=".\Src\Event.hpp"
>
</File>
diff --git a/Source/Core/InputCommon/Src/Configuration.cpp b/Source/Core/InputCommon/Src/Configuration.cpp
index cea2182a9e..20f5bae2af 100644
--- a/Source/Core/InputCommon/Src/Configuration.cpp
+++ b/Source/Core/InputCommon/Src/Configuration.cpp
@@ -33,6 +33,10 @@
//////////////////////////////////////////////////////////////////////////////////////////
// Include
// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
+#if defined HAVE_WX && HAVE_WX
+ #include <wx/wx.h>
+#endif
+
#include "SDL.h" // Local
////////////////////////////////////
@@ -197,11 +201,47 @@ std::vector<int> Square2Circle(int _x, int _y, int _pad, std::string SDiagonal,
vec.push_back(int_y);
// Debugging
- //m_frame->m_pStatusBar2->SetLabel(wxString::Format("%f %f %i", corner_circle_dist, Diagonal, Tmp));
+ //Console::Print("%f %f %i", corner_circle_dist, Diagonal, Tmp));
return vec;
}
/////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////
+// Windows Virtual Key Codes Names
+// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
+#ifdef _WIN32
+std::string VKToString(int keycode)
+{
+ // Default value
+ char KeyStr[64] = {0};
+ GetKeyNameText(MapVirtualKey(keycode, MAPVK_VK_TO_VSC) << 16, KeyStr, 64);
+ std::string KeyString = KeyStr;
+
+ switch(keycode)
+ {
+ // Give it some help with a few keys
+ case VK_END: return "END";
+ case VK_INSERT: return "INS";
+ case VK_DELETE: return "DEL";
+ case VK_PRIOR: return "PGUP";
+ case VK_NEXT: return "PGDN";
+
+ case VK_UP: return "UP";
+ case VK_DOWN: return "DOWN";
+ case VK_LEFT: return "LEFT";
+ case VK_RIGHT: return "RIGHT";
+
+ case VK_LSHIFT: return "LEFT SHIFT";
+ case VK_LCONTROL: return "LEFT CTRL";
+ case VK_RCONTROL: return "RIGHT CTRL";
+ case VK_LMENU: return "LEFT ALT";
+
+ default: return KeyString;
+ }
+}
+#endif
+/////////////////////////////////////////////////////////////////////
+
} \ No newline at end of file
diff --git a/Source/Core/InputCommon/Src/DirectInputBase.cpp b/Source/Core/InputCommon/Src/DirectInputBase.cpp
new file mode 100644
index 0000000000..9658a73b0f
--- /dev/null
+++ b/Source/Core/InputCommon/Src/DirectInputBase.cpp
@@ -0,0 +1,194 @@
+// Copyright (C) 2003-2008 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// 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 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official SVN repository and contact information can be found at
+// http://code.google.com/p/dolphin-emu/
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// Include
+// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
+#include "DirectInputBase.h"
+////////////////////////////////////
+
+
+DInput::DInput()
+ : g_pDI(NULL),
+ g_pKeyboard(NULL)
+{}
+
+
+DInput::~DInput()
+{
+ Free();
+}
+
+void DInput::DIKToString(unsigned int keycode, char *keyStr)
+{
+ switch(keycode) {
+ case DIK_RETURN:
+ sprintf(keyStr, "Enter");
+ break;
+ case DIK_UP:
+ sprintf(keyStr, "Up");
+ break;
+ case DIK_DOWN:
+ sprintf(keyStr, "Down");
+ break;
+ case DIK_LEFT:
+ sprintf(keyStr, "Left");
+ break;
+ case DIK_RIGHT:
+ sprintf(keyStr, "Right");
+ break;
+ case DIK_HOME:
+ strcpy(keyStr, "Home");
+ break;
+ case DIK_END:
+ strcpy(keyStr, "End");
+ break;
+ case DIK_INSERT:
+ strcpy(keyStr, "Ins");
+ break;
+ case DIK_DELETE:
+ strcpy(keyStr, "Del");
+ break;
+ case DIK_PGUP:
+ strcpy(keyStr, "PgUp");
+ break;
+ case DIK_PGDN:
+ strcpy(keyStr, "PgDn");
+ break;
+ case DIK_NUMPAD0:
+ strcpy(keyStr, "Num 0");
+ break;
+ case DIK_NUMPAD1:
+ strcpy(keyStr, "Num 1");
+ break;
+ case DIK_NUMPAD2:
+ strcpy(keyStr, "Num 2");
+ break;
+ case DIK_NUMPAD3:
+ strcpy(keyStr, "Num 3");
+ break;
+ case DIK_NUMPAD4:
+ strcpy(keyStr, "Num 4");
+ break;
+ case DIK_NUMPAD5:
+ strcpy(keyStr, "Num 5");
+ break;
+ case DIK_NUMPAD6:
+ strcpy(keyStr, "Num 6");
+ break;
+ case DIK_NUMPAD7:
+ strcpy(keyStr, "Num 7");
+ break;
+ case DIK_NUMPAD8:
+ strcpy(keyStr, "Num 8");
+ break;
+ case DIK_NUMPAD9:
+ strcpy(keyStr, "Num 9");
+ break;
+ case DIK_NUMPADSLASH:
+ strcpy(keyStr, "Num /");
+ break;
+ default:
+ GetKeyNameText(keycode << 16, keyStr, 64);
+ break;
+ }
+}
+
+HRESULT DInput::Init(HWND hWnd)
+{
+ HRESULT hr;
+ DWORD dwCoopFlags;
+ dwCoopFlags = DISCL_FOREGROUND | DISCL_NOWINKEY;
+
+ // Create a DInput object
+ if (FAILED(hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
+ IID_IDirectInput8, (VOID* *)&g_pDI, NULL)))
+ {
+ MessageBox(0, "Direct Input Create Failed", 0, MB_ICONERROR);
+ return(hr);
+ }
+
+ if (FAILED(hr = g_pDI->CreateDevice(GUID_SysKeyboard, &g_pKeyboard, NULL)))
+ {
+ MessageBox(0, "Couldn't access keyboard", 0, MB_ICONERROR);
+ Free();
+ return(hr);
+ }
+
+ g_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
+ g_pKeyboard->SetCooperativeLevel(hWnd, dwCoopFlags);
+ g_pKeyboard->Acquire();
+
+ return(S_OK);
+}
+
+void DInput::Free()
+{
+ if (g_pKeyboard)
+ {
+ g_pKeyboard->Unacquire();
+ g_pKeyboard->Release();
+ g_pKeyboard = 0;
+ }
+
+ if (g_pDI)
+ {
+ g_pDI->Release();
+ g_pDI = 0;
+ }
+}
+
+// Desc: Read the input device's state when in immediate mode and display it.
+HRESULT DInput::Read()
+{
+ HRESULT hr;
+
+ if (NULL == g_pKeyboard)
+ {
+ return(S_OK);
+ }
+
+ // Get the input's device state, and put the state in dims
+ ZeroMemory(diks, sizeof(diks));
+ hr = g_pKeyboard->GetDeviceState(sizeof(diks), diks);
+
+ //for (int i=0; i<256; i++)
+ // if (diks[i]) MessageBox(0,"DSFJDKSF|",0,0);
+ if (FAILED(hr))
+ {
+ // DirectInput may be telling us that the input stream has been
+ // interrupted. We aren't tracking any state between polls, so
+ // we don't have any special reset that needs to be done.
+ // We just re-acquire and try again.
+
+ // If input is lost then acquire and keep trying
+ hr = g_pKeyboard->Acquire();
+
+ while (hr == DIERR_INPUTLOST)
+ {
+ hr = g_pKeyboard->Acquire();
+ }
+
+ // hr may be DIERR_OTHERAPPHASPRIO or other errors. This
+ // may occur when the app is minimized or in the process of
+ // switching, so just try again later
+ return(S_OK);
+ }
+
+ return(S_OK);
+}
diff --git a/Source/Core/InputCommon/Src/DirectInputBase.h b/Source/Core/InputCommon/Src/DirectInputBase.h
new file mode 100644
index 0000000000..7e90048451
--- /dev/null
+++ b/Source/Core/InputCommon/Src/DirectInputBase.h
@@ -0,0 +1,58 @@
+// Copyright (C) 2003-2008 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// 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 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official SVN repository and contact information can be found at
+// http://code.google.com/p/dolphin-emu/
+
+#ifndef _DIRECTINPUTBASE_H
+#define _DIRECTINPUTBASE_H
+
+
+//////////////////////////////////////////////////////////////////////////////////////////
+// Include
+// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
+#include <windows.h> // System
+#include <stdio.h>
+
+#define DIRECTINPUT_VERSION 0x0800 // DirectInput
+#include <dinput.h>
+
+//#include "ConsoleWindow.h" // Common
+///////////////////////////////
+
+
+class DInput
+{
+ public:
+
+ DInput();
+ ~DInput();
+
+ static void DInput::DIKToString(unsigned int keycode, char *keyStr);
+
+ HRESULT Init(HWND hWnd);
+ void Free();
+ HRESULT Read();
+
+
+ BYTE diks[256]; // DirectInput keyboard state buffer
+
+ private:
+
+ LPDIRECTINPUT8 g_pDI; // The DirectInput object
+ LPDIRECTINPUTDEVICE8 g_pKeyboard; // The keyboard device
+};
+
+#endif
+
diff --git a/Source/Core/InputCommon/Src/SDL.h b/Source/Core/InputCommon/Src/SDL.h
index 649639d75d..9689f70741 100644
--- a/Source/Core/InputCommon/Src/SDL.h
+++ b/Source/Core/InputCommon/Src/SDL.h
@@ -38,10 +38,10 @@
#include <vector>
#include <cmath>
-#ifdef _WIN32 // UGLY HACK FIXME PLEAAAAAAASE
+#ifdef _WIN32
#include <SDL.h> // Externals
#else
-#include <SDL/SDL.h> // Externals
+#include <SDL/SDL.h>
#endif
#include "Common.h" // Common
@@ -171,15 +171,35 @@ struct PadAxis
int Tl; // Triggers
int Tr;
};
+struct PadWiimote
+{
+ int A;
+ int B;
+ int One;
+ int Two;
+ int P;
+ int M;
+ int H;
+ int L, R, U, D;
+ int Shake;
+};
+struct PadNunchuck
+{
+ int Z;
+ int C;
+ int L, R, U, D;
+ int Shake;
+};
struct CONTROLLER_STATE_NEW // GC PAD INFO/STATE
{
PadAxis Axis; // 6 Axes (Main, Sub, Triggers)
SDL_Joystick *joy; // SDL joystick device
};
-
struct CONTROLLER_MAPPING_NEW // GC PAD MAPPING
{
PadAxis Axis; // (See above)
+ PadWiimote Wm;
+ PadNunchuck Nc;
bool enabled; // Pad attached?
int DeadZoneL; // Analog 1 Deadzone
int DeadZoneR; // Analog 2 Deadzone
@@ -212,6 +232,11 @@ float SquareDistance(float deg);
bool IsDeadZone(float DeadZone, int x, int y);
std::vector<int> Square2Circle(int _x, int _y, int _pad, std::string SDiagonal, bool Circle2Square = false);
+// Input configuration
+#ifdef _WIN32
+ std::string VKToString(int keycode);
+#endif
+
#ifndef _SDL_MAIN_
extern int g_LastPad;
#endif