mirror of
https://github.com/CrispyPin/sinpin-vr.git
synced 2024-11-22 18:10:26 +01:00
correctly display cursor position when multiple screens exist
This commit is contained in:
parent
54ea68da6b
commit
03d15b42bd
2 changed files with 13 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue