Skip to content

Commit

Permalink
Fix high-dpi usage
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Oct 3, 2023
1 parent 3d63292 commit 6fd2f6c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cairo/Elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ bool ElementsWidget<BaseWidget>::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;
Expand Down Expand Up @@ -231,7 +232,7 @@ bool ElementsWidget<BaseWidget>::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;
Expand All @@ -248,8 +249,9 @@ bool ElementsWidget<BaseWidget>::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)
Expand All @@ -273,6 +275,7 @@ bool ElementsWidget<BaseWidget>::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<float>(10.f, event.time - host_view_h->last_scroll_time);
Expand All @@ -297,16 +300,16 @@ bool ElementsWidget<BaseWidget>::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;
}

view::scroll(
{ dx, dy },
{ float(event.pos.getX()), float(event.pos.getY()) }
{ float(event.pos.getX()) / scaleFactor, float(event.pos.getY()) / scaleFactor }
);

return true;
Expand Down

0 comments on commit 6fd2f6c

Please sign in to comment.