From 22a05c5e38cfe5cba447caf7b5172f9774425163 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Mon, 12 Aug 2013 23:26:01 +0200 Subject: [PATCH] Preliminary relative mouse mapping. Disabled because it breaks the control mapping UI currently. Needs tweaking. --- Common/KeyMap.cpp | 4 +++- Windows/WindowsHost.cpp | 29 +++++++++++++++++++++++++++++ Windows/WindowsHost.h | 3 +++ Windows/WndMainWindow.cpp | 31 ++++++++++++++++++++++++------- native | 2 +- 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 46e17cf53d..d84f3056f0 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -424,7 +424,9 @@ const KeyMap_IntStrPair axis_names[] = { {JOYSTICK_AXIS_GAS, "Gas"}, {JOYSTICK_AXIS_BRAKE, "Brake"}, {JOYSTICK_AXIS_DISTANCE, "Distance"}, - {JOYSTICK_AXIS_TILT, "Tilt"} + {JOYSTICK_AXIS_TILT, "Tilt"}, + {JOYSTICK_AXIS_MOUSE_REL_X, "MouseDX"}, + {JOYSTICK_AXIS_MOUSE_REL_Y, "MouseDY"}, }; static std::string unknown_key_name = "??"; diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index d5b0324610..773a7867ce 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -15,6 +15,12 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include + +#include "base/NativeApp.h" +#include "input/input_state.h" +#include "input/keycodes.h" + #include "Core/Core.h" #include "Core/Config.h" #include "Core/CoreParameter.h" @@ -42,6 +48,9 @@ static PMixer *curMixer; +float mouseDeltaX = 0; +float mouseDeltaY = 0; + int MyMix(short *buffer, int numSamples, int bits, int rate, int channels) { if (curMixer && !Core_IsStepping()) @@ -62,6 +71,8 @@ WindowsHost::WindowsHost(HWND mainWindow, HWND displayWindow) { mainWindow_ = mainWindow; displayWindow_ = displayWindow; + mouseDeltaX = 0; + mouseDeltaY = 0; #define PUSH_BACK(Cls) do { list.push_back(std::shared_ptr(new Cls())); } while (0) @@ -172,6 +183,24 @@ void WindowsHost::PollControllers(InputState &input_state) if (device->UpdateState(input_state) == InputDevice::UPDATESTATE_SKIP_PAD) doPad = false; } + + mouseDeltaX *= 0.9f; + mouseDeltaY *= 0.9f; + + // TODO: Tweak! + float mx = std::max(-1.0f, std::min(1.0f, mouseDeltaX * 0.01f)); + float my = std::max(-1.0f, std::min(1.0f, mouseDeltaY * 0.01f)); + AxisInput axisX, axisY; + axisX.axisId = JOYSTICK_AXIS_MOUSE_REL_X; + axisX.deviceId = DEVICE_ID_MOUSE; + axisX.value = mx; + axisY.axisId = JOYSTICK_AXIS_MOUSE_REL_Y; + axisY.deviceId = DEVICE_ID_MOUSE; + axisY.value = my; + + // Disabled for now as it makes the mapping dialog unusable! + //if (fabsf(mx) > 0.1f) NativeAxis(axisX); + //if (fabsf(my) > 0.1f) NativeAxis(axisY); } void WindowsHost::BootDone() diff --git a/Windows/WindowsHost.h b/Windows/WindowsHost.h index 4d43671413..a64f568075 100644 --- a/Windows/WindowsHost.h +++ b/Windows/WindowsHost.h @@ -21,6 +21,9 @@ #include #include +extern float mouseDeltaX; +extern float mouseDeltaY; + class WindowsHost : public Host { public: diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 75966b9d7f..5f9fc46ef6 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -80,6 +80,13 @@ extern InputState input_state; #define CURSORUPDATE_INTERVAL_MS 50 #define CURSORUPDATE_MOVE_TIMESPAN_MS 500 +#ifndef HID_USAGE_PAGE_GENERIC +#define HID_USAGE_PAGE_GENERIC ((USHORT) 0x01) +#endif +#ifndef HID_USAGE_GENERIC_MOUSE +#define HID_USAGE_GENERIC_MOUSE ((USHORT) 0x02) +#endif + namespace MainWindow { HWND hwndMain; @@ -349,12 +356,17 @@ namespace MainWindow RegisterTouchWindow(hwndDisplay, TWF_WANTPALM); #endif - RAWINPUTDEVICE keyboard; - memset(&keyboard, 0, sizeof(keyboard)); - keyboard.usUsagePage = 1; - keyboard.usUsage = 6; - keyboard.dwFlags = 0; - RegisterRawInputDevices(&keyboard, 1, sizeof(RAWINPUTDEVICE)); + RAWINPUTDEVICE dev[2]; + memset(dev, 0, sizeof(dev)); + + dev[0].usUsagePage = 1; + dev[0].usUsage = 6; + dev[0].dwFlags = 0; + + dev[1].usUsagePage = HID_USAGE_PAGE_GENERIC; + dev[1].usUsage = HID_USAGE_GENERIC_MOUSE; + dev[1].dwFlags = 0; + RegisterRawInputDevices(dev, 2, sizeof(RAWINPUTDEVICE)); SetFocus(hwndDisplay); @@ -1057,7 +1069,6 @@ namespace MainWindow } GetRawInputData((HRAWINPUT)lParam, RID_INPUT, rawInputBuffer, &dwSize, sizeof(RAWINPUTHEADER)); RAWINPUT* raw = (RAWINPUT*)rawInputBuffer; - if (raw->header.dwType == RIM_TYPEKEYBOARD) { KeyInput key; key.deviceId = DEVICE_ID_KEYBOARD; @@ -1074,6 +1085,12 @@ namespace MainWindow NativeKey(key); } } + } else if (raw->header.dwType == RIM_TYPEMOUSE) { + mouseDeltaX += raw->data.mouse.lLastX; + mouseDeltaY += raw->data.mouse.lLastY; + + // TODO : Smooth and translate to an axis every frame. + // NativeAxis() } } return 0; diff --git a/native b/native index 46f7415bc9..76d0d5ceb3 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 46f7415bc99f89c508dd07aa02ac4452a7281465 +Subproject commit 76d0d5ceb38b6c50225a82501e88f96e503b2ee9