Bind KeyboardController position data to actual mouse position relative to the render canvas.

This makes (or at least should make) the mouse pointer act as the wiimote pointer
This commit is contained in:
EddyFrc 2026-06-15 19:24:05 +02:00
parent 2b358a98d3
commit 7107510443
4 changed files with 24 additions and 2 deletions

View File

@ -1389,6 +1389,12 @@ void MainWindow::OnMouseMove(wxMouseEvent& event)
std::unique_lock lock(instance.m_main_mouse.m_mutex);
auto physPos = ToPhys(event.GetPosition());
instance.m_main_mouse.position = { physPos.x, physPos.y };
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,
});
lock.unlock();
if (!IsFullScreen())

View File

@ -928,6 +928,16 @@ std::optional<glm::ivec2> InputManager::get_right_down_mouse_info(bool* is_pad)
return {};
}
glm::vec2 InputManager::GetMousePositionInRenderBox() const
{
return m_mouseInRenderCanvas;
}
void InputManager::SetMousePositionInRenderBox(glm::vec2 newMousePosition)
{
m_mouseInRenderCanvas = newMousePosition;
}
void InputManager::update_thread()
{
SetThreadName("Input_update");

View File

@ -91,10 +91,17 @@ public:
glm::ivec2 get_mouse_position(bool pad_window) const;
std::optional<glm::ivec2> get_left_down_mouse_info(bool* is_pad);
std::optional<glm::ivec2> get_right_down_mouse_info(bool* is_pad);
// Returns the mouse position relative to the render canvas (see MainWindow::m_render_canvas).
// (0, 0) is up left; (1, 1) is down right. The values may be negative or above 1 if the mouse cursor
// is outside the render canvas. At the time of writing this, it is used only for mouse-to-wiimote pointer feature.
glm::vec2 GetMousePositionInRenderBox() const;
void SetMousePositionInRenderBox(glm::vec2 newMousePosition);
std::atomic<float> m_mouse_wheel;
private:
glm::vec2 m_mouseInRenderCanvas{};
void update_thread();
std::thread m_update_thread;

View File

@ -11,8 +11,7 @@ KeyboardController::KeyboardController()
glm::vec2 KeyboardController::get_position()
{
// arbitrary values for test purpose
return {0.5, 0.5};
return InputManager::instance().GetMousePositionInRenderBox();
}
std::string KeyboardController::get_button_name(uint64 button) const