Browse Source

Move ui::Quantity to Quantity.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
b932a8d87c
15 changed files with 84 additions and 67 deletions
  1. +0
    -3
      include/Quantity.hpp
  2. +3
    -3
      include/app/ParamQuantity.hpp
  3. +2
    -3
      include/ui/Button.hpp
  4. +2
    -2
      include/ui/ProgressBar.hpp
  5. +2
    -2
      include/ui/RadioButton.hpp
  6. +2
    -2
      include/ui/Slider.hpp
  7. +28
    -12
      src/app/ModuleBrowser.cpp
  8. +6
    -6
      src/app/ParamQuantity.cpp
  9. +1
    -1
      src/app/ParamWidget.cpp
  10. +37
    -10
      src/app/Toolbar.cpp
  11. +0
    -5
      src/ui/Button.cpp
  12. +0
    -5
      src/ui/ProgressBar.cpp
  13. +1
    -3
      src/ui/Quantity.cpp
  14. +0
    -5
      src/ui/RadioButton.cpp
  15. +0
    -5
      src/ui/Slider.cpp

include/ui/Quantity.hpp → include/Quantity.hpp View File

@@ -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

+ 3
- 3
include/app/ParamQuantity.hpp View File

@@ -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;



+ 2
- 3
include/ui/Button.hpp View File

@@ -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;


+ 2
- 2
include/ui/ProgressBar.hpp View File

@@ -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;
};



+ 2
- 2
include/ui/RadioButton.hpp View File

@@ -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;


+ 2
- 2
include/ui/Slider.hpp View File

@@ -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;


+ 28
- 12
src/app/ModuleBrowser.cpp View File

@@ -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<ModelFavoriteQuantity*>(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<ShowFavoritesQuantity*>(favoriteButton->quantity)->widget = favoriteButton;
addChild(favoriteButton);

authorLabel = new ui::Label;


+ 6
- 6
src/app/ParamQuantity.cpp View File

@@ -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;
}



+ 1
- 1
src/app/ParamWidget.cpp View File

@@ -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;


+ 37
- 10
src/app/Toolbar.cpp View File

@@ -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;
}


+ 0
- 5
src/ui/Button.cpp View File

@@ -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());
}


+ 0
- 5
src/ui/ProgressBar.cpp View File

@@ -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() : "";


+ 1
- 3
src/ui/Quantity.cpp View File

@@ -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

+ 0
- 5
src/ui/RadioButton.cpp View File

@@ -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;


+ 0
- 5
src/ui/Slider.cpp View File

@@ -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() : "";


Loading…
Cancel
Save