Move the mouse to wiimote pointer implementation in separate classes

This commit is contained in:
EddyFrc 2026-06-17 11:14:38 +02:00
parent 7107510443
commit 6da40ce5a7
12 changed files with 98 additions and 13 deletions

View File

@ -1392,8 +1392,8 @@ void MainWindow::OnMouseMove(wxMouseEvent& event)
auto renderCanvasMouse = m_render_canvas->ScreenToClient(m_mouse_position);
instance.SetMousePositionInRenderBox
({
static_cast<float>(renderCanvasMouse.x) / m_render_canvas->m_width,
static_cast<float>(renderCanvasMouse.y) / m_render_canvas->m_height,
static_cast<float>(renderCanvasMouse.x) / m_render_canvas->m_clientWidth,
static_cast<float>(renderCanvasMouse.y) / m_render_canvas->m_clientHeight,
});
lock.unlock();

View File

@ -173,10 +173,23 @@ void InputAPIAddWindow::on_api_selected(wxCommandEvent& event)
m_controller_list->SetSelection(wxNOT_FOUND);
const auto selection = m_input_api->GetStringSelection();
// keyboard is a special case, as theres only one device supported atm
// keyboard and mouse are special cases, as theres only one device supported atm
bool isSingleDeviceOnly{false};
InputAPI::Type singleDeviceAPI;
if (selection == wxString::FromUTF8(to_string(InputAPI::Keyboard)))
{
const auto controllers = InputManager::instance().get_api_provider(InputAPI::Keyboard)->get_controllers();
isSingleDeviceOnly = true;
singleDeviceAPI = InputAPI::Keyboard;
}
else if (selection == wxString::FromUTF8(to_string(InputAPI::Mouse)))
{
isSingleDeviceOnly = true;
singleDeviceAPI = InputAPI::Mouse;
}
if (isSingleDeviceOnly)
{
const auto controllers = InputManager::instance().get_api_provider(singleDeviceAPI)->get_controllers();
if (!controllers.empty())
{
m_controller = controllers[0];

View File

@ -19,6 +19,10 @@ add_library(CemuInput
api/Keyboard/KeyboardControllerProvider.cpp
api/Keyboard/KeyboardController.cpp
api/Keyboard/KeyboardController.h
api/Mouse/MouseControllerProvider.h
api/Mouse/MouseControllerProvider.cpp
api/Mouse/MouseController.cpp
api/Mouse/MouseController.h
emulated/ProController.cpp
emulated/EmulatedController.h
emulated/EmulatedController.cpp

View File

@ -1,5 +1,6 @@
#include "input/ControllerFactory.h"
#include "api/Mouse/MouseController.h"
#include "input/emulated/VPADController.h"
#include "input/emulated/ProController.h"
#include "input/emulated/ClassicController.h"
@ -31,6 +32,10 @@ ControllerPtr ControllerFactory::CreateController(InputAPI::Type api, std::strin
case InputAPI::Keyboard:
return std::make_shared<KeyboardController>();
#endif
#if HAS_MOUSE
case InputAPI::Mouse:
return std::make_shared<MouseController>();
#endif
#if HAS_DIRECTINPUT
case InputAPI::DirectInput:
{

View File

@ -5,6 +5,7 @@
#include <pugixml.hpp>
#include "Cafe/GameProfile/GameProfile.h"
#include "util/EventService.h"
#include "input/api/Mouse/MouseControllerProvider.h"
InputManager::InputManager()
{
@ -28,6 +29,9 @@ InputManager::InputManager()
#if HAS_KEYBOARD
create_provider<KeyboardControllerProvider>();
#endif
#if HAS_MOUSE
create_provider<MouseControllerProvider>();
#endif
#ifdef HAS_SDL
create_provider<SDLControllerProvider>();
#endif
@ -233,6 +237,8 @@ bool InputManager::migrate_config(const fs::path& file_path)
std::string uuid;
if (api_string == to_string(InputAPI::Keyboard))
uuid = to_string(InputAPI::Keyboard);
else if (api_string == to_string(InputAPI::Mouse))
uuid = to_string(InputAPI::Mouse);
else
{
if (!uuid_opt)

View File

@ -7,6 +7,7 @@ namespace InputAPI
enum Type
{
Keyboard,
Mouse,
SDLController,
XInput,
DirectInput,
@ -26,6 +27,8 @@ namespace InputAPI
{
case Keyboard:
return "Keyboard";
case Mouse:
return "Mouse";
case DirectInput:
return "DirectInput";
case XInput:
@ -53,6 +56,8 @@ namespace InputAPI
{
if (str == to_string(Keyboard))
return Keyboard;
else if (str == to_string(Mouse))
return Mouse;
else if (str == to_string(DirectInput))
return DirectInput;
else if (str == to_string(XInput))

View File

@ -9,11 +9,6 @@ KeyboardController::KeyboardController()
}
glm::vec2 KeyboardController::get_position()
{
return InputManager::instance().GetMousePositionInRenderBox();
}
std::string KeyboardController::get_button_name(uint64 button) const
{
return WindowSystem::GetKeyCodeName(button);

View File

@ -19,10 +19,6 @@ public:
bool has_axis() const override { return false; }
bool has_position() override { return true; }
glm::vec2 get_position() override;
PositionVisibility GetPositionVisibility() override { return PositionVisibility::FULL; }
std::string get_button_name(uint64 button) const override;
protected:

View File

@ -0,0 +1,13 @@
#include "MouseController.h"
#include "input/api/Controller.h"
std::string_view MouseController::api_name() const
{
static_assert(to_string(InputAPI::Mouse) == "Mouse");
return to_string(InputAPI::Mouse);
}
glm::vec2 MouseController::get_position()
{
return InputManager::instance().GetMousePositionInRenderBox();
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "MouseControllerProvider.h"
#include "input/api/Controller.h"
class MouseController : public Controller<MouseControllerProvider>
{
public:
MouseController() : base_type("mouse", "Mouse") {}
std::string_view api_name() const override;
InputAPI::Type api() const override { return InputAPI::Mouse; }
bool is_connected() override { return true; }
ControllerState raw_state() override { return {}; }
bool has_position() override { return true; }
glm::vec2 get_position() override;
PositionVisibility GetPositionVisibility() override { return PositionVisibility::FULL; }
};

View File

@ -0,0 +1,10 @@
#include "MouseControllerProvider.h"
#include "MouseController.h"
std::vector<std::shared_ptr<ControllerBase>> MouseControllerProvider::get_controllers()
{
std::vector<std::shared_ptr<ControllerBase>> result;
result.emplace_back(std::make_shared<MouseController>());
return result;
}

View File

@ -0,0 +1,17 @@
#pragma once
#include "input/api/ControllerProvider.h"
#ifndef HAS_MOUSE
#define HAS_MOUSE 1
#endif
class MouseControllerProvider : public ControllerProviderBase
{
public:
inline static InputAPI::Type kAPIType = InputAPI::Mouse;
InputAPI::Type api() const override { return kAPIType; }
std::vector<std::shared_ptr<ControllerBase>> get_controllers() override;
};