From 6fd2f6c09466cc8f8ec7abce59abf51c28904bdb Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 3 Oct 2023 15:54:58 +0200 Subject: [PATCH] Fix high-dpi usage Signed-off-by: falkTX --- cairo/Elements.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cairo/Elements.cpp b/cairo/Elements.cpp index 86fa516..fdf87c1 100644 --- a/cairo/Elements.cpp +++ b/cairo/Elements.cpp @@ -192,6 +192,7 @@ bool ElementsWidget::onMouse(const Widget::MouseEvent& event) using namespace cycfi::elements; host_view* const host_view_h = host(); + const float scaleFactor = BaseWidget::getWindow().getScaleFactor(); mouse_button btn = {}; btn.down = event.press; @@ -231,7 +232,7 @@ bool ElementsWidget::onMouse(const Widget::MouseEvent& event) btn.modifiers |= mod_action; btn.num_clicks = host_view_h->last_click_count; - btn.pos = { float(event.pos.getX()), float(event.pos.getY()) }; + btn.pos = { float(event.pos.getX()) / scaleFactor, float(event.pos.getY()) / scaleFactor }; host_view_h->last_button = btn; host_view_h->last_cursor_pos = btn.pos; @@ -248,8 +249,9 @@ bool ElementsWidget::onMotion(const Widget::MotionEvent& event) using namespace cycfi::elements; host_view* const host_view_h = host(); + const float scaleFactor = BaseWidget::getWindow().getScaleFactor(); - const point pos = { float(event.pos.getX()), float(event.pos.getY()) }; + const point pos = { float(event.pos.getX()) / scaleFactor, float(event.pos.getY()) / scaleFactor }; host_view_h->last_cursor_pos = pos; if (host_view_h->last_button.down) @@ -273,6 +275,7 @@ bool ElementsWidget::onScroll(const Widget::ScrollEvent& event) using namespace cycfi::elements; host_view* const host_view_h = host(); + const float scaleFactor = BaseWidget::getWindow().getScaleFactor(); static constexpr float _1s = 100; const float elapsed = std::max(10.f, event.time - host_view_h->last_scroll_time); @@ -297,8 +300,8 @@ bool ElementsWidget::onScroll(const Widget::ScrollEvent& event) dx = -step; break; case kScrollSmooth: - dx = event.delta.getX(); - dy = event.delta.getY(); + dx = event.delta.getX() / scaleFactor; + dy = event.delta.getY() / scaleFactor; break; default: break; @@ -306,7 +309,7 @@ bool ElementsWidget::onScroll(const Widget::ScrollEvent& event) view::scroll( { dx, dy }, - { float(event.pos.getX()), float(event.pos.getY()) } + { float(event.pos.getX()) / scaleFactor, float(event.pos.getY()) / scaleFactor } ); return true;