diff --git a/include/ui/Quantity.hpp b/include/Quantity.hpp similarity index 98% rename from include/ui/Quantity.hpp rename to include/Quantity.hpp index 04ac8340..e1b0f352 100644 --- a/include/ui/Quantity.hpp +++ b/include/Quantity.hpp @@ -1,10 +1,8 @@ #pragma once -#include "ui/common.hpp" #include "math.hpp" namespace rack { -namespace ui { /** A controller for manipulating a float value (which subclasses must store somehow) with limits and labels @@ -119,5 +117,4 @@ struct Quantity { }; -} // namespace ui } // namespace rack diff --git a/include/app/ParamQuantity.hpp b/include/app/ParamQuantity.hpp index edd1cca2..4284a4b5 100644 --- a/include/app/ParamQuantity.hpp +++ b/include/app/ParamQuantity.hpp @@ -1,5 +1,5 @@ #pragma once -#include "ui/Quantity.hpp" +#include "Quantity.hpp" #include "engine/Module.hpp" #include "engine/Param.hpp" @@ -8,8 +8,8 @@ namespace rack { namespace app { -/** A ui::Quantity that wraps an engine::Param. */ -struct ParamQuantity : ui::Quantity { +/** A Quantity that wraps an engine::Param. */ +struct ParamQuantity : Quantity { engine::Module *module = NULL; int paramId = 0; diff --git a/include/ui/Button.hpp b/include/ui/Button.hpp index e0ecbb82..0cea196e 100644 --- a/include/ui/Button.hpp +++ b/include/ui/Button.hpp @@ -1,7 +1,7 @@ #pragma once #include "widget/OpaqueWidget.hpp" #include "ui/common.hpp" -#include "ui/Quantity.hpp" +#include "Quantity.hpp" namespace rack { @@ -11,11 +11,10 @@ namespace ui { struct Button : widget::OpaqueWidget { std::string text; BNDwidgetState state = BND_DEFAULT; - /** Optional, owned. Tracks the pressed state of the button.*/ + /** Not owned. Tracks the pressed state of the button.*/ Quantity *quantity = NULL; Button(); - ~Button(); void draw(const DrawArgs &args) override; void onEnter(const widget::EnterEvent &e) override; void onLeave(const widget::LeaveEvent &e) override; diff --git a/include/ui/ProgressBar.hpp b/include/ui/ProgressBar.hpp index 9bd396a6..83c9e034 100644 --- a/include/ui/ProgressBar.hpp +++ b/include/ui/ProgressBar.hpp @@ -1,7 +1,7 @@ #pragma once #include "ui/common.hpp" #include "widget/Widget.hpp" -#include "ui/Quantity.hpp" +#include "Quantity.hpp" namespace rack { @@ -9,10 +9,10 @@ namespace ui { struct ProgressBar : widget::Widget { + /** Not owned. Stores the progress value and label. */ Quantity *quantity = NULL; ProgressBar(); - ~ProgressBar(); void draw(const DrawArgs &args) override; }; diff --git a/include/ui/RadioButton.hpp b/include/ui/RadioButton.hpp index 44922260..7a68d492 100644 --- a/include/ui/RadioButton.hpp +++ b/include/ui/RadioButton.hpp @@ -1,7 +1,7 @@ #pragma once #include "ui/common.hpp" #include "widget/OpaqueWidget.hpp" -#include "ui/Quantity.hpp" +#include "Quantity.hpp" namespace rack { @@ -10,10 +10,10 @@ namespace ui { struct RadioButton : widget::OpaqueWidget { BNDwidgetState state = BND_DEFAULT; + /** Not owned. */ Quantity *quantity = NULL; RadioButton(); - ~RadioButton(); void draw(const DrawArgs &args) override; void onEnter(const widget::EnterEvent &e) override; void onLeave(const widget::LeaveEvent &e) override; diff --git a/include/ui/Slider.hpp b/include/ui/Slider.hpp index 3aa1fe11..34bd8623 100644 --- a/include/ui/Slider.hpp +++ b/include/ui/Slider.hpp @@ -1,6 +1,6 @@ #pragma once #include "widget/OpaqueWidget.hpp" -#include "ui/Quantity.hpp" +#include "Quantity.hpp" #include "ui/common.hpp" #include "app.hpp" @@ -11,10 +11,10 @@ namespace ui { struct Slider : widget::OpaqueWidget { BNDwidgetState state = BND_DEFAULT; + /** Not owned. */ Quantity *quantity = NULL; Slider(); - ~Slider(); void draw(const DrawArgs &args) override; void onDragStart(const widget::DragStartEvent &e) override; void onDragMove(const widget::DragMoveEvent &e) override; diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index 0c7e92a0..9361ecaa 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -121,7 +121,7 @@ struct InfoBox : widget::Widget { }; -struct ModelFavoriteQuantity : ui::Quantity { +struct ModelFavoriteQuantity : Quantity { plugin::Model *model; std::string getLabel() override {return "★";} void setValue(float value) override { @@ -141,6 +141,16 @@ struct ModelFavoriteQuantity : ui::Quantity { }; +struct ModelFavoriteButton : ui::RadioButton { + ModelFavoriteButton() { + quantity = new ModelFavoriteQuantity; + } + ~ModelFavoriteButton() { + delete quantity; + } +}; + + static const float MODEL_BOX_ZOOM = 0.5f; @@ -148,7 +158,7 @@ struct ModelBox : widget::OpaqueWidget { plugin::Model *model; InfoBox *infoBox; widget::Widget *previewWidget; - ui::RadioButton *favoriteButton; + ModelFavoriteButton *favoriteButton; /** Lazily created */ widget::FramebufferWidget *previewFb = NULL; /** Number of frames since draw() has been called */ @@ -176,10 +186,8 @@ struct ModelBox : widget::OpaqueWidget { addChild(infoBox); // Favorite button - favoriteButton = new ui::RadioButton; - ModelFavoriteQuantity *favoriteQuantity = new ModelFavoriteQuantity; - favoriteQuantity->model = model; - favoriteButton->quantity = favoriteQuantity; + favoriteButton = new ModelFavoriteButton; + dynamic_cast(favoriteButton->quantity)->model = model; favoriteButton->box.pos.y = box.size.y; box.size.y += favoriteButton->box.size.y; addChild(favoriteButton); @@ -301,7 +309,7 @@ struct BrowserSearchField : ui::TextField { }; -struct ShowFavoritesQuantity : ui::Quantity { +struct ShowFavoritesQuantity : Quantity { widget::Widget *widget; std::string getLabel() override { int favoritesLen = settings::favoriteModels.size(); @@ -312,9 +320,19 @@ struct ShowFavoritesQuantity : ui::Quantity { }; +struct ShowFavoritesButton : ui::RadioButton { + ShowFavoritesButton() { + quantity = new ShowFavoritesQuantity; + } + ~ShowFavoritesButton() { + delete quantity; + } +}; + + struct BrowserSidebar : widget::Widget { BrowserSearchField *searchField; - ui::RadioButton *favoriteButton; + ShowFavoritesButton *favoriteButton; ui::Label *authorLabel; ui::List *authorList; ui::ScrollWidget *authorScroll; @@ -326,10 +344,8 @@ struct BrowserSidebar : widget::Widget { searchField = new BrowserSearchField; addChild(searchField); - favoriteButton = new ui::RadioButton; - ShowFavoritesQuantity *favoriteQuantity = new ShowFavoritesQuantity; - favoriteQuantity->widget = favoriteButton; - favoriteButton->quantity = favoriteQuantity; + favoriteButton = new ShowFavoritesButton; + dynamic_cast(favoriteButton->quantity)->widget = favoriteButton; addChild(favoriteButton); authorLabel = new ui::Label; diff --git a/src/app/ParamQuantity.cpp b/src/app/ParamQuantity.cpp index f90a0587..b9243d4b 100644 --- a/src/app/ParamQuantity.cpp +++ b/src/app/ParamQuantity.cpp @@ -58,7 +58,7 @@ float ParamQuantity::getDefaultValue() { float ParamQuantity::getDisplayValue() { if (!module) - return ui::Quantity::getDisplayValue(); + return Quantity::getDisplayValue(); float v = getSmoothValue(); float displayBase = getParam()->displayBase; if (displayBase == 0.f) { @@ -95,26 +95,26 @@ void ParamQuantity::setDisplayValue(float displayValue) { } int ParamQuantity::getDisplayPrecision() { - return ui::Quantity::getDisplayPrecision(); + return Quantity::getDisplayPrecision(); } std::string ParamQuantity::getDisplayValueString() { - return ui::Quantity::getDisplayValueString(); + return Quantity::getDisplayValueString(); } void ParamQuantity::setDisplayValueString(std::string s) { - ui::Quantity::setDisplayValueString(s); + Quantity::setDisplayValueString(s); } std::string ParamQuantity::getLabel() { if (!module) - return ui::Quantity::getLabel(); + return Quantity::getLabel(); return getParam()->label; } std::string ParamQuantity::getUnit() { if (!module) - return ui::Quantity::getUnit(); + return Quantity::getUnit(); return getParam()->unit; } diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index ff1e1198..8f6b3bf5 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -63,7 +63,7 @@ struct ParamTooltip : ui::Tooltip { void step() override { if (paramWidget->paramQuantity) { - // ui::Quantity string + // Quantity string text = paramWidget->paramQuantity->getString(); // Param description std::string description = paramWidget->paramQuantity->getParam()->description; diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index b04db7cc..d7fa37d0 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -170,7 +170,7 @@ struct EditButton : MenuButton { }; -struct ZoomQuantity : ui::Quantity { +struct ZoomQuantity : Quantity { void setValue(float value) override { settings::zoom = math::clamp(value, getMinValue(), getMaxValue()); } @@ -187,7 +187,17 @@ struct ZoomQuantity : ui::Quantity { }; -struct CableOpacityQuantity : ui::Quantity { +struct ZoomSlider : ui::Slider { + ZoomSlider() { + quantity = new ZoomQuantity; + } + ~ZoomSlider() { + delete quantity; + } +}; + + +struct CableOpacityQuantity : Quantity { void setValue(float value) override { settings::cableOpacity = math::clamp(value, getMinValue(), getMaxValue()); } @@ -203,7 +213,17 @@ struct CableOpacityQuantity : ui::Quantity { -struct CableTensionQuantity : ui::Quantity { +struct CableOpacitySlider : ui::Slider { + CableOpacitySlider() { + quantity = new CableOpacityQuantity; + } + ~CableOpacitySlider() { + delete quantity; + } +}; + + +struct CableTensionQuantity : Quantity { void setValue(float value) override { settings::cableTension = math::clamp(value, getMinValue(), getMaxValue()); } @@ -216,6 +236,16 @@ struct CableTensionQuantity : ui::Quantity { }; +struct CableTensionSlider : ui::Slider { + CableTensionSlider() { + quantity = new CableTensionQuantity; + } + ~CableTensionSlider() { + delete quantity; + } +}; + + struct CpuMeterItem : ui::MenuItem { void onAction(const widget::ActionEvent &e) override { settings::cpuMeter ^= true; @@ -359,19 +389,16 @@ struct SettingsButton : MenuButton { fullscreenItem->rightText = CHECKMARK_STRING " " + fullscreenItem->rightText; menu->addChild(fullscreenItem); - ui::Slider *zoomSlider = new ui::Slider; + ZoomSlider *zoomSlider = new ZoomSlider; zoomSlider->box.size.x = 200.0; - zoomSlider->quantity = new ZoomQuantity; menu->addChild(zoomSlider); - ui::Slider *cableOpacitySlider = new ui::Slider; + CableOpacitySlider *cableOpacitySlider = new CableOpacitySlider; cableOpacitySlider->box.size.x = 200.0; - cableOpacitySlider->quantity = new CableOpacityQuantity; menu->addChild(cableOpacitySlider); - ui::Slider *cableTensionSlider = new ui::Slider; + CableTensionSlider *cableTensionSlider = new CableTensionSlider; cableTensionSlider->box.size.x = 200.0; - cableTensionSlider->quantity = new CableTensionQuantity; menu->addChild(cableTensionSlider); } }; @@ -490,7 +517,7 @@ struct LogOutItem : ui::MenuItem { }; -struct DownloadQuantity : ui::Quantity { +struct DownloadQuantity : Quantity { float getValue() override { return plugin::downloadProgress; } diff --git a/src/ui/Button.cpp b/src/ui/Button.cpp index b84ee51b..931e6a40 100644 --- a/src/ui/Button.cpp +++ b/src/ui/Button.cpp @@ -9,11 +9,6 @@ Button::Button() { box.size.y = BND_WIDGET_HEIGHT; } -Button::~Button() { - if (quantity) - delete quantity; -} - void Button::draw(const DrawArgs &args) { bndToolButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); } diff --git a/src/ui/ProgressBar.cpp b/src/ui/ProgressBar.cpp index f3abf13a..fee2b9b5 100644 --- a/src/ui/ProgressBar.cpp +++ b/src/ui/ProgressBar.cpp @@ -9,11 +9,6 @@ ProgressBar::ProgressBar() { box.size.y = BND_WIDGET_HEIGHT; } -ProgressBar::~ProgressBar() { - if (quantity) - delete quantity; -} - void ProgressBar::draw(const DrawArgs &args) { float progress = quantity ? quantity->getScaledValue() : 0.f; std::string text = quantity ? quantity->getString() : ""; diff --git a/src/ui/Quantity.cpp b/src/ui/Quantity.cpp index 06d61d1d..41057eb8 100644 --- a/src/ui/Quantity.cpp +++ b/src/ui/Quantity.cpp @@ -1,9 +1,8 @@ -#include "ui/Quantity.hpp" +#include "Quantity.hpp" #include "string.hpp" namespace rack { -namespace ui { int Quantity::getDisplayPrecision() { @@ -44,5 +43,4 @@ std::string Quantity::getString() { } -} // namespace ui } // namespace rack diff --git a/src/ui/RadioButton.cpp b/src/ui/RadioButton.cpp index 446ef48b..618fc526 100644 --- a/src/ui/RadioButton.cpp +++ b/src/ui/RadioButton.cpp @@ -9,11 +9,6 @@ RadioButton::RadioButton() { box.size.y = BND_WIDGET_HEIGHT; } -RadioButton::~RadioButton() { - if (quantity) - delete quantity; -} - void RadioButton::draw(const DrawArgs &args) { BNDwidgetState state = this->state; std::string label; diff --git a/src/ui/Slider.cpp b/src/ui/Slider.cpp index f53770b7..e3765494 100644 --- a/src/ui/Slider.cpp +++ b/src/ui/Slider.cpp @@ -12,11 +12,6 @@ Slider::Slider() { box.size.y = BND_WIDGET_HEIGHT; } -Slider::~Slider() { - if (quantity) - delete quantity; -} - void Slider::draw(const DrawArgs &args) { float progress = quantity ? quantity->getScaledValue() : 0.f; std::string text = quantity ? quantity->getString() : "";