From f505c622eda8cdd02da00742e794c9b940902a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Mon, 17 Apr 2017 11:23:09 +0200 Subject: Write knob value outside of the knob in the humanizer frame. --- plugingui/humanizerframecontent.cc | 6 ++++-- plugingui/humanizerframecontent.h | 20 +++++++++++++++++++- plugingui/knob.cc | 37 ++++++++++++++++++++++--------------- plugingui/knob.h | 3 +++ 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/plugingui/humanizerframecontent.cc b/plugingui/humanizerframecontent.cc index 6a01b7b..9795b76 100644 --- a/plugingui/humanizerframecontent.cc +++ b/plugingui/humanizerframecontent.cc @@ -38,12 +38,14 @@ HumanizerframeContent::HumanizerframeContent(Widget* parent) : Widget(parent) layout.setVAlignment(VAlignment::center); attack.resize(80, 80); - attackKnob.resize(60, 60); + attackKnob.resize(30, 30); + attackKnob.showValue(false); attack.setControl(&attackKnob); layout.addItem(&attack); falloff.resize(80, 80); - falloffKnob.resize(60, 60); + falloffKnob.resize(30, 30); + falloffKnob.showValue(false); falloff.setControl(&falloffKnob); layout.addItem(&falloff); diff --git a/plugingui/humanizerframecontent.h b/plugingui/humanizerframecontent.h index 530742b..0196ea5 100644 --- a/plugingui/humanizerframecontent.h +++ b/plugingui/humanizerframecontent.h @@ -30,6 +30,9 @@ #include "label.h" #include "widget.h" +#include +#include + namespace GUI { @@ -41,6 +44,7 @@ public: { layout.setResizeChildren(false); layout.setHAlignment(HAlignment::center); + layout.setSpacing(2); caption.setText(name); caption.resize(100, 20); @@ -48,14 +52,28 @@ public: layout.addItem(&caption); } - void setControl(Widget* control) + void setControl(Knob* control) { layout.addItem(control); + + CONNECT(control, valueChangedNotifier, this, &LabeledControl::setValue); + setValue(control->value()); + value.resize(100, 20); + value.setAlignment(TextAlignment::center); + layout.addItem(&value); } private: VBoxLayout layout{this}; Label caption{this}; + Label value{this}; + + void setValue(float new_value) + { + std::stringstream stream; + stream << std::fixed << std::setprecision(2) << new_value; + value.setText(stream.str()); + } }; class HumanizerframeContent : public Widget diff --git a/plugingui/knob.cc b/plugingui/knob.cc index 0c7159f..7a5efc1 100644 --- a/plugingui/knob.cc +++ b/plugingui/knob.cc @@ -73,6 +73,11 @@ float Knob::value() return current_value * (maximum - minimum) + minimum; } +void Knob::showValue(bool show_value) +{ + this->show_value = show_value; +} + void Knob::scrollEvent(ScrollEvent* scrollEvent) { float value = (current_value - (scrollEvent->delta / 200.0)); @@ -168,22 +173,24 @@ void Knob::repaintEvent(RepaintEvent* repaintEvent) float range = maximum - minimum; - // Show 0, 1 or 2 decimal point depending on the size of the range - char buf[64]; - if(range> 100.0f) - { - sprintf(buf, "%.0f", current_value * range + minimum); - } - else if(range > 10.0f) - { - sprintf(buf, "%.1f", current_value * range + minimum); - } - else - { - sprintf(buf, "%.2f", current_value * range + minimum); + if (show_value) { + // Show 0, 1 or 2 decimal point depending on the size of the range + char buf[64]; + if(range> 100.0f) + { + sprintf(buf, "%.0f", current_value * range + minimum); + } + else if(range > 10.0f) + { + sprintf(buf, "%.1f", current_value * range + minimum); + } + else + { + sprintf(buf, "%.2f", current_value * range + minimum); + } + p.drawText(center_x - font.textWidth(buf) / 2 + 1, + center_y + font.textHeight(buf) / 2 + 1, font, buf); } - p.drawText(center_x - font.textWidth(buf) / 2 + 1, - center_y + font.textHeight(buf) / 2 + 1, font, buf); // Make it start from 20% and stop at 80% double padval = current_value * 0.8 + 0.1; diff --git a/plugingui/knob.h b/plugingui/knob.h index 5710b78..d8771d8 100644 --- a/plugingui/knob.h +++ b/plugingui/knob.h @@ -46,6 +46,7 @@ public: void setValue(float value); void setRange(float minimum, float maximum); float value(); + void showValue(bool show_value); Notifier valueChangedNotifier; // (float newValue) @@ -74,6 +75,8 @@ private: float maximum; float minimum; + bool show_value{true}; + Texture img_knob; int mouse_offset_x; -- cgit v1.2.3