Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gizmos): fix gizmos selection on HiDPI screens #1405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (**@diogomsmiranda**, **@RiscadoA**).

## [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 @@

cubos.system("do Gizmos picking")
.after(drawToRenderPickerTag)
.call([](GizmosRenderer& gizmosRenderer, Gizmos& gizmos,
.call([](const Window& window, GizmosRenderer& gizmosRenderer, Gizmos& gizmos,

Check warning on line 245 in engine/src/gizmos/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/gizmos/plugin.cpp#L245

Added line #L245 was not covered by tests
Query<const RenderTarget&, const RenderPicker&> renderPickers) {
int mouseX = gizmosRenderer.lastMousePosition.x;
int mouseY = gizmosRenderer.lastMousePosition.y;
Expand All @@ -252,6 +252,11 @@
{
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));

Check warning on line 258 in engine/src/gizmos/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/gizmos/plugin.cpp#L255-L258

Added lines #L255 - L258 were not covered by tests

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 @@
// 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)));

Check warning on line 40 in engine/src/tools/selection/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/tools/selection/plugin.cpp#L37-L40

Added lines #L37 - L40 were not covered by tests

if (entityId == UINT32_MAX)
{
Expand Down
Loading