summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2020-04-25 12:22:20 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2020-04-25 12:22:20 +0200
commite4c45796cf94e8df70d6859d5f891acf8ee38fca (patch)
tree77dca1cf5b2e05bcef1233d2a4dddce0d30cfd79
parentc2c991815b73817d2a89e93f399bd95f1385eb37 (diff)
WIP: Drag 'em balls
-rw-r--r--plugingui/powerwidget.cc69
-rw-r--r--plugingui/powerwidget.h6
2 files changed, 72 insertions, 3 deletions
diff --git a/plugingui/powerwidget.cc b/plugingui/powerwidget.cc
index a1af333..83ce2b9 100644
--- a/plugingui/powerwidget.cc
+++ b/plugingui/powerwidget.cc
@@ -35,6 +35,7 @@
#include <powermap.h>
#include <hugin.hpp>
+#include <cmath>
PowerWidget::PowerWidget(GUI::Widget* parent,
Settings& settings,
@@ -179,13 +180,14 @@ void PowerWidget::Canvas::repaintEvent(GUI::RepaintEvent *repaintEvent)
p.clear();
// draw the fixed nodes of the spline
+ float rad = radius * width();
p.setColour(GUI::Colour{0.f, 0.7f, .5f, 1.f});
p.drawFilledCircle(power_map.getFixed0().in*width(),
- height() - power_map.getFixed0().out*height(), 3);
+ height() - power_map.getFixed0().out*height(), rad);
p.drawFilledCircle(power_map.getFixed1().in*width(),
- height() - power_map.getFixed1().out*height(), 3);
+ height() - power_map.getFixed1().out*height(), rad);
p.drawFilledCircle(power_map.getFixed2().in*width(),
- height() - power_map.getFixed2().out*height(), 3);
+ height() - power_map.getFixed2().out*height(), rad);
if(enabled)
{
@@ -216,6 +218,67 @@ void PowerWidget::Canvas::repaintEvent(GUI::RepaintEvent *repaintEvent)
old = { x, height() - y };
}
+void PowerWidget::Canvas::buttonEvent(GUI::ButtonEvent* buttonEvent)
+{
+ float x0 = (float)buttonEvent->x / width();
+ float y0 = (float)(height() - buttonEvent->y) / height();
+
+ switch(buttonEvent->direction)
+ {
+ case GUI::Direction::up:
+ in_point = -1;
+ break;
+ case GUI::Direction::down:
+ if(std::abs(x0 - settings.fixed0_x.load()) < radius &&
+ std::abs(y0 - settings.fixed0_y.load()) < radius)
+ {
+ in_point = 0;
+ }
+
+ if(std::abs(x0 - settings.fixed1_x.load()) < radius &&
+ std::abs(y0 - settings.fixed1_y.load()) < radius)
+ {
+ in_point = 1;
+ }
+
+ if(std::abs(x0 - settings.fixed2_x.load()) < radius &&
+ std::abs(y0 - settings.fixed2_y.load()) < radius)
+ {
+ in_point = 2;
+ }
+ break;
+ }
+}
+
+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());
+ redraw();
+ break;
+ case 1:
+ settings.fixed1_x.store((float)mouseMoveEvent->x / width());
+ settings.fixed1_y.store((float)(height() - mouseMoveEvent->y) / height());
+ redraw();
+ break;
+ case 2:
+ settings.fixed2_x.store((float)mouseMoveEvent->x / width());
+ settings.fixed2_y.store((float)(height() - mouseMoveEvent->y) / height());
+ redraw();
+ break;
+ default:
+ break;
+ }
+}
+
+void PowerWidget::Canvas::mouseLeaveEvent()
+{
+ //in_point = -1;
+}
+
void PowerWidget::Canvas::parameterChangedFloat(float)
{
power_map.setFixed0({settings.fixed0_x.load(), settings.fixed0_y.load()});
diff --git a/plugingui/powerwidget.h b/plugingui/powerwidget.h
index 3645dc7..54f5564 100644
--- a/plugingui/powerwidget.h
+++ b/plugingui/powerwidget.h
@@ -63,6 +63,9 @@ private:
// From Widget:
virtual void repaintEvent(GUI::RepaintEvent *repaintEvent) override;
+ virtual void buttonEvent(GUI::ButtonEvent* buttonEvent) override;
+ virtual void mouseMoveEvent(GUI::MouseMoveEvent* mouseMoveEvent) override;
+ virtual void mouseLeaveEvent() override;
private:
Powermap power_map;
@@ -74,6 +77,9 @@ private:
Settings& settings;
bool enabled{true};
+
+ int in_point{-1};
+ const float radius = 0.015;
};
void chk_enable(bool v);