From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- .../DInput/DInputKeyboardMouse.cpp | 311 +++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp new file mode 100644 index 0000000000..850ff27281 --- /dev/null +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -0,0 +1,311 @@ + +#include "DInputKeyboardMouse.h" +#include "DInput.h" + + // (lower would be more sensitive) user can lower sensitivity by setting range + // seems decent here ( at 8 ), I don't think anyone would need more sensitive than this + // and user can lower it much farther than they would want to with the range +#define MOUSE_AXIS_SENSITIVITY 8 + + // if input hasn't been received for this many ms, mouse input will be skipped + // otherwise it is just some crazy value +#define DROP_INPUT_TIME 250 + +namespace ciface +{ +namespace DInput +{ + +static const struct +{ + const BYTE code; + const char* const name; +} named_keys[] = +{ +#include "NamedKeys.h" +}; + +static const struct +{ + const BYTE code; + const char* const name; +} named_lights[] = +{ + { VK_NUMLOCK, "NUM LOCK" }, + { VK_CAPITAL, "CAPS LOCK" }, + { VK_SCROLL, "SCROLL LOCK" } +}; + +// lil silly +static HWND hwnd; + +void InitKeyboardMouse(IDirectInput8* const idi8, std::vector& devices, HWND _hwnd) +{ + hwnd = _hwnd; + + // mouse and keyboard are a combined device, to allow shift+click and stuff + // if that's dumb, I will make a VirtualDevice class that just uses ranges of inputs/outputs from other devices + // so there can be a separated Keyboard and mouse, as well as combined KeyboardMouse + + LPDIRECTINPUTDEVICE8 kb_device = NULL; + LPDIRECTINPUTDEVICE8 mo_device = NULL; + + if (SUCCEEDED(idi8->CreateDevice( GUID_SysKeyboard, &kb_device, NULL))) + { + if (SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard))) + { + if (SUCCEEDED(kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) + { + if (SUCCEEDED(idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL ))) + { + if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2))) + { + if (SUCCEEDED(mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) + { + devices.push_back(new KeyboardMouse(kb_device, mo_device)); + return; + } + } + } + } + } + } + + if (kb_device) + kb_device->Release(); + if (mo_device) + mo_device->Release(); +} + +KeyboardMouse::~KeyboardMouse() +{ + // kb + m_kb_device->Unacquire(); + m_kb_device->Release(); + // mouse + m_mo_device->Unacquire(); + m_mo_device->Release(); +} + +KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device) + : m_kb_device(kb_device) + , m_mo_device(mo_device) +{ + m_kb_device->Acquire(); + m_mo_device->Acquire(); + + m_last_update = GetTickCount(); + + ZeroMemory(&m_state_in, sizeof(m_state_in)); + ZeroMemory(m_state_out, sizeof(m_state_out)); + ZeroMemory(&m_current_state_out, sizeof(m_current_state_out)); + + // KEYBOARD + // add keys + for (u8 i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i) + AddInput(new Key(i, m_state_in.keyboard[named_keys[i].code])); + // add lights + for (u8 i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i) + AddOutput(new Light(i)); + + // MOUSE + // get caps + DIDEVCAPS mouse_caps; + ZeroMemory( &mouse_caps, sizeof(mouse_caps) ); + mouse_caps.dwSize = sizeof(mouse_caps); + m_mo_device->GetCapabilities(&mouse_caps); + // mouse buttons + for (u8 i = 0; i < mouse_caps.dwButtons; ++i) + AddInput(new Button(i, m_state_in.mouse.rgbButtons[i])); + // mouse axes + for (unsigned int i = 0; i < mouse_caps.dwAxes; ++i) + { + const LONG& ax = (&m_state_in.mouse.lX)[i]; + + // each axis gets a negative and a positive input instance associated with it + AddInput(new Axis(i, ax, (2==i) ? -1 : -MOUSE_AXIS_SENSITIVITY)); + AddInput(new Axis(i, ax, -(2==i) ? 1 : MOUSE_AXIS_SENSITIVITY)); + } + // cursor, with a hax for-loop + for (unsigned int i=0; i<4; ++i) + AddInput(new Cursor(!!(i&2), (&m_state_in.cursor.x)[i/2], !!(i&1))); +} + +void GetMousePos(float* const x, float* const y) +{ + unsigned int win_width = 2, win_height = 2; + POINT point = { 1, 1 }; + GetCursorPos(&point); + // Get the cursor position relative to the upper left corner of the rendering window + ScreenToClient(hwnd, &point); + + // Get the size of the rendering window. (In my case Rect.top and Rect.left was zero.) + RECT rect; + GetClientRect(hwnd, &rect); + // Width and height is the size of the rendering window + win_width = rect.right - rect.left; + win_height = rect.bottom - rect.top; + + // Return the mouse position as a range from -1 to 1 + *x = (float)point.x / (float)win_width * 2 - 1; + *y = (float)point.y / (float)win_height * 2 - 1; +} + +bool KeyboardMouse::UpdateInput() +{ + DIMOUSESTATE2 tmp_mouse; + + // if mouse position hasn't been updated in a short while, skip a dev state + DWORD cur_time = GetTickCount(); + if (cur_time - m_last_update > DROP_INPUT_TIME) + { + // set axes to zero + ZeroMemory(&m_state_in.mouse, sizeof(m_state_in.mouse)); + // skip this input state + m_mo_device->GetDeviceState(sizeof(tmp_mouse), &tmp_mouse); + } + + m_last_update = cur_time; + + HRESULT kb_hr = m_kb_device->GetDeviceState(sizeof(m_state_in.keyboard), &m_state_in.keyboard); + HRESULT mo_hr = m_mo_device->GetDeviceState(sizeof(tmp_mouse), &tmp_mouse); + + if (DIERR_INPUTLOST == kb_hr || DIERR_NOTACQUIRED == kb_hr) + m_kb_device->Acquire(); + + if (DIERR_INPUTLOST == mo_hr || DIERR_NOTACQUIRED == mo_hr) + m_mo_device->Acquire(); + + if (SUCCEEDED(kb_hr) && SUCCEEDED(mo_hr)) + { + // need to smooth out the axes, otherwise it doesn't work for shit + for (unsigned int i = 0; i < 3; ++i) + ((&m_state_in.mouse.lX)[i] += (&tmp_mouse.lX)[i]) /= 2; + + // copy over the buttons + memcpy(m_state_in.mouse.rgbButtons, tmp_mouse.rgbButtons, sizeof(m_state_in.mouse.rgbButtons)); + + // update mouse cursor + GetMousePos(&m_state_in.cursor.x, &m_state_in.cursor.y); + + return true; + } + + return false; +} + +bool KeyboardMouse::UpdateOutput() +{ + class KInput : public INPUT + { + public: + KInput( const unsigned char key, const bool up = false ) + { + memset( this, 0, sizeof(*this) ); + type = INPUT_KEYBOARD; + ki.wVk = key; + + if (up) + ki.dwFlags = KEYEVENTF_KEYUP; + } + }; + + std::vector< KInput > kbinputs; + for (unsigned int i = 0; i < sizeof(m_state_out)/sizeof(*m_state_out); ++i) + { + bool want_on = false; + if (m_state_out[i]) + want_on = m_state_out[i] > GetTickCount() % 255 ; // light should flash when output is 0.5 + + // lights are set to their original state when output is zero + if (want_on ^ m_current_state_out[i]) + { + kbinputs.push_back(KInput(named_lights[i].code)); // press + kbinputs.push_back(KInput(named_lights[i].code, true)); // release + + m_current_state_out[i] ^= 1; + } + } + + if (kbinputs.size()) + return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) ); + else + return true; +} + +std::string KeyboardMouse::GetName() const +{ + return "Keyboard Mouse"; +} + +int KeyboardMouse::GetId() const +{ + // should this be -1, idk + return 0; +} + +std::string KeyboardMouse::GetSource() const +{ + return DINPUT_SOURCE_NAME; +} + +// names +std::string KeyboardMouse::Key::GetName() const +{ + return named_keys[m_index].name; +} + +std::string KeyboardMouse::Button::GetName() const +{ + return std::string("Click ") + char('0' + m_index); +} + +std::string KeyboardMouse::Axis::GetName() const +{ + static char tmpstr[] = "Axis .."; + tmpstr[5] = (char)('X' + m_index); + tmpstr[6] = (m_range<0 ? '-' : '+'); + return tmpstr; +} + +std::string KeyboardMouse::Cursor::GetName() const +{ + static char tmpstr[] = "Cursor .."; + tmpstr[7] = (char)('X' + m_index); + tmpstr[8] = (m_positive ? '+' : '-'); + return tmpstr; +} + +std::string KeyboardMouse::Light::GetName() const +{ + return named_lights[m_index].name; +} + +// get/set state +ControlState KeyboardMouse::Key::GetState() const +{ + return (m_key != 0); +} + +ControlState KeyboardMouse::Button::GetState() const +{ + return (m_button != 0); +} + +ControlState KeyboardMouse::Axis::GetState() const +{ + return std::max(0.0f, ControlState(m_axis) / m_range); +} + +ControlState KeyboardMouse::Cursor::GetState() const +{ + return std::max(0.0f, ControlState(m_axis) / (m_positive ? 1.0f : -1.0f)); +} + +void KeyboardMouse::Light::SetState(const ControlState state) +{ + //state_out[m_index] = (unsigned char)(state * 255); +} + +} +} -- cgit v1.2.3 From d91a5abba1d66948cc43cc7a6c80827ede061bc8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 30 Jan 2014 19:51:21 -0500 Subject: Light cleanup to a little bit of InputCommon. Replaces much of the iterators that litter this section of the codebase. Also clean up a little bit of the comments that describe the interface classes. --- .../ControllerInterface/DInput/DInputKeyboardMouse.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 850ff27281..50f065f92f 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -5,11 +5,11 @@ // (lower would be more sensitive) user can lower sensitivity by setting range // seems decent here ( at 8 ), I don't think anyone would need more sensitive than this // and user can lower it much farther than they would want to with the range -#define MOUSE_AXIS_SENSITIVITY 8 +#define MOUSE_AXIS_SENSITIVITY 8 // if input hasn't been received for this many ms, mouse input will be skipped // otherwise it is just some crazy value -#define DROP_INPUT_TIME 250 +#define DROP_INPUT_TIME 250 namespace ciface { @@ -18,8 +18,8 @@ namespace DInput static const struct { - const BYTE code; - const char* const name; + const BYTE code; + const char* const name; } named_keys[] = { #include "NamedKeys.h" @@ -27,8 +27,8 @@ static const struct static const struct { - const BYTE code; - const char* const name; + const BYTE code; + const char* const name; } named_lights[] = { { VK_NUMLOCK, "NUM LOCK" }, -- cgit v1.2.3 From d2038049f51192fbb55fbde2fc08128bacfb7707 Mon Sep 17 00:00:00 2001 From: lioncash Date: Mon, 10 Feb 2014 13:54:46 -0500 Subject: Replace all include guard ifdefs with "#pragma once" --- .../InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 50f065f92f..c79f4e3365 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -1,3 +1,6 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. #include "DInputKeyboardMouse.h" #include "DInput.h" -- cgit v1.2.3 From 3fd87a7636ff434118a5d7f7334550be8db55c0b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 16 Feb 2014 23:51:41 -0500 Subject: Second and final pass of clearing out tabs. --- .../InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index c79f4e3365..4b17574d7b 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -218,12 +218,12 @@ bool KeyboardMouse::UpdateOutput() { bool want_on = false; if (m_state_out[i]) - want_on = m_state_out[i] > GetTickCount() % 255 ; // light should flash when output is 0.5 + want_on = m_state_out[i] > GetTickCount() % 255 ; // light should flash when output is 0.5 // lights are set to their original state when output is zero if (want_on ^ m_current_state_out[i]) { - kbinputs.push_back(KInput(named_lights[i].code)); // press + kbinputs.push_back(KInput(named_lights[i].code)); // press kbinputs.push_back(KInput(named_lights[i].code, true)); // release m_current_state_out[i] ^= 1; -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- .../InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 4b17574d7b..fa036ced79 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -2,8 +2,9 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "DInputKeyboardMouse.h" -#include "DInput.h" +#include +#include "InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h" +#include "InputCommon/ControllerInterface/DInput/DInput.h" // (lower would be more sensitive) user can lower sensitivity by setting range // seems decent here ( at 8 ), I don't think anyone would need more sensitive than this @@ -25,7 +26,7 @@ static const struct const char* const name; } named_keys[] = { -#include "NamedKeys.h" +#include "InputCommon/ControllerInterface/DInput/NamedKeys.h" }; static const struct -- cgit v1.2.3 From 6847a0fc0c1699eb01fadd50cfaf76e4e34a02cb Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Wed, 19 Feb 2014 02:17:31 +0100 Subject: Fix more header sorting issues in InputCommon/ (now check-includes clean). --- .../InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index fa036ced79..c9dd9034fe 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -3,8 +3,9 @@ // Refer to the license.txt file included. #include -#include "InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h" + #include "InputCommon/ControllerInterface/DInput/DInput.h" +#include "InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h" // (lower would be more sensitive) user can lower sensitivity by setting range // seems decent here ( at 8 ), I don't think anyone would need more sensitive than this @@ -26,7 +27,7 @@ static const struct const char* const name; } named_keys[] = { -#include "InputCommon/ControllerInterface/DInput/NamedKeys.h" +#include "InputCommon/ControllerInterface/DInput/NamedKeys.h" // NOLINT }; static const struct -- cgit v1.2.3 From 315a8ba1c04bf8cffd9b04096be898ac462fa89e Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 23 Feb 2014 23:03:39 +0100 Subject: Various changes suggested by cppcheck - remove unused variables - reduce the scope where it makes sense - correct limits (did you know that strcat()'s last parameter does not include the \0 that is always added?) - set some free()'d pointers to NULL --- .../InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index c9dd9034fe..0cd55b448c 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -138,7 +138,6 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIREC void GetMousePos(float* const x, float* const y) { - unsigned int win_width = 2, win_height = 2; POINT point = { 1, 1 }; GetCursorPos(&point); // Get the cursor position relative to the upper left corner of the rendering window @@ -148,8 +147,8 @@ void GetMousePos(float* const x, float* const y) RECT rect; GetClientRect(hwnd, &rect); // Width and height is the size of the rendering window - win_width = rect.right - rect.left; - win_height = rect.bottom - rect.top; + unsigned int win_width = rect.right - rect.left; + unsigned int win_height = rect.bottom - rect.top; // Return the mouse position as a range from -1 to 1 *x = (float)point.x / (float)win_width * 2 - 1; -- cgit v1.2.3 From d802d392811be44d34ae9cd23f616db93e54c50f Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 9 Mar 2014 21:14:26 +0100 Subject: clang-modernize -use-nullptr and s/\bNULL\b/nullptr/g for *.cpp/h/mm files not compiled on my machine --- .../ControllerInterface/DInput/DInputKeyboardMouse.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 0cd55b448c..52960bbc3c 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -52,20 +52,20 @@ void InitKeyboardMouse(IDirectInput8* const idi8, std::vector& de // if that's dumb, I will make a VirtualDevice class that just uses ranges of inputs/outputs from other devices // so there can be a separated Keyboard and mouse, as well as combined KeyboardMouse - LPDIRECTINPUTDEVICE8 kb_device = NULL; - LPDIRECTINPUTDEVICE8 mo_device = NULL; + LPDIRECTINPUTDEVICE8 kb_device = nullptr; + LPDIRECTINPUTDEVICE8 mo_device = nullptr; - if (SUCCEEDED(idi8->CreateDevice( GUID_SysKeyboard, &kb_device, NULL))) + if (SUCCEEDED(idi8->CreateDevice( GUID_SysKeyboard, &kb_device, nullptr))) { if (SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard))) { - if (SUCCEEDED(kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) + if (SUCCEEDED(kb_device->SetCooperativeLevel(nullptr, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) { - if (SUCCEEDED(idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL ))) + if (SUCCEEDED(idi8->CreateDevice( GUID_SysMouse, &mo_device, nullptr ))) { if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2))) { - if (SUCCEEDED(mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) + if (SUCCEEDED(mo_device->SetCooperativeLevel(nullptr, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) { devices.push_back(new KeyboardMouse(kb_device, mo_device)); return; -- cgit v1.2.3 From 5adbc83453d14b23818442f545ceede0e4548196 Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Mon, 11 Aug 2014 13:43:26 -0400 Subject: Change ControlState typedef to double, and change all related floats/doubles to use it. Fixes an off by 1 issue related to double->float->double conversion, and eliminates numerous warnings. --- .../InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 52960bbc3c..d9728dcbac 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -298,12 +298,12 @@ ControlState KeyboardMouse::Button::GetState() const ControlState KeyboardMouse::Axis::GetState() const { - return std::max(0.0f, ControlState(m_axis) / m_range); + return std::max(0.0, ControlState(m_axis) / m_range); } ControlState KeyboardMouse::Cursor::GetState() const { - return std::max(0.0f, ControlState(m_axis) / (m_positive ? 1.0f : -1.0f)); + return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0)); } void KeyboardMouse::Light::SetState(const ControlState state) -- cgit v1.2.3 From e9cb629723bb0fabbad130c2a63b3cdbaaf8ba6a Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Sun, 9 Nov 2014 15:02:18 -0500 Subject: Fix some double->float conversions. --- .../InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index d9728dcbac..05f28c79ae 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -136,7 +136,7 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIREC AddInput(new Cursor(!!(i&2), (&m_state_in.cursor.x)[i/2], !!(i&1))); } -void GetMousePos(float* const x, float* const y) +void GetMousePos(ControlState* const x, ControlState* const y) { POINT point = { 1, 1 }; GetCursorPos(&point); @@ -151,8 +151,8 @@ void GetMousePos(float* const x, float* const y) unsigned int win_height = rect.bottom - rect.top; // Return the mouse position as a range from -1 to 1 - *x = (float)point.x / (float)win_width * 2 - 1; - *y = (float)point.y / (float)win_height * 2 - 1; + *x = (ControlState)point.x / (ControlState)win_width * 2 - 1; + *y = (ControlState)point.y / (ControlState)win_height * 2 - 1; } bool KeyboardMouse::UpdateInput() -- cgit v1.2.3 From 0c056c64118673ece8fefcc22fa64b78c5431ab6 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:35:29 -0800 Subject: DInput: Remove the unsupported Lights output The LEDs feature doesn't actually do anything: the SetState method is entirely commented out. --- .../DInput/DInputKeyboardMouse.cpp | 65 ---------------------- 1 file changed, 65 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 05f28c79ae..692826aebb 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -30,17 +30,6 @@ static const struct #include "InputCommon/ControllerInterface/DInput/NamedKeys.h" // NOLINT }; -static const struct -{ - const BYTE code; - const char* const name; -} named_lights[] = -{ - { VK_NUMLOCK, "NUM LOCK" }, - { VK_CAPITAL, "CAPS LOCK" }, - { VK_SCROLL, "SCROLL LOCK" } -}; - // lil silly static HWND hwnd; @@ -102,16 +91,11 @@ KeyboardMouse::KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIREC m_last_update = GetTickCount(); ZeroMemory(&m_state_in, sizeof(m_state_in)); - ZeroMemory(m_state_out, sizeof(m_state_out)); - ZeroMemory(&m_current_state_out, sizeof(m_current_state_out)); // KEYBOARD // add keys for (u8 i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i) AddInput(new Key(i, m_state_in.keyboard[named_keys[i].code])); - // add lights - for (u8 i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i) - AddOutput(new Light(i)); // MOUSE // get caps @@ -198,45 +182,6 @@ bool KeyboardMouse::UpdateInput() return false; } -bool KeyboardMouse::UpdateOutput() -{ - class KInput : public INPUT - { - public: - KInput( const unsigned char key, const bool up = false ) - { - memset( this, 0, sizeof(*this) ); - type = INPUT_KEYBOARD; - ki.wVk = key; - - if (up) - ki.dwFlags = KEYEVENTF_KEYUP; - } - }; - - std::vector< KInput > kbinputs; - for (unsigned int i = 0; i < sizeof(m_state_out)/sizeof(*m_state_out); ++i) - { - bool want_on = false; - if (m_state_out[i]) - want_on = m_state_out[i] > GetTickCount() % 255 ; // light should flash when output is 0.5 - - // lights are set to their original state when output is zero - if (want_on ^ m_current_state_out[i]) - { - kbinputs.push_back(KInput(named_lights[i].code)); // press - kbinputs.push_back(KInput(named_lights[i].code, true)); // release - - m_current_state_out[i] ^= 1; - } - } - - if (kbinputs.size()) - return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) ); - else - return true; -} - std::string KeyboardMouse::GetName() const { return "Keyboard Mouse"; @@ -280,11 +225,6 @@ std::string KeyboardMouse::Cursor::GetName() const return tmpstr; } -std::string KeyboardMouse::Light::GetName() const -{ - return named_lights[m_index].name; -} - // get/set state ControlState KeyboardMouse::Key::GetState() const { @@ -306,10 +246,5 @@ ControlState KeyboardMouse::Cursor::GetState() const return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0)); } -void KeyboardMouse::Light::SetState(const ControlState state) -{ - //state_out[m_index] = (unsigned char)(state * 255); -} - } } -- cgit v1.2.3 From f2787f620eebbbfb746f59cfbd0318210297061b Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:55:14 -0800 Subject: ControllerInterface: Make UpdateInput / UpdateOutput return void The return values here have never been checked, so it doesn't make sense to return a value to begin with. --- .../InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 692826aebb..c96e51a830 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -139,7 +139,7 @@ void GetMousePos(ControlState* const x, ControlState* const y) *y = (ControlState)point.y / (ControlState)win_height * 2 - 1; } -bool KeyboardMouse::UpdateInput() +void KeyboardMouse::UpdateInput() { DIMOUSESTATE2 tmp_mouse; @@ -175,11 +175,7 @@ bool KeyboardMouse::UpdateInput() // update mouse cursor GetMousePos(&m_state_in.cursor.x, &m_state_in.cursor.y); - - return true; } - - return false; } std::string KeyboardMouse::GetName() const -- cgit v1.2.3 From 9947324296d942897b5248bd5651cddbd9078751 Mon Sep 17 00:00:00 2001 From: skidau Date: Sat, 28 Mar 2015 11:38:14 +1100 Subject: Track the co-ordinates of the mouse relative to the pointed window instead of the original hwnd. --- .../ControllerInterface/DInput/DInputKeyboardMouse.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index c96e51a830..af4e3f0981 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -31,11 +31,11 @@ static const struct }; // lil silly -static HWND hwnd; +static HWND m_hwnd; void InitKeyboardMouse(IDirectInput8* const idi8, std::vector& devices, HWND _hwnd) { - hwnd = _hwnd; + m_hwnd = _hwnd; // mouse and keyboard are a combined device, to allow shift+click and stuff // if that's dumb, I will make a VirtualDevice class that just uses ranges of inputs/outputs from other devices @@ -124,10 +124,11 @@ void GetMousePos(ControlState* const x, ControlState* const y) { POINT point = { 1, 1 }; GetCursorPos(&point); - // Get the cursor position relative to the upper left corner of the rendering window + // Get the cursor position relative to the upper left corner of the current window (separate or render to main) + HWND hwnd = WindowFromPoint(point); ScreenToClient(hwnd, &point); - // Get the size of the rendering window. (In my case Rect.top and Rect.left was zero.) + // Get the size of the current window. (In my case Rect.top and Rect.left was zero.) RECT rect; GetClientRect(hwnd, &rect); // Width and height is the size of the rendering window -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- .../Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index af4e3f0981..3a7a4497e4 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -1,5 +1,5 @@ // Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. #include -- cgit v1.2.3 From 30ebb2459eb97ba544547183854775df8460b475 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:55:12 +0200 Subject: Set copyright year to when a file was created --- .../Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp index 3a7a4497e4..6db8a86a3a 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.cpp @@ -1,4 +1,4 @@ -// Copyright 2013 Dolphin Emulator Project +// Copyright 2010 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -- cgit v1.2.3