summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;