summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugin/Makefile.mingw32.in1
-rw-r--r--plugingui/Makefile.am2
-rw-r--r--plugingui/powerwidget.cc215
-rw-r--r--plugingui/powerwidget.h99
-rw-r--r--test/uitests/Makefile.am11
-rw-r--r--test/uitests/powerwidgettest.cc125
6 files changed, 452 insertions, 1 deletions
diff --git a/plugin/Makefile.mingw32.in b/plugin/Makefile.mingw32.in
index 067a132..68ea960 100644
--- a/plugin/Makefile.mingw32.in
+++ b/plugin/Makefile.mingw32.in
@@ -88,6 +88,7 @@ GUI_SRC = \
@top_srcdir@/plugingui/pixelbuffer.cc \
@top_srcdir@/plugingui/pluginconfig.cc \
@top_srcdir@/plugingui/powerbutton.cc \
+ @top_srcdir@/plugingui/powerwidget.cc \
@top_srcdir@/plugingui/progressbar.cc \
@top_srcdir@/plugingui/resamplingframecontent.cc \
@top_srcdir@/plugingui/resource.cc \
diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am
index 91e95bf..40d7f08 100644
--- a/plugingui/Makefile.am
+++ b/plugingui/Makefile.am
@@ -91,6 +91,7 @@ nodist_libdggui_la_SOURCES = \
pixelbuffer.cc \
pluginconfig.cc \
powerbutton.cc \
+ powerwidget.cc \
progressbar.cc \
resamplingframecontent.cc \
resource.cc \
@@ -231,6 +232,7 @@ EXTRA_DIST = \
pixelbuffer.h \
pluginconfig.h \
powerbutton.h \
+ powerwidget.h \
progressbar.h \
resamplingframecontent.h \
resource.h \
diff --git a/plugingui/powerwidget.cc b/plugingui/powerwidget.cc
new file mode 100644
index 0000000..1cecafc
--- /dev/null
+++ b/plugingui/powerwidget.cc
@@ -0,0 +1,215 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * powerwidget.cc
+ *
+ * Fri Apr 24 17:30:45 CEST 2020
+ * Copyright 2020 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "powerwidget.h"
+
+#include "painter.h"
+
+#include <notifier.h>
+#include <settings.h>
+#include <colour.h>
+
+#include <powermap.h>
+
+#include <hugin.hpp>
+
+PowerWidget::PowerWidget(GUI::Widget* parent,
+ Settings& settings,
+ SettingsNotifier& settings_notifier)
+ : GUI::Widget(parent)
+ , canvas(this, settings, settings_notifier)
+ , settings(settings)
+{
+ canvas.move(7, 7);
+
+ checkbox_enable.setChecked(settings.enable_powermap.load());
+ knob0_x.setValue(settings.fixed0_x.load());
+ knob0_y.setValue(settings.fixed0_y.load());
+ knob1_x.setValue(settings.fixed1_x.load());
+ knob1_y.setValue(settings.fixed1_y.load());
+ knob2_x.setValue(settings.fixed2_x.load());
+ knob2_y.setValue(settings.fixed2_y.load());
+ checkbox_shelf.setChecked(settings.shelf.load());
+
+ CONNECT(&checkbox_enable, stateChangedNotifier, this, &PowerWidget::chk_enable);
+ CONNECT(&knob0_x, valueChangedNotifier, this, &PowerWidget::k0_x);
+ CONNECT(&knob0_y, valueChangedNotifier, this, &PowerWidget::k0_y);
+ CONNECT(&knob1_x, valueChangedNotifier, this, &PowerWidget::k1_x);
+ CONNECT(&knob1_y, valueChangedNotifier, this, &PowerWidget::k1_y);
+ CONNECT(&knob2_x, valueChangedNotifier, this, &PowerWidget::k2_x);
+ CONNECT(&knob2_y, valueChangedNotifier, this, &PowerWidget::k2_y);
+ CONNECT(&checkbox_shelf, stateChangedNotifier, this, &PowerWidget::chk_shelf);
+
+ checkbox_enable.resize(100, 42);
+ knob0_x.resize(42, 42);
+ knob0_y.resize(42, 42);
+ knob1_x.resize(42, 42);
+ knob1_y.resize(42, 42);
+ knob2_x.resize(42, 42);
+ knob2_y.resize(42, 42);
+ checkbox_shelf.resize(100, 42);
+}
+
+void PowerWidget::chk_enable(bool v)
+{
+ settings.enable_powermap.store(v);
+}
+
+void PowerWidget::k0_x(float v)
+{
+ settings.fixed0_x.store(v);
+}
+
+void PowerWidget::k0_y(float v)
+{
+ settings.fixed0_y.store(v);
+}
+
+void PowerWidget::k1_x(float v)
+{
+ settings.fixed1_x.store(v);
+}
+
+void PowerWidget::k1_y(float v)
+{
+ settings.fixed1_y.store(v);
+}
+
+void PowerWidget::k2_x(float v)
+{
+ settings.fixed2_x.store(v);
+}
+
+void PowerWidget::k2_y(float v)
+{
+ settings.fixed2_y.store(v);
+}
+
+void PowerWidget::chk_shelf(bool v)
+{
+ settings.shelf.store(v);
+}
+
+void PowerWidget::repaintEvent(GUI::RepaintEvent *repaintEvent)
+{
+ GUI::Painter p(*this);
+ box.setSize(width(), height() / 2);
+ p.drawImage(0, 0, box);
+}
+
+void PowerWidget::resize(std::size_t width, std::size_t height)
+{
+ Widget::resize(width, height);
+ if(width < 14 || height < 14)
+ {
+ canvas.resize(1, 1);
+ return;
+ }
+ canvas.resize(width - 14, height / 2 - 14);
+
+ checkbox_enable.move(220, height / 2 + 14);
+ knob0_x.move(0, height / 2 + 14);
+ knob0_y.move(0, height / 2 + 14 + 60);
+ knob1_x.move(80, height / 2 + 14);
+ knob1_y.move(80, height / 2 + 14 + 60);
+ knob2_x.move(160, height / 2 + 14);
+ knob2_y.move(160, height / 2 + 14 + 60);
+ checkbox_shelf.move(220, height / 2 + 14 + 60);
+}
+
+PowerWidget::Canvas::Canvas(GUI::Widget* parent,
+ Settings& settings,
+ SettingsNotifier& settings_notifier)
+ : GUI::Widget(parent)
+ , settings_notifier(settings_notifier)
+ , settings(settings)
+{
+ CONNECT(this, settings_notifier.enable_powermap,
+ this, &PowerWidget::Canvas::parameterChangedBool);
+ CONNECT(this, settings_notifier.fixed0_x,
+ this, &PowerWidget::Canvas::parameterChangedFloat);
+ CONNECT(this, settings_notifier.fixed0_y,
+ this, &PowerWidget::Canvas::parameterChangedFloat);
+ CONNECT(this, settings_notifier.fixed1_x,
+ this, &PowerWidget::Canvas::parameterChangedFloat);
+ CONNECT(this, settings_notifier.fixed1_y,
+ this, &PowerWidget::Canvas::parameterChangedFloat);
+ CONNECT(this, settings_notifier.fixed2_x,
+ this, &PowerWidget::Canvas::parameterChangedFloat);
+ CONNECT(this, settings_notifier.fixed2_y,
+ this, &PowerWidget::Canvas::parameterChangedFloat);
+ CONNECT(this, settings_notifier.shelf,
+ this, &PowerWidget::Canvas::parameterChangedBool);
+
+ parameterChangedFloat(0);
+}
+
+void PowerWidget::Canvas::repaintEvent(GUI::RepaintEvent *repaintEvent)
+{
+ if(width() < 1 || height() < 1)
+ {
+ return;
+ }
+
+ GUI::Painter p(*this);
+
+ p.clear();
+// GUI::Colour c(1.0f, 1.0f, 0.0f, 0.2f);
+// p.setColour(c);
+// p.drawFilledRectangle(0, 0, width(), height());
+
+ if(enabled)
+ {
+ // enabled green
+ p.setColour(GUI::Colour(0.0f, 1.0f, 0.0f, 1.0f));
+ }
+ else
+ {
+ // disabled grey
+ p.setColour(GUI::Colour(0.5f, 0.5f, 0.5f, 1.0f));
+ }
+
+ for(std::size_t x = 0; x < width(); ++x)
+ {
+ int y = power_map.map((float)x / width()) * height();
+ p.drawPoint(x, height() - y);
+ }
+}
+
+void PowerWidget::Canvas::parameterChangedFloat(float)
+{
+ power_map.setFixed0({settings.fixed0_x.load(), settings.fixed0_y.load()});
+ power_map.setFixed1({settings.fixed1_x.load(), settings.fixed1_y.load()});
+ power_map.setFixed2({settings.fixed2_x.load(), settings.fixed2_y.load()});
+ power_map.setShelf(settings.shelf.load());
+ enabled = settings.enable_powermap.load();
+ redraw();
+}
+
+void PowerWidget::Canvas::parameterChangedBool(bool)
+{
+ parameterChangedFloat(0);
+}
diff --git a/plugingui/powerwidget.h b/plugingui/powerwidget.h
new file mode 100644
index 0000000..3645dc7
--- /dev/null
+++ b/plugingui/powerwidget.h
@@ -0,0 +1,99 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * powerwidget.h
+ *
+ * Fri Apr 24 17:30:45 CEST 2020
+ * Copyright 2020 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#pragma once
+
+#include <widget.h>
+#include <texturedbox.h>
+#include <texture.h>
+#include <knob.h>
+#include <checkbox.h>
+#include <powermap.h>
+
+struct Settings;
+class SettingsNotifier;
+
+class PowerWidget
+ : public GUI::Widget
+{
+public:
+ PowerWidget(GUI::Widget* parent,
+ Settings& settings,
+ SettingsNotifier& settings_notifier);
+
+ // From Widget:
+ virtual void repaintEvent(GUI::RepaintEvent *repaintEvent) override;
+ virtual void resize(std::size_t width, std::size_t height) override;
+
+private:
+ GUI::TexturedBox box{getImageCache(), ":resources/widget.png",
+ 0, 0, // atlas offset (x, y)
+ 7, 1, 7, // dx1, dx2, dx3
+ 7, 63, 7}; // dy1, dy2, dy3
+
+ class Canvas
+ : public GUI::Widget
+ {
+ public:
+ Canvas(GUI::Widget* parent, Settings& settings,
+ SettingsNotifier& settings_notifier);
+
+ // From Widget:
+ virtual void repaintEvent(GUI::RepaintEvent *repaintEvent) override;
+
+ private:
+ Powermap power_map;
+
+ void parameterChangedFloat(float);
+ void parameterChangedBool(bool);
+
+ SettingsNotifier& settings_notifier;
+ Settings& settings;
+
+ bool enabled{true};
+ };
+
+ void chk_enable(bool v);
+ void k0_x(float v);
+ void k0_y(float v);
+ void k1_x(float v);
+ void k1_y(float v);
+ void k2_x(float v);
+ void k2_y(float v);
+ void chk_shelf(bool v);
+
+ Canvas canvas;
+ GUI::CheckBox checkbox_enable{this};
+ GUI::Knob knob0_x{this};
+ GUI::Knob knob0_y{this};
+ GUI::Knob knob1_x{this};
+ GUI::Knob knob1_y{this};
+ GUI::Knob knob2_x{this};
+ GUI::Knob knob2_y{this};
+ GUI::CheckBox checkbox_shelf{this};
+
+ Settings& settings;
+};
diff --git a/test/uitests/Makefile.am b/test/uitests/Makefile.am
index 0c6821e..c78c262 100644
--- a/test/uitests/Makefile.am
+++ b/test/uitests/Makefile.am
@@ -1,5 +1,5 @@
noinst_PROGRAMS = resizetest tabwidgettest framewidgettest \
- filebrowsertest benchmarktest
+ filebrowsertest benchmarktest powerwidgettest
resizetest_LDADD = $(top_srcdir)/plugingui/libdggui.la $(top_srcdir)/src/libdg.la
resizetest_CXXFLAGS = \
@@ -57,4 +57,13 @@ benchmarktest_SOURCES = \
benchmarktest_resource_data.cc \
$(top_srcdir)/hugin/hugin.c
+powerwidgettest_LDADD = $(top_srcdir)/plugingui/libdggui.la $(top_srcdir)/src/libdg.la
+powerwidgettest_CXXFLAGS = \
+ -I$(top_srcdir)/plugingui \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/hugin
+powerwidgettest_SOURCES = \
+ powerwidgettest.cc \
+ $(top_srcdir)/hugin/hugin.c
+
EXTRA_DIST = $(RES)
diff --git a/test/uitests/powerwidgettest.cc b/test/uitests/powerwidgettest.cc
new file mode 100644
index 0000000..9ab0458
--- /dev/null
+++ b/test/uitests/powerwidgettest.cc
@@ -0,0 +1,125 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * powerwidgettest.cc
+ *
+ * Fri Apr 24 17:26:30 CEST 2020
+ * Copyright 2020 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include <iostream>
+#include <chrono>
+#include <thread>
+
+#include <button.h>
+#include <checkbox.h>
+#include <frame.h>
+#include <hugin.hpp>
+#include <label.h>
+#include <layout.h>
+#include <window.h>
+#include <painter.h>
+#include <settings.h>
+#include <powerwidget.h>
+
+class TestWindow
+ : public GUI::Window
+{
+public:
+ TestWindow()
+ : GUI::Window()
+ {
+ setCaption("PowerWidgetTest Window");
+ CONNECT(eventHandler(), closeNotifier, this,
+ &TestWindow::closeEventHandler);
+ CONNECT(this, sizeChangeNotifier, this, &TestWindow::sizeChanged);
+ }
+
+ void sizeChanged(std::size_t width, std::size_t height)
+ {
+ w.resize(width, height);
+ }
+
+ void closeEventHandler()
+ {
+ closing = true;
+ }
+
+ bool processEvents()
+ {
+ settings_notifier.evaluate();
+ eventHandler()->processEvents();
+// static unsigned int cnt = 500;
+// ++cnt;
+//
+// bool a = cnt / 1000 % 2 == 0;
+// float b = (((cnt * 6) % 300) + 0) / 1000.0;
+// float c = (((cnt * 5) % 300) + 0) / 1000.0;
+// float d = (((cnt * 4) % 300) + 300) / 1000.0;
+// float e = (((cnt * 3) % 300) + 300) / 1000.0;
+// float f = (((cnt * 2) % 300) + 600) / 1000.0;
+// float g = (((cnt * 1) % 300) + 600) / 1000.0;
+// bool h = cnt / 400 % 2 == 0;
+//
+// printf("cnt: % 4d: [ %s (%f %f) (%f %f) (%f %f) %s ]\n",
+// cnt, a?"true":"false", b, c, d, e, f, g, h?"true":"false");
+//
+// settings.enable_powermap.store(a);
+// settings.fixed0_x.store(b);
+// settings.fixed0_y.store(c);
+// settings.fixed1_x.store(d);
+// settings.fixed1_y.store(e);
+// settings.fixed2_x.store(f);
+// settings.fixed2_y.store(g);
+// settings.shelf.store(h);
+
+ return !closing;
+ }
+
+ void repaintEvent(GUI::RepaintEvent* repaintEvent) override
+ {
+ GUI::Painter painter(*this);
+ painter.setColour(GUI::Colour(0.85));
+ painter.drawFilledRectangle(0, 0, width() - 1, height() - 1);
+ }
+
+private:
+ bool closing{false};
+
+ Settings settings;
+ SettingsNotifier settings_notifier{settings};
+ PowerWidget w{this, settings, settings_notifier};
+};
+
+int main()
+{
+ INFO(example, "We are up and running");
+
+ TestWindow test_window;
+ test_window.show();
+ test_window.resize(300, 300);
+
+ while(test_window.processEvents())
+ {
+ std::this_thread::sleep_for(std::chrono::milliseconds(20));
+ }
+
+ return 0;
+}