From 683fcc3a6ab41b0758eebb104565c41c2ef8af3c Mon Sep 17 00:00:00 2001 From: Diogo Miranda Date: Mon, 9 Dec 2024 13:34:02 +0000 Subject: [PATCH] fix(rendering): consider HiDPI screens when using the render picker Co-Authored-By: Ricardo Antunes --- CHANGELOG.md | 8 ++++++++ engine/src/gizmos/plugin.cpp | 7 ++++++- engine/src/tools/selection/plugin.cpp | 7 +++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33a522df41..3fba86f81b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +### Fixed + +- Consider HiDPI screens when using the render picker (**@RiscadoA**, **@diogomsmiranda**). + ## [v0.5.0] - 2024-12-01 ### Added diff --git a/engine/src/gizmos/plugin.cpp b/engine/src/gizmos/plugin.cpp index 80b0c2262b..af376c51f0 100644 --- a/engine/src/gizmos/plugin.cpp +++ b/engine/src/gizmos/plugin.cpp @@ -242,7 +242,7 @@ void cubos::engine::gizmosPlugin(Cubos& cubos) cubos.system("do Gizmos picking") .after(drawToRenderPickerTag) - .call([](GizmosRenderer& gizmosRenderer, Gizmos& gizmos, + .call([](const Window& window, GizmosRenderer& gizmosRenderer, Gizmos& gizmos, Query renderPickers) { int mouseX = gizmosRenderer.lastMousePosition.x; int mouseY = gizmosRenderer.lastMousePosition.y; @@ -252,6 +252,11 @@ void cubos::engine::gizmosPlugin(Cubos& cubos) { if (target.framebuffer == nullptr) { + mouseX = static_cast(static_cast(mouseX) * static_cast(target.size.x) / + static_cast(window->size().x)); + mouseY = static_cast(static_cast(mouseY) * static_cast(target.size.y) / + static_cast(window->size().y)); + auto id = picker.read(static_cast(mouseX), static_cast(mouseY)); if (id < static_cast(1 << 31)) { diff --git a/engine/src/tools/selection/plugin.cpp b/engine/src/tools/selection/plugin.cpp index ea2f97b979..9ac865569d 100644 --- a/engine/src/tools/selection/plugin.cpp +++ b/engine/src/tools/selection/plugin.cpp @@ -33,8 +33,11 @@ void cubos::engine::selectionPlugin(Cubos& cubos) // Find the render picker for the main window (nullptr framebuffer) if (target.framebuffer == nullptr) { - uint32_t entityId = picker.read(static_cast(ImGui::GetMousePos().x), - static_cast(ImGui::GetMousePos().y)); + uint32_t entityId = + picker.read(static_cast((ImGui::GetMousePos().x / ImGui::GetWindowWidth()) * + static_cast(target.size.x)), + static_cast((ImGui::GetMousePos().y / ImGui::GetWindowHeight()) * + static_cast(target.size.y))); if (entityId == UINT32_MAX) {