@@ -1,10 +1,8 @@ | |||||
#pragma once | #pragma once | ||||
#include "ui/common.hpp" | |||||
#include "math.hpp" | #include "math.hpp" | ||||
namespace rack { | namespace rack { | ||||
namespace ui { | |||||
/** A controller for manipulating a float value (which subclasses must store somehow) with limits and labels | /** 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 | } // namespace rack |
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "ui/Quantity.hpp" | |||||
#include "Quantity.hpp" | |||||
#include "engine/Module.hpp" | #include "engine/Module.hpp" | ||||
#include "engine/Param.hpp" | #include "engine/Param.hpp" | ||||
@@ -8,8 +8,8 @@ namespace rack { | |||||
namespace app { | 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; | engine::Module *module = NULL; | ||||
int paramId = 0; | int paramId = 0; | ||||
@@ -1,7 +1,7 @@ | |||||
#pragma once | #pragma once | ||||
#include "widget/OpaqueWidget.hpp" | #include "widget/OpaqueWidget.hpp" | ||||
#include "ui/common.hpp" | #include "ui/common.hpp" | ||||
#include "ui/Quantity.hpp" | |||||
#include "Quantity.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -11,11 +11,10 @@ namespace ui { | |||||
struct Button : widget::OpaqueWidget { | struct Button : widget::OpaqueWidget { | ||||
std::string text; | std::string text; | ||||
BNDwidgetState state = BND_DEFAULT; | 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; | Quantity *quantity = NULL; | ||||
Button(); | Button(); | ||||
~Button(); | |||||
void draw(const DrawArgs &args) override; | void draw(const DrawArgs &args) override; | ||||
void onEnter(const widget::EnterEvent &e) override; | void onEnter(const widget::EnterEvent &e) override; | ||||
void onLeave(const widget::LeaveEvent &e) override; | void onLeave(const widget::LeaveEvent &e) override; | ||||
@@ -1,7 +1,7 @@ | |||||
#pragma once | #pragma once | ||||
#include "ui/common.hpp" | #include "ui/common.hpp" | ||||
#include "widget/Widget.hpp" | #include "widget/Widget.hpp" | ||||
#include "ui/Quantity.hpp" | |||||
#include "Quantity.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -9,10 +9,10 @@ namespace ui { | |||||
struct ProgressBar : widget::Widget { | struct ProgressBar : widget::Widget { | ||||
/** Not owned. Stores the progress value and label. */ | |||||
Quantity *quantity = NULL; | Quantity *quantity = NULL; | ||||
ProgressBar(); | ProgressBar(); | ||||
~ProgressBar(); | |||||
void draw(const DrawArgs &args) override; | void draw(const DrawArgs &args) override; | ||||
}; | }; | ||||
@@ -1,7 +1,7 @@ | |||||
#pragma once | #pragma once | ||||
#include "ui/common.hpp" | #include "ui/common.hpp" | ||||
#include "widget/OpaqueWidget.hpp" | #include "widget/OpaqueWidget.hpp" | ||||
#include "ui/Quantity.hpp" | |||||
#include "Quantity.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -10,10 +10,10 @@ namespace ui { | |||||
struct RadioButton : widget::OpaqueWidget { | struct RadioButton : widget::OpaqueWidget { | ||||
BNDwidgetState state = BND_DEFAULT; | BNDwidgetState state = BND_DEFAULT; | ||||
/** Not owned. */ | |||||
Quantity *quantity = NULL; | Quantity *quantity = NULL; | ||||
RadioButton(); | RadioButton(); | ||||
~RadioButton(); | |||||
void draw(const DrawArgs &args) override; | void draw(const DrawArgs &args) override; | ||||
void onEnter(const widget::EnterEvent &e) override; | void onEnter(const widget::EnterEvent &e) override; | ||||
void onLeave(const widget::LeaveEvent &e) override; | void onLeave(const widget::LeaveEvent &e) override; | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "widget/OpaqueWidget.hpp" | #include "widget/OpaqueWidget.hpp" | ||||
#include "ui/Quantity.hpp" | |||||
#include "Quantity.hpp" | |||||
#include "ui/common.hpp" | #include "ui/common.hpp" | ||||
#include "app.hpp" | #include "app.hpp" | ||||
@@ -11,10 +11,10 @@ namespace ui { | |||||
struct Slider : widget::OpaqueWidget { | struct Slider : widget::OpaqueWidget { | ||||
BNDwidgetState state = BND_DEFAULT; | BNDwidgetState state = BND_DEFAULT; | ||||
/** Not owned. */ | |||||
Quantity *quantity = NULL; | Quantity *quantity = NULL; | ||||
Slider(); | Slider(); | ||||
~Slider(); | |||||
void draw(const DrawArgs &args) override; | void draw(const DrawArgs &args) override; | ||||
void onDragStart(const widget::DragStartEvent &e) override; | void onDragStart(const widget::DragStartEvent &e) override; | ||||
void onDragMove(const widget::DragMoveEvent &e) override; | void onDragMove(const widget::DragMoveEvent &e) override; | ||||
@@ -121,7 +121,7 @@ struct InfoBox : widget::Widget { | |||||
}; | }; | ||||
struct ModelFavoriteQuantity : ui::Quantity { | |||||
struct ModelFavoriteQuantity : Quantity { | |||||
plugin::Model *model; | plugin::Model *model; | ||||
std::string getLabel() override {return "★";} | std::string getLabel() override {return "★";} | ||||
void setValue(float value) override { | 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; | static const float MODEL_BOX_ZOOM = 0.5f; | ||||
@@ -148,7 +158,7 @@ struct ModelBox : widget::OpaqueWidget { | |||||
plugin::Model *model; | plugin::Model *model; | ||||
InfoBox *infoBox; | InfoBox *infoBox; | ||||
widget::Widget *previewWidget; | widget::Widget *previewWidget; | ||||
ui::RadioButton *favoriteButton; | |||||
ModelFavoriteButton *favoriteButton; | |||||
/** Lazily created */ | /** Lazily created */ | ||||
widget::FramebufferWidget *previewFb = NULL; | widget::FramebufferWidget *previewFb = NULL; | ||||
/** Number of frames since draw() has been called */ | /** Number of frames since draw() has been called */ | ||||
@@ -176,10 +186,8 @@ struct ModelBox : widget::OpaqueWidget { | |||||
addChild(infoBox); | addChild(infoBox); | ||||
// Favorite button | // Favorite button | ||||
favoriteButton = new ui::RadioButton; | |||||
ModelFavoriteQuantity *favoriteQuantity = new ModelFavoriteQuantity; | |||||
favoriteQuantity->model = model; | |||||
favoriteButton->quantity = favoriteQuantity; | |||||
favoriteButton = new ModelFavoriteButton; | |||||
dynamic_cast<ModelFavoriteQuantity*>(favoriteButton->quantity)->model = model; | |||||
favoriteButton->box.pos.y = box.size.y; | favoriteButton->box.pos.y = box.size.y; | ||||
box.size.y += favoriteButton->box.size.y; | box.size.y += favoriteButton->box.size.y; | ||||
addChild(favoriteButton); | addChild(favoriteButton); | ||||
@@ -301,7 +309,7 @@ struct BrowserSearchField : ui::TextField { | |||||
}; | }; | ||||
struct ShowFavoritesQuantity : ui::Quantity { | |||||
struct ShowFavoritesQuantity : Quantity { | |||||
widget::Widget *widget; | widget::Widget *widget; | ||||
std::string getLabel() override { | std::string getLabel() override { | ||||
int favoritesLen = settings::favoriteModels.size(); | 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 { | struct BrowserSidebar : widget::Widget { | ||||
BrowserSearchField *searchField; | BrowserSearchField *searchField; | ||||
ui::RadioButton *favoriteButton; | |||||
ShowFavoritesButton *favoriteButton; | |||||
ui::Label *authorLabel; | ui::Label *authorLabel; | ||||
ui::List *authorList; | ui::List *authorList; | ||||
ui::ScrollWidget *authorScroll; | ui::ScrollWidget *authorScroll; | ||||
@@ -326,10 +344,8 @@ struct BrowserSidebar : widget::Widget { | |||||
searchField = new BrowserSearchField; | searchField = new BrowserSearchField; | ||||
addChild(searchField); | addChild(searchField); | ||||
favoriteButton = new ui::RadioButton; | |||||
ShowFavoritesQuantity *favoriteQuantity = new ShowFavoritesQuantity; | |||||
favoriteQuantity->widget = favoriteButton; | |||||
favoriteButton->quantity = favoriteQuantity; | |||||
favoriteButton = new ShowFavoritesButton; | |||||
dynamic_cast<ShowFavoritesQuantity*>(favoriteButton->quantity)->widget = favoriteButton; | |||||
addChild(favoriteButton); | addChild(favoriteButton); | ||||
authorLabel = new ui::Label; | authorLabel = new ui::Label; | ||||
@@ -58,7 +58,7 @@ float ParamQuantity::getDefaultValue() { | |||||
float ParamQuantity::getDisplayValue() { | float ParamQuantity::getDisplayValue() { | ||||
if (!module) | if (!module) | ||||
return ui::Quantity::getDisplayValue(); | |||||
return Quantity::getDisplayValue(); | |||||
float v = getSmoothValue(); | float v = getSmoothValue(); | ||||
float displayBase = getParam()->displayBase; | float displayBase = getParam()->displayBase; | ||||
if (displayBase == 0.f) { | if (displayBase == 0.f) { | ||||
@@ -95,26 +95,26 @@ void ParamQuantity::setDisplayValue(float displayValue) { | |||||
} | } | ||||
int ParamQuantity::getDisplayPrecision() { | int ParamQuantity::getDisplayPrecision() { | ||||
return ui::Quantity::getDisplayPrecision(); | |||||
return Quantity::getDisplayPrecision(); | |||||
} | } | ||||
std::string ParamQuantity::getDisplayValueString() { | std::string ParamQuantity::getDisplayValueString() { | ||||
return ui::Quantity::getDisplayValueString(); | |||||
return Quantity::getDisplayValueString(); | |||||
} | } | ||||
void ParamQuantity::setDisplayValueString(std::string s) { | void ParamQuantity::setDisplayValueString(std::string s) { | ||||
ui::Quantity::setDisplayValueString(s); | |||||
Quantity::setDisplayValueString(s); | |||||
} | } | ||||
std::string ParamQuantity::getLabel() { | std::string ParamQuantity::getLabel() { | ||||
if (!module) | if (!module) | ||||
return ui::Quantity::getLabel(); | |||||
return Quantity::getLabel(); | |||||
return getParam()->label; | return getParam()->label; | ||||
} | } | ||||
std::string ParamQuantity::getUnit() { | std::string ParamQuantity::getUnit() { | ||||
if (!module) | if (!module) | ||||
return ui::Quantity::getUnit(); | |||||
return Quantity::getUnit(); | |||||
return getParam()->unit; | return getParam()->unit; | ||||
} | } | ||||
@@ -63,7 +63,7 @@ struct ParamTooltip : ui::Tooltip { | |||||
void step() override { | void step() override { | ||||
if (paramWidget->paramQuantity) { | if (paramWidget->paramQuantity) { | ||||
// ui::Quantity string | |||||
// Quantity string | |||||
text = paramWidget->paramQuantity->getString(); | text = paramWidget->paramQuantity->getString(); | ||||
// Param description | // Param description | ||||
std::string description = paramWidget->paramQuantity->getParam()->description; | std::string description = paramWidget->paramQuantity->getParam()->description; | ||||
@@ -170,7 +170,7 @@ struct EditButton : MenuButton { | |||||
}; | }; | ||||
struct ZoomQuantity : ui::Quantity { | |||||
struct ZoomQuantity : Quantity { | |||||
void setValue(float value) override { | void setValue(float value) override { | ||||
settings::zoom = math::clamp(value, getMinValue(), getMaxValue()); | 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 { | void setValue(float value) override { | ||||
settings::cableOpacity = math::clamp(value, getMinValue(), getMaxValue()); | 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 { | void setValue(float value) override { | ||||
settings::cableTension = math::clamp(value, getMinValue(), getMaxValue()); | 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 { | struct CpuMeterItem : ui::MenuItem { | ||||
void onAction(const widget::ActionEvent &e) override { | void onAction(const widget::ActionEvent &e) override { | ||||
settings::cpuMeter ^= true; | settings::cpuMeter ^= true; | ||||
@@ -359,19 +389,16 @@ struct SettingsButton : MenuButton { | |||||
fullscreenItem->rightText = CHECKMARK_STRING " " + fullscreenItem->rightText; | fullscreenItem->rightText = CHECKMARK_STRING " " + fullscreenItem->rightText; | ||||
menu->addChild(fullscreenItem); | menu->addChild(fullscreenItem); | ||||
ui::Slider *zoomSlider = new ui::Slider; | |||||
ZoomSlider *zoomSlider = new ZoomSlider; | |||||
zoomSlider->box.size.x = 200.0; | zoomSlider->box.size.x = 200.0; | ||||
zoomSlider->quantity = new ZoomQuantity; | |||||
menu->addChild(zoomSlider); | menu->addChild(zoomSlider); | ||||
ui::Slider *cableOpacitySlider = new ui::Slider; | |||||
CableOpacitySlider *cableOpacitySlider = new CableOpacitySlider; | |||||
cableOpacitySlider->box.size.x = 200.0; | cableOpacitySlider->box.size.x = 200.0; | ||||
cableOpacitySlider->quantity = new CableOpacityQuantity; | |||||
menu->addChild(cableOpacitySlider); | menu->addChild(cableOpacitySlider); | ||||
ui::Slider *cableTensionSlider = new ui::Slider; | |||||
CableTensionSlider *cableTensionSlider = new CableTensionSlider; | |||||
cableTensionSlider->box.size.x = 200.0; | cableTensionSlider->box.size.x = 200.0; | ||||
cableTensionSlider->quantity = new CableTensionQuantity; | |||||
menu->addChild(cableTensionSlider); | menu->addChild(cableTensionSlider); | ||||
} | } | ||||
}; | }; | ||||
@@ -490,7 +517,7 @@ struct LogOutItem : ui::MenuItem { | |||||
}; | }; | ||||
struct DownloadQuantity : ui::Quantity { | |||||
struct DownloadQuantity : Quantity { | |||||
float getValue() override { | float getValue() override { | ||||
return plugin::downloadProgress; | return plugin::downloadProgress; | ||||
} | } | ||||
@@ -9,11 +9,6 @@ Button::Button() { | |||||
box.size.y = BND_WIDGET_HEIGHT; | box.size.y = BND_WIDGET_HEIGHT; | ||||
} | } | ||||
Button::~Button() { | |||||
if (quantity) | |||||
delete quantity; | |||||
} | |||||
void Button::draw(const DrawArgs &args) { | 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()); | bndToolButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); | ||||
} | } | ||||
@@ -9,11 +9,6 @@ ProgressBar::ProgressBar() { | |||||
box.size.y = BND_WIDGET_HEIGHT; | box.size.y = BND_WIDGET_HEIGHT; | ||||
} | } | ||||
ProgressBar::~ProgressBar() { | |||||
if (quantity) | |||||
delete quantity; | |||||
} | |||||
void ProgressBar::draw(const DrawArgs &args) { | void ProgressBar::draw(const DrawArgs &args) { | ||||
float progress = quantity ? quantity->getScaledValue() : 0.f; | float progress = quantity ? quantity->getScaledValue() : 0.f; | ||||
std::string text = quantity ? quantity->getString() : ""; | std::string text = quantity ? quantity->getString() : ""; | ||||
@@ -1,9 +1,8 @@ | |||||
#include "ui/Quantity.hpp" | |||||
#include "Quantity.hpp" | |||||
#include "string.hpp" | #include "string.hpp" | ||||
namespace rack { | namespace rack { | ||||
namespace ui { | |||||
int Quantity::getDisplayPrecision() { | int Quantity::getDisplayPrecision() { | ||||
@@ -44,5 +43,4 @@ std::string Quantity::getString() { | |||||
} | } | ||||
} // namespace ui | |||||
} // namespace rack | } // namespace rack |
@@ -9,11 +9,6 @@ RadioButton::RadioButton() { | |||||
box.size.y = BND_WIDGET_HEIGHT; | box.size.y = BND_WIDGET_HEIGHT; | ||||
} | } | ||||
RadioButton::~RadioButton() { | |||||
if (quantity) | |||||
delete quantity; | |||||
} | |||||
void RadioButton::draw(const DrawArgs &args) { | void RadioButton::draw(const DrawArgs &args) { | ||||
BNDwidgetState state = this->state; | BNDwidgetState state = this->state; | ||||
std::string label; | std::string label; | ||||
@@ -12,11 +12,6 @@ Slider::Slider() { | |||||
box.size.y = BND_WIDGET_HEIGHT; | box.size.y = BND_WIDGET_HEIGHT; | ||||
} | } | ||||
Slider::~Slider() { | |||||
if (quantity) | |||||
delete quantity; | |||||
} | |||||
void Slider::draw(const DrawArgs &args) { | void Slider::draw(const DrawArgs &args) { | ||||
float progress = quantity ? quantity->getScaledValue() : 0.f; | float progress = quantity ? quantity->getScaledValue() : 0.f; | ||||
std::string text = quantity ? quantity->getString() : ""; | std::string text = quantity ? quantity->getString() : ""; | ||||