@@ -41,9 +41,9 @@ | |||||
#include <ui/MenuLabel.hpp> | #include <ui/MenuLabel.hpp> | ||||
#include <ui/MenuItem.hpp> | #include <ui/MenuItem.hpp> | ||||
#include <ui/Button.hpp> | #include <ui/Button.hpp> | ||||
#include <ui/IconButton.hpp> | |||||
#include <ui/ChoiceButton.hpp> | #include <ui/ChoiceButton.hpp> | ||||
#include <ui/RadioButton.hpp> | #include <ui/RadioButton.hpp> | ||||
#include <ui/OptionButton.hpp> | |||||
#include <ui/ProgressBar.hpp> | #include <ui/ProgressBar.hpp> | ||||
#include <app/AudioWidget.hpp> | #include <app/AudioWidget.hpp> | ||||
@@ -8,6 +8,13 @@ namespace rack { | |||||
namespace ui { | namespace ui { | ||||
/** A clickable button with text. | |||||
Dispatches Action event when clicked. | |||||
If quantity is set, its value is set to 1.0 when pressed, 0.0 when released. | |||||
If text is not set, the quantity label is used. | |||||
*/ | |||||
struct Button : widget::OpaqueWidget { | struct Button : widget::OpaqueWidget { | ||||
std::string text; | std::string text; | ||||
/** Not owned. Tracks the pressed state of the button.*/ | /** Not owned. Tracks the pressed state of the button.*/ | ||||
@@ -7,6 +7,8 @@ namespace rack { | |||||
namespace ui { | namespace ui { | ||||
/** Button with a dropdown icon on its right. | |||||
*/ | |||||
struct ChoiceButton : Button { | struct ChoiceButton : Button { | ||||
void draw(const DrawArgs& args) override; | void draw(const DrawArgs& args) override; | ||||
}; | }; | ||||
@@ -1,25 +0,0 @@ | |||||
#pragma once | |||||
#include <widget/FramebufferWidget.hpp> | |||||
#include <widget/SvgWidget.hpp> | |||||
#include <ui/common.hpp> | |||||
#include <ui/Button.hpp> | |||||
namespace rack { | |||||
namespace ui { | |||||
struct IconButton : Button { | |||||
widget::FramebufferWidget* fw; | |||||
widget::SvgWidget* sw; | |||||
IconButton(); | |||||
void setSvg(std::shared_ptr<Svg> svg); | |||||
DEPRECATED void setSVG(std::shared_ptr<Svg> svg) { | |||||
setSvg(svg); | |||||
} | |||||
}; | |||||
} // namespace ui | |||||
} // namespace rack |
@@ -1,21 +1,16 @@ | |||||
#pragma once | #pragma once | ||||
#include <widget/OpaqueWidget.hpp> | |||||
#include <ui/common.hpp> | #include <ui/common.hpp> | ||||
#include <Quantity.hpp> | |||||
#include <ui/RadioButton.hpp> | |||||
namespace rack { | namespace rack { | ||||
namespace ui { | namespace ui { | ||||
struct OptionButton : widget::OpaqueWidget { | |||||
std::string text; | |||||
/** Not owned. Tracks the pressed state of the button.*/ | |||||
Quantity* quantity = NULL; | |||||
OptionButton(); | |||||
/** Behaves like a RadioButton and appears with a checkmark beside text. | |||||
*/ | |||||
struct OptionButton : RadioButton { | |||||
void draw(const DrawArgs& args) override; | void draw(const DrawArgs& args) override; | ||||
void onDragDrop(const DragDropEvent& e) override; | |||||
}; | }; | ||||
@@ -1,20 +1,18 @@ | |||||
#pragma once | #pragma once | ||||
#include <ui/common.hpp> | #include <ui/common.hpp> | ||||
#include <widget/OpaqueWidget.hpp> | |||||
#include <Quantity.hpp> | |||||
#include <context.hpp> | |||||
#include <ui/Button.hpp> | |||||
namespace rack { | namespace rack { | ||||
namespace ui { | namespace ui { | ||||
struct RadioButton : widget::OpaqueWidget { | |||||
/** Not owned. */ | |||||
Quantity* quantity = NULL; | |||||
RadioButton(); | |||||
/** Toggles a Quantity between 1.0 and 0.0 when clicked. | |||||
*/ | |||||
struct RadioButton : Button { | |||||
void draw(const DrawArgs& args) override; | void draw(const DrawArgs& args) override; | ||||
void onDragStart(const DragStartEvent& e) override; | |||||
void onDragEnd(const DragEndEvent& e) override; | |||||
void onDragDrop(const DragDropEvent& e) override; | void onDragDrop(const DragDropEvent& e) override; | ||||
}; | }; | ||||
@@ -10,15 +10,21 @@ Button::Button() { | |||||
box.size.y = BND_WIDGET_HEIGHT; | box.size.y = BND_WIDGET_HEIGHT; | ||||
} | } | ||||
void Button::draw(const DrawArgs& args) { | void Button::draw(const DrawArgs& args) { | ||||
BNDwidgetState state = BND_DEFAULT; | BNDwidgetState state = BND_DEFAULT; | ||||
if (APP->event->hoveredWidget == this) | |||||
if (APP->event->getHoveredWidget() == this) | |||||
state = BND_HOVER; | state = BND_HOVER; | ||||
if (APP->event->draggedWidget == this) | |||||
if (APP->event->getDraggedWidget() == this) | |||||
state = BND_ACTIVE; | state = BND_ACTIVE; | ||||
std::string text = this->text; | |||||
if (text.empty() && quantity) | |||||
text = quantity->getLabel(); | |||||
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()); | ||||
} | } | ||||
void Button::onDragStart(const DragStartEvent& e) { | void Button::onDragStart(const DragStartEvent& e) { | ||||
if (e.button != GLFW_MOUSE_BUTTON_LEFT) | if (e.button != GLFW_MOUSE_BUTTON_LEFT) | ||||
return; | return; | ||||
@@ -27,11 +33,13 @@ void Button::onDragStart(const DragStartEvent& e) { | |||||
quantity->setMax(); | quantity->setMax(); | ||||
} | } | ||||
void Button::onDragEnd(const DragEndEvent& e) { | void Button::onDragEnd(const DragEndEvent& e) { | ||||
if (quantity) | if (quantity) | ||||
quantity->setMin(); | quantity->setMin(); | ||||
} | } | ||||
void Button::onDragDrop(const DragDropEvent& e) { | void Button::onDragDrop(const DragDropEvent& e) { | ||||
if (e.origin == this) { | if (e.origin == this) { | ||||
ActionEvent eAction; | ActionEvent eAction; | ||||
@@ -8,10 +8,14 @@ namespace ui { | |||||
void ChoiceButton::draw(const DrawArgs& args) { | void ChoiceButton::draw(const DrawArgs& args) { | ||||
BNDwidgetState state = BND_DEFAULT; | BNDwidgetState state = BND_DEFAULT; | ||||
if (APP->event->hoveredWidget == this) | |||||
if (APP->event->getHoveredWidget() == this) | |||||
state = BND_HOVER; | state = BND_HOVER; | ||||
if (APP->event->draggedWidget == this) | |||||
if (APP->event->getDraggedWidget() == this) | |||||
state = BND_ACTIVE; | state = BND_ACTIVE; | ||||
std::string text = this->text; | |||||
if (text.empty() && quantity) | |||||
text = quantity->getLabel(); | |||||
bndChoiceButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); | bndChoiceButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); | ||||
} | } | ||||
@@ -1,27 +0,0 @@ | |||||
#include <ui/IconButton.hpp> | |||||
namespace rack { | |||||
namespace ui { | |||||
IconButton::IconButton() { | |||||
box.size.x = BND_TOOL_WIDTH; | |||||
fw = new widget::FramebufferWidget; | |||||
fw->oversample = 2; | |||||
addChild(fw); | |||||
sw = new widget::SvgWidget; | |||||
sw->box.pos = math::Vec(2, 2); | |||||
fw->addChild(sw); | |||||
} | |||||
void IconButton::setSvg(std::shared_ptr<Svg> svg) { | |||||
sw->setSvg(svg); | |||||
fw->dirty = true; | |||||
} | |||||
} // namespace ui | |||||
} // namespace rack |
@@ -5,27 +5,17 @@ namespace rack { | |||||
namespace ui { | namespace ui { | ||||
OptionButton::OptionButton() { | |||||
box.size.y = BND_WIDGET_HEIGHT; | |||||
} | |||||
void OptionButton::draw(const DrawArgs& args) { | void OptionButton::draw(const DrawArgs& args) { | ||||
BNDwidgetState state = BND_DEFAULT; | BNDwidgetState state = BND_DEFAULT; | ||||
if (quantity && !quantity->isMin()) | |||||
state = BND_ACTIVE; | |||||
bndOptionButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, text.c_str()); | |||||
} | |||||
void OptionButton::onDragDrop(const DragDropEvent& e) { | |||||
if (e.origin == this) { | |||||
if (quantity) | |||||
quantity->toggle(); | |||||
ActionEvent eAction; | |||||
onAction(eAction); | |||||
if (quantity) { | |||||
if (quantity->isMax()) | |||||
state = BND_ACTIVE; | |||||
} | } | ||||
std::string text = this->text; | |||||
if (text.empty() && quantity) | |||||
text = quantity->getLabel(); | |||||
bndOptionButton(args.vg, 0.0, 0.0, INFINITY, box.size.y, state, text.c_str()); | |||||
} | } | ||||
@@ -1,36 +1,42 @@ | |||||
#include <ui/RadioButton.hpp> | #include <ui/RadioButton.hpp> | ||||
#include <context.hpp> | |||||
namespace rack { | namespace rack { | ||||
namespace ui { | namespace ui { | ||||
RadioButton::RadioButton() { | |||||
box.size.y = BND_WIDGET_HEIGHT; | |||||
} | |||||
void RadioButton::draw(const DrawArgs& args) { | void RadioButton::draw(const DrawArgs& args) { | ||||
BNDwidgetState state = BND_DEFAULT; | BNDwidgetState state = BND_DEFAULT; | ||||
if (APP->event->hoveredWidget == this) | |||||
if (APP->event->getHoveredWidget() == this) | |||||
state = BND_HOVER; | state = BND_HOVER; | ||||
std::string label; | |||||
if (quantity) { | if (quantity) { | ||||
label = quantity->getLabel(); | |||||
if (quantity->isMax()) | if (quantity->isMax()) | ||||
state = BND_ACTIVE; | state = BND_ACTIVE; | ||||
} | } | ||||
bndRadioButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, label.c_str()); | |||||
std::string text = this->text; | |||||
if (text.empty() && quantity) | |||||
text = quantity->getLabel(); | |||||
bndRadioButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); | |||||
} | |||||
void RadioButton::onDragStart(const DragStartEvent& e) { | |||||
OpaqueWidget::onDragStart(e); | |||||
} | } | ||||
void RadioButton::onDragEnd(const DragEndEvent& e) { | |||||
OpaqueWidget::onDragEnd(e); | |||||
} | |||||
void RadioButton::onDragDrop(const DragDropEvent& e) { | void RadioButton::onDragDrop(const DragDropEvent& e) { | ||||
if (e.origin == this) { | if (e.origin == this) { | ||||
if (quantity) { | |||||
if (quantity->isMax()) | |||||
quantity->setMin(); | |||||
else | |||||
quantity->setMax(); | |||||
} | |||||
if (quantity) | |||||
quantity->toggle(); | |||||
ActionEvent eAction; | ActionEvent eAction; | ||||
onAction(eAction); | onAction(eAction); | ||||