Skip to content

Commit

Permalink
fix(rendering): consider HiDPI screens when using the render picker
Browse files Browse the repository at this point in the history
Co-Authored-By: Ricardo Antunes <[email protected]>
  • Loading branch information
diogomsmiranda and RiscadoA committed Dec 9, 2024
1 parent 9d530fe commit 683fcc3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion engine/src/gizmos/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const RenderTarget&, const RenderPicker&> renderPickers) {
int mouseX = gizmosRenderer.lastMousePosition.x;
int mouseY = gizmosRenderer.lastMousePosition.y;
Expand All @@ -252,6 +252,11 @@ void cubos::engine::gizmosPlugin(Cubos& cubos)
{
if (target.framebuffer == nullptr)
{
mouseX = static_cast<int>(static_cast<float>(mouseX) * static_cast<float>(target.size.x) /
static_cast<float>(window->size().x));
mouseY = static_cast<int>(static_cast<float>(mouseY) * static_cast<float>(target.size.y) /
static_cast<float>(window->size().y));

auto id = picker.read(static_cast<unsigned int>(mouseX), static_cast<unsigned int>(mouseY));
if (id < static_cast<uint32_t>(1 << 31))
{
Expand Down
7 changes: 5 additions & 2 deletions engine/src/tools/selection/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int>(ImGui::GetMousePos().x),
static_cast<unsigned int>(ImGui::GetMousePos().y));
uint32_t entityId =
picker.read(static_cast<unsigned int>((ImGui::GetMousePos().x / ImGui::GetWindowWidth()) *
static_cast<float>(target.size.x)),
static_cast<unsigned int>((ImGui::GetMousePos().y / ImGui::GetWindowHeight()) *
static_cast<float>(target.size.y)));

if (entityId == UINT32_MAX)
{
Expand Down

0 comments on commit 683fcc3

Please sign in to comment.