Skip to content

Commit b3748aa

Browse files
committed
Fix for #32 (hopefully !!): take hidpi scaling into account
1 parent 43fd677 commit b3748aa

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

geogram

src/lib/OGF/skin_imgui/widgets/render_area.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,7 @@ namespace OGF {
414414
}
415415
}
416416

417-
void RenderArea::cursor_pos_callback(
418-
double xf, double yf
419-
) {
417+
void RenderArea::cursor_pos_callback(double xf, double yf) {
420418
// For retina displays: x and y are in 'window pixels',
421419
// and GLUP project / unproject expect 'framebuffer pixels'.
422420
double sx = double(get_frame_buffer_width()) / double(get_width());
@@ -460,8 +458,8 @@ namespace OGF {
460458

461459

462460
// Take into account retina display scaling
461+
double sx = double(get_frame_buffer_width()) / double(get_width());
463462
double sy = double(get_frame_buffer_height()) / double(get_height());
464-
yoffset /= sy;
465463

466464
// Synthetize move/press/release mouse events
467465
// with center button pressed.
@@ -473,17 +471,19 @@ namespace OGF {
473471

474472
// Note: this is a GLFW button code (not RenderArea::Button that uses
475473
// a different mapping).
476-
const int button = 3; // (yoffset > 0) ? 3 : 4;
474+
const int button = (yoffset > 0) ? 3 : 4;
477475

478476
int mods = (ctrl ? GLFW_MOD_CONTROL : 0) |
479477
(shift ? GLFW_MOD_SHIFT : 0) ;
480478

481479
// Wheel emulates move/press/move/release event
482-
cursor_pos_callback(last_point_dc_.x, last_point_dc_.y);
480+
cursor_pos_callback(last_point_dc_.x / sx, last_point_dc_.y / sy);
483481
mouse_button_callback(button, GLFW_PRESS, mods);
484-
cursor_pos_callback(last_point_dc_.x,last_point_dc_.y-double(yoffset));
482+
cursor_pos_callback(
483+
last_point_dc_.x / sx, (last_point_dc_.y-double(yoffset)) / sy
484+
);
485485
mouse_button_callback(button, GLFW_RELEASE, mods);
486-
cursor_pos_callback(last_point_dc_bak.x, last_point_dc_bak.y);
486+
cursor_pos_callback(last_point_dc_bak.x / sx, last_point_dc_bak.y / sy);
487487
}
488488

489489
void RenderArea::drop_callback(int nb, const char** p) {

0 commit comments

Comments
 (0)