From 03d15b42bdaa0b07ce3807d6a8672df08d1090fe Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 7 Apr 2023 19:27:35 +0200 Subject: [PATCH] correctly display cursor position when multiple screens exist --- src/panel.cpp | 15 +++++++++++---- src/panel.h | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/panel.cpp b/src/panel.cpp index cfe0e27..69f1ace 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -95,13 +95,20 @@ void Panel::Render() void Panel::UpdateCursor() { - auto global = _app->GetCursorPosition(); + auto global_pos = _app->GetCursorPosition(); + if (global_pos.x < _x || global_pos.x >= _x + _width || global_pos.y < _y || global_pos.y >= _y + _height) + { + _app->vr_overlay->ClearOverlayCursorPositionOverride(_id); + return; + } + int local_x = global_pos.x - _x; + int local_y = global_pos.y - _y; + // TODO: make this work when aspect ratio is >1 (root window is taller than it is wide) - // TODO take into account that the panel is smaller than the root window float ratio = (float)_height / (float)_width; float top_edge = 0.5f - ratio / 2.0f; - float x = global.x / (float)_width; - float y = 1.0f - (global.y / (float)_width + top_edge); + float x = local_x / (float)_width; + float y = 1.0f - (local_y / (float)_width + top_edge); auto pos = vr::HmdVector2_t{x, y}; _app->vr_overlay->SetOverlayCursorPositionOverride(_id, &pos); } diff --git a/src/panel.h b/src/panel.h index 7f80c00..afca6fc 100644 --- a/src/panel.h +++ b/src/panel.h @@ -28,8 +28,8 @@ class Panel TrackerID _active_hand; bool _is_held; - unsigned int _x, _y; - unsigned int _width, _height; + int _x, _y; + int _width, _height; float _alpha; vr::Texture_t _texture;