summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2020-04-25 16:17:53 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2020-04-25 16:17:53 +0200
commitc637d8630e6843c4677193da1ec5b2d7a60b6f07 (patch)
tree041b41a6e7067b3ef539b6997edf6478e489e887 /plugingui
parent486fafea19c459175eaff3e3f2339064028d399d (diff)
WIP: Fix button release outside window.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/powerwidget.cc20
-rw-r--r--plugingui/powerwidget.h1
2 files changed, 15 insertions, 6 deletions
diff --git a/plugingui/powerwidget.cc b/plugingui/powerwidget.cc
index 0fb4c7d..c05e0eb 100644
--- a/plugingui/powerwidget.cc
+++ b/plugingui/powerwidget.cc
@@ -260,23 +260,31 @@ void PowerWidget::Canvas::buttonEvent(GUI::ButtonEvent* buttonEvent)
}
}
+namespace
+{
+float clamp(float val)
+{
+ return std::max(0.0f, std::min(1.0f, val));
+}
+}
+
void PowerWidget::Canvas::mouseMoveEvent(GUI::MouseMoveEvent* mouseMoveEvent)
{
switch(in_point)
{
case 0:
- settings.fixed0_x.store((float)mouseMoveEvent->x / width());
- settings.fixed0_y.store((float)(height() - mouseMoveEvent->y) / height());
+ settings.fixed0_x.store(clamp((float)mouseMoveEvent->x / width()));
+ settings.fixed0_y.store(1.0f - clamp((float)mouseMoveEvent->y / height()));
redraw();
break;
case 1:
- settings.fixed1_x.store((float)mouseMoveEvent->x / width());
- settings.fixed1_y.store((float)(height() - mouseMoveEvent->y) / height());
+ settings.fixed1_x.store(clamp((float)mouseMoveEvent->x / width()));
+ settings.fixed1_y.store(1.0f - clamp((float)mouseMoveEvent->y / height()));
redraw();
break;
case 2:
- settings.fixed2_x.store((float)mouseMoveEvent->x / width());
- settings.fixed2_y.store((float)(height() - mouseMoveEvent->y) / height());
+ settings.fixed2_x.store(clamp((float)mouseMoveEvent->x / width()));
+ settings.fixed2_y.store(1.0f - clamp((float)mouseMoveEvent->y / height()));
redraw();
break;
default:
diff --git a/plugingui/powerwidget.h b/plugingui/powerwidget.h
index 54f5564..125d1d9 100644
--- a/plugingui/powerwidget.h
+++ b/plugingui/powerwidget.h
@@ -62,6 +62,7 @@ private:
SettingsNotifier& settings_notifier);
// From Widget:
+ virtual bool catchMouse() override { return true; }
virtual void repaintEvent(GUI::RepaintEvent *repaintEvent) override;
virtual void buttonEvent(GUI::ButtonEvent* buttonEvent) override;
virtual void mouseMoveEvent(GUI::MouseMoveEvent* mouseMoveEvent) override;