From a1e032338b4cc3228c1f3e27e0c26bebe1b98d99 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:44:05 +0000 Subject: [PATCH 01/58] init --- .../mapping/mouse/MouseKeyToAnyMapping.cpp | 47 +++++++++++++++++++ .../mapping/mouse/MouseKeyToAnyMapping.h | 20 ++++++++ .../mapping/mouse/MouseKeyToButtonMapping.cpp | 0 .../mapping/mouse/MouseKeyToButtonMapping.h | 0 4 files changed, 67 insertions(+) create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp new file mode 100644 index 000000000..bb9cbead9 --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp @@ -0,0 +1,47 @@ +#include "MouseKeyToAnyMapping.h" +#include "Context.h" + +#include "utils/StringHelper.h" +#include "window/gui/IconsFontAwesome4.h" + +namespace Ship { +KeyboardKeyToAnyMapping::MouseKeyToAnyMapping(MouseBtn button) // TODO: should it have separate device index? + : ControllerInputMapping(ShipDeviceIndex::Keyboard), mButton(button), mKeyPressed(false) { +} + +MouseKeyToAnyMapping::~MouseKeyToAnyMapping() { +} + +std::string MouseKeyToAnyMapping::GetPhysicalInputName() { + using MouseBtn; + switch (mButton) { + case LEFT: + return "Left"; + case MIDDLE: + return "Middle"; + case RIGHT: + return "Right"; + case BACKWARD: + return "Backward"; + case FORWARD: + return "Forward"; + } +} + +bool MouseKeyToAnyMapping::ProcessMouseEvent(bool isPressed, MouseBtn button) { + if (mButton != button) { + return false; + } + + mKeyPressed = isPressed; + return true; +} + +std::string MouseKeyToAnyMapping::GetPhysicalDeviceName() { + return "Mouse"; +} + +bool MouseKeyToAnyMapping::PhysicalDeviceIsConnected() { + return true; +} +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h new file mode 100644 index 000000000..ced08f017 --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h @@ -0,0 +1,20 @@ +#pragma once + +#include "controller/controldevice/controller/mapping/ControllerInputMapping.h" +#include "window/Window.h" + +namespace Ship { +class MouseKeyToAnyMapping : virtual public ControllerInputMapping { + public: + MouseKeyToAnyMapping(MouseBtn button); + ~MouseKeyToAnyMapping(); + std::string GetPhysicalInputName() override; + bool ProcessMouseEvent(bool isPressed, MouseBtn button); + std::string GetPhysicalDeviceName() override; + bool PhysicalDeviceIsConnected() override; + + protected: + MouseBtn mButton; + bool mKeyPressed; +}; +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h new file mode 100644 index 000000000..e69de29bb From c4650b6a20acb2e0389dfb69afaaff4c93e88525 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 11 Dec 2024 19:26:58 +0700 Subject: [PATCH 02/58] fix spelling --- .../controller/mapping/mouse/MouseKeyToAnyMapping.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp index bb9cbead9..48a2694a0 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp @@ -5,7 +5,7 @@ #include "window/gui/IconsFontAwesome4.h" namespace Ship { -KeyboardKeyToAnyMapping::MouseKeyToAnyMapping(MouseBtn button) // TODO: should it have separate device index? +MouseKeyToAnyMapping::MouseKeyToAnyMapping(MouseBtn button) // TODO: should it have separate device index? : ControllerInputMapping(ShipDeviceIndex::Keyboard), mButton(button), mKeyPressed(false) { } From 62a8f515475689f124cd6a6d7076de8d9d61f88a Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 11 Dec 2024 22:10:25 +0700 Subject: [PATCH 03/58] mose key to button mapping --- src/controller/controldeck/ControlDeck.cpp | 18 +++++++ src/controller/controldeck/ControlDeck.h | 3 ++ .../controldevice/controller/Controller.cpp | 11 ++++ .../controldevice/controller/Controller.h | 1 + .../controller/mapping/ControllerMapping.h | 3 +- .../mapping/mouse/MouseKeyToAnyMapping.cpp | 15 +++--- .../mapping/mouse/MouseKeyToButtonMapping.cpp | 52 +++++++++++++++++++ .../mapping/mouse/MouseKeyToButtonMapping.h | 14 +++++ src/controller/deviceindex/ShipDeviceIndex.h | 1 + 9 files changed, 109 insertions(+), 9 deletions(-) diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index fbb79fc69..ddddfc30f 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -51,6 +51,19 @@ bool ControlDeck::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancod return result; } +bool ControlDeck::ProcessMouseEvent(bool isPressed, MouseBtn button) { + bool result = false; + for (auto port : mPorts) { + auto controller = port->GetConnectedController(); + + if (controller != nullptr) { + result = controller->ProcessMouseEvent(isPressed, button) || result; + } + } + + return result; +} + bool ControlDeck::AllGameInputBlocked() { return !mGameInputBlockers.empty(); } @@ -66,6 +79,11 @@ bool ControlDeck::KeyboardGameInputBlocked() { return AllGameInputBlocked() || ImGui::GetIO().WantCaptureKeyboard; } +bool ControlDeck::MouseGameInputBlocked() { + // block mouse input when mouse capture (hidden & window-focused mouse) mode disabled + return AllGameInputBlocked() || !Context::GetInstance()->GetWindow()->IsMouseCaptured(); +} + std::shared_ptr ControlDeck::GetControllerByPort(uint8_t port) { return mPorts[port]->GetConnectedController(); } diff --git a/src/controller/controldeck/ControlDeck.h b/src/controller/controldeck/ControlDeck.h index f54675eff..65e9572e6 100644 --- a/src/controller/controldeck/ControlDeck.h +++ b/src/controller/controldeck/ControlDeck.h @@ -21,9 +21,12 @@ class ControlDeck { void UnblockGameInput(int32_t blockId); bool GamepadGameInputBlocked(); bool KeyboardGameInputBlocked(); + bool MouseGameInputBlocked(); void SetSinglePlayerMappingMode(bool singlePlayer); bool IsSinglePlayerMappingMode(); bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode); + bool ProcessMouseEvent(bool isPressed, MouseBtn button); + std::shared_ptr GetDeviceIndexMappingManager(); protected: diff --git a/src/controller/controldevice/controller/Controller.cpp b/src/controller/controldevice/controller/Controller.cpp index 217f7673e..428279fba 100644 --- a/src/controller/controldevice/controller/Controller.cpp +++ b/src/controller/controldevice/controller/Controller.cpp @@ -9,6 +9,7 @@ #endif #include #include "utils/StringHelper.h" +#include "window/Window.h" #define M_TAU 6.2831853071795864769252867665590057 // 2 * pi #define MINIMUM_RADIUS_TO_MAP_NOTCH 0.9 @@ -136,6 +137,16 @@ bool Controller::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode return result; } +bool Controller::ProcessMouseEvent(bool isPressed, MouseBtn button) { + bool result = false; + for (auto [bitmask, button] : GetAllButtons()) { + result = button->ProcessMouseEvent(isPressed, button) || result; + } + result = GetLeftStick()->ProcessMouseEvent(isPressed, button) || result; + result = GetRightStick()->ProcessMouseEvent(isPressed, button) || result; + return result; +} + bool Controller::HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex) { for (auto [bitmask, button] : GetAllButtons()) { if (button->HasMappingsForShipDeviceIndex(lusIndex)) { diff --git a/src/controller/controldevice/controller/Controller.h b/src/controller/controldevice/controller/Controller.h index f963b6c68..409899bf2 100644 --- a/src/controller/controldevice/controller/Controller.h +++ b/src/controller/controldevice/controller/Controller.h @@ -49,6 +49,7 @@ class Controller : public ControlDevice { std::vector> GetAllMappings(); bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode); + bool ProcessMouseEvent(bool isPressed, MouseBtn button); bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); void MoveMappingsToDifferentController(std::shared_ptr newController, ShipDeviceIndex lusIndex); diff --git a/src/controller/controldevice/controller/mapping/ControllerMapping.h b/src/controller/controldevice/controller/mapping/ControllerMapping.h index c594e0123..c827e372a 100644 --- a/src/controller/controldevice/controller/mapping/ControllerMapping.h +++ b/src/controller/controldevice/controller/mapping/ControllerMapping.h @@ -7,7 +7,8 @@ namespace Ship { #define MAPPING_TYPE_GAMEPAD 0 #define MAPPING_TYPE_KEYBOARD 1 -#define MAPPING_TYPE_UNKNOWN 2 +#define MAPPING_TYPE_MOUSE 2 +#define MAPPING_TYPE_UNKNOWN 3 class ControllerMapping { public: diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp index 48a2694a0..3c67d2973 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp @@ -5,25 +5,24 @@ #include "window/gui/IconsFontAwesome4.h" namespace Ship { -MouseKeyToAnyMapping::MouseKeyToAnyMapping(MouseBtn button) // TODO: should it have separate device index? - : ControllerInputMapping(ShipDeviceIndex::Keyboard), mButton(button), mKeyPressed(false) { +MouseKeyToAnyMapping::MouseKeyToAnyMapping(MouseBtn button) + : ControllerInputMapping(ShipDeviceIndex::Mouse), mButton(button), mKeyPressed(false) { } MouseKeyToAnyMapping::~MouseKeyToAnyMapping() { } std::string MouseKeyToAnyMapping::GetPhysicalInputName() { - using MouseBtn; switch (mButton) { - case LEFT: + case MouseBtn::LEFT: return "Left"; - case MIDDLE: + case MouseBtn::MIDDLE: return "Middle"; - case RIGHT: + case MouseBtn::RIGHT: return "Right"; - case BACKWARD: + case MouseBtn::BACKWARD: return "Backward"; - case FORWARD: + case MouseBtn::FORWARD: return "Forward"; } } diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp index e69de29bb..df48d7fca 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp @@ -0,0 +1,52 @@ +#include "MouseKeyToButtonMapping.h" +#include +#include "utils/StringHelper.h" +#include "public/bridge/consolevariablebridge.h" +#include "Context.h" + +namespace Ship { +MouseKeyToButtonMapping::MouseKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, + MouseBtn button) + : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(scancode), // TODO: device index? + ControllerButtonMapping(ShipDeviceIndex::Mouse, portIndex, bitmask) { +} + +void MouseKeyToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) { + if (Context::GetInstance()->GetControlDeck()->MouseGameInputBlocked()) { + return; + } + + if (!mKeyPressed) { + return; + } + + padButtons |= mBitmask; +} + +uint8_t MouseKeyToButtonMapping::GetMappingType() { + return MAPPING_TYPE_MOUSE; +} + +std::string MouseKeyToButtonMapping::GetButtonMappingId() { + return StringHelper::Sprintf("P%d-B%d-MOUSE%d", mPortIndex, mBitmask, mButton); +} + +void MouseKeyToButtonMapping::SaveToConfig() { + const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".ButtonMappings." + GetButtonMappingId(); + CVarSetString(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str(), + "MouseKeyToButtonMapping"); + CVarSetInteger(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str(), mBitmask); + CVarSetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), mButton); + CVarSave(); +} + +void MouseKeyToButtonMapping::EraseFromConfig() { + const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".ButtonMappings." + GetButtonMappingId(); + + CVarClear(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str()); + + CVarSave(); +} +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h index e69de29bb..59d0b3a4b 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h @@ -0,0 +1,14 @@ +#include "controller/controldevice/controller/mapping/ControllerButtonMapping.h" +#include "MouseKeyToAnyMapping.h" + +namespace Ship { +class MouseKeyToButtonMapping final : public MouseKeyToAnyMapping, public ControllerButtonMapping { + public: + MouseKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button); + void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override; + uint8_t GetMappingType() override; + std::string GetButtonMappingId() override; + void SaveToConfig() override; + void EraseFromConfig() override; +}; +} // namespace Ship diff --git a/src/controller/deviceindex/ShipDeviceIndex.h b/src/controller/deviceindex/ShipDeviceIndex.h index f22cbfee2..6280ed405 100644 --- a/src/controller/deviceindex/ShipDeviceIndex.h +++ b/src/controller/deviceindex/ShipDeviceIndex.h @@ -3,6 +3,7 @@ namespace Ship { #define SHIPDK_DEVICE_INDEX_VALUES \ + X(Mouse, -2) \ X(Keyboard, -1) \ X(Blue, 0) \ X(Red, 1) \ From 67c92c30ca3aca307bcfab1446a0d6ceddc2d07c Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Fri, 13 Dec 2024 22:46:12 +0700 Subject: [PATCH 04/58] more button mouse mapping --- .../controller/ControllerButton.cpp | 29 ++++++++++++++++++- .../controller/ControllerButton.h | 3 ++ src/window/Window.h | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index 7fc139874..a76aee16b 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -3,7 +3,9 @@ #include "controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h" +#include "controller/controldevice/controller/mapping/keyboard/MouseKeyToButtonMapping.h" +#include "window/Window.h" #include "public/bridge/consolevariablebridge.h" #include "utils/StringHelper.h" #include @@ -12,7 +14,7 @@ namespace Ship { ControllerButton::ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) : mPortIndex(portIndex), mBitmask(bitmask), mUseKeydownEventToCreateNewMapping(false), - mKeyboardScancodeForNewMapping(LUS_KB_UNKNOWN) { + mKeyboardScancodeForNewMapping(LUS_KB_UNKNOWN), mMouseButtonForNewMapping(MouseBtn::MOUSE_BTN_UNKNOWN) { } ControllerButton::~ControllerButton() { @@ -180,6 +182,11 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); } + // FIXME: click cancel button with mouse might trigger binding (yeah) + if (mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { + mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); + } + if (mapping == nullptr) { mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask); } @@ -189,6 +196,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi } mKeyboardScancodeForNewMapping = LUS_KB_UNKNOWN; + mMouseButtonForNewMapping = MouseBtn::MOUSE_BTN_UNKNOWN; mUseKeydownEventToCreateNewMapping = false; if (id != "") { @@ -228,6 +236,25 @@ bool ControllerButton::ProcessKeyboardEvent(KbEventType eventType, KbScancode sc return result; } +bool ControllerButton::ProcessMouseEvent(bool isPressed, MouseBtn button) { + if (mUseKeydownEventToCreateNewMapping && isPressed) { + mMouseButtonForNewMapping = button; + return true; + } + + bool result = false; + for (auto [id, mapping] : GetAllButtonMappings()) { + if (mapping->GetMappingType() == MAPPING_TYPE_MOUSE) { + std::shared_ptr mtobMapping = + std::dynamic_pointer_cast(mapping); + if (mtobMapping != nullptr) { + result = result || mtobMapping->ProcessMouseEvent(isPressed, button); + } + } + } + return result; +} + void ControllerButton::AddDefaultMappings(ShipDeviceIndex shipDeviceIndex) { for (auto mapping : ButtonMappingFactory::CreateDefaultSDLButtonMappings(shipDeviceIndex, mPortIndex, mBitmask)) { AddButtonMapping(mapping); diff --git a/src/controller/controldevice/controller/ControllerButton.h b/src/controller/controldevice/controller/ControllerButton.h index dc9e967cd..610c0a7c3 100644 --- a/src/controller/controldevice/controller/ControllerButton.h +++ b/src/controller/controldevice/controller/ControllerButton.h @@ -6,6 +6,7 @@ #include #include "libultraship/libultra/controller.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" +#include "window/Window.h" namespace Ship { @@ -37,6 +38,7 @@ class ControllerButton { void UpdatePad(CONTROLLERBUTTONS_T& padButtons); bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode); + bool ProcessMouseEvent(bool isPressed, MouseBtn button); bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); @@ -48,5 +50,6 @@ class ControllerButton { bool mUseKeydownEventToCreateNewMapping; KbScancode mKeyboardScancodeForNewMapping; + MouseBtn mMouseButtonForNewMapping; }; } // namespace Ship diff --git a/src/window/Window.h b/src/window/Window.h index 5da4c3c7d..866d4e3cd 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -11,7 +11,7 @@ namespace Ship { enum class WindowBackend { FAST3D_DXGI_DX11, FAST3D_SDL_OPENGL, FAST3D_SDL_METAL, WINDOW_BACKEND_COUNT }; -enum class MouseBtn { LEFT, MIDDLE, RIGHT, BACKWARD, FORWARD, MOUSE_BTN_COUNT }; +enum class MouseBtn { MOUSE_BTN_UNKNOWN = -1, LEFT, MIDDLE, RIGHT, BACKWARD, FORWARD, MOUSE_BTN_COUNT }; struct Coords { int32_t x; From 1c2a495e26fea5281d24d9a70146425cf07341f3 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Sat, 14 Dec 2024 17:08:28 +0700 Subject: [PATCH 05/58] separate file for mouse things cause Ive got recursive include problem --- src/graphic/Fast3D/gfx_opengl.cpp | 1 - src/window/MouseMeta.h | 16 ++++++++++++++++ src/window/Window.h | 3 +-- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/window/MouseMeta.h diff --git a/src/graphic/Fast3D/gfx_opengl.cpp b/src/graphic/Fast3D/gfx_opengl.cpp index fd6545164..a29c6508c 100644 --- a/src/graphic/Fast3D/gfx_opengl.cpp +++ b/src/graphic/Fast3D/gfx_opengl.cpp @@ -42,7 +42,6 @@ #include "gfx_cc.h" #include "gfx_rendering_api.h" #include "window/gui/Gui.h" -#include "window/Window.h" #include "gfx_pc.h" #include diff --git a/src/window/MouseMeta.h b/src/window/MouseMeta.h new file mode 100644 index 000000000..2b326d223 --- /dev/null +++ b/src/window/MouseMeta.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace Ship { +enum class MouseBtn { LEFT, MIDDLE, RIGHT, BACKWARD, FORWARD, MOUSE_BTN_COUNT, MOUSE_BTN_UNKNOWN }; +static std::string mouseBtnNames[7] = { + "MouseLeft", + "MouseMiddle", + "MouseRight", + "MouseBackward", + "MouseForward", + "MOUSE_BTN_COUNT", + "MOUSE_BTN_UNKNOWN" +}; +} // namespace Ship diff --git a/src/window/Window.h b/src/window/Window.h index 866d4e3cd..7f7a818af 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -7,12 +7,11 @@ #include #include #include "window/gui/Gui.h" +#include "window/MouseMeta.h" namespace Ship { enum class WindowBackend { FAST3D_DXGI_DX11, FAST3D_SDL_OPENGL, FAST3D_SDL_METAL, WINDOW_BACKEND_COUNT }; -enum class MouseBtn { MOUSE_BTN_UNKNOWN = -1, LEFT, MIDDLE, RIGHT, BACKWARD, FORWARD, MOUSE_BTN_COUNT }; - struct Coords { int32_t x; int32_t y; From ed62652a0b4633e48a88a421429e2963e742b5df Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Sat, 14 Dec 2024 17:12:50 +0700 Subject: [PATCH 06/58] some fixes --- src/controller/controldeck/ControlDeck.h | 1 + .../controldevice/controller/Controller.cpp | 10 +++++----- .../controldevice/controller/Controller.h | 1 + .../controldevice/controller/ControllerButton.cpp | 3 +-- .../controldevice/controller/ControllerButton.h | 4 ++-- .../mapping/mouse/MouseKeyToAnyMapping.cpp | 13 +------------ .../controller/mapping/mouse/MouseKeyToAnyMapping.h | 2 +- .../mapping/mouse/MouseKeyToButtonMapping.cpp | 4 ++-- .../mapping/mouse/MouseKeyToButtonMapping.h | 3 +++ src/graphic/Fast3D/Fast3dWindow.h | 1 + 10 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/controller/controldeck/ControlDeck.h b/src/controller/controldeck/ControlDeck.h index 65e9572e6..8ff1a6098 100644 --- a/src/controller/controldeck/ControlDeck.h +++ b/src/controller/controldeck/ControlDeck.h @@ -5,6 +5,7 @@ #include #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" #include "controller/deviceindex/ShipDeviceIndexMappingManager.h" +#include "window/MouseMeta.h" namespace Ship { diff --git a/src/controller/controldevice/controller/Controller.cpp b/src/controller/controldevice/controller/Controller.cpp index 428279fba..edd7e3933 100644 --- a/src/controller/controldevice/controller/Controller.cpp +++ b/src/controller/controldevice/controller/Controller.cpp @@ -9,7 +9,6 @@ #endif #include #include "utils/StringHelper.h" -#include "window/Window.h" #define M_TAU 6.2831853071795864769252867665590057 // 2 * pi #define MINIMUM_RADIUS_TO_MAP_NOTCH 0.9 @@ -137,13 +136,14 @@ bool Controller::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode return result; } -bool Controller::ProcessMouseEvent(bool isPressed, MouseBtn button) { +bool Controller::ProcessMouseEvent(bool isPressed, MouseBtn mouseButton) { bool result = false; for (auto [bitmask, button] : GetAllButtons()) { - result = button->ProcessMouseEvent(isPressed, button) || result; + result = button->ProcessMouseEvent(isPressed, mouseButton) || result; } - result = GetLeftStick()->ProcessMouseEvent(isPressed, button) || result; - result = GetRightStick()->ProcessMouseEvent(isPressed, button) || result; + // FIXME: implement + // result = GetLeftStick()->ProcessMouseEvent(isPressed, mouseButton) || result; + // result = GetRightStick()->ProcessMouseEvent(isPressed, mouseButton) || result; return result; } diff --git a/src/controller/controldevice/controller/Controller.h b/src/controller/controldevice/controller/Controller.h index 409899bf2..92e764944 100644 --- a/src/controller/controldevice/controller/Controller.h +++ b/src/controller/controldevice/controller/Controller.h @@ -17,6 +17,7 @@ #include "ControllerLED.h" #include "controller/controldevice/ControlDevice.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" +#include "window/MouseMeta.h" namespace Ship { diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index a76aee16b..cfbcd9322 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -3,9 +3,8 @@ #include "controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h" -#include "controller/controldevice/controller/mapping/keyboard/MouseKeyToButtonMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h" -#include "window/Window.h" #include "public/bridge/consolevariablebridge.h" #include "utils/StringHelper.h" #include diff --git a/src/controller/controldevice/controller/ControllerButton.h b/src/controller/controldevice/controller/ControllerButton.h index 610c0a7c3..b5dd1e8f6 100644 --- a/src/controller/controldevice/controller/ControllerButton.h +++ b/src/controller/controldevice/controller/ControllerButton.h @@ -6,7 +6,7 @@ #include #include "libultraship/libultra/controller.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" -#include "window/Window.h" +#include "window/MouseMeta.h" namespace Ship { @@ -38,7 +38,7 @@ class ControllerButton { void UpdatePad(CONTROLLERBUTTONS_T& padButtons); bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode); - bool ProcessMouseEvent(bool isPressed, MouseBtn button); + bool ProcessMouseEvent(bool isPressed, Ship::MouseBtn button); bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp index 3c67d2973..98afda036 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp @@ -13,18 +13,7 @@ MouseKeyToAnyMapping::~MouseKeyToAnyMapping() { } std::string MouseKeyToAnyMapping::GetPhysicalInputName() { - switch (mButton) { - case MouseBtn::LEFT: - return "Left"; - case MouseBtn::MIDDLE: - return "Middle"; - case MouseBtn::RIGHT: - return "Right"; - case MouseBtn::BACKWARD: - return "Backward"; - case MouseBtn::FORWARD: - return "Forward"; - } + return mouseBtnNames[static_cast(mButton)]; } bool MouseKeyToAnyMapping::ProcessMouseEvent(bool isPressed, MouseBtn button) { diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h index ced08f017..16ff28c87 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h @@ -1,7 +1,7 @@ #pragma once #include "controller/controldevice/controller/mapping/ControllerInputMapping.h" -#include "window/Window.h" +#include "window/MouseMeta.h" namespace Ship { class MouseKeyToAnyMapping : virtual public ControllerInputMapping { diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp index df48d7fca..09ef06599 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp @@ -7,7 +7,7 @@ namespace Ship { MouseKeyToButtonMapping::MouseKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button) - : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(scancode), // TODO: device index? + : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button), ControllerButtonMapping(ShipDeviceIndex::Mouse, portIndex, bitmask) { } @@ -36,7 +36,7 @@ void MouseKeyToButtonMapping::SaveToConfig() { CVarSetString(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str(), "MouseKeyToButtonMapping"); CVarSetInteger(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str(), mBitmask); - CVarSetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), mButton); + CVarSetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), static_cast(mButton)); CVarSave(); } diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h index 59d0b3a4b..cb91ec464 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h @@ -1,5 +1,8 @@ +#pragma once + #include "controller/controldevice/controller/mapping/ControllerButtonMapping.h" #include "MouseKeyToAnyMapping.h" +#include "window/MouseMeta.h" namespace Ship { class MouseKeyToButtonMapping final : public MouseKeyToAnyMapping, public ControllerButtonMapping { diff --git a/src/graphic/Fast3D/Fast3dWindow.h b/src/graphic/Fast3D/Fast3dWindow.h index 4c3e84b1e..ba587926a 100644 --- a/src/graphic/Fast3D/Fast3dWindow.h +++ b/src/graphic/Fast3D/Fast3dWindow.h @@ -3,6 +3,7 @@ #include "graphic/Fast3D/gfx_window_manager_api.h" #include "graphic/Fast3D/gfx_rendering_api.h" #include "public/bridge/gfxbridge.h" +#include "window/MouseMeta.h" namespace Fast { class Fast3dWindow : public Ship::Window { From 68601285466dfa3bbe3da24eeb95413c53780af8 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Sun, 15 Dec 2024 20:31:51 +0700 Subject: [PATCH 07/58] updating dxgi mouse capture now compatible with sdl one --- src/graphic/Fast3D/gfx_dxgi.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index 250a9279f..f2c9caf07 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -550,14 +550,29 @@ static bool gfx_dxgi_get_mouse_state(uint32_t btn) { static void gfx_dxgi_set_mouse_capture(bool capture) { if (capture) { + RECT rect; + rect.left = dxgi.posX + 1; + rect.top = dxgi.posY + 1; + rect.right = dxgi.posX + dxgi.current_width - 1; + rect.bottom = dxgi.posY + dxgi.current_height - 1; + ClipCursor(&rect); + ShowCursor(FALSE); SetCapture(dxgi.h_wnd); } else { + ClipCursor(nullptr); + ShowCursor(TRUE); ReleaseCapture(); } } static bool gfx_dxgi_is_mouse_captured() { - return (GetCapture() != NULL); + CURSORINFO ci; + ci.cbSize = sizeof(ci); + if (!GetCursorInfo(&ci)) { + fprintf(stderr, "Error: failed to fetch cursor info\n"); + return false; + } + return (ci.flags > 0); // if cursor not showing } static void gfx_dxgi_set_fullscreen(bool enable) { From 8d0465e467f610e9924aacc50d75747aba7346cb Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Sun, 15 Dec 2024 21:21:50 +0700 Subject: [PATCH 08/58] fix --- src/graphic/Fast3D/gfx_dxgi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index f2c9caf07..fca64591c 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -572,7 +572,7 @@ static bool gfx_dxgi_is_mouse_captured() { fprintf(stderr, "Error: failed to fetch cursor info\n"); return false; } - return (ci.flags > 0); // if cursor not showing + return (ci.flags != 1); // if cursor not showing } static void gfx_dxgi_set_fullscreen(bool enable) { From fc096dc09545aca21a7322ee1c5228e2bed4e797 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Sun, 15 Dec 2024 22:40:59 +0700 Subject: [PATCH 09/58] fix mouse capture clip missing after alt+tab --- src/graphic/Fast3D/gfx_dxgi.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index fca64591c..a4d809c3b 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -91,6 +91,7 @@ static struct { bool mouse_pressed[5]; float mouse_wheel[2]; LARGE_INTEGER previous_present_time; + bool is_mouse_captured; void (*on_fullscreen_changed)(bool is_now_fullscreen); bool (*on_key_down)(int scancode); @@ -306,6 +307,15 @@ static void gfx_dxgi_close() { dxgi.is_running = false; } +static void apply_mouse_capture_clip() { + RECT rect; + rect.left = dxgi.posX + 1; + rect.top = dxgi.posY + 1; + rect.right = dxgi.posX + dxgi.current_width - 1; + rect.bottom = dxgi.posY + dxgi.current_height - 1; + ClipCursor(&rect); +} + static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_param, LPARAM l_param) { char fileName[256]; Ship::WindowEvent event_impl; @@ -404,6 +414,11 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par dxgi.h_Monitor); GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); break; + case WM_SETFOCUS: + if (dxgi.is_mouse_captured) { + apply_mouse_capture_clip(); + } + break; default: return DefWindowProcW(h_wnd, message, w_param, l_param); } @@ -550,12 +565,7 @@ static bool gfx_dxgi_get_mouse_state(uint32_t btn) { static void gfx_dxgi_set_mouse_capture(bool capture) { if (capture) { - RECT rect; - rect.left = dxgi.posX + 1; - rect.top = dxgi.posY + 1; - rect.right = dxgi.posX + dxgi.current_width - 1; - rect.bottom = dxgi.posY + dxgi.current_height - 1; - ClipCursor(&rect); + apply_mouse_capture_clip(); ShowCursor(FALSE); SetCapture(dxgi.h_wnd); } else { @@ -563,16 +573,11 @@ static void gfx_dxgi_set_mouse_capture(bool capture) { ShowCursor(TRUE); ReleaseCapture(); } + dxgi.is_mouse_captured = capture; } static bool gfx_dxgi_is_mouse_captured() { - CURSORINFO ci; - ci.cbSize = sizeof(ci); - if (!GetCursorInfo(&ci)) { - fprintf(stderr, "Error: failed to fetch cursor info\n"); - return false; - } - return (ci.flags != 1); // if cursor not showing + return dxgi.is_mouse_captured; } static void gfx_dxgi_set_fullscreen(bool enable) { From b0f724660523933aa10e83a90ffad57c3d94415e Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 17 Dec 2024 20:50:43 +0700 Subject: [PATCH 10/58] mouse binding & gui conflict check --- .../controldevice/controller/ControllerButton.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index cfbcd9322..b3aee66ac 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -10,6 +10,8 @@ #include #include +#include + namespace Ship { ControllerButton::ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) : mPortIndex(portIndex), mBitmask(bitmask), mUseKeydownEventToCreateNewMapping(false), @@ -181,8 +183,8 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); } - // FIXME: click cancel button with mouse might trigger binding (yeah) - if (mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { + // TODO: I dont think direct ImGui calls should be here + if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); } From 0050de205e3824e06f0cad2ba2be4cf6efbb2dba Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 17 Dec 2024 21:27:04 +0700 Subject: [PATCH 11/58] new mouse input block --- src/controller/controldeck/ControlDeck.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index ddddfc30f..781627ae5 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -10,6 +10,8 @@ #include #include "controller/deviceindex/ShipDeviceIndexMappingManager.h" +#include "spdlog/spdlog.h" + namespace Ship { ControlDeck::ControlDeck(std::vector additionalBitmasks) : mSinglePlayerMappingMode(false) { @@ -80,8 +82,14 @@ bool ControlDeck::KeyboardGameInputBlocked() { } bool ControlDeck::MouseGameInputBlocked() { - // block mouse input when mouse capture (hidden & window-focused mouse) mode disabled - return AllGameInputBlocked() || !Context::GetInstance()->GetWindow()->IsMouseCaptured(); + // block mouse input when user interacting with gui + // TODO: check perfomance + static ImGuiID gameWindowID = ImGui::FindWindowByName("Main Game")->ID; + ImGuiWindow *window = ImGui::GetCurrentContext()->HoveredWindow; + if (window == NULL) { + return true; + } + return AllGameInputBlocked() || (window->ID != gameWindowID); } std::shared_ptr ControlDeck::GetControllerByPort(uint8_t port) { From 4c9f5772beb799d59f9fb26a9c515ab8b88f1881 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 18 Dec 2024 03:44:46 +0700 Subject: [PATCH 12/58] Mouse mapping menu update --- src/controller/controldeck/ControlDeck.cpp | 1 + src/window/gui/InputEditorWindow.cpp | 53 +++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index 781627ae5..492846f89 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -35,6 +35,7 @@ void ControlDeck::Init(uint8_t* controllerBits) { // if we don't have a config for controller 1, set default keyboard bindings if (!mPorts[0]->GetConnectedController()->HasConfig()) { mPorts[0]->GetConnectedController()->AddDefaultMappings(ShipDeviceIndex::Keyboard); + mPorts[0]->GetConnectedController()->AddDefaultMappings(ShipDeviceIndex::Mouse); } Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Controller Reordering")->Show(); diff --git a/src/window/gui/InputEditorWindow.cpp b/src/window/gui/InputEditorWindow.cpp index c2d2d7fa5..6f0ad5ad8 100644 --- a/src/window/gui/InputEditorWindow.cpp +++ b/src/window/gui/InputEditorWindow.cpp @@ -25,6 +25,7 @@ void InputEditorWindow::InitElement() { mDeviceIndexVisiblity.clear(); mDeviceIndexVisiblity[ShipDeviceIndex::Keyboard] = true; + mDeviceIndexVisiblity[ShipDeviceIndex::Mouse] = true; mDeviceIndexVisiblity[ShipDeviceIndex::Blue] = true; for (auto index = 1; index < ShipDeviceIndex::Max; index++) { mDeviceIndexVisiblity[static_cast(index)] = false; @@ -151,6 +152,9 @@ void InputEditorWindow::DrawAnalogPreview(const char* label, ImVec2 stick, float #define BUTTON_COLOR_KEYBOARD_BEIGE ImVec4(0.651f, 0.482f, 0.357f, 0.5f) #define BUTTON_COLOR_KEYBOARD_BEIGE_HOVERED ImVec4(0.651f, 0.482f, 0.357f, 1.0f) +#define BUTTON_COLOR_MOUSE_BEIGE ImVec4(0.5f, 0.5f, 0.5f, 0.5f) +#define BUTTON_COLOR_MOUSE_BEIGE_HOVERED ImVec4(0.5f, 0.5f, 0.5f, 1.0f) + #define BUTTON_COLOR_GAMEPAD_BLUE ImVec4(0.0f, 0.255f, 0.976f, 0.5f) #define BUTTON_COLOR_GAMEPAD_BLUE_HOVERED ImVec4(0.0f, 0.255f, 0.976f, 1.0f) @@ -173,6 +177,10 @@ void InputEditorWindow::GetButtonColorsForShipDeviceIndex(ShipDeviceIndex lusInd buttonColor = BUTTON_COLOR_KEYBOARD_BEIGE; buttonHoveredColor = BUTTON_COLOR_KEYBOARD_BEIGE_HOVERED; break; + case ShipDeviceIndex::Mouse: + buttonColor = BUTTON_COLOR_MOUSE_BEIGE; + buttonHoveredColor = BUTTON_COLOR_MOUSE_BEIGE_HOVERED; + break; case ShipDeviceIndex::Blue: buttonColor = BUTTON_COLOR_GAMEPAD_BLUE; buttonHoveredColor = BUTTON_COLOR_GAMEPAD_BLUE_HOVERED; @@ -250,6 +258,7 @@ void InputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, CONTROLLER icon = ICON_FA_GAMEPAD; break; case MAPPING_TYPE_KEYBOARD: + case MAPPING_TYPE_MOUSE: icon = ICON_FA_KEYBOARD_O; break; case MAPPING_TYPE_UNKNOWN: @@ -516,6 +525,7 @@ void InputEditorWindow::DrawStickDirectionLineEditMappingButton(uint8_t port, ui icon = ICON_FA_GAMEPAD; break; case MAPPING_TYPE_KEYBOARD: + case MAPPING_TYPE_MOUSE: icon = ICON_FA_KEYBOARD_O; break; case MAPPING_TYPE_UNKNOWN: @@ -1180,6 +1190,7 @@ void InputEditorWindow::DrawGyroSection(uint8_t port) { void InputEditorWindow::DrawButtonDeviceIcons(uint8_t portIndex, std::set bitmasks) { std::set allLusDeviceIndices; allLusDeviceIndices.insert(ShipDeviceIndex::Keyboard); + allLusDeviceIndices.insert(ShipDeviceIndex::Mouse); for (auto [lusIndex, mapping] : Context::GetInstance() ->GetControlDeck() ->GetDeviceIndexMappingManager() @@ -1215,7 +1226,7 @@ void InputEditorWindow::DrawButtonDeviceIcons(uint8_t portIndex, std::set allLusDeviceIndices; allLusDeviceIndices.insert(ShipDeviceIndex::Keyboard); + allLusDeviceIndices.insert(ShipDeviceIndex::Mouse); for (auto [lusIndex, mapping] : Context::GetInstance() ->GetControlDeck() ->GetDeviceIndexMappingManager() @@ -1266,7 +1278,7 @@ void InputEditorWindow::DrawAnalogStickDeviceIcons(uint8_t portIndex, StickIndex ImGui::PushStyleColor(ImGuiCol_Button, buttonColor); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, buttonHoveredColor); ImGui::SameLine(); - if (lusIndex == ShipDeviceIndex::Keyboard) { + if (lusIndex == ShipDeviceIndex::Keyboard || lusIndex == ShipDeviceIndex::Mouse) { ImGui::SmallButton(ICON_FA_KEYBOARD_O); } else { ImGui::SmallButton(connected ? ICON_FA_GAMEPAD : ICON_FA_CHAIN_BROKEN); @@ -1418,6 +1430,20 @@ void InputEditorWindow::DrawDeviceVisibilityButtons() { ImGui::PopStyleColor(); ImGui::PopStyleColor(); + auto mouseButtonColor = ImGui::GetStyleColorVec4(ImGuiCol_Button); + auto mouseButtonHoveredColor = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered); + GetButtonColorsForShipDeviceIndex(ShipDeviceIndex::Mouse, mouseButtonColor, mouseButtonHoveredColor); + ImGui::PushStyleColor(ImGuiCol_Button, mouseButtonColor); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, mouseButtonHoveredColor); + bool mouseVisible = mDeviceIndexVisiblity[ShipDeviceIndex::Mouse]; + if (ImGui::Button(StringHelper::Sprintf("%s %s mouse", mouseVisible ? ICON_FA_EYE : ICON_FA_EYE_SLASH, + ICON_FA_KEYBOARD_O) + .c_str())) { + mDeviceIndexVisiblity[ShipDeviceIndex::Mouse] = !mouseVisible; + } + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + for (auto [lusIndex, info] : indexMappings) { auto [name, sdlIndex] = info; bool connected = sdlIndex != -1; @@ -1593,6 +1619,29 @@ void InputEditorWindow::DrawSetDefaultsButton(uint8_t portIndex) { } ImGui::EndPopup(); } + ImGui::PushStyleColor(ImGuiCol_Button, BUTTON_COLOR_MOUSE_BEIGE); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, BUTTON_COLOR_MOUSE_BEIGE_HOVERED); + if (ImGui::Button(StringHelper::Sprintf("%s Mouse", ICON_FA_KEYBOARD_O).c_str())) { + ImGui::OpenPopup("Set Defaults for Mouse"); + } + ImGui::PopStyleColor(); + ImGui::PopStyleColor(); + if (ImGui::BeginPopupModal("Set Defaults for Mouse", NULL, ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::Text("This will clear all existing mappings for\nMouse on port %d.\n\nContinue?", portIndex + 1); + if (ImGui::Button("Cancel")) { + shouldClose = true; + ImGui::CloseCurrentPopup(); + } + if (ImGui::Button("Set defaults")) { + Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->ClearAllMappingsForDevice( + ShipDeviceIndex::Mouse); + Context::GetInstance()->GetControlDeck()->GetControllerByPort(portIndex)->AddDefaultMappings( + ShipDeviceIndex::Mouse); + shouldClose = true; + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } for (auto [lusIndex, info] : indexMappings) { auto [name, sdlIndex] = info; From 3d9fb467a2e2d4048b4ea8dcae3593a3122c05fa Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 18 Dec 2024 06:13:14 +0700 Subject: [PATCH 13/58] fix ImGui `WantCaptureKeyboard` locks when holding mouse button --- src/controller/controldeck/ControlDeck.cpp | 8 +++++--- src/window/gui/Gui.cpp | 8 ++++++++ src/window/gui/Gui.h | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index 492846f89..31734dfc5 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -79,18 +79,20 @@ bool ControlDeck::GamepadGameInputBlocked() { bool ControlDeck::KeyboardGameInputBlocked() { // block keyboard input when typing in imgui - return AllGameInputBlocked() || ImGui::GetIO().WantCaptureKeyboard; + ImGuiWindow *activeIDWindow = ImGui::GetCurrentContext()->ActiveIdWindow; + return AllGameInputBlocked() || + (activeIDWindow != NULL && activeIDWindow->ID != Context::GetInstance()->GetWindow()->GetGui()->GetMainGameWindowID()) || + ImGui::GetTopMostPopupModal() != NULL; //ImGui::GetIO().WantCaptureKeyboard, but ActiveId check altered } bool ControlDeck::MouseGameInputBlocked() { // block mouse input when user interacting with gui // TODO: check perfomance - static ImGuiID gameWindowID = ImGui::FindWindowByName("Main Game")->ID; ImGuiWindow *window = ImGui::GetCurrentContext()->HoveredWindow; if (window == NULL) { return true; } - return AllGameInputBlocked() || (window->ID != gameWindowID); + return AllGameInputBlocked() || (window->ID != Context::GetInstance()->GetWindow()->GetGui()->GetMainGameWindowID()); } std::shared_ptr ControlDeck::GetControllerByPort(uint8_t port) { diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 3291b4951..034d1e769 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -291,6 +291,14 @@ void Gui::UnblockGamepadNavigation() { } } +ImGuiID Gui::GetMainGameWindowID() { + ImGuiWindow *window = ImGui::FindWindowByName("Main Game"); + if (window == NULL) { + return 0; + } + return window->ID; +} + void Gui::ImGuiBackendNewFrame() { switch (Context::GetInstance()->GetWindow()->GetWindowBackend()) { #ifdef ENABLE_OPENGL diff --git a/src/window/gui/Gui.h b/src/window/gui/Gui.h index ce828822e..224d32eab 100644 --- a/src/window/gui/Gui.h +++ b/src/window/gui/Gui.h @@ -77,6 +77,7 @@ class Gui { void SetupRendererFrame(); void SaveConsoleVariablesNextFrame(); bool SupportsViewports(); + ImGuiID GetMainGameWindowID(); void AddGuiWindow(std::shared_ptr guiWindow); std::shared_ptr GetGuiWindow(const std::string& name); From 67c75107e1b990a2c3f14bdc4bca4d6bd3a3a1d9 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 18 Dec 2024 06:49:41 +0700 Subject: [PATCH 14/58] reading mouse from config casually forgotten --- .../mapping/factories/ButtonMappingFactory.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp index 627e259db..e26b01a83 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp @@ -4,9 +4,11 @@ #include "libultraship/libultra/controller.h" #include "Context.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h" #include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h" +#include "window/MouseMeta.h" namespace Ship { std::shared_ptr ButtonMappingFactory::CreateButtonMappingFromConfig(uint8_t portIndex, @@ -65,6 +67,13 @@ std::shared_ptr ButtonMappingFactory::CreateButtonMappi return std::make_shared(portIndex, bitmask, static_cast(scancode)); } + + if (mappingClass == "MouseKeyToButtonMapping") { + int mouseButton = + CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0); + + return std::make_shared(portIndex, bitmask, static_cast(mouseButton)); + } return nullptr; } From e8b01af5fedc17a44dc4ec440f8656a7435f4f80 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 18 Dec 2024 08:57:15 +0700 Subject: [PATCH 15/58] fixed strange buffered mapping bug --- .../controller/ControllerButton.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index b3aee66ac..999eeb864 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -181,14 +181,10 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi mUseKeydownEventToCreateNewMapping = true; if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); - } - - // TODO: I dont think direct ImGui calls should be here - if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { + } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { + // TODO: I dont think direct ImGui calls should be here mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); - } - - if (mapping == nullptr) { + } else { mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask); } @@ -215,7 +211,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi } bool ControllerButton::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) { - if (mUseKeydownEventToCreateNewMapping && eventType == LUS_KB_EVENT_KEY_DOWN) { + if (mUseKeydownEventToCreateNewMapping) { if (eventType == LUS_KB_EVENT_KEY_DOWN) { mKeyboardScancodeForNewMapping = scancode; return true; @@ -238,9 +234,13 @@ bool ControllerButton::ProcessKeyboardEvent(KbEventType eventType, KbScancode sc } bool ControllerButton::ProcessMouseEvent(bool isPressed, MouseBtn button) { - if (mUseKeydownEventToCreateNewMapping && isPressed) { - mMouseButtonForNewMapping = button; - return true; + if (mUseKeydownEventToCreateNewMapping) { + if (isPressed) { + mMouseButtonForNewMapping = button; + return true; + } else { + mMouseButtonForNewMapping = MouseBtn::MOUSE_BTN_UNKNOWN; + } } bool result = false; From 80742d2e7dee6d51461c9a08bfb2ab17a217a076 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Fri, 13 Dec 2024 23:44:14 +0700 Subject: [PATCH 16/58] mouse buttons callbacks --- src/graphic/Fast3D/Fast3dWindow.cpp | 18 ++++++++- src/graphic/Fast3D/Fast3dWindow.h | 2 + src/graphic/Fast3D/gfx_dxgi.cpp | 42 ++++++++++++++++++--- src/graphic/Fast3D/gfx_sdl2.cpp | 27 +++++++++++++ src/graphic/Fast3D/gfx_window_manager_api.h | 1 + 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 82f43b541..cecb4bf02 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -82,6 +82,7 @@ void Fast3dWindow::Init() { height, posX, posY); mWindowManagerApi->set_fullscreen_changed_callback(OnFullscreenChanged); mWindowManagerApi->set_keyboard_callbacks(KeyDown, KeyUp, AllKeysUp); + mWindowManagerApi->set_mouse_callbacks(MouseButtonDown, MouseButtonUp); SetTextureFilter((FilteringMode)CVarGetInteger(CVAR_TEXTURE_FILTER, FILTER_THREE_POINT)); } @@ -287,6 +288,21 @@ void Fast3dWindow::AllKeysUp() { Ship::KbScancode::LUS_KB_UNKNOWN); } +bool Fast3dWindow::MouseButtonUp(int button) { + return Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseEvent( + false, + static_cast(button) + ); +} + +bool Fast3dWindow::MouseButtonDown(int button) { + bool isProcessed = Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseEvent( + true, + static_cast(button) + ); + return isProcessed; +} + void Fast3dWindow::OnFullscreenChanged(bool isNowFullscreen) { std::shared_ptr wnd = Ship::Context::GetInstance()->GetWindow(); @@ -298,4 +314,4 @@ void Fast3dWindow::OnFullscreenChanged(bool isNowFullscreen) { wnd->SetCursorVisibility(true); } } -} // namespace Fast \ No newline at end of file +} // namespace Fast diff --git a/src/graphic/Fast3D/Fast3dWindow.h b/src/graphic/Fast3D/Fast3dWindow.h index ba587926a..6bd8b6404 100644 --- a/src/graphic/Fast3D/Fast3dWindow.h +++ b/src/graphic/Fast3D/Fast3dWindow.h @@ -51,6 +51,8 @@ class Fast3dWindow : public Ship::Window { static bool KeyDown(int32_t scancode); static bool KeyUp(int32_t scancode); static void AllKeysUp(); + static bool MouseButtonDown(int button); + static bool MouseButtonUp(int button); static void OnFullscreenChanged(bool isNowFullscreen); private: diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index a4d809c3b..30e33397d 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -96,7 +96,9 @@ static struct { void (*on_fullscreen_changed)(bool is_now_fullscreen); bool (*on_key_down)(int scancode); bool (*on_key_up)(int scancode); - void (*on_all_keys_up)(); + void (*on_all_keys_up)(void); + bool (*on_mouse_button_down)(int btn); + bool (*on_mouse_button_up)(int btn); } dxgi; static void load_dxgi_library() { @@ -260,6 +262,18 @@ static void onkeyup(WPARAM w_param, LPARAM l_param) { } } +static void on_mouse_button_down(int btn) { + // TODO: maybe check boundaries + if (dxgi.on_mouse_button_down != nullptr) { + dxgi.on_mouse_button_down(btn); + } +} +static void on_mouse_button_up(int btn) { + if (dxgi.on_mouse_button_up != nullptr) { + dxgi.on_mouse_button_up(btn); + } +} + double HzToPeriod(double Frequency) { if (Frequency == 0) Frequency = 60; // Default to 60, to prevent devision by zero @@ -374,29 +388,41 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par onkeyup(w_param, l_param); break; case WM_LBUTTONDOWN: + on_mouse_button_down(0); dxgi.mouse_pressed[0] = true; break; case WM_LBUTTONUP: + on_mouse_button_up(0); dxgi.mouse_pressed[0] = false; break; case WM_MBUTTONDOWN: + on_mouse_button_down(1); dxgi.mouse_pressed[1] = true; break; case WM_MBUTTONUP: + on_mouse_button_up(1); dxgi.mouse_pressed[1] = false; break; case WM_RBUTTONDOWN: + on_mouse_button_down(2); dxgi.mouse_pressed[2] = true; break; case WM_RBUTTONUP: + on_mouse_button_up(2); dxgi.mouse_pressed[2] = false; break; - case WM_XBUTTONDOWN: - dxgi.mouse_pressed[2 + GET_XBUTTON_WPARAM(w_param)] = true; + case WM_XBUTTONDOWN: { + int btn = 2 + GET_XBUTTON_WPARAM(w_param); + on_mouse_button_down(btn); + dxgi.mouse_pressed[btn] = true; break; - case WM_XBUTTONUP: - dxgi.mouse_pressed[2 + GET_XBUTTON_WPARAM(w_param)] = false; + } + case WM_XBUTTONUP: { + int btn = 2 + GET_XBUTTON_WPARAM(w_param); + on_mouse_button_up(btn); + dxgi.mouse_pressed[btn] = false; break; + } case WM_MOUSEWHEEL: dxgi.mouse_wheel[0] = GET_WHEEL_DELTA_WPARAM(w_param) / WHEEL_DELTA; dxgi.mouse_wheel[1] = 0; @@ -595,6 +621,11 @@ static void gfx_dxgi_set_keyboard_callbacks(bool (*on_key_down)(int scancode), b dxgi.on_all_keys_up = on_all_keys_up; } +static void gfx_dxgi_set_mouse_callbacks(bool (*on_btn_down)(int btn), bool (*on_btn_up)(int btn)) { + dxgi.on_mouse_button_down = on_btn_down; + dxgi.on_mouse_button_up = on_btn_up; +} + static void gfx_dxgi_get_dimensions(uint32_t* width, uint32_t* height, int32_t* posX, int32_t* posY) { *width = dxgi.current_width; *height = dxgi.current_height; @@ -1003,6 +1034,7 @@ bool gfx_dxgi_is_fullscreen() { extern "C" struct GfxWindowManagerAPI gfx_dxgi_api = { gfx_dxgi_init, gfx_dxgi_close, gfx_dxgi_set_keyboard_callbacks, + gfx_dxgi_set_mouse_callbacks, gfx_dxgi_set_fullscreen_changed_callback, gfx_dxgi_set_fullscreen, gfx_dxgi_get_active_window_refresh_rate, diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index e8d3316a5..c1e0a3a5b 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -55,6 +55,8 @@ static void (*on_fullscreen_changed_callback)(bool is_now_fullscreen); static bool (*on_key_down_callback)(int scancode); static bool (*on_key_up_callback)(int scancode); static void (*on_all_keys_up_callback)(); +static bool (*on_mouse_button_down_callback)(int btn); +static bool (*on_mouse_button_up_callback)(int btn); #ifdef _WIN32 LONG_PTR SDL_WndProc; @@ -485,6 +487,11 @@ static void gfx_sdl_set_keyboard_callbacks(bool (*on_key_down)(int scancode), bo on_all_keys_up_callback = on_all_keys_up; } +static void gfx_sdl_set_mouse_callbacks(bool (*on_btn_down)(int btn), bool (*on_btn_up)(int btn)) { + on_mouse_button_down_callback = on_btn_down; + on_mouse_button_up_callback = on_btn_up; +} + static void gfx_sdl_get_dimensions(uint32_t* width, uint32_t* height, int32_t* posX, int32_t* posY) { SDL_GL_GetDrawableSize(wnd, static_cast((void*)width), static_cast((void*)height)); SDL_GetWindowPosition(wnd, static_cast(posX), static_cast(posY)); @@ -521,6 +528,19 @@ static void gfx_sdl_onkeyup(int scancode) { } } +static void gfx_sdl_on_mouse_button_down(int btn) { + // TODO: maybe check for boundaries? >= 0 & < 5 + if (on_mouse_button_down_callback != NULL) { + on_mouse_button_down_callback(btn); + } +} + +static void gfx_sdl_on_mouse_button_up(int btn) { + if (on_mouse_button_up_callback != NULL) { + on_mouse_button_up_callback(btn); + } +} + static void gfx_sdl_handle_single_event(SDL_Event& event) { Ship::WindowEvent event_impl; event_impl.Sdl = { &event }; @@ -534,6 +554,12 @@ static void gfx_sdl_handle_single_event(SDL_Event& event) { case SDL_KEYUP: gfx_sdl_onkeyup(event.key.keysym.scancode); break; + case SDL_MOUSEBUTTONDOWN: + gfx_sdl_on_mouse_button_down(event.button.button - 1); + break; + case SDL_MOUSEBUTTONUP: + gfx_sdl_on_mouse_button_up(event.button.button - 1); + break; case SDL_MOUSEWHEEL: mouse_wheel_x = event.wheel.x; mouse_wheel_y = event.wheel.y; @@ -670,6 +696,7 @@ bool gfx_sdl_is_fullscreen() { struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_init, gfx_sdl_close, gfx_sdl_set_keyboard_callbacks, + gfx_sdl_set_mouse_callbacks, gfx_sdl_set_fullscreen_changed_callback, gfx_sdl_set_fullscreen, gfx_sdl_get_active_window_refresh_rate, diff --git a/src/graphic/Fast3D/gfx_window_manager_api.h b/src/graphic/Fast3D/gfx_window_manager_api.h index c078fb807..9fd3555db 100644 --- a/src/graphic/Fast3D/gfx_window_manager_api.h +++ b/src/graphic/Fast3D/gfx_window_manager_api.h @@ -10,6 +10,7 @@ struct GfxWindowManagerAPI { void (*close)(); void (*set_keyboard_callbacks)(bool (*on_key_down)(int scancode), bool (*on_key_up)(int scancode), void (*on_all_keys_up)()); + void (*set_mouse_callbacks)(bool (*on_mouse_button_down)(int btn), bool (*on_mouse_button_up)(int btn)); void (*set_fullscreen_changed_callback)(void (*on_fullscreen_changed)(bool is_now_fullscreen)); void (*set_fullscreen)(bool enable); void (*get_active_window_refresh_rate)(uint32_t* refresh_rate); From 8d0d51b793583585957cf337989ca47d58b983df Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 18 Dec 2024 10:27:04 +0700 Subject: [PATCH 17/58] mouse button to axis mapping --- .../controldevice/controller/Controller.cpp | 5 +- .../controller/ControllerStick.cpp | 43 +++++++++++++--- .../controller/ControllerStick.h | 3 ++ .../factories/AxisDirectionMappingFactory.cpp | 18 +++++++ .../mouse/MouseKeyToAxisDirectionMapping.cpp | 49 +++++++++++++++++++ .../mouse/MouseKeyToAxisDirectionMapping.h | 17 +++++++ 6 files changed, 125 insertions(+), 10 deletions(-) create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h diff --git a/src/controller/controldevice/controller/Controller.cpp b/src/controller/controldevice/controller/Controller.cpp index edd7e3933..5310fbf00 100644 --- a/src/controller/controldevice/controller/Controller.cpp +++ b/src/controller/controldevice/controller/Controller.cpp @@ -141,9 +141,8 @@ bool Controller::ProcessMouseEvent(bool isPressed, MouseBtn mouseButton) { for (auto [bitmask, button] : GetAllButtons()) { result = button->ProcessMouseEvent(isPressed, mouseButton) || result; } - // FIXME: implement - // result = GetLeftStick()->ProcessMouseEvent(isPressed, mouseButton) || result; - // result = GetRightStick()->ProcessMouseEvent(isPressed, mouseButton) || result; + result = GetLeftStick()->ProcessMouseEvent(isPressed, mouseButton) || result; + result = GetRightStick()->ProcessMouseEvent(isPressed, mouseButton) || result; return result; } diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 8aa11def6..5ccfc88d7 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -2,6 +2,7 @@ #include #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h" @@ -11,6 +12,8 @@ #include #include +#include + // for some reason windows isn't seeing M_PI // this is copied from my system's math.h #ifndef M_PI @@ -22,8 +25,8 @@ namespace Ship { ControllerStick::ControllerStick(uint8_t portIndex, StickIndex stickIndex) - : mPortIndex(portIndex), mStickIndex(stickIndex), mUseKeydownEventToCreateNewMapping(false), - mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN) { + : mPortIndex(portIndex), mStickIndex(stickIndex),, mUseKeydownEventToCreateNewMapping(false), + mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN), mMouseButtonForNewMapping(MouseBtn::MOUSE_BTN_UNKNOWN) { mSensitivityPercentage = DEFAULT_STICK_SENSITIVITY_PERCENTAGE; mSensitivity = 1.0f; mDeadzonePercentage = DEFAULT_STICK_DEADZONE_PERCENTAGE; @@ -272,11 +275,11 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mKeyboardScancodeForNewMapping); - } - - if (mapping == nullptr) { - mapping = - AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(mPortIndex, mStickIndex, direction); + } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { + // TODO: I dont think direct ImGui calls should be here (again) + mapping = std::make_shared(mPortIndex, mStickIndex, direction, mMouseButtonForNewMapping); + } else { + mapping = AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(mPortIndex, mStickIndex, direction); } if (mapping == nullptr) { @@ -284,6 +287,7 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct } mKeyboardScancodeForNewMapping = LUS_KB_UNKNOWN; + mMouseButtonForNewMapping = MouseBtn::MOUSE_BTN_UNKNOWN; mUseKeydownEventToCreateNewMapping = false; if (id != "") { @@ -343,6 +347,31 @@ bool ControllerStick::ProcessKeyboardEvent(KbEventType eventType, KbScancode sca return result; } +bool ControllerStick::ProcessMouseEvent(bool isPressed, MouseBtn button) { + if (mUseKeydownEventToCreateNewMapping) { + if (isPressed) { + mMouseButtonForNewMapping = button; + return true; + } else { + mMouseButtonForNewMapping = MouseBtn::MOUSE_BTN_UNKNOWN; + } + } + + bool result = false; + for (auto [direction, mappings] : mAxisDirectionMappings) { + for (auto [id, mapping] : mappings) { + if (mapping->GetMappingType() == MAPPING_TYPE_MOUSE) { + std::shared_ptr mtoadMapping = + std::dynamic_pointer_cast(mapping); + if (mtoadMapping != nullptr) { + result = result || mtoadMapping->ProcessMouseEvent(isPressed, button); + } + } + } + } + return result; +} + void ControllerStick::SetSensitivity(uint8_t sensitivityPercentage) { mSensitivityPercentage = sensitivityPercentage; mSensitivity = sensitivityPercentage / 100.0f; diff --git a/src/controller/controldevice/controller/ControllerStick.h b/src/controller/controldevice/controller/ControllerStick.h index 8bc80aba7..6b5f3e5dc 100644 --- a/src/controller/controldevice/controller/ControllerStick.h +++ b/src/controller/controldevice/controller/ControllerStick.h @@ -5,6 +5,7 @@ #include #include #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" +#include "window/MouseMeta.h" namespace Ship { @@ -52,6 +53,7 @@ class ControllerStick { bool NotchSnapAngleIsDefault(); bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode); + bool ProcessMouseEvent(bool isPressed, Ship::MouseBtn button); bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); StickIndex GetStickIndex(); @@ -77,5 +79,6 @@ class ControllerStick { bool mUseKeydownEventToCreateNewMapping; KbScancode mKeyboardScancodeForNewMapping; + MouseBtn mMouseButtonForNewMapping; }; } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index ab6a4a35b..898cf65f8 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -9,6 +9,8 @@ #include "Context.h" #include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h" +#include "window/MouseMeta.h" + namespace Ship { std::shared_ptr AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIndex, StickIndex stickIndex, @@ -75,6 +77,22 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn portIndex, stickIndex, static_cast(direction), static_cast(scancode)); } + if (mappingClass == "MouseKeyToAxisDirectionMapping") { + int32_t direction = CVarGetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), -1); + int mouseButton = + CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0); + + if (direction != LEFT && direction != RIGHT && direction != UP && direction != DOWN) { + // something about this mapping is invalid + CVarClear(mappingCvarKey.c_str()); + CVarSave(); + return nullptr; + } + + return std::make_shared(portIndex, stick, static_cast(direction), + static_cast(mouseButton)); + } + return nullptr; } diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp new file mode 100644 index 000000000..b255b9b53 --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp @@ -0,0 +1,49 @@ +#include "MouseKeyToAxisDirectionMapping.h" +#include +#include "utils/StringHelper.h" +#include "window/gui/IconsFontAwesome4.h" +#include "public/bridge/consolevariablebridge.h" +#include "Context.h" + +namespace Ship { +KeyMouseToAxisDirectionMapping::MouseKeyToAxisDirectionMapping(uint8_t portIndex, Stick stick, + Direction direction, MouseBtn button) + : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button), + ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stick, direction) { +} + +float MouseKeyToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { + if (Context::GetInstance()->GetControlDeck()->MouseGameInputBlocked()) { + return 0.0f; + } + + return mKeyPressed ? MAX_AXIS_RANGE : 0.0f; +} + +std::string MouseKeyToAxisDirectionMapping::GetAxisDirectionMappingId() { + return StringHelper::Sprintf("P%d-S%d-D%d-MOUSE%d", mPortIndex, mStick, mDirection, mButton); +} + +void MouseKeyToAxisDirectionMapping::SaveToConfig() { + const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId(); + CVarSetString(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str(), + "MouseKeyToAxisDirectionMapping"); + CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStick); + CVarSetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), mDirection); + CVarSetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), static_cast(mButton)); + CVarSave(); +} + +void MouseKeyToAxisDirectionMapping::EraseFromConfig() { + const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId(); + CVarClear(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str()); + CVarSave(); +} + +uint8_t MouseKeyToAxisDirectionMapping::GetMappingType() { + return MAPPING_TYPE_MOUSE; +} +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h new file mode 100644 index 000000000..aa640529a --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h @@ -0,0 +1,17 @@ +#pragma once + +#include "controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h" +#include "MouseKeyToAnyMapping.h" +#include "window/MouseMeta.h" + +namespace Ship { +class MouseKeyToAxisDirectionMapping final : public MouseKeyToAnyMapping, public ControllerAxisDirectionMapping { + public: + MouseKeyToAxisDirectionMapping(uint8_t portIndex, Stick stick, Direction direction, MouseBtn button); + float GetNormalizedAxisDirectionValue() override; + std::string GetAxisDirectionMappingId() override; + uint8_t GetMappingType() override; + void SaveToConfig() override; + void EraseFromConfig() override; +}; +} // namespace Ship From 266588980646ace7f33e12900ad645589ac18a25 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 18 Dec 2024 10:40:08 +0700 Subject: [PATCH 18/58] fix --- .../mapping/factories/AxisDirectionMappingFactory.cpp | 1 + .../controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index 898cf65f8..bc281b17f 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -1,5 +1,6 @@ #include "AxisDirectionMappingFactory.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h" diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp index b255b9b53..3532aa466 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp @@ -6,7 +6,7 @@ #include "Context.h" namespace Ship { -KeyMouseToAxisDirectionMapping::MouseKeyToAxisDirectionMapping(uint8_t portIndex, Stick stick, +MouseKeyToAxisDirectionMapping::MouseKeyToAxisDirectionMapping(uint8_t portIndex, Stick stick, Direction direction, MouseBtn button) : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button), ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stick, direction) { From a788868f4ace1943e5b3edd753bec3022090523a Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 18 Dec 2024 11:09:16 +0700 Subject: [PATCH 19/58] mark --- src/window/gui/Gui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 034d1e769..0d413adfd 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -489,6 +489,7 @@ void Gui::DrawMenu() { GetMenuBar()->ToggleVisibility(); } if (wnd->IsFullscreen()) { + // TODO: mouse capture? Context::GetInstance()->GetWindow()->SetCursorVisibility(GetMenuOrMenubarVisible() || wnd->ShouldForceCursorVisibility()); } From eb02689beff0a8a2eea7d961305034d672775b40 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 18 Dec 2024 11:36:23 +0700 Subject: [PATCH 20/58] use propper cursor hide method --- src/graphic/Fast3D/gfx_dxgi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index 30e33397d..588a1ee13 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -592,11 +592,11 @@ static bool gfx_dxgi_get_mouse_state(uint32_t btn) { static void gfx_dxgi_set_mouse_capture(bool capture) { if (capture) { apply_mouse_capture_clip(); - ShowCursor(FALSE); + gfx_dxgi_set_cursor_visibility(false); SetCapture(dxgi.h_wnd); } else { ClipCursor(nullptr); - ShowCursor(TRUE); + gfx_dxgi_set_cursor_visibility(true); ReleaseCapture(); } dxgi.is_mouse_captured = capture; From 31b3ca851c7738207e0e041e04150b97220d2901 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 05:34:24 +0000 Subject: [PATCH 21/58] merge-fixes --- .../controldevice/controller/ControllerStick.cpp | 2 +- .../mapping/factories/AxisDirectionMappingFactory.cpp | 2 +- .../mapping/mouse/MouseKeyToAxisDirectionMapping.cpp | 8 ++++---- .../mapping/mouse/MouseKeyToAxisDirectionMapping.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 5ccfc88d7..f92122569 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -25,7 +25,7 @@ namespace Ship { ControllerStick::ControllerStick(uint8_t portIndex, StickIndex stickIndex) - : mPortIndex(portIndex), mStickIndex(stickIndex),, mUseKeydownEventToCreateNewMapping(false), + : mPortIndex(portIndex), mStickIndex(stickIndex), mUseKeydownEventToCreateNewMapping(false), mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN), mMouseButtonForNewMapping(MouseBtn::MOUSE_BTN_UNKNOWN) { mSensitivityPercentage = DEFAULT_STICK_SENSITIVITY_PERCENTAGE; mSensitivity = 1.0f; diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index bc281b17f..4b2f37741 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -90,7 +90,7 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn return nullptr; } - return std::make_shared(portIndex, stick, static_cast(direction), + return std::make_shared(portIndex, stickIndex, static_cast(direction), static_cast(mouseButton)); } diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp index 3532aa466..896ba5d0f 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp @@ -6,10 +6,10 @@ #include "Context.h" namespace Ship { -MouseKeyToAxisDirectionMapping::MouseKeyToAxisDirectionMapping(uint8_t portIndex, Stick stick, +MouseKeyToAxisDirectionMapping::MouseKeyToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, MouseBtn button) : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button), - ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stick, direction) { + ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stickIndex, direction) { } float MouseKeyToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { @@ -21,14 +21,14 @@ float MouseKeyToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { } std::string MouseKeyToAxisDirectionMapping::GetAxisDirectionMappingId() { - return StringHelper::Sprintf("P%d-S%d-D%d-MOUSE%d", mPortIndex, mStick, mDirection, mButton); + return StringHelper::Sprintf("P%d-S%d-D%d-MOUSE%d", mPortIndex, mStickIndex, mDirection, mButton); } void MouseKeyToAxisDirectionMapping::SaveToConfig() { const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId(); CVarSetString(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str(), "MouseKeyToAxisDirectionMapping"); - CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStick); + CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStickIndex); CVarSetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), mDirection); CVarSetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), static_cast(mButton)); CVarSave(); diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h index aa640529a..9ce17d8f3 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h @@ -7,7 +7,7 @@ namespace Ship { class MouseKeyToAxisDirectionMapping final : public MouseKeyToAnyMapping, public ControllerAxisDirectionMapping { public: - MouseKeyToAxisDirectionMapping(uint8_t portIndex, Stick stick, Direction direction, MouseBtn button); + MouseKeyToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, MouseBtn button); float GetNormalizedAxisDirectionValue() override; std::string GetAxisDirectionMappingId() override; uint8_t GetMappingType() override; From 68116b8c6a03fb24eb1a081ce06a25eab1175073 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 05:56:49 +0000 Subject: [PATCH 22/58] clang-format --- src/controller/controldeck/ControlDeck.cpp | 12 +++++++----- .../controldevice/controller/ControllerStick.cpp | 9 ++++++--- .../factories/AxisDirectionMappingFactory.cpp | 7 +++---- .../mapping/factories/ButtonMappingFactory.cpp | 5 ++--- .../mapping/mouse/MouseKeyToAxisDirectionMapping.cpp | 2 +- .../mapping/mouse/MouseKeyToButtonMapping.cpp | 3 +-- src/graphic/Fast3D/Fast3dWindow.cpp | 12 ++++-------- src/graphic/Fast3D/gfx_dxgi.cpp | 4 ++-- src/window/MouseMeta.h | 11 ++--------- src/window/gui/Gui.cpp | 2 +- src/window/gui/InputEditorWindow.cpp | 6 +++--- 11 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index 31734dfc5..d3d4ca24f 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -79,20 +79,22 @@ bool ControlDeck::GamepadGameInputBlocked() { bool ControlDeck::KeyboardGameInputBlocked() { // block keyboard input when typing in imgui - ImGuiWindow *activeIDWindow = ImGui::GetCurrentContext()->ActiveIdWindow; + ImGuiWindow* activeIDWindow = ImGui::GetCurrentContext()->ActiveIdWindow; return AllGameInputBlocked() || - (activeIDWindow != NULL && activeIDWindow->ID != Context::GetInstance()->GetWindow()->GetGui()->GetMainGameWindowID()) || - ImGui::GetTopMostPopupModal() != NULL; //ImGui::GetIO().WantCaptureKeyboard, but ActiveId check altered + (activeIDWindow != NULL && + activeIDWindow->ID != Context::GetInstance()->GetWindow()->GetGui()->GetMainGameWindowID()) || + ImGui::GetTopMostPopupModal() != NULL; // ImGui::GetIO().WantCaptureKeyboard, but ActiveId check altered } bool ControlDeck::MouseGameInputBlocked() { // block mouse input when user interacting with gui // TODO: check perfomance - ImGuiWindow *window = ImGui::GetCurrentContext()->HoveredWindow; + ImGuiWindow* window = ImGui::GetCurrentContext()->HoveredWindow; if (window == NULL) { return true; } - return AllGameInputBlocked() || (window->ID != Context::GetInstance()->GetWindow()->GetGui()->GetMainGameWindowID()); + return AllGameInputBlocked() || + (window->ID != Context::GetInstance()->GetWindow()->GetGui()->GetMainGameWindowID()); } std::shared_ptr ControlDeck::GetControllerByPort(uint8_t port) { diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index f92122569..3d037ed30 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -26,7 +26,8 @@ namespace Ship { ControllerStick::ControllerStick(uint8_t portIndex, StickIndex stickIndex) : mPortIndex(portIndex), mStickIndex(stickIndex), mUseKeydownEventToCreateNewMapping(false), - mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN), mMouseButtonForNewMapping(MouseBtn::MOUSE_BTN_UNKNOWN) { + mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN), + mMouseButtonForNewMapping(MouseBtn::MOUSE_BTN_UNKNOWN) { mSensitivityPercentage = DEFAULT_STICK_SENSITIVITY_PERCENTAGE; mSensitivity = 1.0f; mDeadzonePercentage = DEFAULT_STICK_DEADZONE_PERCENTAGE; @@ -277,9 +278,11 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct mKeyboardScancodeForNewMapping); } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { // TODO: I dont think direct ImGui calls should be here (again) - mapping = std::make_shared(mPortIndex, mStickIndex, direction, mMouseButtonForNewMapping); + mapping = std::make_shared(mPortIndex, mStickIndex, direction, + mMouseButtonForNewMapping); } else { - mapping = AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(mPortIndex, mStickIndex, direction); + mapping = + AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(mPortIndex, mStickIndex, direction); } if (mapping == nullptr) { diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index 4b2f37741..5eda7f3e6 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -80,8 +80,7 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn if (mappingClass == "MouseKeyToAxisDirectionMapping") { int32_t direction = CVarGetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), -1); - int mouseButton = - CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0); + int mouseButton = CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0); if (direction != LEFT && direction != RIGHT && direction != UP && direction != DOWN) { // something about this mapping is invalid @@ -90,8 +89,8 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn return nullptr; } - return std::make_shared(portIndex, stickIndex, static_cast(direction), - static_cast(mouseButton)); + return std::make_shared( + portIndex, stickIndex, static_cast(direction), static_cast(mouseButton)); } return nullptr; diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp index e26b01a83..dee1fe5c3 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp @@ -67,10 +67,9 @@ std::shared_ptr ButtonMappingFactory::CreateButtonMappi return std::make_shared(portIndex, bitmask, static_cast(scancode)); } - + if (mappingClass == "MouseKeyToButtonMapping") { - int mouseButton = - CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0); + int mouseButton = CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0); return std::make_shared(portIndex, bitmask, static_cast(mouseButton)); } diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp index 896ba5d0f..aee10ecde 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp @@ -7,7 +7,7 @@ namespace Ship { MouseKeyToAxisDirectionMapping::MouseKeyToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, - Direction direction, MouseBtn button) + Direction direction, MouseBtn button) : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button), ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stickIndex, direction) { } diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp index 09ef06599..688ee5511 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp @@ -5,8 +5,7 @@ #include "Context.h" namespace Ship { -MouseKeyToButtonMapping::MouseKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, - MouseBtn button) +MouseKeyToButtonMapping::MouseKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button) : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button), ControllerButtonMapping(ShipDeviceIndex::Mouse, portIndex, bitmask) { } diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index cecb4bf02..494a0e233 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -289,17 +289,13 @@ void Fast3dWindow::AllKeysUp() { } bool Fast3dWindow::MouseButtonUp(int button) { - return Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseEvent( - false, - static_cast(button) - ); + return Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseEvent(false, + static_cast(button)); } bool Fast3dWindow::MouseButtonDown(int button) { - bool isProcessed = Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseEvent( - true, - static_cast(button) - ); + bool isProcessed = + Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseEvent(true, static_cast(button)); return isProcessed; } diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index 588a1ee13..8851e1243 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -416,13 +416,13 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par on_mouse_button_down(btn); dxgi.mouse_pressed[btn] = true; break; - } + } case WM_XBUTTONUP: { int btn = 2 + GET_XBUTTON_WPARAM(w_param); on_mouse_button_up(btn); dxgi.mouse_pressed[btn] = false; break; - } + } case WM_MOUSEWHEEL: dxgi.mouse_wheel[0] = GET_WHEEL_DELTA_WPARAM(w_param) / WHEEL_DELTA; dxgi.mouse_wheel[1] = 0; diff --git a/src/window/MouseMeta.h b/src/window/MouseMeta.h index 2b326d223..b5271ff66 100644 --- a/src/window/MouseMeta.h +++ b/src/window/MouseMeta.h @@ -4,13 +4,6 @@ namespace Ship { enum class MouseBtn { LEFT, MIDDLE, RIGHT, BACKWARD, FORWARD, MOUSE_BTN_COUNT, MOUSE_BTN_UNKNOWN }; -static std::string mouseBtnNames[7] = { - "MouseLeft", - "MouseMiddle", - "MouseRight", - "MouseBackward", - "MouseForward", - "MOUSE_BTN_COUNT", - "MOUSE_BTN_UNKNOWN" -}; +static std::string mouseBtnNames[7] = { "MouseLeft", "MouseMiddle", "MouseRight", "MouseBackward", + "MouseForward", "MOUSE_BTN_COUNT", "MOUSE_BTN_UNKNOWN" }; } // namespace Ship diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 0d413adfd..2015c9ac4 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -292,7 +292,7 @@ void Gui::UnblockGamepadNavigation() { } ImGuiID Gui::GetMainGameWindowID() { - ImGuiWindow *window = ImGui::FindWindowByName("Main Game"); + ImGuiWindow* window = ImGui::FindWindowByName("Main Game"); if (window == NULL) { return 0; } diff --git a/src/window/gui/InputEditorWindow.cpp b/src/window/gui/InputEditorWindow.cpp index 6f0ad5ad8..e9e26a771 100644 --- a/src/window/gui/InputEditorWindow.cpp +++ b/src/window/gui/InputEditorWindow.cpp @@ -1436,9 +1436,9 @@ void InputEditorWindow::DrawDeviceVisibilityButtons() { ImGui::PushStyleColor(ImGuiCol_Button, mouseButtonColor); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, mouseButtonHoveredColor); bool mouseVisible = mDeviceIndexVisiblity[ShipDeviceIndex::Mouse]; - if (ImGui::Button(StringHelper::Sprintf("%s %s mouse", mouseVisible ? ICON_FA_EYE : ICON_FA_EYE_SLASH, - ICON_FA_KEYBOARD_O) - .c_str())) { + if (ImGui::Button( + StringHelper::Sprintf("%s %s mouse", mouseVisible ? ICON_FA_EYE : ICON_FA_EYE_SLASH, ICON_FA_KEYBOARD_O) + .c_str())) { mDeviceIndexVisiblity[ShipDeviceIndex::Mouse] = !mouseVisible; } ImGui::PopStyleColor(); From c9265c953ea4b5e988c3c66a8c5f40d904844af6 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 06:32:42 +0000 Subject: [PATCH 23/58] store main game window ID to reduce load --- src/controller/controldeck/ControlDeck.cpp | 3 --- src/window/gui/Gui.cpp | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index d3d4ca24f..b2d7f6abe 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -10,8 +10,6 @@ #include #include "controller/deviceindex/ShipDeviceIndexMappingManager.h" -#include "spdlog/spdlog.h" - namespace Ship { ControlDeck::ControlDeck(std::vector additionalBitmasks) : mSinglePlayerMappingMode(false) { @@ -88,7 +86,6 @@ bool ControlDeck::KeyboardGameInputBlocked() { bool ControlDeck::MouseGameInputBlocked() { // block mouse input when user interacting with gui - // TODO: check perfomance ImGuiWindow* window = ImGui::GetCurrentContext()->HoveredWindow; if (window == NULL) { return true; diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 2015c9ac4..2f3af046c 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -292,11 +292,16 @@ void Gui::UnblockGamepadNavigation() { } ImGuiID Gui::GetMainGameWindowID() { + static ImGuiID windowID = 0; + if (windowID != 0) { + return windowID; + } ImGuiWindow* window = ImGui::FindWindowByName("Main Game"); if (window == NULL) { return 0; } - return window->ID; + windowID = window->ID; + return windowID; } void Gui::ImGuiBackendNewFrame() { From 8f2beadc1d9beb91f9999b99e9f0f7617bab0a24 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:27:18 +0000 Subject: [PATCH 24/58] update on_mouse_up/down in dxgi --- src/graphic/Fast3D/gfx_dxgi.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index 8851e1243..f45c0199a 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -264,11 +264,13 @@ static void onkeyup(WPARAM w_param, LPARAM l_param) { static void on_mouse_button_down(int btn) { // TODO: maybe check boundaries + dxgi.mouse_pressed[btn] = true; if (dxgi.on_mouse_button_down != nullptr) { dxgi.on_mouse_button_down(btn); } } static void on_mouse_button_up(int btn) { + dxgi.mouse_pressed[btn] = false; if (dxgi.on_mouse_button_up != nullptr) { dxgi.on_mouse_button_up(btn); } @@ -389,38 +391,30 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par break; case WM_LBUTTONDOWN: on_mouse_button_down(0); - dxgi.mouse_pressed[0] = true; break; case WM_LBUTTONUP: on_mouse_button_up(0); - dxgi.mouse_pressed[0] = false; break; case WM_MBUTTONDOWN: on_mouse_button_down(1); - dxgi.mouse_pressed[1] = true; break; case WM_MBUTTONUP: on_mouse_button_up(1); - dxgi.mouse_pressed[1] = false; break; case WM_RBUTTONDOWN: on_mouse_button_down(2); - dxgi.mouse_pressed[2] = true; break; case WM_RBUTTONUP: on_mouse_button_up(2); - dxgi.mouse_pressed[2] = false; break; case WM_XBUTTONDOWN: { int btn = 2 + GET_XBUTTON_WPARAM(w_param); on_mouse_button_down(btn); - dxgi.mouse_pressed[btn] = true; break; } case WM_XBUTTONUP: { int btn = 2 + GET_XBUTTON_WPARAM(w_param); on_mouse_button_up(btn); - dxgi.mouse_pressed[btn] = false; break; } case WM_MOUSEWHEEL: From 559f2707fc0c89eb7d38b31b340a3465950c8f65 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:36:47 +0000 Subject: [PATCH 25/58] MouseMeta migration --- src/controller/controldeck/ControlDeck.h | 1 - src/controller/controldevice/controller/Controller.h | 1 - .../controldevice/controller/ControllerButton.h | 1 - .../controldevice/controller/ControllerStick.h | 1 - .../mapping/factories/AxisDirectionMappingFactory.cpp | 2 +- .../mapping/factories/ButtonMappingFactory.cpp | 2 +- .../controller/mapping/keyboard/KeyboardScancodes.h | 6 ++++++ .../controller/mapping/mouse/MouseKeyToAnyMapping.h | 2 +- .../mapping/mouse/MouseKeyToAxisDirectionMapping.h | 2 +- .../controller/mapping/mouse/MouseKeyToButtonMapping.h | 2 +- src/graphic/Fast3D/Fast3dWindow.h | 2 +- src/window/MouseMeta.h | 9 --------- src/window/Window.h | 2 +- 13 files changed, 13 insertions(+), 20 deletions(-) delete mode 100644 src/window/MouseMeta.h diff --git a/src/controller/controldeck/ControlDeck.h b/src/controller/controldeck/ControlDeck.h index 8ff1a6098..65e9572e6 100644 --- a/src/controller/controldeck/ControlDeck.h +++ b/src/controller/controldeck/ControlDeck.h @@ -5,7 +5,6 @@ #include #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" #include "controller/deviceindex/ShipDeviceIndexMappingManager.h" -#include "window/MouseMeta.h" namespace Ship { diff --git a/src/controller/controldevice/controller/Controller.h b/src/controller/controldevice/controller/Controller.h index 92e764944..409899bf2 100644 --- a/src/controller/controldevice/controller/Controller.h +++ b/src/controller/controldevice/controller/Controller.h @@ -17,7 +17,6 @@ #include "ControllerLED.h" #include "controller/controldevice/ControlDevice.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" -#include "window/MouseMeta.h" namespace Ship { diff --git a/src/controller/controldevice/controller/ControllerButton.h b/src/controller/controldevice/controller/ControllerButton.h index b5dd1e8f6..0678d3813 100644 --- a/src/controller/controldevice/controller/ControllerButton.h +++ b/src/controller/controldevice/controller/ControllerButton.h @@ -6,7 +6,6 @@ #include #include "libultraship/libultra/controller.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" -#include "window/MouseMeta.h" namespace Ship { diff --git a/src/controller/controldevice/controller/ControllerStick.h b/src/controller/controldevice/controller/ControllerStick.h index 6b5f3e5dc..806aeb4c9 100644 --- a/src/controller/controldevice/controller/ControllerStick.h +++ b/src/controller/controldevice/controller/ControllerStick.h @@ -5,7 +5,6 @@ #include #include #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" -#include "window/MouseMeta.h" namespace Ship { diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index 5eda7f3e6..eb39ad5fd 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -10,7 +10,7 @@ #include "Context.h" #include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h" -#include "window/MouseMeta.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Ship { std::shared_ptr diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp index dee1fe5c3..640f8f06c 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp @@ -8,7 +8,7 @@ #include "controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h" #include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h" -#include "window/MouseMeta.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Ship { std::shared_ptr ButtonMappingFactory::CreateButtonMappingFromConfig(uint8_t portIndex, diff --git a/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h b/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h index 4e92ef6f2..601b29b20 100644 --- a/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h +++ b/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h @@ -1,6 +1,8 @@ #pragma once #ifdef __cplusplus +#include + namespace Ship { #endif @@ -118,6 +120,10 @@ typedef enum KbScancode { LUS_KB_MAX } KbScancode; +typedef enum MouseBtn { LEFT, MIDDLE, RIGHT, BACKWARD, FORWARD, MOUSE_BTN_COUNT, MOUSE_BTN_UNKNOWN } MouseBtn; + #ifdef __cplusplus +static std::string mouseBtnNames[7] = { "MouseLeft", "MouseMiddle", "MouseRight", "MouseBackward", + "MouseForward", "MOUSE_BTN_COUNT", "MOUSE_BTN_UNKNOWN" }; } // namespace Ship #endif diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h index 16ff28c87..7a1f1fbf0 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h @@ -1,7 +1,7 @@ #pragma once #include "controller/controldevice/controller/mapping/ControllerInputMapping.h" -#include "window/MouseMeta.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Ship { class MouseKeyToAnyMapping : virtual public ControllerInputMapping { diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h index 9ce17d8f3..11f955fdb 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h @@ -2,7 +2,7 @@ #include "controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h" #include "MouseKeyToAnyMapping.h" -#include "window/MouseMeta.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Ship { class MouseKeyToAxisDirectionMapping final : public MouseKeyToAnyMapping, public ControllerAxisDirectionMapping { diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h index cb91ec464..0fe7f9897 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h @@ -2,7 +2,7 @@ #include "controller/controldevice/controller/mapping/ControllerButtonMapping.h" #include "MouseKeyToAnyMapping.h" -#include "window/MouseMeta.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Ship { class MouseKeyToButtonMapping final : public MouseKeyToAnyMapping, public ControllerButtonMapping { diff --git a/src/graphic/Fast3D/Fast3dWindow.h b/src/graphic/Fast3D/Fast3dWindow.h index 6bd8b6404..86676cf9d 100644 --- a/src/graphic/Fast3D/Fast3dWindow.h +++ b/src/graphic/Fast3D/Fast3dWindow.h @@ -3,7 +3,7 @@ #include "graphic/Fast3D/gfx_window_manager_api.h" #include "graphic/Fast3D/gfx_rendering_api.h" #include "public/bridge/gfxbridge.h" -#include "window/MouseMeta.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Fast { class Fast3dWindow : public Ship::Window { diff --git a/src/window/MouseMeta.h b/src/window/MouseMeta.h deleted file mode 100644 index b5271ff66..000000000 --- a/src/window/MouseMeta.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -namespace Ship { -enum class MouseBtn { LEFT, MIDDLE, RIGHT, BACKWARD, FORWARD, MOUSE_BTN_COUNT, MOUSE_BTN_UNKNOWN }; -static std::string mouseBtnNames[7] = { "MouseLeft", "MouseMiddle", "MouseRight", "MouseBackward", - "MouseForward", "MOUSE_BTN_COUNT", "MOUSE_BTN_UNKNOWN" }; -} // namespace Ship diff --git a/src/window/Window.h b/src/window/Window.h index 7f7a818af..708b29bfe 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -7,7 +7,7 @@ #include #include #include "window/gui/Gui.h" -#include "window/MouseMeta.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Ship { enum class WindowBackend { FAST3D_DXGI_DX11, FAST3D_SDL_OPENGL, FAST3D_SDL_METAL, WINDOW_BACKEND_COUNT }; From a64397f5ce7cbc55aca302004d7420dd7f47f826 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:45:02 +0000 Subject: [PATCH 26/58] MouseKey -> MouseButton --- .../controller/ControllerButton.cpp | 8 ++++---- .../controller/ControllerStick.cpp | 8 ++++---- .../factories/AxisDirectionMappingFactory.cpp | 6 +++--- .../mapping/factories/ButtonMappingFactory.cpp | 6 +++--- ...Mapping.cpp => MouseButtonToAnyMapping.cpp} | 14 +++++++------- ...oAnyMapping.h => MouseButtonToAnyMapping.h} | 6 +++--- ...p => MouseButtonToAxisDirectionMapping.cpp} | 18 +++++++++--------- ...g.h => MouseButtonToAxisDirectionMapping.h} | 6 +++--- ...ping.cpp => MouseButtonToButtonMapping.cpp} | 18 +++++++++--------- ...nMapping.h => MouseButtonToButtonMapping.h} | 6 +++--- 10 files changed, 48 insertions(+), 48 deletions(-) rename src/controller/controldevice/controller/mapping/mouse/{MouseKeyToAnyMapping.cpp => MouseButtonToAnyMapping.cpp} (50%) rename src/controller/controldevice/controller/mapping/mouse/{MouseKeyToAnyMapping.h => MouseButtonToAnyMapping.h} (76%) rename src/controller/controldevice/controller/mapping/mouse/{MouseKeyToAxisDirectionMapping.cpp => MouseButtonToAxisDirectionMapping.cpp} (73%) rename src/controller/controldevice/controller/mapping/mouse/{MouseKeyToAxisDirectionMapping.h => MouseButtonToAxisDirectionMapping.h} (62%) rename src/controller/controldevice/controller/mapping/mouse/{MouseKeyToButtonMapping.cpp => MouseButtonToButtonMapping.cpp} (69%) rename src/controller/controldevice/controller/mapping/mouse/{MouseKeyToButtonMapping.h => MouseButtonToButtonMapping.h} (65%) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index 999eeb864..a127b6cb7 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -3,7 +3,7 @@ #include "controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h" -#include "controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h" #include "public/bridge/consolevariablebridge.h" #include "utils/StringHelper.h" @@ -183,7 +183,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { // TODO: I dont think direct ImGui calls should be here - mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); + mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); } else { mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask); } @@ -246,8 +246,8 @@ bool ControllerButton::ProcessMouseEvent(bool isPressed, MouseBtn button) { bool result = false; for (auto [id, mapping] : GetAllButtonMappings()) { if (mapping->GetMappingType() == MAPPING_TYPE_MOUSE) { - std::shared_ptr mtobMapping = - std::dynamic_pointer_cast(mapping); + std::shared_ptr mtobMapping = + std::dynamic_pointer_cast(mapping); if (mtobMapping != nullptr) { result = result || mtobMapping->ProcessMouseEvent(isPressed, button); } diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 3d037ed30..3ad3c6a0f 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -2,7 +2,7 @@ #include #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h" -#include "controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h" @@ -278,7 +278,7 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct mKeyboardScancodeForNewMapping); } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { // TODO: I dont think direct ImGui calls should be here (again) - mapping = std::make_shared(mPortIndex, mStickIndex, direction, + mapping = std::make_shared(mPortIndex, mStickIndex, direction, mMouseButtonForNewMapping); } else { mapping = @@ -364,8 +364,8 @@ bool ControllerStick::ProcessMouseEvent(bool isPressed, MouseBtn button) { for (auto [direction, mappings] : mAxisDirectionMappings) { for (auto [id, mapping] : mappings) { if (mapping->GetMappingType() == MAPPING_TYPE_MOUSE) { - std::shared_ptr mtoadMapping = - std::dynamic_pointer_cast(mapping); + std::shared_ptr mtoadMapping = + std::dynamic_pointer_cast(mapping); if (mtoadMapping != nullptr) { result = result || mtoadMapping->ProcessMouseEvent(isPressed, button); } diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index eb39ad5fd..5259c735e 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -1,6 +1,6 @@ #include "AxisDirectionMappingFactory.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h" -#include "controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h" @@ -78,7 +78,7 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn portIndex, stickIndex, static_cast(direction), static_cast(scancode)); } - if (mappingClass == "MouseKeyToAxisDirectionMapping") { + if (mappingClass == "MouseButtonToAxisDirectionMapping") { int32_t direction = CVarGetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), -1); int mouseButton = CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0); @@ -89,7 +89,7 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn return nullptr; } - return std::make_shared( + return std::make_shared( portIndex, stickIndex, static_cast(direction), static_cast(mouseButton)); } diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp index 640f8f06c..19052e813 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp @@ -4,7 +4,7 @@ #include "libultraship/libultra/controller.h" #include "Context.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h" -#include "controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h" #include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h" @@ -68,10 +68,10 @@ std::shared_ptr ButtonMappingFactory::CreateButtonMappi return std::make_shared(portIndex, bitmask, static_cast(scancode)); } - if (mappingClass == "MouseKeyToButtonMapping") { + if (mappingClass == "MouseButtonToButtonMapping") { int mouseButton = CVarGetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), 0); - return std::make_shared(portIndex, bitmask, static_cast(mouseButton)); + return std::make_shared(portIndex, bitmask, static_cast(mouseButton)); } return nullptr; diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.cpp similarity index 50% rename from src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp rename to src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.cpp index 98afda036..cb9622e12 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.cpp @@ -1,22 +1,22 @@ -#include "MouseKeyToAnyMapping.h" +#include "MouseButtonToAnyMapping.h" #include "Context.h" #include "utils/StringHelper.h" #include "window/gui/IconsFontAwesome4.h" namespace Ship { -MouseKeyToAnyMapping::MouseKeyToAnyMapping(MouseBtn button) +MouseButtonToAnyMapping::MouseButtonToAnyMapping(MouseBtn button) : ControllerInputMapping(ShipDeviceIndex::Mouse), mButton(button), mKeyPressed(false) { } -MouseKeyToAnyMapping::~MouseKeyToAnyMapping() { +MouseButtonToAnyMapping::~MouseButtonToAnyMapping() { } -std::string MouseKeyToAnyMapping::GetPhysicalInputName() { +std::string MouseButtonToAnyMapping::GetPhysicalInputName() { return mouseBtnNames[static_cast(mButton)]; } -bool MouseKeyToAnyMapping::ProcessMouseEvent(bool isPressed, MouseBtn button) { +bool MouseButtonToAnyMapping::ProcessMouseEvent(bool isPressed, MouseBtn button) { if (mButton != button) { return false; } @@ -25,11 +25,11 @@ bool MouseKeyToAnyMapping::ProcessMouseEvent(bool isPressed, MouseBtn button) { return true; } -std::string MouseKeyToAnyMapping::GetPhysicalDeviceName() { +std::string MouseButtonToAnyMapping::GetPhysicalDeviceName() { return "Mouse"; } -bool MouseKeyToAnyMapping::PhysicalDeviceIsConnected() { +bool MouseButtonToAnyMapping::PhysicalDeviceIsConnected() { return true; } } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.h similarity index 76% rename from src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h rename to src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.h index 7a1f1fbf0..20d106dae 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAnyMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.h @@ -4,10 +4,10 @@ #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Ship { -class MouseKeyToAnyMapping : virtual public ControllerInputMapping { +class MouseButtonToAnyMapping : virtual public ControllerInputMapping { public: - MouseKeyToAnyMapping(MouseBtn button); - ~MouseKeyToAnyMapping(); + MouseButtonToAnyMapping(MouseBtn button); + ~MouseButtonToAnyMapping(); std::string GetPhysicalInputName() override; bool ProcessMouseEvent(bool isPressed, MouseBtn button); std::string GetPhysicalDeviceName() override; diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp similarity index 73% rename from src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp rename to src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp index aee10ecde..10ec75242 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp @@ -1,4 +1,4 @@ -#include "MouseKeyToAxisDirectionMapping.h" +#include "MouseButtonToAxisDirectionMapping.h" #include #include "utils/StringHelper.h" #include "window/gui/IconsFontAwesome4.h" @@ -6,13 +6,13 @@ #include "Context.h" namespace Ship { -MouseKeyToAxisDirectionMapping::MouseKeyToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, +MouseButtonToAxisDirectionMapping::MouseButtonToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, MouseBtn button) - : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button), + : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseButtonToAnyMapping(button), ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stickIndex, direction) { } -float MouseKeyToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { +float MouseButtonToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { if (Context::GetInstance()->GetControlDeck()->MouseGameInputBlocked()) { return 0.0f; } @@ -20,21 +20,21 @@ float MouseKeyToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { return mKeyPressed ? MAX_AXIS_RANGE : 0.0f; } -std::string MouseKeyToAxisDirectionMapping::GetAxisDirectionMappingId() { +std::string MouseButtonToAxisDirectionMapping::GetAxisDirectionMappingId() { return StringHelper::Sprintf("P%d-S%d-D%d-MOUSE%d", mPortIndex, mStickIndex, mDirection, mButton); } -void MouseKeyToAxisDirectionMapping::SaveToConfig() { +void MouseButtonToAxisDirectionMapping::SaveToConfig() { const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId(); CVarSetString(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str(), - "MouseKeyToAxisDirectionMapping"); + "MouseButtonToAxisDirectionMapping"); CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStickIndex); CVarSetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), mDirection); CVarSetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), static_cast(mButton)); CVarSave(); } -void MouseKeyToAxisDirectionMapping::EraseFromConfig() { +void MouseButtonToAxisDirectionMapping::EraseFromConfig() { const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId(); CVarClear(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str()); CVarClear(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str()); @@ -43,7 +43,7 @@ void MouseKeyToAxisDirectionMapping::EraseFromConfig() { CVarSave(); } -uint8_t MouseKeyToAxisDirectionMapping::GetMappingType() { +uint8_t MouseButtonToAxisDirectionMapping::GetMappingType() { return MAPPING_TYPE_MOUSE; } } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h similarity index 62% rename from src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h rename to src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h index 11f955fdb..1ca59eda7 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToAxisDirectionMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h @@ -1,13 +1,13 @@ #pragma once #include "controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h" -#include "MouseKeyToAnyMapping.h" +#include "MouseButtonToAnyMapping.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Ship { -class MouseKeyToAxisDirectionMapping final : public MouseKeyToAnyMapping, public ControllerAxisDirectionMapping { +class MouseButtonToAxisDirectionMapping final : public MouseButtonToAnyMapping, public ControllerAxisDirectionMapping { public: - MouseKeyToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, MouseBtn button); + MouseButtonToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, MouseBtn button); float GetNormalizedAxisDirectionValue() override; std::string GetAxisDirectionMappingId() override; uint8_t GetMappingType() override; diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.cpp similarity index 69% rename from src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp rename to src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.cpp index 688ee5511..bcc639746 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.cpp @@ -1,16 +1,16 @@ -#include "MouseKeyToButtonMapping.h" +#include "MouseButtonToButtonMapping.h" #include #include "utils/StringHelper.h" #include "public/bridge/consolevariablebridge.h" #include "Context.h" namespace Ship { -MouseKeyToButtonMapping::MouseKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button) - : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseKeyToAnyMapping(button), +MouseButtonToButtonMapping::MouseButtonToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button) + : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseButtonToAnyMapping(button), ControllerButtonMapping(ShipDeviceIndex::Mouse, portIndex, bitmask) { } -void MouseKeyToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) { +void MouseButtonToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) { if (Context::GetInstance()->GetControlDeck()->MouseGameInputBlocked()) { return; } @@ -22,24 +22,24 @@ void MouseKeyToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) { padButtons |= mBitmask; } -uint8_t MouseKeyToButtonMapping::GetMappingType() { +uint8_t MouseButtonToButtonMapping::GetMappingType() { return MAPPING_TYPE_MOUSE; } -std::string MouseKeyToButtonMapping::GetButtonMappingId() { +std::string MouseButtonToButtonMapping::GetButtonMappingId() { return StringHelper::Sprintf("P%d-B%d-MOUSE%d", mPortIndex, mBitmask, mButton); } -void MouseKeyToButtonMapping::SaveToConfig() { +void MouseButtonToButtonMapping::SaveToConfig() { const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".ButtonMappings." + GetButtonMappingId(); CVarSetString(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str(), - "MouseKeyToButtonMapping"); + "MouseButtonToButtonMapping"); CVarSetInteger(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str(), mBitmask); CVarSetInteger(StringHelper::Sprintf("%s.MouseButton", mappingCvarKey.c_str()).c_str(), static_cast(mButton)); CVarSave(); } -void MouseKeyToButtonMapping::EraseFromConfig() { +void MouseButtonToButtonMapping::EraseFromConfig() { const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".ButtonMappings." + GetButtonMappingId(); CVarClear(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str()); diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h similarity index 65% rename from src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h rename to src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h index 0fe7f9897..9eb71308c 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseKeyToButtonMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h @@ -1,13 +1,13 @@ #pragma once #include "controller/controldevice/controller/mapping/ControllerButtonMapping.h" -#include "MouseKeyToAnyMapping.h" +#include "MouseButtonToAnyMapping.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" namespace Ship { -class MouseKeyToButtonMapping final : public MouseKeyToAnyMapping, public ControllerButtonMapping { +class MouseButtonToButtonMapping final : public MouseButtonToAnyMapping, public ControllerButtonMapping { public: - MouseKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button); + MouseButtonToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button); void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override; uint8_t GetMappingType() override; std::string GetButtonMappingId() override; From 2a8ba19bf0a556de86a95b631fe268ac2b65982a Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:50:15 +0000 Subject: [PATCH 27/58] fix name collision --- .../controldevice/controller/ControllerButton.cpp | 8 ++++---- .../controldevice/controller/ControllerStick.cpp | 8 ++++---- .../controller/mapping/keyboard/KeyboardScancodes.h | 10 +++++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index a127b6cb7..2766e4543 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -15,7 +15,7 @@ namespace Ship { ControllerButton::ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) : mPortIndex(portIndex), mBitmask(bitmask), mUseKeydownEventToCreateNewMapping(false), - mKeyboardScancodeForNewMapping(LUS_KB_UNKNOWN), mMouseButtonForNewMapping(MouseBtn::MOUSE_BTN_UNKNOWN) { + mKeyboardScancodeForNewMapping(LUS_KB_UNKNOWN), mMouseButtonForNewMapping(LUS_MOUSE_UNKNOWN) { } ControllerButton::~ControllerButton() { @@ -181,7 +181,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi mUseKeydownEventToCreateNewMapping = true; if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); - } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { + } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { // TODO: I dont think direct ImGui calls should be here mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); } else { @@ -193,7 +193,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi } mKeyboardScancodeForNewMapping = LUS_KB_UNKNOWN; - mMouseButtonForNewMapping = MouseBtn::MOUSE_BTN_UNKNOWN; + mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN; mUseKeydownEventToCreateNewMapping = false; if (id != "") { @@ -239,7 +239,7 @@ bool ControllerButton::ProcessMouseEvent(bool isPressed, MouseBtn button) { mMouseButtonForNewMapping = button; return true; } else { - mMouseButtonForNewMapping = MouseBtn::MOUSE_BTN_UNKNOWN; + mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN; } } diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 3ad3c6a0f..a2593801c 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -27,7 +27,7 @@ namespace Ship { ControllerStick::ControllerStick(uint8_t portIndex, StickIndex stickIndex) : mPortIndex(portIndex), mStickIndex(stickIndex), mUseKeydownEventToCreateNewMapping(false), mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN), - mMouseButtonForNewMapping(MouseBtn::MOUSE_BTN_UNKNOWN) { + mMouseButtonForNewMapping(LUS_MOUSE_BTN_UNKNOWN) { mSensitivityPercentage = DEFAULT_STICK_SENSITIVITY_PERCENTAGE; mSensitivity = 1.0f; mDeadzonePercentage = DEFAULT_STICK_DEADZONE_PERCENTAGE; @@ -276,7 +276,7 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mKeyboardScancodeForNewMapping); - } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != MouseBtn::MOUSE_BTN_UNKNOWN) { + } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { // TODO: I dont think direct ImGui calls should be here (again) mapping = std::make_shared(mPortIndex, mStickIndex, direction, mMouseButtonForNewMapping); @@ -290,7 +290,7 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct } mKeyboardScancodeForNewMapping = LUS_KB_UNKNOWN; - mMouseButtonForNewMapping = MouseBtn::MOUSE_BTN_UNKNOWN; + mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN; mUseKeydownEventToCreateNewMapping = false; if (id != "") { @@ -356,7 +356,7 @@ bool ControllerStick::ProcessMouseEvent(bool isPressed, MouseBtn button) { mMouseButtonForNewMapping = button; return true; } else { - mMouseButtonForNewMapping = MouseBtn::MOUSE_BTN_UNKNOWN; + mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN; } } diff --git a/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h b/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h index 601b29b20..f1e9b70b5 100644 --- a/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h +++ b/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h @@ -120,7 +120,15 @@ typedef enum KbScancode { LUS_KB_MAX } KbScancode; -typedef enum MouseBtn { LEFT, MIDDLE, RIGHT, BACKWARD, FORWARD, MOUSE_BTN_COUNT, MOUSE_BTN_UNKNOWN } MouseBtn; +typedef enum MouseBtn { + LUS_MOUSE_BTN_LEFT, + LUS_MOUSE_BTN_MIDDLE, + LUS_MOUSE_BTN_RIGHT, + LUS_MOUSE_BTN_BACKWARD, + LUS_MOUSE_BTN_FORWARD, + LUS_MOUSE_BTN_COUNT, + LUS_MOUSE_BTN_UNKNOWN +} MouseBtn; #ifdef __cplusplus static std::string mouseBtnNames[7] = { "MouseLeft", "MouseMiddle", "MouseRight", "MouseBackward", From 29a9112f024bf109cd084e4070e1ec4fdc72379e Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:55:16 +0000 Subject: [PATCH 28/58] another name collision fix --- src/controller/controldevice/controller/ControllerButton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index 2766e4543..9ce818297 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -15,7 +15,7 @@ namespace Ship { ControllerButton::ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) : mPortIndex(portIndex), mBitmask(bitmask), mUseKeydownEventToCreateNewMapping(false), - mKeyboardScancodeForNewMapping(LUS_KB_UNKNOWN), mMouseButtonForNewMapping(LUS_MOUSE_UNKNOWN) { + mKeyboardScancodeForNewMapping(LUS_KB_UNKNOWN), mMouseButtonForNewMapping(LUS_MOUSE_BTN_UNKNOWN) { } ControllerButton::~ControllerButton() { From 83aa166b11e4123e4867fa1326f1e83cc72ff683 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:15:31 +0000 Subject: [PATCH 29/58] remove imgui direct calls --- src/controller/controldevice/controller/ControllerButton.cpp | 5 ++--- src/controller/controldevice/controller/ControllerStick.cpp | 5 ++--- src/window/gui/Gui.cpp | 4 ++++ src/window/gui/Gui.h | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index 9ce818297..8b7aa7b7c 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include "Context.h" namespace Ship { ControllerButton::ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) @@ -181,8 +181,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi mUseKeydownEventToCreateNewMapping = true; if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); - } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { - // TODO: I dont think direct ImGui calls should be here + } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); } else { mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask); diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index a2593801c..278d432be 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include "Context.h" // for some reason windows isn't seeing M_PI // this is copied from my system's math.h @@ -276,8 +276,7 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mKeyboardScancodeForNewMapping); - } else if (!ImGui::IsAnyItemHovered() && mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { - // TODO: I dont think direct ImGui calls should be here (again) + } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mMouseButtonForNewMapping); } else { diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 2f3af046c..e87c3b65e 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -991,6 +991,10 @@ bool Gui::GetMenuOrMenubarVisible() { return (GetMenuBar() && GetMenuBar()->IsVisible()) || (GetMenu() && GetMenu()->IsVisible()); } +bool Gui::IsMouseOverAnyGuiItem() { + return ImGui::IsAnyItemHovered(); +} + std::shared_ptr Gui::GetMenu() { return mMenu; } diff --git a/src/window/gui/Gui.h b/src/window/gui/Gui.h index 224d32eab..12913bad0 100644 --- a/src/window/gui/Gui.h +++ b/src/window/gui/Gui.h @@ -99,6 +99,7 @@ class Gui { void SetMenu(std::shared_ptr menu); std::shared_ptr GetMenu(); bool GetMenuOrMenubarVisible(); + bool IsMouseOverAnyGuiItem(); bool GamepadNavigationEnabled(); void BlockGamepadNavigation(); From 3be8ed35e89866bd305f14d989d5bc59403c1828 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:16:21 +0000 Subject: [PATCH 30/58] clang-format --- .../controldevice/controller/ControllerButton.cpp | 3 ++- .../controldevice/controller/ControllerStick.cpp | 8 ++++---- .../mapping/mouse/MouseButtonToAxisDirectionMapping.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index 8b7aa7b7c..44a915f84 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -181,7 +181,8 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi mUseKeydownEventToCreateNewMapping = true; if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); - } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && + mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); } else { mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask); diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 278d432be..547779c12 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -26,8 +26,7 @@ namespace Ship { ControllerStick::ControllerStick(uint8_t portIndex, StickIndex stickIndex) : mPortIndex(portIndex), mStickIndex(stickIndex), mUseKeydownEventToCreateNewMapping(false), - mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN), - mMouseButtonForNewMapping(LUS_MOUSE_BTN_UNKNOWN) { + mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN), mMouseButtonForNewMapping(LUS_MOUSE_BTN_UNKNOWN) { mSensitivityPercentage = DEFAULT_STICK_SENSITIVITY_PERCENTAGE; mSensitivity = 1.0f; mDeadzonePercentage = DEFAULT_STICK_DEADZONE_PERCENTAGE; @@ -276,9 +275,10 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mKeyboardScancodeForNewMapping); - } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && + mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, - mMouseButtonForNewMapping); + mMouseButtonForNewMapping); } else { mapping = AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(mPortIndex, mStickIndex, direction); diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp index 10ec75242..2b36ee8ab 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp @@ -7,7 +7,7 @@ namespace Ship { MouseButtonToAxisDirectionMapping::MouseButtonToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, - Direction direction, MouseBtn button) + Direction direction, MouseBtn button) : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseButtonToAnyMapping(button), ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stickIndex, direction) { } From dbd830fa78e45f9ec666c1b1560f824b2965ad3e Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:32:21 +0000 Subject: [PATCH 31/58] MouseCapture keybind --- src/graphic/Fast3D/Fast3dWindow.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 494a0e233..7f876eff2 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -270,6 +270,13 @@ bool Fast3dWindow::KeyUp(int32_t scancode) { Ship::Context::GetInstance()->GetWindow()->ToggleFullscreen(); } + if (scancode == Ship::Context::GetInstance()->GetConfig()->GetInt("Shortcuts.MouseCapture", Ship::KbScancode::LUS_KB_F2)) { + bool captureState = Ship::Context::GetInstance()->GetWindow()->IsMouseCaptured(); + if (captureState || !Ship::Context::GetInstance()->GetWindow()->GetGui()->GetMenuOrMenubarVisible()) { + Ship::Context::GetInstance()->GetWindow()->SetMouseCapture(!captureState); + } + } + Ship::Context::GetInstance()->GetWindow()->SetLastScancode(-1); return Ship::Context::GetInstance()->GetControlDeck()->ProcessKeyboardEvent( Ship::KbEventType::LUS_KB_EVENT_KEY_UP, static_cast(scancode)); From e3159772fce3b056c52bc090cdeabdc626fde5f1 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:54:24 +0000 Subject: [PATCH 32/58] replace cursor visibility with mouse capture --- src/graphic/Fast3D/Fast3dWindow.cpp | 6 +++--- src/window/gui/Gui.cpp | 13 ++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 7f876eff2..28c86279f 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -311,10 +311,10 @@ void Fast3dWindow::OnFullscreenChanged(bool isNowFullscreen) { if (isNowFullscreen) { auto menuBar = wnd->GetGui()->GetMenuBar(); - wnd->SetCursorVisibility(menuBar && menuBar->IsVisible() || wnd->ShouldForceCursorVisibility() || - CVarGetInteger("gWindows.Menu", 0)); + wnd->SetMouseCapture(!(menuBar && menuBar->IsVisible() || wnd->ShouldForceCursorVisibility() || + CVarGetInteger("gWindows.Menu", 0))); } else { - wnd->SetCursorVisibility(true); + wnd->SetMouseCapture(false); } } } // namespace Fast diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index e87c3b65e..18903683a 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -494,9 +494,8 @@ void Gui::DrawMenu() { GetMenuBar()->ToggleVisibility(); } if (wnd->IsFullscreen()) { - // TODO: mouse capture? - Context::GetInstance()->GetWindow()->SetCursorVisibility(GetMenuOrMenubarVisible() || - wnd->ShouldForceCursorVisibility()); + Context::GetInstance()->GetWindow()->SetMouseCapture(!(GetMenuOrMenubarVisible() || + wnd->ShouldForceCursorVisibility())); } if (CVarGetInteger(CVAR_IMGUI_CONTROLLER_NAV, 0) && GetMenuOrMenubarVisible()) { mImGuiIo->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; @@ -963,9 +962,9 @@ void Gui::SetMenuBar(std::shared_ptr menuBar) { } if (Context::GetInstance()->GetWindow()->IsFullscreen()) { - Context::GetInstance()->GetWindow()->SetCursorVisibility( + Context::GetInstance()->GetWindow()->SetMouseCapture(!( (GetMenuBar() && GetMenuBar()->IsVisible()) || - Context::GetInstance()->GetWindow()->ShouldForceCursorVisibility()); + Context::GetInstance()->GetWindow()->ShouldForceCursorVisibility())); } } @@ -977,9 +976,9 @@ void Gui::SetMenu(std::shared_ptr menu) { } if (Context::GetInstance()->GetWindow()->IsFullscreen()) { - Context::GetInstance()->GetWindow()->SetCursorVisibility( + Context::GetInstance()->GetWindow()->SetMouseCapture(!( (GetMenu() && GetMenu()->IsVisible()) || - Context::GetInstance()->GetWindow()->ShouldForceCursorVisibility()); + Context::GetInstance()->GetWindow()->ShouldForceCursorVisibility())); } } From 478daf4013dcefdb4b828061a31fed3d02cf422c Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:55:06 +0000 Subject: [PATCH 33/58] clang-format --- src/graphic/Fast3D/Fast3dWindow.cpp | 5 +++-- src/window/gui/Gui.cpp | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 28c86279f..0cee39af6 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -270,7 +270,8 @@ bool Fast3dWindow::KeyUp(int32_t scancode) { Ship::Context::GetInstance()->GetWindow()->ToggleFullscreen(); } - if (scancode == Ship::Context::GetInstance()->GetConfig()->GetInt("Shortcuts.MouseCapture", Ship::KbScancode::LUS_KB_F2)) { + if (scancode == + Ship::Context::GetInstance()->GetConfig()->GetInt("Shortcuts.MouseCapture", Ship::KbScancode::LUS_KB_F2)) { bool captureState = Ship::Context::GetInstance()->GetWindow()->IsMouseCaptured(); if (captureState || !Ship::Context::GetInstance()->GetWindow()->GetGui()->GetMenuOrMenubarVisible()) { Ship::Context::GetInstance()->GetWindow()->SetMouseCapture(!captureState); @@ -312,7 +313,7 @@ void Fast3dWindow::OnFullscreenChanged(bool isNowFullscreen) { if (isNowFullscreen) { auto menuBar = wnd->GetGui()->GetMenuBar(); wnd->SetMouseCapture(!(menuBar && menuBar->IsVisible() || wnd->ShouldForceCursorVisibility() || - CVarGetInteger("gWindows.Menu", 0))); + CVarGetInteger("gWindows.Menu", 0))); } else { wnd->SetMouseCapture(false); } diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 18903683a..aa6b8edb4 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -494,8 +494,8 @@ void Gui::DrawMenu() { GetMenuBar()->ToggleVisibility(); } if (wnd->IsFullscreen()) { - Context::GetInstance()->GetWindow()->SetMouseCapture(!(GetMenuOrMenubarVisible() || - wnd->ShouldForceCursorVisibility())); + Context::GetInstance()->GetWindow()->SetMouseCapture( + !(GetMenuOrMenubarVisible() || wnd->ShouldForceCursorVisibility())); } if (CVarGetInteger(CVAR_IMGUI_CONTROLLER_NAV, 0) && GetMenuOrMenubarVisible()) { mImGuiIo->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; @@ -962,9 +962,9 @@ void Gui::SetMenuBar(std::shared_ptr menuBar) { } if (Context::GetInstance()->GetWindow()->IsFullscreen()) { - Context::GetInstance()->GetWindow()->SetMouseCapture(!( - (GetMenuBar() && GetMenuBar()->IsVisible()) || - Context::GetInstance()->GetWindow()->ShouldForceCursorVisibility())); + Context::GetInstance()->GetWindow()->SetMouseCapture( + !((GetMenuBar() && GetMenuBar()->IsVisible()) || + Context::GetInstance()->GetWindow()->ShouldForceCursorVisibility())); } } @@ -976,9 +976,9 @@ void Gui::SetMenu(std::shared_ptr menu) { } if (Context::GetInstance()->GetWindow()->IsFullscreen()) { - Context::GetInstance()->GetWindow()->SetMouseCapture(!( - (GetMenu() && GetMenu()->IsVisible()) || - Context::GetInstance()->GetWindow()->ShouldForceCursorVisibility())); + Context::GetInstance()->GetWindow()->SetMouseCapture( + !((GetMenu() && GetMenu()->IsVisible()) || + Context::GetInstance()->GetWindow()->ShouldForceCursorVisibility())); } } From 1b4a616a44bfeb5483bf1665f1a7632438aea71c Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:54:24 +0000 Subject: [PATCH 34/58] mUseKeydownEventToCreateNewMapping -> mUseInputToCreateNewMapping --- .../controldevice/controller/ControllerButton.cpp | 10 +++++----- .../controldevice/controller/ControllerButton.h | 2 +- .../controldevice/controller/ControllerStick.cpp | 10 +++++----- .../controldevice/controller/ControllerStick.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index 44a915f84..fc81dc193 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -14,7 +14,7 @@ namespace Ship { ControllerButton::ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) - : mPortIndex(portIndex), mBitmask(bitmask), mUseKeydownEventToCreateNewMapping(false), + : mPortIndex(portIndex), mBitmask(bitmask), mUseInputToCreateNewMapping(false), mKeyboardScancodeForNewMapping(LUS_KB_UNKNOWN), mMouseButtonForNewMapping(LUS_MOUSE_BTN_UNKNOWN) { } @@ -178,7 +178,7 @@ bool ControllerButton::HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex) { bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bitmask, std::string id) { std::shared_ptr mapping = nullptr; - mUseKeydownEventToCreateNewMapping = true; + mUseInputToCreateNewMapping = true; if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && @@ -194,7 +194,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi mKeyboardScancodeForNewMapping = LUS_KB_UNKNOWN; mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN; - mUseKeydownEventToCreateNewMapping = false; + mUseInputToCreateNewMapping = false; if (id != "") { ClearButtonMapping(id); @@ -211,7 +211,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi } bool ControllerButton::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) { - if (mUseKeydownEventToCreateNewMapping) { + if (mUseInputToCreateNewMapping) { if (eventType == LUS_KB_EVENT_KEY_DOWN) { mKeyboardScancodeForNewMapping = scancode; return true; @@ -234,7 +234,7 @@ bool ControllerButton::ProcessKeyboardEvent(KbEventType eventType, KbScancode sc } bool ControllerButton::ProcessMouseEvent(bool isPressed, MouseBtn button) { - if (mUseKeydownEventToCreateNewMapping) { + if (mUseInputToCreateNewMapping) { if (isPressed) { mMouseButtonForNewMapping = button; return true; diff --git a/src/controller/controldevice/controller/ControllerButton.h b/src/controller/controldevice/controller/ControllerButton.h index 0678d3813..d541c76dc 100644 --- a/src/controller/controldevice/controller/ControllerButton.h +++ b/src/controller/controldevice/controller/ControllerButton.h @@ -47,7 +47,7 @@ class ControllerButton { std::unordered_map> mButtonMappings; std::string GetConfigNameFromBitmask(CONTROLLERBUTTONS_T bitmask); - bool mUseKeydownEventToCreateNewMapping; + bool mUseInputToCreateNewMapping; KbScancode mKeyboardScancodeForNewMapping; MouseBtn mMouseButtonForNewMapping; }; diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 547779c12..4dcb57ce0 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -25,7 +25,7 @@ namespace Ship { ControllerStick::ControllerStick(uint8_t portIndex, StickIndex stickIndex) - : mPortIndex(portIndex), mStickIndex(stickIndex), mUseKeydownEventToCreateNewMapping(false), + : mPortIndex(portIndex), mStickIndex(stickIndex), mUseInputToCreateNewMapping(false), mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN), mMouseButtonForNewMapping(LUS_MOUSE_BTN_UNKNOWN) { mSensitivityPercentage = DEFAULT_STICK_SENSITIVITY_PERCENTAGE; mSensitivity = 1.0f; @@ -271,7 +271,7 @@ void ControllerStick::Process(int8_t& x, int8_t& y) { bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direction, std::string id) { std::shared_ptr mapping = nullptr; - mUseKeydownEventToCreateNewMapping = true; + mUseInputToCreateNewMapping = true; if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mKeyboardScancodeForNewMapping); @@ -290,7 +290,7 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct mKeyboardScancodeForNewMapping = LUS_KB_UNKNOWN; mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN; - mUseKeydownEventToCreateNewMapping = false; + mUseInputToCreateNewMapping = false; if (id != "") { ClearAxisDirectionMapping(direction, id); @@ -325,7 +325,7 @@ void ControllerStick::UpdatePad(int8_t& x, int8_t& y) { } bool ControllerStick::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) { - if (mUseKeydownEventToCreateNewMapping) { + if (mUseInputToCreateNewMapping) { if (eventType == LUS_KB_EVENT_KEY_DOWN) { mKeyboardScancodeForNewMapping = scancode; return true; @@ -350,7 +350,7 @@ bool ControllerStick::ProcessKeyboardEvent(KbEventType eventType, KbScancode sca } bool ControllerStick::ProcessMouseEvent(bool isPressed, MouseBtn button) { - if (mUseKeydownEventToCreateNewMapping) { + if (mUseInputToCreateNewMapping) { if (isPressed) { mMouseButtonForNewMapping = button; return true; diff --git a/src/controller/controldevice/controller/ControllerStick.h b/src/controller/controldevice/controller/ControllerStick.h index 806aeb4c9..ea0283ba3 100644 --- a/src/controller/controldevice/controller/ControllerStick.h +++ b/src/controller/controldevice/controller/ControllerStick.h @@ -76,7 +76,7 @@ class ControllerStick { std::unordered_map>> mAxisDirectionMappings; - bool mUseKeydownEventToCreateNewMapping; + bool mUseInputToCreateNewMapping; KbScancode mKeyboardScancodeForNewMapping; MouseBtn mMouseButtonForNewMapping; }; From d27d4f47024344277356c202c7bdb3bccddc8171 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Thu, 19 Dec 2024 06:11:27 +0700 Subject: [PATCH 35/58] change MAPPING_TYPE_UNKNOWN to -1 --- .../controldevice/controller/mapping/ControllerMapping.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/controldevice/controller/mapping/ControllerMapping.h b/src/controller/controldevice/controller/mapping/ControllerMapping.h index c827e372a..646693765 100644 --- a/src/controller/controldevice/controller/mapping/ControllerMapping.h +++ b/src/controller/controldevice/controller/mapping/ControllerMapping.h @@ -5,10 +5,10 @@ namespace Ship { +#define MAPPING_TYPE_UNKNOWN -1 #define MAPPING_TYPE_GAMEPAD 0 #define MAPPING_TYPE_KEYBOARD 1 #define MAPPING_TYPE_MOUSE 2 -#define MAPPING_TYPE_UNKNOWN 3 class ControllerMapping { public: From ee65d7fc2c2a1c8202b19d70a0b130f121de522c Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Sun, 22 Dec 2024 03:29:15 +0000 Subject: [PATCH 36/58] dxgi/sdl GetMouseDelta parity --- src/graphic/Fast3D/gfx_dxgi.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index f45c0199a..c70d11db5 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -564,12 +564,14 @@ static void gfx_dxgi_get_mouse_pos(int32_t* x, int32_t* y) { } static void gfx_dxgi_get_mouse_delta(int32_t* x, int32_t* y) { - POINT p; - GetCursorPos(&p); - ScreenToClient(dxgi.h_wnd, &p); - *x = p.x - dxgi.current_width / 2; - *y = p.y - dxgi.current_height / 2; - SetCursorPos(dxgi.current_width / 2, dxgi.current_height / 2); + if (dxgi.is_mouse_captured) { + POINT p; + GetCursorPos(&p); + ScreenToClient(dxgi.h_wnd, &p); + *x = p.x - dxgi.current_width / 2; + *y = p.y - dxgi.current_height / 2; + SetCursorPos(dxgi.current_width / 2, dxgi.current_height / 2); + } } static void gfx_dxgi_get_mouse_wheel(float* x, float* y) { From a272e1a6b87d99743af84cae11a77df964028475 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Sun, 22 Dec 2024 03:38:43 +0000 Subject: [PATCH 37/58] set x/y to zero when no capture --- src/graphic/Fast3D/gfx_dxgi.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index c70d11db5..f65647818 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -571,6 +571,9 @@ static void gfx_dxgi_get_mouse_delta(int32_t* x, int32_t* y) { *x = p.x - dxgi.current_width / 2; *y = p.y - dxgi.current_height / 2; SetCursorPos(dxgi.current_width / 2, dxgi.current_height / 2); + } else { + *x = 0; + *y = 0; } } From 2a2e05d3cbff73233c87137c8d16edfe603d22a0 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Fri, 27 Dec 2024 04:58:23 +0700 Subject: [PATCH 38/58] mapping type uint -> int for MAPPING_TYPE_UNKNOWN = -1 --- .../controller/mapping/ControllerAxisDirectionMapping.cpp | 2 +- .../controller/mapping/ControllerAxisDirectionMapping.h | 2 +- .../controller/mapping/ControllerButtonMapping.cpp | 2 +- .../controldevice/controller/mapping/ControllerButtonMapping.h | 2 +- .../mapping/keyboard/KeyboardKeyToAxisDirectionMapping.cpp | 2 +- .../mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h | 2 +- .../controller/mapping/keyboard/KeyboardKeyToButtonMapping.cpp | 2 +- .../controller/mapping/keyboard/KeyboardKeyToButtonMapping.h | 2 +- .../mapping/mouse/MouseButtonToAxisDirectionMapping.cpp | 2 +- .../mapping/mouse/MouseButtonToAxisDirectionMapping.h | 2 +- .../controller/mapping/mouse/MouseButtonToButtonMapping.cpp | 2 +- .../controller/mapping/mouse/MouseButtonToButtonMapping.h | 2 +- .../mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.cpp | 2 +- .../mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h | 2 +- .../controller/mapping/sdl/SDLAxisDirectionToButtonMapping.cpp | 2 +- .../controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h | 2 +- .../controller/mapping/sdl/SDLButtonToAxisDirectionMapping.cpp | 2 +- .../controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h | 2 +- .../controller/mapping/sdl/SDLButtonToButtonMapping.cpp | 2 +- .../controller/mapping/sdl/SDLButtonToButtonMapping.h | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.cpp index 9fce4939b..454dc902e 100644 --- a/src/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.cpp @@ -12,7 +12,7 @@ ControllerAxisDirectionMapping::ControllerAxisDirectionMapping(ShipDeviceIndex s ControllerAxisDirectionMapping::~ControllerAxisDirectionMapping() { } -uint8_t ControllerAxisDirectionMapping::GetMappingType() { +int8_t ControllerAxisDirectionMapping::GetMappingType() { return MAPPING_TYPE_UNKNOWN; } diff --git a/src/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h index 5655049be..6a825a826 100644 --- a/src/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h +++ b/src/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h @@ -17,7 +17,7 @@ class ControllerAxisDirectionMapping : virtual public ControllerInputMapping { Direction direction); ~ControllerAxisDirectionMapping(); virtual float GetNormalizedAxisDirectionValue() = 0; - virtual uint8_t GetMappingType(); + virtual int8_t GetMappingType(); virtual std::string GetAxisDirectionMappingId() = 0; virtual void SaveToConfig() = 0; diff --git a/src/controller/controldevice/controller/mapping/ControllerButtonMapping.cpp b/src/controller/controldevice/controller/mapping/ControllerButtonMapping.cpp index 2362fb6c0..8040eff42 100644 --- a/src/controller/controldevice/controller/mapping/ControllerButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/ControllerButtonMapping.cpp @@ -18,7 +18,7 @@ CONTROLLERBUTTONS_T ControllerButtonMapping::GetBitmask() { return mBitmask; } -uint8_t ControllerButtonMapping::GetMappingType() { +int8_t ControllerButtonMapping::GetMappingType() { return MAPPING_TYPE_UNKNOWN; } diff --git a/src/controller/controldevice/controller/mapping/ControllerButtonMapping.h b/src/controller/controldevice/controller/mapping/ControllerButtonMapping.h index b4e57b92b..324839349 100644 --- a/src/controller/controldevice/controller/mapping/ControllerButtonMapping.h +++ b/src/controller/controldevice/controller/mapping/ControllerButtonMapping.h @@ -20,7 +20,7 @@ class ControllerButtonMapping : virtual public ControllerInputMapping { CONTROLLERBUTTONS_T GetBitmask(); virtual void UpdatePad(CONTROLLERBUTTONS_T& padButtons) = 0; - virtual uint8_t GetMappingType(); + virtual int8_t GetMappingType(); void SetPortIndex(uint8_t portIndex); virtual void SaveToConfig() = 0; diff --git a/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.cpp index 063432eef..992ac7643 100644 --- a/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.cpp @@ -43,7 +43,7 @@ void KeyboardKeyToAxisDirectionMapping::EraseFromConfig() { CVarSave(); } -uint8_t KeyboardKeyToAxisDirectionMapping::GetMappingType() { +int8_t KeyboardKeyToAxisDirectionMapping::GetMappingType() { return MAPPING_TYPE_KEYBOARD; } } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h index 000076ff1..a4e3bbacb 100644 --- a/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h +++ b/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h @@ -8,7 +8,7 @@ class KeyboardKeyToAxisDirectionMapping final : public KeyboardKeyToAnyMapping, KbScancode scancode); float GetNormalizedAxisDirectionValue() override; std::string GetAxisDirectionMappingId() override; - uint8_t GetMappingType() override; + int8_t GetMappingType() override; void SaveToConfig() override; void EraseFromConfig() override; }; diff --git a/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.cpp index ad3760cba..55caa2efc 100644 --- a/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.cpp @@ -23,7 +23,7 @@ void KeyboardKeyToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) { padButtons |= mBitmask; } -uint8_t KeyboardKeyToButtonMapping::GetMappingType() { +int8_t KeyboardKeyToButtonMapping::GetMappingType() { return MAPPING_TYPE_KEYBOARD; } diff --git a/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h b/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h index 81128c75a..be8f423a9 100644 --- a/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h +++ b/src/controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h @@ -6,7 +6,7 @@ class KeyboardKeyToButtonMapping final : public KeyboardKeyToAnyMapping, public public: KeyboardKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, KbScancode scancode); void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override; - uint8_t GetMappingType() override; + int8_t GetMappingType() override; std::string GetButtonMappingId() override; void SaveToConfig() override; void EraseFromConfig() override; diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp index 2b36ee8ab..39c1b1158 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.cpp @@ -43,7 +43,7 @@ void MouseButtonToAxisDirectionMapping::EraseFromConfig() { CVarSave(); } -uint8_t MouseButtonToAxisDirectionMapping::GetMappingType() { +int8_t MouseButtonToAxisDirectionMapping::GetMappingType() { return MAPPING_TYPE_MOUSE; } } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h index 1ca59eda7..62cd47950 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h @@ -10,7 +10,7 @@ class MouseButtonToAxisDirectionMapping final : public MouseButtonToAnyMapping, MouseButtonToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, MouseBtn button); float GetNormalizedAxisDirectionValue() override; std::string GetAxisDirectionMappingId() override; - uint8_t GetMappingType() override; + int8_t GetMappingType() override; void SaveToConfig() override; void EraseFromConfig() override; }; diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.cpp index bcc639746..238a0b05e 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.cpp @@ -22,7 +22,7 @@ void MouseButtonToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) { padButtons |= mBitmask; } -uint8_t MouseButtonToButtonMapping::GetMappingType() { +int8_t MouseButtonToButtonMapping::GetMappingType() { return MAPPING_TYPE_MOUSE; } diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h index 9eb71308c..7116ae9ce 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h @@ -9,7 +9,7 @@ class MouseButtonToButtonMapping final : public MouseButtonToAnyMapping, public public: MouseButtonToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button); void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override; - uint8_t GetMappingType() override; + int8_t GetMappingType() override; std::string GetButtonMappingId() override; void SaveToConfig() override; void EraseFromConfig() override; diff --git a/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.cpp index 7916dee94..f94c307cb 100644 --- a/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.cpp @@ -68,7 +68,7 @@ void SDLAxisDirectionToAxisDirectionMapping::EraseFromConfig() { CVarSave(); } -uint8_t SDLAxisDirectionToAxisDirectionMapping::GetMappingType() { +int8_t SDLAxisDirectionToAxisDirectionMapping::GetMappingType() { return MAPPING_TYPE_GAMEPAD; } } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h index 133bb1e3c..1ff06e295 100644 --- a/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h +++ b/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h @@ -9,7 +9,7 @@ class SDLAxisDirectionToAxisDirectionMapping final : public ControllerAxisDirect Direction direction, int32_t sdlControllerAxis, int32_t axisDirection); float GetNormalizedAxisDirectionValue() override; std::string GetAxisDirectionMappingId() override; - uint8_t GetMappingType() override; + int8_t GetMappingType() override; void SaveToConfig() override; void EraseFromConfig() override; }; diff --git a/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.cpp index 2d9219a90..de57fe4b9 100644 --- a/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.cpp @@ -45,7 +45,7 @@ void SDLAxisDirectionToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) } } -uint8_t SDLAxisDirectionToButtonMapping::GetMappingType() { +int8_t SDLAxisDirectionToButtonMapping::GetMappingType() { return MAPPING_TYPE_GAMEPAD; } diff --git a/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h b/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h index 6b4590025..b5e9aeb6e 100644 --- a/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h +++ b/src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h @@ -7,7 +7,7 @@ class SDLAxisDirectionToButtonMapping final : public ControllerButtonMapping, pu SDLAxisDirectionToButtonMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, int32_t sdlControllerAxis, int32_t axisDirection); void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override; - uint8_t GetMappingType() override; + int8_t GetMappingType() override; std::string GetButtonMappingId() override; void SaveToConfig() override; void EraseFromConfig() override; diff --git a/src/controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.cpp index 5693a492e..5044f4839 100644 --- a/src/controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.cpp @@ -52,7 +52,7 @@ void SDLButtonToAxisDirectionMapping::EraseFromConfig() { CVarSave(); } -uint8_t SDLButtonToAxisDirectionMapping::GetMappingType() { +int8_t SDLButtonToAxisDirectionMapping::GetMappingType() { return MAPPING_TYPE_GAMEPAD; } } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h index 2b1faa42b..445c02615 100644 --- a/src/controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h +++ b/src/controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h @@ -8,7 +8,7 @@ class SDLButtonToAxisDirectionMapping final : public ControllerAxisDirectionMapp Direction direction, int32_t sdlControllerButton); float GetNormalizedAxisDirectionValue() override; std::string GetAxisDirectionMappingId() override; - uint8_t GetMappingType() override; + int8_t GetMappingType() override; void SaveToConfig() override; void EraseFromConfig() override; }; diff --git a/src/controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.cpp index c6cfce52d..1c3d730be 100644 --- a/src/controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.cpp @@ -26,7 +26,7 @@ void SDLButtonToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) { } } -uint8_t SDLButtonToButtonMapping::GetMappingType() { +int8_t SDLButtonToButtonMapping::GetMappingType() { return MAPPING_TYPE_GAMEPAD; } diff --git a/src/controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h b/src/controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h index d31941496..3271a6e0a 100644 --- a/src/controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h +++ b/src/controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h @@ -7,7 +7,7 @@ class SDLButtonToButtonMapping final : public SDLButtonToAnyMapping, public Cont SDLButtonToButtonMapping(ShipDeviceIndex shipDeviceIndex, uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, int32_t sdlControllerButton); void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override; - uint8_t GetMappingType() override; + int8_t GetMappingType() override; std::string GetButtonMappingId() override; void SaveToConfig() override; void EraseFromConfig() override; From e16544ffc087ac64e1dd0df88fdd6a8365e3a03b Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Tue, 24 Dec 2024 23:15:39 +0000 Subject: [PATCH 39/58] offset mapping popup --- src/window/gui/InputEditorWindow.cpp | 15 +++++++++++++++ src/window/gui/InputEditorWindow.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/window/gui/InputEditorWindow.cpp b/src/window/gui/InputEditorWindow.cpp index e9e26a771..e121c45bc 100644 --- a/src/window/gui/InputEditorWindow.cpp +++ b/src/window/gui/InputEditorWindow.cpp @@ -217,6 +217,7 @@ void InputEditorWindow::DrawButtonLineAddMappingButton(uint8_t port, CONTROLLERB if (ImGui::Button(StringHelper::Sprintf("%s###addButtonMappingButton%d-%d", ICON_FA_PLUS, port, bitmask).c_str(), ImVec2(SCALE_IMGUI_SIZE(20.0f), 0.0f))) { ImGui::OpenPopup(popupId.c_str()); + OffsetMappingPopup(); }; ImGui::PopStyleVar(); @@ -278,6 +279,7 @@ void InputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, CONTROLLER .c_str(), ImVec2(ImGui::CalcTextSize(physicalInputDisplayName.c_str()).x + SCALE_IMGUI_SIZE(12.0f), 0.0f))) { ImGui::OpenPopup(popupId.c_str()); + OffsetMappingPopup(); } if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal | ImGuiHoveredFlags_NoSharedDelay)) { ImGui::SetTooltip("%s", mapping->GetPhysicalDeviceName().c_str()); @@ -325,6 +327,7 @@ void InputEditorWindow::DrawButtonLineEditMappingButton(uint8_t port, CONTROLLER if (ImGui::Button(StringHelper::Sprintf("%s###editAxisThresholdButton%s", ICON_FA_COG, id.c_str()).c_str(), ImVec2(ImGui::CalcTextSize(ICON_FA_COG).x + SCALE_IMGUI_SIZE(10.0f), 0.0f))) { ImGui::OpenPopup(popupId.c_str()); + OffsetMappingPopup(); } if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal | ImGuiHoveredFlags_NoSharedDelay)) { ImGui::SetTooltip("Edit axis threshold"); @@ -460,6 +463,7 @@ void InputEditorWindow::DrawStickDirectionLineAddMappingButton(uint8_t port, uin .c_str(), ImVec2(SCALE_IMGUI_SIZE(20.0f), 0.0f))) { ImGui::OpenPopup(popupId.c_str()); + OffsetMappingPopup(); }; ImGui::PopStyleVar(); @@ -546,6 +550,7 @@ void InputEditorWindow::DrawStickDirectionLineEditMappingButton(uint8_t port, ui .c_str(), ImVec2(ImGui::CalcTextSize(physicalInputDisplayName.c_str()).x + SCALE_IMGUI_SIZE(12.0f), 0.0f))) { ImGui::OpenPopup(popupId.c_str()); + OffsetMappingPopup(); } if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal | ImGuiHoveredFlags_NoSharedDelay)) { ImGui::SetTooltip("%s", mapping->GetPhysicalDeviceName().c_str()); @@ -822,6 +827,7 @@ void InputEditorWindow::DrawAddRumbleMappingButton(uint8_t port) { if (ImGui::Button(StringHelper::Sprintf("%s###addRumbleMapping%d", ICON_FA_PLUS, port).c_str(), ImVec2(SCALE_IMGUI_SIZE(20.0f), SCALE_IMGUI_SIZE(20.0f)))) { ImGui::OpenPopup(popupId.c_str()); + OffsetMappingPopup(); } ImGui::PopStyleVar(); @@ -1002,6 +1008,7 @@ void InputEditorWindow::DrawAddLEDMappingButton(uint8_t port) { if (ImGui::Button(StringHelper::Sprintf("%s###addLEDMapping%d", ICON_FA_PLUS, port).c_str(), ImVec2(SCALE_IMGUI_SIZE(20.0f), SCALE_IMGUI_SIZE(20.0f)))) { ImGui::OpenPopup(popupId.c_str()); + OffsetMappingPopup(); } ImGui::PopStyleVar(); @@ -1081,6 +1088,7 @@ void InputEditorWindow::DrawAddGyroMappingButton(uint8_t port) { if (ImGui::Button(StringHelper::Sprintf("%s###addGyroMapping%d", ICON_FA_PLUS, port).c_str(), ImVec2(SCALE_IMGUI_SIZE(20.0f), SCALE_IMGUI_SIZE(20.0f)))) { ImGui::OpenPopup(popupId.c_str()); + OffsetMappingPopup(); } ImGui::PopStyleVar(); @@ -1692,4 +1700,11 @@ void InputEditorWindow::DrawElement() { } ImGui::EndTabBar(); } + +void InputEditorWindow::OffsetMappingPopup() { + const float HORIZONTAL_OFFSET = 10.0f; + ImVec2 pos = ImGui::GetMousePos(); + pos.x += HORIZONTAL_OFFSET; + ImGui::SetNextWindowPos(pos); +} } // namespace Ship diff --git a/src/window/gui/InputEditorWindow.h b/src/window/gui/InputEditorWindow.h index d2c28ebe6..29f515232 100644 --- a/src/window/gui/InputEditorWindow.h +++ b/src/window/gui/InputEditorWindow.h @@ -81,5 +81,6 @@ class InputEditorWindow : public GuiWindow { std::map mDeviceIndexVisiblity; void DrawDeviceVisibilityButtons(); + void OffsetMappingPopup(); }; } // namespace Ship From f02012c9491e1ce56fafb96d444227ede625036e Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Sat, 28 Dec 2024 05:37:44 +0700 Subject: [PATCH 40/58] simple popup check completely dropped complexity --- .../controldevice/controller/ControllerButton.cpp | 3 ++- .../controldevice/controller/ControllerStick.cpp | 3 ++- src/window/gui/Gui.cpp | 12 ++++++++++++ src/window/gui/Gui.h | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index fc81dc193..dd3005758 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -182,7 +182,8 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && - mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && + mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); } else { mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask); diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 4dcb57ce0..781b2c6a6 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -276,7 +276,8 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct mapping = std::make_shared(mPortIndex, mStickIndex, direction, mKeyboardScancodeForNewMapping); } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && - mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && + mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mMouseButtonForNewMapping); } else { diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index aa6b8edb4..41dc00dcd 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -994,6 +994,18 @@ bool Gui::IsMouseOverAnyGuiItem() { return ImGui::IsAnyItemHovered(); } +bool Gui::IsMouseOverActivePopup() { + ImGuiContext* ctx = ImGui::GetCurrentContext(); + if (ctx->OpenPopupStack.Size == 0 || ctx->HoveredWindow == NULL) { + return false; + } + ImGuiPopupData data = ctx->OpenPopupStack.back(); + if (data.Window == NULL) { + return false; + } + return (ctx->HoveredWindow->ID == data.Window->ID); +} + std::shared_ptr Gui::GetMenu() { return mMenu; } diff --git a/src/window/gui/Gui.h b/src/window/gui/Gui.h index 12913bad0..7f4629777 100644 --- a/src/window/gui/Gui.h +++ b/src/window/gui/Gui.h @@ -100,6 +100,7 @@ class Gui { std::shared_ptr GetMenu(); bool GetMenuOrMenubarVisible(); bool IsMouseOverAnyGuiItem(); + bool IsMouseOverActivePopup(); bool GamepadNavigationEnabled(); void BlockGamepadNavigation(); From 4cf0142285e306d7e12021d4f5c83e487e7a817d Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Fri, 27 Dec 2024 23:48:24 +0000 Subject: [PATCH 41/58] clang format --- src/controller/controldevice/controller/ControllerButton.cpp | 4 ++-- src/controller/controldevice/controller/ControllerStick.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index dd3005758..946d60010 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -182,8 +182,8 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && - Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && - mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && + mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); } else { mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask); diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 781b2c6a6..55723e3b3 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -276,8 +276,8 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct mapping = std::make_shared(mPortIndex, mStickIndex, direction, mKeyboardScancodeForNewMapping); } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && - Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && - mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && + mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mMouseButtonForNewMapping); } else { From ee8e12427df53f5dea48fc08cda85be4e0c54072 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Sun, 29 Dec 2024 00:38:00 +0700 Subject: [PATCH 42/58] simplify mouse capture toggle --- src/graphic/Fast3D/Fast3dWindow.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 0cee39af6..546976f10 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -273,9 +273,7 @@ bool Fast3dWindow::KeyUp(int32_t scancode) { if (scancode == Ship::Context::GetInstance()->GetConfig()->GetInt("Shortcuts.MouseCapture", Ship::KbScancode::LUS_KB_F2)) { bool captureState = Ship::Context::GetInstance()->GetWindow()->IsMouseCaptured(); - if (captureState || !Ship::Context::GetInstance()->GetWindow()->GetGui()->GetMenuOrMenubarVisible()) { - Ship::Context::GetInstance()->GetWindow()->SetMouseCapture(!captureState); - } + Ship::Context::GetInstance()->GetWindow()->SetMouseCapture(!captureState); } Ship::Context::GetInstance()->GetWindow()->SetLastScancode(-1); From 7d0982b0e9ac61a10cdecc037c922e01d6857a23 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Sun, 29 Dec 2024 01:08:47 +0700 Subject: [PATCH 43/58] boundaries check for mouse buttons --- src/graphic/Fast3D/gfx_dxgi.cpp | 4 +++- src/graphic/Fast3D/gfx_sdl2.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index f65647818..fbcdfbde3 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -263,7 +263,9 @@ static void onkeyup(WPARAM w_param, LPARAM l_param) { } static void on_mouse_button_down(int btn) { - // TODO: maybe check boundaries + if (!(btn >= 0 && btn < 5)) { + return; + } dxgi.mouse_pressed[btn] = true; if (dxgi.on_mouse_button_down != nullptr) { dxgi.on_mouse_button_down(btn); diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index c1e0a3a5b..97d8da638 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -529,7 +529,9 @@ static void gfx_sdl_onkeyup(int scancode) { } static void gfx_sdl_on_mouse_button_down(int btn) { - // TODO: maybe check for boundaries? >= 0 & < 5 + if (!(btn >= 0 && btn < 5)) { + return; + } if (on_mouse_button_down_callback != NULL) { on_mouse_button_down_callback(btn); } From 7be66eb2c720e137858ea3334b56af413a65a091 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Sun, 29 Dec 2024 19:51:52 +0700 Subject: [PATCH 44/58] remove duplicate cursor visibility change in fullscreen --- src/graphic/Fast3D/gfx_sdl2.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index 97d8da638..864dc6581 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -235,7 +235,6 @@ static void set_fullscreen(bool on, bool call_callback) { SDL_DisplayMode mode; if (SDL_GetDesktopDisplayMode(display_in_use, &mode) >= 0) { SDL_SetWindowDisplayMode(wnd, &mode); - SDL_ShowCursor(false); } else { SPDLOG_ERROR(SDL_GetError()); } @@ -261,7 +260,6 @@ static void set_fullscreen(bool on, bool call_callback) { SPDLOG_ERROR("Failed to switch from or to fullscreen mode."); SPDLOG_ERROR(SDL_GetError()); } - SDL_SetCursor(SDL_DISABLE); if (on_fullscreen_changed_callback != NULL && call_callback) { on_fullscreen_changed_callback(on); From 7aa1d807deff9bbbd8b8efc35620d4e553506414 Mon Sep 17 00:00:00 2001 From: lilacLunatic <8488221+lilacLunatic@users.noreply.github.com> Date: Mon, 30 Dec 2024 13:59:21 -0300 Subject: [PATCH 45/58] Windows ignore mouse input while mouse is captured --- src/window/gui/Gui.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 41dc00dcd..44cf27cc0 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -539,6 +539,23 @@ void Gui::DrawMenu() { } void Gui::StartFrame() { + ImGuiWindowFlags flags = ImGuiWindowFlags_NoMouseInputs; + + if(Context::GetInstance()->GetWindow()->IsMouseCaptured()) { + for (auto windowIter : ImGui::GetCurrentContext()->WindowsById.Data) { + if (windowIter.key != GetMainGameWindowID() && + std::string(((ImGuiWindow*)windowIter.val_p)->Name) != std::string("GameOverlay")) { + ((ImGuiWindow*)windowIter.val_p)->Flags |= flags; + } + } + } else { + for (auto windowIter : ImGui::GetCurrentContext()->WindowsById.Data) { + if (windowIter.key != GetMainGameWindowID() && + std::string(((ImGuiWindow*)windowIter.val_p)->Name) != std::string("GameOverlay")) { + ((ImGuiWindow*)windowIter.val_p)->Flags &= ~(flags); + } + } + } ImGuiBackendNewFrame(); ImGuiWMNewFrame(); ImGui::NewFrame(); From 29858179e04927eff1b6116c0ebd9700b075130f Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 31 Dec 2024 09:41:57 +0700 Subject: [PATCH 46/58] simplify --- src/window/gui/GameOverlay.cpp | 13 +++++++++++++ src/window/gui/GameOverlay.h | 1 + src/window/gui/Gui.cpp | 16 +++++----------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/window/gui/GameOverlay.cpp b/src/window/gui/GameOverlay.cpp index 6eaf75ef7..c7a706062 100644 --- a/src/window/gui/GameOverlay.cpp +++ b/src/window/gui/GameOverlay.cpp @@ -251,4 +251,17 @@ void GameOverlay::Draw() { ImGui::End(); } + +ImGuiID GameOverlay::GetID() { + static ImGuiID windowID = 0; + if (windowID != 0) { + return windowID; + } + ImGuiWindow* window = ImGui::FindWindowByName("GameOverlay"); + if (window == NULL) { + return 0; + } + windowID = window->ID; + return windowID; +} } // namespace Ship diff --git a/src/window/gui/GameOverlay.h b/src/window/gui/GameOverlay.h index daef5e5c6..34f28927d 100644 --- a/src/window/gui/GameOverlay.h +++ b/src/window/gui/GameOverlay.h @@ -39,6 +39,7 @@ class GameOverlay { void TextDraw(float x, float y, bool shadow, ImVec4 color, const char* text, ...); void TextDrawNotification(float duration, bool shadow, const char* fmt, ...); void ClearNotifications(); + ImGuiID GetID(); protected: float GetScreenWidth(); diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 44cf27cc0..ea8d819c0 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -540,22 +540,16 @@ void Gui::DrawMenu() { void Gui::StartFrame() { ImGuiWindowFlags flags = ImGuiWindowFlags_NoMouseInputs; - - if(Context::GetInstance()->GetWindow()->IsMouseCaptured()) { - for (auto windowIter : ImGui::GetCurrentContext()->WindowsById.Data) { - if (windowIter.key != GetMainGameWindowID() && - std::string(((ImGuiWindow*)windowIter.val_p)->Name) != std::string("GameOverlay")) { + for (auto windowIter : ImGui::GetCurrentContext()->WindowsById.Data) { + if (windowIter.key != GetMainGameWindowID() && windowIter.key != GetGameOverlay()->GetID()) { + if (Context::GetInstance()->GetWindow()->IsMouseCaptured()) { ((ImGuiWindow*)windowIter.val_p)->Flags |= flags; - } - } - } else { - for (auto windowIter : ImGui::GetCurrentContext()->WindowsById.Data) { - if (windowIter.key != GetMainGameWindowID() && - std::string(((ImGuiWindow*)windowIter.val_p)->Name) != std::string("GameOverlay")) { + } else { ((ImGuiWindow*)windowIter.val_p)->Flags &= ~(flags); } } } + ImGuiBackendNewFrame(); ImGuiWMNewFrame(); ImGui::NewFrame(); From 82f940d4e48962f94058eaf500738853ce9c0425 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 31 Dec 2024 10:01:13 +0700 Subject: [PATCH 47/58] make separate method for handling capture --- src/window/gui/Gui.cpp | 10 +++++++--- src/window/gui/Gui.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index ea8d819c0..b4a825a4c 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -538,18 +538,22 @@ void Gui::DrawMenu() { ImGui::End(); } -void Gui::StartFrame() { +void Gui::HandleMouseCapture() { ImGuiWindowFlags flags = ImGuiWindowFlags_NoMouseInputs; for (auto windowIter : ImGui::GetCurrentContext()->WindowsById.Data) { if (windowIter.key != GetMainGameWindowID() && windowIter.key != GetGameOverlay()->GetID()) { + ImGuiWindow* window = windowIter.val_p; if (Context::GetInstance()->GetWindow()->IsMouseCaptured()) { - ((ImGuiWindow*)windowIter.val_p)->Flags |= flags; + window->Flags |= flags; } else { - ((ImGuiWindow*)windowIter.val_p)->Flags &= ~(flags); + window->Flags &= ~(flags); } } } +} +void Gui::StartFrame() { + HandleMouseCapture(); ImGuiBackendNewFrame(); ImGuiWMNewFrame(); ImGui::NewFrame(); diff --git a/src/window/gui/Gui.h b/src/window/gui/Gui.h index 7f4629777..10d09c865 100644 --- a/src/window/gui/Gui.h +++ b/src/window/gui/Gui.h @@ -123,6 +123,7 @@ class Gui { void ApplyResolutionChanges(); int16_t GetIntegerScaleFactor(); void CheckSaveCvars(); + void HandleMouseCapture(); private: GuiWindowInitData mImpl; From c1a5f0816c5fde80fb22ce69680a024f65cb3e53 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 31 Dec 2024 10:06:49 +0700 Subject: [PATCH 48/58] fix cast --- src/window/gui/Gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index b4a825a4c..5c4d13d6f 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -542,7 +542,7 @@ void Gui::HandleMouseCapture() { ImGuiWindowFlags flags = ImGuiWindowFlags_NoMouseInputs; for (auto windowIter : ImGui::GetCurrentContext()->WindowsById.Data) { if (windowIter.key != GetMainGameWindowID() && windowIter.key != GetGameOverlay()->GetID()) { - ImGuiWindow* window = windowIter.val_p; + ImGuiWindow* window = (ImGuiWindow*) windowIter.val_p; if (Context::GetInstance()->GetWindow()->IsMouseCaptured()) { window->Flags |= flags; } else { From 785c41a64b5afdc485d509671ad7f24cadad39d6 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 31 Dec 2024 10:15:41 +0700 Subject: [PATCH 49/58] clang-format --- src/window/gui/Gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 5c4d13d6f..281dadad6 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -542,7 +542,7 @@ void Gui::HandleMouseCapture() { ImGuiWindowFlags flags = ImGuiWindowFlags_NoMouseInputs; for (auto windowIter : ImGui::GetCurrentContext()->WindowsById.Data) { if (windowIter.key != GetMainGameWindowID() && windowIter.key != GetGameOverlay()->GetID()) { - ImGuiWindow* window = (ImGuiWindow*) windowIter.val_p; + ImGuiWindow* window = (ImGuiWindow*)windowIter.val_p; if (Context::GetInstance()->GetWindow()->IsMouseCaptured()) { window->Flags |= flags; } else { From 711360dcf452283b626ccecc0f2150a879249d04 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 31 Dec 2024 14:28:03 +0700 Subject: [PATCH 50/58] ProcessMouseEvent -> ProcessMouseButtonEvent --- src/controller/controldeck/ControlDeck.cpp | 4 ++-- src/controller/controldeck/ControlDeck.h | 2 +- src/controller/controldevice/controller/Controller.cpp | 8 ++++---- src/controller/controldevice/controller/Controller.h | 2 +- .../controldevice/controller/ControllerButton.cpp | 4 ++-- .../controldevice/controller/ControllerButton.h | 2 +- .../controldevice/controller/ControllerStick.cpp | 4 ++-- src/controller/controldevice/controller/ControllerStick.h | 2 +- .../controller/mapping/mouse/MouseButtonToAnyMapping.cpp | 2 +- .../controller/mapping/mouse/MouseButtonToAnyMapping.h | 2 +- src/graphic/Fast3D/Fast3dWindow.cpp | 4 ++-- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index b2d7f6abe..232a3caeb 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -52,13 +52,13 @@ bool ControlDeck::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancod return result; } -bool ControlDeck::ProcessMouseEvent(bool isPressed, MouseBtn button) { +bool ControlDeck::ProcessMouseButtonEvent(bool isPressed, MouseBtn button) { bool result = false; for (auto port : mPorts) { auto controller = port->GetConnectedController(); if (controller != nullptr) { - result = controller->ProcessMouseEvent(isPressed, button) || result; + result = controller->ProcessMouseButtonEvent(isPressed, button) || result; } } diff --git a/src/controller/controldeck/ControlDeck.h b/src/controller/controldeck/ControlDeck.h index 65e9572e6..ac51d8302 100644 --- a/src/controller/controldeck/ControlDeck.h +++ b/src/controller/controldeck/ControlDeck.h @@ -25,7 +25,7 @@ class ControlDeck { void SetSinglePlayerMappingMode(bool singlePlayer); bool IsSinglePlayerMappingMode(); bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode); - bool ProcessMouseEvent(bool isPressed, MouseBtn button); + bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button); std::shared_ptr GetDeviceIndexMappingManager(); diff --git a/src/controller/controldevice/controller/Controller.cpp b/src/controller/controldevice/controller/Controller.cpp index 5310fbf00..9d4e72a57 100644 --- a/src/controller/controldevice/controller/Controller.cpp +++ b/src/controller/controldevice/controller/Controller.cpp @@ -136,13 +136,13 @@ bool Controller::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode return result; } -bool Controller::ProcessMouseEvent(bool isPressed, MouseBtn mouseButton) { +bool Controller::ProcessMouseButtonEvent(bool isPressed, MouseBtn mouseButton) { bool result = false; for (auto [bitmask, button] : GetAllButtons()) { - result = button->ProcessMouseEvent(isPressed, mouseButton) || result; + result = button->ProcessMouseButtonEvent(isPressed, mouseButton) || result; } - result = GetLeftStick()->ProcessMouseEvent(isPressed, mouseButton) || result; - result = GetRightStick()->ProcessMouseEvent(isPressed, mouseButton) || result; + result = GetLeftStick()->ProcessMouseButtonEvent(isPressed, mouseButton) || result; + result = GetRightStick()->ProcessMouseButtonEvent(isPressed, mouseButton) || result; return result; } diff --git a/src/controller/controldevice/controller/Controller.h b/src/controller/controldevice/controller/Controller.h index 409899bf2..fe2cff1e0 100644 --- a/src/controller/controldevice/controller/Controller.h +++ b/src/controller/controldevice/controller/Controller.h @@ -49,7 +49,7 @@ class Controller : public ControlDevice { std::vector> GetAllMappings(); bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode); - bool ProcessMouseEvent(bool isPressed, MouseBtn button); + bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button); bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); void MoveMappingsToDifferentController(std::shared_ptr newController, ShipDeviceIndex lusIndex); diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index 946d60010..66ec8b46a 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -234,7 +234,7 @@ bool ControllerButton::ProcessKeyboardEvent(KbEventType eventType, KbScancode sc return result; } -bool ControllerButton::ProcessMouseEvent(bool isPressed, MouseBtn button) { +bool ControllerButton::ProcessMouseButtonEvent(bool isPressed, MouseBtn button) { if (mUseInputToCreateNewMapping) { if (isPressed) { mMouseButtonForNewMapping = button; @@ -250,7 +250,7 @@ bool ControllerButton::ProcessMouseEvent(bool isPressed, MouseBtn button) { std::shared_ptr mtobMapping = std::dynamic_pointer_cast(mapping); if (mtobMapping != nullptr) { - result = result || mtobMapping->ProcessMouseEvent(isPressed, button); + result = result || mtobMapping->ProcessMouseButtonEvent(isPressed, button); } } } diff --git a/src/controller/controldevice/controller/ControllerButton.h b/src/controller/controldevice/controller/ControllerButton.h index d541c76dc..082cfa1fd 100644 --- a/src/controller/controldevice/controller/ControllerButton.h +++ b/src/controller/controldevice/controller/ControllerButton.h @@ -37,7 +37,7 @@ class ControllerButton { void UpdatePad(CONTROLLERBUTTONS_T& padButtons); bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode); - bool ProcessMouseEvent(bool isPressed, Ship::MouseBtn button); + bool ProcessMouseButtonEvent(bool isPressed, Ship::MouseBtn button); bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 55723e3b3..b2cb895c4 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -350,7 +350,7 @@ bool ControllerStick::ProcessKeyboardEvent(KbEventType eventType, KbScancode sca return result; } -bool ControllerStick::ProcessMouseEvent(bool isPressed, MouseBtn button) { +bool ControllerStick::ProcessMouseButtonEvent(bool isPressed, MouseBtn button) { if (mUseInputToCreateNewMapping) { if (isPressed) { mMouseButtonForNewMapping = button; @@ -367,7 +367,7 @@ bool ControllerStick::ProcessMouseEvent(bool isPressed, MouseBtn button) { std::shared_ptr mtoadMapping = std::dynamic_pointer_cast(mapping); if (mtoadMapping != nullptr) { - result = result || mtoadMapping->ProcessMouseEvent(isPressed, button); + result = result || mtoadMapping->ProcessMouseButtonEvent(isPressed, button); } } } diff --git a/src/controller/controldevice/controller/ControllerStick.h b/src/controller/controldevice/controller/ControllerStick.h index ea0283ba3..44da701a3 100644 --- a/src/controller/controldevice/controller/ControllerStick.h +++ b/src/controller/controldevice/controller/ControllerStick.h @@ -52,7 +52,7 @@ class ControllerStick { bool NotchSnapAngleIsDefault(); bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode); - bool ProcessMouseEvent(bool isPressed, Ship::MouseBtn button); + bool ProcessMouseButtonEvent(bool isPressed, Ship::MouseBtn button); bool HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex); StickIndex GetStickIndex(); diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.cpp index cb9622e12..b57c36be0 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.cpp @@ -16,7 +16,7 @@ std::string MouseButtonToAnyMapping::GetPhysicalInputName() { return mouseBtnNames[static_cast(mButton)]; } -bool MouseButtonToAnyMapping::ProcessMouseEvent(bool isPressed, MouseBtn button) { +bool MouseButtonToAnyMapping::ProcessMouseButtonEvent(bool isPressed, MouseBtn button) { if (mButton != button) { return false; } diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.h index 20d106dae..24b37ac93 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseButtonToAnyMapping.h @@ -9,7 +9,7 @@ class MouseButtonToAnyMapping : virtual public ControllerInputMapping { MouseButtonToAnyMapping(MouseBtn button); ~MouseButtonToAnyMapping(); std::string GetPhysicalInputName() override; - bool ProcessMouseEvent(bool isPressed, MouseBtn button); + bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button); std::string GetPhysicalDeviceName() override; bool PhysicalDeviceIsConnected() override; diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 546976f10..70fdc77fa 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -295,13 +295,13 @@ void Fast3dWindow::AllKeysUp() { } bool Fast3dWindow::MouseButtonUp(int button) { - return Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseEvent(false, + return Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseButtonEvent(false, static_cast(button)); } bool Fast3dWindow::MouseButtonDown(int button) { bool isProcessed = - Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseEvent(true, static_cast(button)); + Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseButtonEvent(true, static_cast(button)); return isProcessed; } From 402c6d29e1e869b8a97fb40f8c4b711ca0ab0be9 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 31 Dec 2024 22:56:31 +0700 Subject: [PATCH 51/58] wheel mapping support WIP --- src/controller/controldeck/ControlDeck.cpp | 2 + .../controller/ControllerButton.cpp | 27 +++++--- .../controller/ControllerButton.h | 2 +- .../controller/ControllerStick.cpp | 23 ++++--- .../controller/ControllerStick.h | 2 +- .../factories/AxisDirectionMappingFactory.cpp | 31 +++++++++ .../factories/AxisDirectionMappingFactory.h | 3 + .../factories/ButtonMappingFactory.cpp | 22 ++++++ .../mapping/factories/ButtonMappingFactory.h | 2 + .../mapping/keyboard/KeyboardScancodes.h | 11 +++ .../mapping/mouse/MouseWheelToAnyMapping.cpp | 26 +++++++ .../mapping/mouse/MouseWheelToAnyMapping.h | 18 +++++ .../MouseWheelToAxisDirectionMapping.cpp | 51 ++++++++++++++ .../mouse/MouseWheelToAxisDirectionMapping.h | 17 +++++ .../mouse/MouseWheelToButtonMapping.cpp | 51 ++++++++++++++ .../mapping/mouse/MouseWheelToButtonMapping.h | 17 +++++ .../controller/mapping/mouse/WheelHandler.cpp | 67 +++++++++++++++++++ .../controller/mapping/mouse/WheelHandler.h | 31 +++++++++ 18 files changed, 382 insertions(+), 21 deletions(-) create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.cpp create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.h create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.h create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.cpp create mode 100644 src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.h create mode 100644 src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp create mode 100644 src/controller/controldevice/controller/mapping/mouse/WheelHandler.h diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index 232a3caeb..4b7416433 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -9,6 +9,7 @@ #endif #include #include "controller/deviceindex/ShipDeviceIndexMappingManager.h" +#include "controller/controldevice/controller/mapping/mouse/WheelHandler.h" namespace Ship { @@ -140,6 +141,7 @@ void ControlDeck::WriteToPad(void* pad) { void ControlDeck::WriteToOSContPad(OSContPad* pad) { SDL_PumpEvents(); + Ship::WheelHandler::GetInstance()->Update(); if (AllGameInputBlocked()) { return; diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index 66ec8b46a..efd867448 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -14,7 +14,7 @@ namespace Ship { ControllerButton::ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) - : mPortIndex(portIndex), mBitmask(bitmask), mUseInputToCreateNewMapping(false), + : mPortIndex(portIndex), mBitmask(bitmask), mUseEventInputToCreateNewMapping(false), mKeyboardScancodeForNewMapping(LUS_KB_UNKNOWN), mMouseButtonForNewMapping(LUS_MOUSE_BTN_UNKNOWN) { } @@ -178,14 +178,21 @@ bool ControllerButton::HasMappingsForShipDeviceIndex(ShipDeviceIndex lusIndex) { bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bitmask, std::string id) { std::shared_ptr mapping = nullptr; - mUseInputToCreateNewMapping = true; + mUseEventInputToCreateNewMapping = true; if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mKeyboardScancodeForNewMapping); - } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && - Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && - mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { - mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); - } else { + } + + else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && + Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup()) { + if (mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); + } else { + mapping = ButtonMappingFactory::CreateButtonMappingFromMouseWheelInput(mPortIndex, bitmask); + } + } + + if (mapping == nullptr) { mapping = ButtonMappingFactory::CreateButtonMappingFromSDLInput(mPortIndex, bitmask); } @@ -195,7 +202,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi mKeyboardScancodeForNewMapping = LUS_KB_UNKNOWN; mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN; - mUseInputToCreateNewMapping = false; + mUseEventInputToCreateNewMapping = false; if (id != "") { ClearButtonMapping(id); @@ -212,7 +219,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi } bool ControllerButton::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) { - if (mUseInputToCreateNewMapping) { + if (mUseEventInputToCreateNewMapping) { if (eventType == LUS_KB_EVENT_KEY_DOWN) { mKeyboardScancodeForNewMapping = scancode; return true; @@ -235,7 +242,7 @@ bool ControllerButton::ProcessKeyboardEvent(KbEventType eventType, KbScancode sc } bool ControllerButton::ProcessMouseButtonEvent(bool isPressed, MouseBtn button) { - if (mUseInputToCreateNewMapping) { + if (mUseEventInputToCreateNewMapping) { if (isPressed) { mMouseButtonForNewMapping = button; return true; diff --git a/src/controller/controldevice/controller/ControllerButton.h b/src/controller/controldevice/controller/ControllerButton.h index 082cfa1fd..12dbf048c 100644 --- a/src/controller/controldevice/controller/ControllerButton.h +++ b/src/controller/controldevice/controller/ControllerButton.h @@ -47,7 +47,7 @@ class ControllerButton { std::unordered_map> mButtonMappings; std::string GetConfigNameFromBitmask(CONTROLLERBUTTONS_T bitmask); - bool mUseInputToCreateNewMapping; + bool mUseEventInputToCreateNewMapping; KbScancode mKeyboardScancodeForNewMapping; MouseBtn mMouseButtonForNewMapping; }; diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index b2cb895c4..5d5afafc2 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -25,7 +25,7 @@ namespace Ship { ControllerStick::ControllerStick(uint8_t portIndex, StickIndex stickIndex) - : mPortIndex(portIndex), mStickIndex(stickIndex), mUseInputToCreateNewMapping(false), + : mPortIndex(portIndex), mStickIndex(stickIndex), mUseEventInputToCreateNewMapping(false), mKeyboardScancodeForNewMapping(KbScancode::LUS_KB_UNKNOWN), mMouseButtonForNewMapping(LUS_MOUSE_BTN_UNKNOWN) { mSensitivityPercentage = DEFAULT_STICK_SENSITIVITY_PERCENTAGE; mSensitivity = 1.0f; @@ -271,16 +271,21 @@ void ControllerStick::Process(int8_t& x, int8_t& y) { bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direction, std::string id) { std::shared_ptr mapping = nullptr; - mUseInputToCreateNewMapping = true; + mUseEventInputToCreateNewMapping = true; if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, mKeyboardScancodeForNewMapping); } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && - Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup() && - mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { - mapping = std::make_shared(mPortIndex, mStickIndex, direction, + Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup()) { + if (mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { + mapping = std::make_shared(mPortIndex, mStickIndex, direction, mMouseButtonForNewMapping); - } else { + } else { + mapping = + AxisDirectionMappingFactory::CreateAxisDirectionMappingFromMouseWheelInput(mPortIndex, mStickIndex, direction); + } + } + if (mapping == nullptr) { mapping = AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(mPortIndex, mStickIndex, direction); } @@ -291,7 +296,7 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct mKeyboardScancodeForNewMapping = LUS_KB_UNKNOWN; mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN; - mUseInputToCreateNewMapping = false; + mUseEventInputToCreateNewMapping = false; if (id != "") { ClearAxisDirectionMapping(direction, id); @@ -326,7 +331,7 @@ void ControllerStick::UpdatePad(int8_t& x, int8_t& y) { } bool ControllerStick::ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode) { - if (mUseInputToCreateNewMapping) { + if (mUseEventInputToCreateNewMapping) { if (eventType == LUS_KB_EVENT_KEY_DOWN) { mKeyboardScancodeForNewMapping = scancode; return true; @@ -351,7 +356,7 @@ bool ControllerStick::ProcessKeyboardEvent(KbEventType eventType, KbScancode sca } bool ControllerStick::ProcessMouseButtonEvent(bool isPressed, MouseBtn button) { - if (mUseInputToCreateNewMapping) { + if (mUseEventInputToCreateNewMapping) { if (isPressed) { mMouseButtonForNewMapping = button; return true; diff --git a/src/controller/controldevice/controller/ControllerStick.h b/src/controller/controldevice/controller/ControllerStick.h index 44da701a3..e6d1f1fe7 100644 --- a/src/controller/controldevice/controller/ControllerStick.h +++ b/src/controller/controldevice/controller/ControllerStick.h @@ -76,7 +76,7 @@ class ControllerStick { std::unordered_map>> mAxisDirectionMappings; - bool mUseInputToCreateNewMapping; + bool mUseEventInputToCreateNewMapping; KbScancode mKeyboardScancodeForNewMapping; MouseBtn mMouseButtonForNewMapping; }; diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index 5259c735e..ff52cd9c0 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -1,6 +1,7 @@ #include "AxisDirectionMappingFactory.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLButtonToAxisDirectionMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAxisDirectionMapping.h" @@ -11,6 +12,7 @@ #include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" +#include "controller/controldevice/controller/mapping/mouse/WheelHandler.h" namespace Ship { std::shared_ptr @@ -93,6 +95,21 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn portIndex, stickIndex, static_cast(direction), static_cast(mouseButton)); } + if (mappingClass == "MouseWheelToAxisDirectionMapping") { + int32_t direction = CVarGetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), -1); + int wheelDirection = CVarGetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), 0); + + if (direction != LEFT && direction != RIGHT && direction != UP && direction != DOWN) { + // something about this mapping is invalid + CVarClear(mappingCvarKey.c_str()); + CVarSave(); + return nullptr; + } + + return std::make_shared( + portIndex, stickIndex, static_cast(direction), static_cast(wheelDirection)); + } + return nullptr; } @@ -200,4 +217,18 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(uint8_t port return mapping; } + +std::shared_ptr AxisDirectionMappingFactory::CreateAxisDirectionMappingFromMouseWheelInput(uint8_t portIndex, StickIndex stickIndex, Direction direction) { + WheelDirections wheelDirections = WheelHandler::GetInstance()->GetDirections(); + WheelDirection wheelDirection; + if (wheelDirections.x != LUS_WHEEL_NONE) { + wheelDirection = wheelDirections.x; + } else if (wheelDirections.y != LUS_WHEEL_NONE) { + wheelDirection = wheelDirections.y; + } else { + return nullptr; + } + + return std::make_shared(portIndex, stickIndex, direction, wheelDirection); +} } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h index 98887bb10..7cdd16377 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h @@ -19,5 +19,8 @@ class AxisDirectionMappingFactory { static std::shared_ptr CreateAxisDirectionMappingFromSDLInput(uint8_t portIndex, StickIndex stickIndex, Direction direction); + + static std::shared_ptr + CreateAxisDirectionMappingFromMouseWheelInput(uint8_t portIndex, StickIndex stickIndex, Direction direction); }; } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp index 19052e813..92bd0d341 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp @@ -5,10 +5,12 @@ #include "Context.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardKeyToButtonMapping.h" #include "controller/controldevice/controller/mapping/mouse/MouseButtonToButtonMapping.h" +#include "controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLButtonToButtonMapping.h" #include "controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.h" #include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h" #include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" +#include "controller/controldevice/controller/mapping/mouse/WheelHandler.h" namespace Ship { std::shared_ptr ButtonMappingFactory::CreateButtonMappingFromConfig(uint8_t portIndex, @@ -74,6 +76,12 @@ std::shared_ptr ButtonMappingFactory::CreateButtonMappi return std::make_shared(portIndex, bitmask, static_cast(mouseButton)); } + if (mappingClass == "MouseWheelToButtonMapping") { + int wheelDirection = CVarGetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), 0); + + return std::make_shared(portIndex, bitmask, static_cast(wheelDirection)); + } + return nullptr; } @@ -296,4 +304,18 @@ ButtonMappingFactory::CreateButtonMappingFromSDLInput(uint8_t portIndex, CONTROL return mapping; } + +std::shared_ptr ButtonMappingFactory::CreateButtonMappingFromMouseWheelInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) { + WheelDirections wheelDirections = WheelHandler::GetInstance()->GetDirections(); + WheelDirection wheelDirection; + if (wheelDirections.x != LUS_WHEEL_NONE) { + wheelDirection = wheelDirections.x; + } else if (wheelDirections.y != LUS_WHEEL_NONE) { + wheelDirection = wheelDirections.y; + } else { + return nullptr; + } + + return std::make_shared(portIndex, bitmask, wheelDirection); +} } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h index 1a11b3312..a56f04f9f 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h @@ -18,5 +18,7 @@ class ButtonMappingFactory { static std::shared_ptr CreateButtonMappingFromSDLInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask); + + static std::shared_ptr CreateButtonMappingFromMouseWheelInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask); }; } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h b/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h index f1e9b70b5..f420273ea 100644 --- a/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h +++ b/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h @@ -130,8 +130,19 @@ typedef enum MouseBtn { LUS_MOUSE_BTN_UNKNOWN } MouseBtn; +typedef enum WheelDirection { + LUS_WHEEL_NONE, + LUS_WHEEL_LEFT, + LUS_WHEEL_RIGHT, + LUS_WHEEL_UP, + LUS_WHEEL_DOWN, + LUS_WHEEL_UNKNOWN +} WheelDirection; + #ifdef __cplusplus static std::string mouseBtnNames[7] = { "MouseLeft", "MouseMiddle", "MouseRight", "MouseBackward", "MouseForward", "MOUSE_BTN_COUNT", "MOUSE_BTN_UNKNOWN" }; +static std::string wheelDirectionNames[6] = { "LUS_WHEEL_NONE", "WheelLeft", "WheelRight", "WheelUp", + "WheelDown", "LUS_WHEEL_UNKNOWN" }; } // namespace Ship #endif diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.cpp new file mode 100644 index 000000000..7a2565457 --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.cpp @@ -0,0 +1,26 @@ +#include "MouseWheelToAnyMapping.h" +#include "Context.h" + +#include "utils/StringHelper.h" +#include "window/gui/IconsFontAwesome4.h" + +namespace Ship { +MouseWheelToAnyMapping::MouseWheelToAnyMapping(WheelDirection wheelDirection) + : ControllerInputMapping(ShipDeviceIndex::Mouse), mWheelDirection(wheelDirection) { +} + +MouseWheelToAnyMapping::~MouseWheelToAnyMapping() { +} + +std::string MouseWheelToAnyMapping::GetPhysicalInputName() { + return wheelDirectionNames[static_cast(mWheelDirection)]; +} + +std::string MouseWheelToAnyMapping::GetPhysicalDeviceName() { + return "Mouse"; +} + +bool MouseWheelToAnyMapping::PhysicalDeviceIsConnected() { + return true; +} +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.h new file mode 100644 index 000000000..8067fa851 --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.h @@ -0,0 +1,18 @@ +#pragma once + +#include "controller/controldevice/controller/mapping/ControllerInputMapping.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" + +namespace Ship { +class MouseWheelToAnyMapping : virtual public ControllerInputMapping { + public: + MouseWheelToAnyMapping(WheelDirection wheelDirection); + ~MouseWheelToAnyMapping(); + std::string GetPhysicalInputName() override; + std::string GetPhysicalDeviceName() override; + bool PhysicalDeviceIsConnected() override; + + protected: + WheelDirection mWheelDirection; +}; +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp new file mode 100644 index 000000000..623420240 --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp @@ -0,0 +1,51 @@ +#include "MouseWheelToAxisDirectionMapping.h" +#include +#include "utils/StringHelper.h" +#include "window/gui/IconsFontAwesome4.h" +#include "public/bridge/consolevariablebridge.h" +#include "Context.h" +#include "WheelHandler.h" + +namespace Ship { +MouseWheelToAxisDirectionMapping::MouseWheelToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, + Direction direction, WheelDirection wheelDirection) + : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseWheelToAnyMapping(wheelDirection), + ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stickIndex, direction) { +} + +float MouseWheelToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { + if (Context::GetInstance()->GetControlDeck()->MouseGameInputBlocked()) { + return 0.0f; + } + + // TODO: scale input to match with MAX_AXIS_RANGE + return WheelHandler::GetInstance()->GetDirectionValue(mWheelDirection); +} + +std::string MouseWheelToAxisDirectionMapping::GetAxisDirectionMappingId() { + return StringHelper::Sprintf("P%d-S%d-D%d-WHEEL%d", mPortIndex, mStickIndex, mDirection, mWheelDirection); +} + +void MouseWheelToAxisDirectionMapping::SaveToConfig() { + const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId(); + CVarSetString(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str(), + "MouseWheelToAxisDirectionMapping"); + CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStickIndex); + CVarSetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), mDirection); + CVarSetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), static_cast(mWheelDirection)); + CVarSave(); +} + +void MouseWheelToAxisDirectionMapping::EraseFromConfig() { + const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".AxisDirectionMappings." + GetAxisDirectionMappingId(); + CVarClear(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.AxisDirectionMappingClass", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str()); + CVarSave(); +} + +int8_t MouseWheelToAxisDirectionMapping::GetMappingType() { + return MAPPING_TYPE_MOUSE; +} +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.h new file mode 100644 index 000000000..b6df8d36c --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.h @@ -0,0 +1,17 @@ +#pragma once + +#include "MouseWheelToAnyMapping.h" +#include "controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" + +namespace Ship { +class MouseWheelToAxisDirectionMapping final : public MouseWheelToAnyMapping, public ControllerAxisDirectionMapping { + public: + MouseWheelToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, WheelDirection wheelDirection); + float GetNormalizedAxisDirectionValue() override; + std::string GetAxisDirectionMappingId() override; + int8_t GetMappingType() override; + void SaveToConfig() override; + void EraseFromConfig() override; +}; +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.cpp new file mode 100644 index 000000000..c0c361059 --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.cpp @@ -0,0 +1,51 @@ +#include "MouseWheelToButtonMapping.h" +#include +#include "utils/StringHelper.h" +#include "public/bridge/consolevariablebridge.h" +#include "WheelHandler.h" +#include "Context.h" + +namespace Ship { +MouseWheelToButtonMapping::MouseWheelToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, WheelDirection wheelDirection) + : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseWheelToAnyMapping(wheelDirection), + ControllerButtonMapping(ShipDeviceIndex::Mouse, portIndex, bitmask) { +} + +void MouseWheelToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons) { + if (Context::GetInstance()->GetControlDeck()->MouseGameInputBlocked()) { + return; + } + + WheelDirections directions = WheelHandler::GetInstance()->GetDirections(); + if (mWheelDirection == directions.x || mWheelDirection == directions.y) { + padButtons |= mBitmask; + } +} + +int8_t MouseWheelToButtonMapping::GetMappingType() { + return MAPPING_TYPE_MOUSE; +} + +std::string MouseWheelToButtonMapping::GetButtonMappingId() { + return StringHelper::Sprintf("P%d-B%d-WHEEL%d", mPortIndex, mBitmask, mWheelDirection); +} + +void MouseWheelToButtonMapping::SaveToConfig() { + const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".ButtonMappings." + GetButtonMappingId(); + CVarSetString(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str(), + "MouseWheelToButtonMapping"); + CVarSetInteger(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str(), mBitmask); + CVarSetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), static_cast(mWheelDirection)); + CVarSave(); +} + +void MouseWheelToButtonMapping::EraseFromConfig() { + const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".ButtonMappings." + GetButtonMappingId(); + + CVarClear(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str()); + CVarClear(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str()); + + CVarSave(); +} +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.h new file mode 100644 index 000000000..6188ab716 --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.h @@ -0,0 +1,17 @@ +#pragma once + +#include "MouseWheelToAnyMapping.h" +#include "controller/controldevice/controller/mapping/ControllerButtonMapping.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" + +namespace Ship { +class MouseWheelToButtonMapping final : public MouseWheelToAnyMapping, public ControllerButtonMapping { + public: + MouseWheelToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, WheelDirection wheelDirection); + void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override; + int8_t GetMappingType() override; + std::string GetButtonMappingId() override; + void SaveToConfig() override; + void EraseFromConfig() override; +}; +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp new file mode 100644 index 000000000..b6982546a --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp @@ -0,0 +1,67 @@ +#include "WheelHandler.h" +#include "Context.h" + +namespace Ship { +WheelHandler::WheelHandler() : mDirections(LUS_WHEEL_NONE, LUS_WHEEL_NONE) { +} + +WheelHandler::~WheelHandler() {} + +std::shared_ptr WheelHandler::mInstance; + +std::shared_ptr WheelHandler::GetInstance() { + if (mInstance == nullptr) { + mInstance = std::make_shared(); + } + return mInstance; +} + +void WheelHandler::Update() { + mCoords = Context::GetInstance()->GetWindow()->GetMouseWheel(); + + mDirections.x = mDirections.y = LUS_WHEEL_NONE; + if (mCoords.x < 0) { + mDirections.x = LUS_WHEEL_LEFT; + } else if (mCoords.x > 0) { + mDirections.x = LUS_WHEEL_RIGHT; + } + if (mCoords.y < 0) { + mDirections.y = LUS_WHEEL_DOWN; + } else if (mCoords.y > 0) { + mDirections.y = LUS_WHEEL_UP; + } +} + +CoordsF WheelHandler::GetCoords() { + return mCoords; +} + +WheelDirections WheelHandler::GetDirections() { + return mDirections; +} + +float WheelHandler::GetDirectionValue(WheelDirection direction) { + switch (direction) { + case LUS_WHEEL_LEFT: + if (mCoords.x < 0) { + return -mCoords.x; + } + break; + case LUS_WHEEL_RIGHT: + if (mCoords.x > 0) { + return mCoords.x; + } + break; + case LUS_WHEEL_DOWN: + if (mCoords.y < 0) { + return -mCoords.y; + } + break; + case LUS_WHEEL_UP: + if (mCoords.y > 0) { + return mCoords.y; + } + } + return 0.0f; +} +} // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h new file mode 100644 index 000000000..8a182cbdd --- /dev/null +++ b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include "window/Window.h" +#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h" + +namespace Ship { +struct WheelDirections { + WheelDirection x; + WheelDirection y; +}; + +class WheelHandler { + public: + WheelHandler(); + ~WheelHandler(); + static std::shared_ptr GetInstance(); + + void Update(); + CoordsF GetCoords(); + WheelDirections GetDirections(); + float GetDirectionValue(WheelDirection direction); + + private: + static std::shared_ptr mInstance; + + WheelDirections mDirections; + CoordsF mCoords; +}; +} // namespace Ship From b288dce2b497cc3240bfdb91deb8ef33b9873e36 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 31 Dec 2024 23:08:16 +0700 Subject: [PATCH 52/58] fix for axis --- .../mapping/mouse/MouseWheelToAxisDirectionMapping.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp index 623420240..49efdfddb 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp @@ -1,5 +1,6 @@ #include "MouseWheelToAxisDirectionMapping.h" #include +#include #include "utils/StringHelper.h" #include "window/gui/IconsFontAwesome4.h" #include "public/bridge/consolevariablebridge.h" @@ -19,7 +20,8 @@ float MouseWheelToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { } // TODO: scale input to match with MAX_AXIS_RANGE - return WheelHandler::GetInstance()->GetDirectionValue(mWheelDirection); + // note: this is temporary solution to test numbers on different backends + return fmin(WheelHandler::GetInstance()->GetDirectionValue(mWheelDirection) * MAX_AXIS_RANGE, MAX_AXIS_RANGE); } std::string MouseWheelToAxisDirectionMapping::GetAxisDirectionMappingId() { From 43082d871b668968de9228b0fd3836fce4186a27 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Tue, 31 Dec 2024 23:08:21 +0700 Subject: [PATCH 53/58] wheel logging --- .../controldevice/controller/mapping/mouse/WheelHandler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp index b6982546a..a9b183b43 100644 --- a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp @@ -1,5 +1,6 @@ #include "WheelHandler.h" #include "Context.h" +#include "spdlog/spdlog.h" namespace Ship { WheelHandler::WheelHandler() : mDirections(LUS_WHEEL_NONE, LUS_WHEEL_NONE) { @@ -30,6 +31,7 @@ void WheelHandler::Update() { } else if (mCoords.y > 0) { mDirections.y = LUS_WHEEL_UP; } + SPDLOG_INFO("WHEEEL: {} {}", mCoords.x, mCoords.y); } CoordsF WheelHandler::GetCoords() { From ceb3da3b6d09f2f54389f8afb434c5f54f4fb538 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 1 Jan 2025 00:41:38 +0700 Subject: [PATCH 54/58] macos fix? --- .../controldevice/controller/mapping/mouse/WheelHandler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp index a9b183b43..d655b5e52 100644 --- a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp @@ -3,7 +3,8 @@ #include "spdlog/spdlog.h" namespace Ship { -WheelHandler::WheelHandler() : mDirections(LUS_WHEEL_NONE, LUS_WHEEL_NONE) { +WheelHandler::WheelHandler() { + mDirections = {LUS_WHEEL_NONE, LUS_WHEEL_NONE}; } WheelHandler::~WheelHandler() {} From 1271aabce7ce70be794239d8c653eeaa77509b6f Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 1 Jan 2025 01:20:52 +0700 Subject: [PATCH 55/58] clang format --- .../controldevice/controller/ControllerButton.cpp | 2 +- .../controldevice/controller/ControllerStick.cpp | 6 +++--- .../mapping/factories/AxisDirectionMappingFactory.cpp | 7 +++++-- .../mapping/factories/ButtonMappingFactory.cpp | 9 ++++++--- .../controller/mapping/factories/ButtonMappingFactory.h | 3 ++- .../controller/mapping/keyboard/KeyboardScancodes.h | 4 ++-- .../mapping/mouse/MouseWheelToAxisDirectionMapping.cpp | 5 +++-- .../mapping/mouse/MouseWheelToAxisDirectionMapping.h | 3 ++- .../mapping/mouse/MouseWheelToButtonMapping.cpp | 6 ++++-- .../controller/mapping/mouse/WheelHandler.cpp | 5 +++-- .../controller/mapping/mouse/WheelHandler.h | 4 ++-- src/graphic/Fast3D/Fast3dWindow.cpp | 6 +++--- src/utils/glob.c | 5 ++--- 13 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/controller/controldevice/controller/ControllerButton.cpp b/src/controller/controldevice/controller/ControllerButton.cpp index efd867448..9d9bb42d1 100644 --- a/src/controller/controldevice/controller/ControllerButton.cpp +++ b/src/controller/controldevice/controller/ControllerButton.cpp @@ -184,7 +184,7 @@ bool ControllerButton::AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bi } else if (!Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverAnyGuiItem() && - Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup()) { + Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup()) { if (mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, bitmask, mMouseButtonForNewMapping); } else { diff --git a/src/controller/controldevice/controller/ControllerStick.cpp b/src/controller/controldevice/controller/ControllerStick.cpp index 5d5afafc2..55659fc60 100644 --- a/src/controller/controldevice/controller/ControllerStick.cpp +++ b/src/controller/controldevice/controller/ControllerStick.cpp @@ -279,10 +279,10 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct Context::GetInstance()->GetWindow()->GetGui()->IsMouseOverActivePopup()) { if (mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) { mapping = std::make_shared(mPortIndex, mStickIndex, direction, - mMouseButtonForNewMapping); + mMouseButtonForNewMapping); } else { - mapping = - AxisDirectionMappingFactory::CreateAxisDirectionMappingFromMouseWheelInput(mPortIndex, mStickIndex, direction); + mapping = AxisDirectionMappingFactory::CreateAxisDirectionMappingFromMouseWheelInput( + mPortIndex, mStickIndex, direction); } } if (mapping == nullptr) { diff --git a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp index ff52cd9c0..2fe627d22 100644 --- a/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.cpp @@ -97,7 +97,8 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromConfig(uint8_t portIn if (mappingClass == "MouseWheelToAxisDirectionMapping") { int32_t direction = CVarGetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), -1); - int wheelDirection = CVarGetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), 0); + int wheelDirection = + CVarGetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), 0); if (direction != LEFT && direction != RIGHT && direction != UP && direction != DOWN) { // something about this mapping is invalid @@ -218,7 +219,9 @@ AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput(uint8_t port return mapping; } -std::shared_ptr AxisDirectionMappingFactory::CreateAxisDirectionMappingFromMouseWheelInput(uint8_t portIndex, StickIndex stickIndex, Direction direction) { +std::shared_ptr +AxisDirectionMappingFactory::CreateAxisDirectionMappingFromMouseWheelInput(uint8_t portIndex, StickIndex stickIndex, + Direction direction) { WheelDirections wheelDirections = WheelHandler::GetInstance()->GetDirections(); WheelDirection wheelDirection; if (wheelDirections.x != LUS_WHEEL_NONE) { diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp index 92bd0d341..f707f98f3 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.cpp @@ -77,9 +77,11 @@ std::shared_ptr ButtonMappingFactory::CreateButtonMappi } if (mappingClass == "MouseWheelToButtonMapping") { - int wheelDirection = CVarGetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), 0); + int wheelDirection = + CVarGetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), 0); - return std::make_shared(portIndex, bitmask, static_cast(wheelDirection)); + return std::make_shared(portIndex, bitmask, + static_cast(wheelDirection)); } return nullptr; @@ -305,7 +307,8 @@ ButtonMappingFactory::CreateButtonMappingFromSDLInput(uint8_t portIndex, CONTROL return mapping; } -std::shared_ptr ButtonMappingFactory::CreateButtonMappingFromMouseWheelInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) { +std::shared_ptr +ButtonMappingFactory::CreateButtonMappingFromMouseWheelInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask) { WheelDirections wheelDirections = WheelHandler::GetInstance()->GetDirections(); WheelDirection wheelDirection; if (wheelDirections.x != LUS_WHEEL_NONE) { diff --git a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h index a56f04f9f..325a96562 100644 --- a/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h +++ b/src/controller/controldevice/controller/mapping/factories/ButtonMappingFactory.h @@ -19,6 +19,7 @@ class ButtonMappingFactory { static std::shared_ptr CreateButtonMappingFromSDLInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask); - static std::shared_ptr CreateButtonMappingFromMouseWheelInput(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask); + static std::shared_ptr CreateButtonMappingFromMouseWheelInput(uint8_t portIndex, + CONTROLLERBUTTONS_T bitmask); }; } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h b/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h index f420273ea..1f61d8b13 100644 --- a/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h +++ b/src/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h @@ -142,7 +142,7 @@ typedef enum WheelDirection { #ifdef __cplusplus static std::string mouseBtnNames[7] = { "MouseLeft", "MouseMiddle", "MouseRight", "MouseBackward", "MouseForward", "MOUSE_BTN_COUNT", "MOUSE_BTN_UNKNOWN" }; -static std::string wheelDirectionNames[6] = { "LUS_WHEEL_NONE", "WheelLeft", "WheelRight", "WheelUp", - "WheelDown", "LUS_WHEEL_UNKNOWN" }; +static std::string wheelDirectionNames[6] = { "LUS_WHEEL_NONE", "WheelLeft", "WheelRight", + "WheelUp", "WheelDown", "LUS_WHEEL_UNKNOWN" }; } // namespace Ship #endif diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp index 49efdfddb..7038df86f 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp @@ -9,7 +9,7 @@ namespace Ship { MouseWheelToAxisDirectionMapping::MouseWheelToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, - Direction direction, WheelDirection wheelDirection) + Direction direction, WheelDirection wheelDirection) : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseWheelToAnyMapping(wheelDirection), ControllerAxisDirectionMapping(ShipDeviceIndex::Mouse, portIndex, stickIndex, direction) { } @@ -34,7 +34,8 @@ void MouseWheelToAxisDirectionMapping::SaveToConfig() { "MouseWheelToAxisDirectionMapping"); CVarSetInteger(StringHelper::Sprintf("%s.Stick", mappingCvarKey.c_str()).c_str(), mStickIndex); CVarSetInteger(StringHelper::Sprintf("%s.Direction", mappingCvarKey.c_str()).c_str(), mDirection); - CVarSetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), static_cast(mWheelDirection)); + CVarSetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), + static_cast(mWheelDirection)); CVarSave(); } diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.h b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.h index b6df8d36c..47ba14c1b 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.h +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.h @@ -7,7 +7,8 @@ namespace Ship { class MouseWheelToAxisDirectionMapping final : public MouseWheelToAnyMapping, public ControllerAxisDirectionMapping { public: - MouseWheelToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, WheelDirection wheelDirection); + MouseWheelToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, + WheelDirection wheelDirection); float GetNormalizedAxisDirectionValue() override; std::string GetAxisDirectionMappingId() override; int8_t GetMappingType() override; diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.cpp index c0c361059..7591060a3 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToButtonMapping.cpp @@ -6,7 +6,8 @@ #include "Context.h" namespace Ship { -MouseWheelToButtonMapping::MouseWheelToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, WheelDirection wheelDirection) +MouseWheelToButtonMapping::MouseWheelToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, + WheelDirection wheelDirection) : ControllerInputMapping(ShipDeviceIndex::Mouse), MouseWheelToAnyMapping(wheelDirection), ControllerButtonMapping(ShipDeviceIndex::Mouse, portIndex, bitmask) { } @@ -35,7 +36,8 @@ void MouseWheelToButtonMapping::SaveToConfig() { CVarSetString(StringHelper::Sprintf("%s.ButtonMappingClass", mappingCvarKey.c_str()).c_str(), "MouseWheelToButtonMapping"); CVarSetInteger(StringHelper::Sprintf("%s.Bitmask", mappingCvarKey.c_str()).c_str(), mBitmask); - CVarSetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), static_cast(mWheelDirection)); + CVarSetInteger(StringHelper::Sprintf("%s.WheelDirection", mappingCvarKey.c_str()).c_str(), + static_cast(mWheelDirection)); CVarSave(); } diff --git a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp index d655b5e52..74a56baa3 100644 --- a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp @@ -4,10 +4,11 @@ namespace Ship { WheelHandler::WheelHandler() { - mDirections = {LUS_WHEEL_NONE, LUS_WHEEL_NONE}; + mDirections = { LUS_WHEEL_NONE, LUS_WHEEL_NONE }; } -WheelHandler::~WheelHandler() {} +WheelHandler::~WheelHandler() { +} std::shared_ptr WheelHandler::mInstance; diff --git a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h index 8a182cbdd..9fef39c39 100644 --- a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h +++ b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h @@ -7,8 +7,8 @@ namespace Ship { struct WheelDirections { - WheelDirection x; - WheelDirection y; + WheelDirection x; + WheelDirection y; }; class WheelHandler { diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 70fdc77fa..44ba7a416 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -296,12 +296,12 @@ void Fast3dWindow::AllKeysUp() { bool Fast3dWindow::MouseButtonUp(int button) { return Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseButtonEvent(false, - static_cast(button)); + static_cast(button)); } bool Fast3dWindow::MouseButtonDown(int button) { - bool isProcessed = - Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseButtonEvent(true, static_cast(button)); + bool isProcessed = Ship::Context::GetInstance()->GetControlDeck()->ProcessMouseButtonEvent( + true, static_cast(button)); return isProcessed; } diff --git a/src/utils/glob.c b/src/utils/glob.c index ef1464b9f..a3e102930 100644 --- a/src/utils/glob.c +++ b/src/utils/glob.c @@ -101,7 +101,7 @@ bool glob_match(char const* pat, char const* str) { #ifndef _WIN32 __attribute__((fallthrough)); #endif - //fallthrough; + // fallthrough; default: /* Literal character */ literal: if (c == d) { @@ -121,6 +121,5 @@ bool glob_match(char const* pat, char const* str) { } #ifdef __cplusplus -} -; +}; #endif \ No newline at end of file From 0cc649734f24a1877dbead7188991a5b99d59c78 Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 1 Jan 2025 01:56:30 +0700 Subject: [PATCH 56/58] fix wheel axis on dx backend --- src/graphic/Fast3D/gfx_dxgi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index fbcdfbde3..4e0387561 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -420,8 +420,8 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par break; } case WM_MOUSEWHEEL: - dxgi.mouse_wheel[0] = GET_WHEEL_DELTA_WPARAM(w_param) / WHEEL_DELTA; - dxgi.mouse_wheel[1] = 0; + dxgi.mouse_wheel[0] = 0; + dxgi.mouse_wheel[1] = GET_WHEEL_DELTA_WPARAM(w_param) / WHEEL_DELTA; break; case WM_DROPFILES: DragQueryFileA((HDROP)w_param, 0, fileName, 256); From e98eb3cc7686edc9fe6555a20c06c6bd671cf36a Mon Sep 17 00:00:00 2001 From: lightmanLP Date: Wed, 1 Jan 2025 12:52:47 +0700 Subject: [PATCH 57/58] Revert "wheel logging" This reverts commit 43082d871b668968de9228b0fd3836fce4186a27. --- .../controldevice/controller/mapping/mouse/WheelHandler.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp index 74a56baa3..4632e71c4 100644 --- a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp @@ -1,6 +1,5 @@ #include "WheelHandler.h" #include "Context.h" -#include "spdlog/spdlog.h" namespace Ship { WheelHandler::WheelHandler() { @@ -33,7 +32,6 @@ void WheelHandler::Update() { } else if (mCoords.y > 0) { mDirections.y = LUS_WHEEL_UP; } - SPDLOG_INFO("WHEEEL: {} {}", mCoords.x, mCoords.y); } CoordsF WheelHandler::GetCoords() { From 99302084e1a01a513f87c9f6c18dc2a2dddeb7e7 Mon Sep 17 00:00:00 2001 From: lightmanLP <50497969+lightmanLP@users.noreply.github.com> Date: Thu, 2 Jan 2025 05:02:42 +0000 Subject: [PATCH 58/58] buffered wheel axis mapping (test) --- .../MouseWheelToAxisDirectionMapping.cpp | 4 +- .../controller/mapping/mouse/WheelHandler.cpp | 45 +++++++++++++++---- .../controller/mapping/mouse/WheelHandler.h | 2 + 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp index 7038df86f..84fce8a6a 100644 --- a/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/MouseWheelToAxisDirectionMapping.cpp @@ -19,9 +19,7 @@ float MouseWheelToAxisDirectionMapping::GetNormalizedAxisDirectionValue() { return 0.0f; } - // TODO: scale input to match with MAX_AXIS_RANGE - // note: this is temporary solution to test numbers on different backends - return fmin(WheelHandler::GetInstance()->GetDirectionValue(mWheelDirection) * MAX_AXIS_RANGE, MAX_AXIS_RANGE); + return fmin(WheelHandler::GetInstance()->GetBufferedDirectionValue(mWheelDirection), 1.0f) * MAX_AXIS_RANGE; } std::string MouseWheelToAxisDirectionMapping::GetAxisDirectionMappingId() { diff --git a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp index 4632e71c4..b0c168ea1 100644 --- a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp +++ b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.cpp @@ -1,5 +1,6 @@ #include "WheelHandler.h" #include "Context.h" +#include namespace Ship { WheelHandler::WheelHandler() { @@ -18,9 +19,27 @@ std::shared_ptr WheelHandler::GetInstance() { return mInstance; } +void ApplyToBuffer(float* dst, float src) { + if (src == 0) { + return; + } + *dst += src; + if (fabs(*dst) > 2) { + *dst = copysignf(2.0f, *dst); + } +} + void WheelHandler::Update() { mCoords = Context::GetInstance()->GetWindow()->GetMouseWheel(); + // reduce buffered value + ApplyToBuffer(&mBufferedCoords.x, -copysignf(1.0f, mBufferedCoords.x)); + ApplyToBuffer(&mBufferedCoords.y, -copysignf(1.0f, mBufferedCoords.y)); + + // add new value to buffer + ApplyToBuffer(&mBufferedCoords.x, mCoords.x); + ApplyToBuffer(&mBufferedCoords.y, mCoords.y); + mDirections.x = mDirections.y = LUS_WHEEL_NONE; if (mCoords.x < 0) { mDirections.x = LUS_WHEEL_LEFT; @@ -42,28 +61,36 @@ WheelDirections WheelHandler::GetDirections() { return mDirections; } -float WheelHandler::GetDirectionValue(WheelDirection direction) { +float CalcDirectionValue(CoordsF& coords, WheelDirection direction) { switch (direction) { case LUS_WHEEL_LEFT: - if (mCoords.x < 0) { - return -mCoords.x; + if (coords.x < 0) { + return -coords.x; } break; case LUS_WHEEL_RIGHT: - if (mCoords.x > 0) { - return mCoords.x; + if (coords.x > 0) { + return coords.x; } break; case LUS_WHEEL_DOWN: - if (mCoords.y < 0) { - return -mCoords.y; + if (coords.y < 0) { + return -coords.y; } break; case LUS_WHEEL_UP: - if (mCoords.y > 0) { - return mCoords.y; + if (coords.y > 0) { + return coords.y; } } return 0.0f; } + +float WheelHandler::GetDirectionValue(WheelDirection direction) { + return CalcDirectionValue(mCoords, direction); +} + +float WheelHandler::GetBufferedDirectionValue(WheelDirection direction) { + return CalcDirectionValue(mBufferedCoords, direction); +} } // namespace Ship diff --git a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h index 9fef39c39..092d600f7 100644 --- a/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h +++ b/src/controller/controldevice/controller/mapping/mouse/WheelHandler.h @@ -21,11 +21,13 @@ class WheelHandler { CoordsF GetCoords(); WheelDirections GetDirections(); float GetDirectionValue(WheelDirection direction); + float GetBufferedDirectionValue(WheelDirection direction); private: static std::shared_ptr mInstance; WheelDirections mDirections; CoordsF mCoords; + CoordsF mBufferedCoords; }; } // namespace Ship