@@ -10,14 +10,11 @@ namespace ui { | |||||
struct Button : widget::OpaqueWidget { | struct Button : widget::OpaqueWidget { | ||||
std::string text; | std::string text; | ||||
BNDwidgetState state = BND_DEFAULT; | |||||
/** Not 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(); | ||||
void draw(const DrawArgs &args) override; | void draw(const DrawArgs &args) override; | ||||
void onEnter(const event::Enter &e) override; | |||||
void onLeave(const event::Leave &e) override; | |||||
void onDragStart(const event::DragStart &e) override; | void onDragStart(const event::DragStart &e) override; | ||||
void onDragEnd(const event::DragEnd &e) override; | void onDragEnd(const event::DragEnd &e) override; | ||||
void onDragDrop(const event::DragDrop &e) override; | void onDragDrop(const event::DragDrop &e) override; | ||||
@@ -2,6 +2,8 @@ | |||||
#include "ui/common.hpp" | #include "ui/common.hpp" | ||||
#include "widget/OpaqueWidget.hpp" | #include "widget/OpaqueWidget.hpp" | ||||
#include "Quantity.hpp" | #include "Quantity.hpp" | ||||
#include "app.hpp" | |||||
#include "event.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -9,14 +11,11 @@ namespace ui { | |||||
struct RadioButton : widget::OpaqueWidget { | struct RadioButton : widget::OpaqueWidget { | ||||
BNDwidgetState state = BND_DEFAULT; | |||||
/** Not owned. */ | /** Not owned. */ | ||||
Quantity *quantity = NULL; | Quantity *quantity = NULL; | ||||
RadioButton(); | RadioButton(); | ||||
void draw(const DrawArgs &args) override; | void draw(const DrawArgs &args) override; | ||||
void onEnter(const event::Enter &e) override; | |||||
void onLeave(const event::Leave &e) override; | |||||
void onDragDrop(const event::DragDrop &e) override; | void onDragDrop(const event::DragDrop &e) override; | ||||
}; | }; | ||||
@@ -14,7 +14,6 @@ struct ScrollBar : widget::OpaqueWidget { | |||||
HORIZONTAL | HORIZONTAL | ||||
}; | }; | ||||
Orientation orientation; | Orientation orientation; | ||||
BNDwidgetState state = BND_DEFAULT; | |||||
float offset = 0.0; | float offset = 0.0; | ||||
float size = 0.0; | float size = 0.0; | ||||
@@ -10,7 +10,6 @@ namespace ui { | |||||
struct Slider : widget::OpaqueWidget { | struct Slider : widget::OpaqueWidget { | ||||
BNDwidgetState state = BND_DEFAULT; | |||||
/** Not owned. */ | /** Not owned. */ | ||||
Quantity *quantity = NULL; | Quantity *quantity = NULL; | ||||
@@ -28,6 +28,11 @@ struct MenuButton : ui::Button { | |||||
Widget::step(); | Widget::step(); | ||||
} | } | ||||
void draw(const DrawArgs &args) override { | void draw(const DrawArgs &args) override { | ||||
BNDwidgetState state = BND_DEFAULT; | |||||
if (APP->event->hoveredWidget == this) | |||||
state = BND_HOVER; | |||||
if (APP->event->draggedWidget == this) | |||||
state = BND_ACTIVE; | |||||
bndMenuItem(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str()); | bndMenuItem(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str()); | ||||
} | } | ||||
}; | }; | ||||
@@ -1,4 +1,6 @@ | |||||
#include "ui/Button.hpp" | #include "ui/Button.hpp" | ||||
#include "app.hpp" | |||||
#include "event.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -10,28 +12,23 @@ Button::Button() { | |||||
} | } | ||||
void Button::draw(const DrawArgs &args) { | void Button::draw(const DrawArgs &args) { | ||||
BNDwidgetState state = BND_DEFAULT; | |||||
if (APP->event->hoveredWidget == this) | |||||
state = BND_HOVER; | |||||
if (APP->event->draggedWidget == this) | |||||
state = BND_ACTIVE; | |||||
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::onEnter(const event::Enter &e) { | |||||
state = BND_HOVER; | |||||
} | |||||
void Button::onLeave(const event::Leave &e) { | |||||
state = BND_DEFAULT; | |||||
} | |||||
void Button::onDragStart(const event::DragStart &e) { | void Button::onDragStart(const event::DragStart &e) { | ||||
if (e.button != GLFW_MOUSE_BUTTON_LEFT) | if (e.button != GLFW_MOUSE_BUTTON_LEFT) | ||||
return; | return; | ||||
state = BND_ACTIVE; | |||||
if (quantity) | if (quantity) | ||||
quantity->setMax(); | quantity->setMax(); | ||||
} | } | ||||
void Button::onDragEnd(const event::DragEnd &e) { | void Button::onDragEnd(const event::DragEnd &e) { | ||||
state = BND_HOVER; | |||||
if (quantity) | if (quantity) | ||||
quantity->setMin(); | quantity->setMin(); | ||||
} | } | ||||
@@ -1,4 +1,6 @@ | |||||
#include "ui/ChoiceButton.hpp" | #include "ui/ChoiceButton.hpp" | ||||
#include "app.hpp" | |||||
#include "event.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -6,6 +8,11 @@ namespace ui { | |||||
void ChoiceButton::draw(const DrawArgs &args) { | void ChoiceButton::draw(const DrawArgs &args) { | ||||
BNDwidgetState state = BND_DEFAULT; | |||||
if (APP->event->hoveredWidget == this) | |||||
state = BND_HOVER; | |||||
if (APP->event->draggedWidget == this) | |||||
state = BND_ACTIVE; | |||||
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()); | ||||
} | } | ||||
@@ -10,7 +10,10 @@ RadioButton::RadioButton() { | |||||
} | } | ||||
void RadioButton::draw(const DrawArgs &args) { | void RadioButton::draw(const DrawArgs &args) { | ||||
BNDwidgetState state = this->state; | |||||
BNDwidgetState state = BND_DEFAULT; | |||||
if (APP->event->hoveredWidget == this) | |||||
state = BND_HOVER; | |||||
std::string label; | std::string label; | ||||
if (quantity) { | if (quantity) { | ||||
label = quantity->getLabel(); | label = quantity->getLabel(); | ||||
@@ -20,14 +23,6 @@ void RadioButton::draw(const DrawArgs &args) { | |||||
bndRadioButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, label.c_str()); | bndRadioButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, label.c_str()); | ||||
} | } | ||||
void RadioButton::onEnter(const event::Enter &e) { | |||||
state = BND_HOVER; | |||||
} | |||||
void RadioButton::onLeave(const event::Leave &e) { | |||||
state = BND_DEFAULT; | |||||
} | |||||
void RadioButton::onDragDrop(const event::DragDrop &e) { | void RadioButton::onDragDrop(const event::DragDrop &e) { | ||||
if (e.origin == this) { | if (e.origin == this) { | ||||
if (quantity) { | if (quantity) { | ||||
@@ -13,6 +13,12 @@ ScrollBar::ScrollBar() { | |||||
} | } | ||||
void ScrollBar::draw(const DrawArgs &args) { | void ScrollBar::draw(const DrawArgs &args) { | ||||
BNDwidgetState state = BND_DEFAULT; | |||||
if (APP->event->hoveredWidget == this) | |||||
state = BND_HOVER; | |||||
if (APP->event->draggedWidget == this) | |||||
state = BND_ACTIVE; | |||||
bndScrollBar(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size); | bndScrollBar(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size); | ||||
} | } | ||||
@@ -20,7 +26,6 @@ void ScrollBar::onDragStart(const event::DragStart &e) { | |||||
if (e.button != GLFW_MOUSE_BUTTON_LEFT) | if (e.button != GLFW_MOUSE_BUTTON_LEFT) | ||||
return; | return; | ||||
state = BND_ACTIVE; | |||||
APP->window->cursorLock(); | APP->window->cursorLock(); | ||||
} | } | ||||
@@ -36,7 +41,6 @@ void ScrollBar::onDragMove(const event::DragMove &e) { | |||||
} | } | ||||
void ScrollBar::onDragEnd(const event::DragEnd &e) { | void ScrollBar::onDragEnd(const event::DragEnd &e) { | ||||
state = BND_DEFAULT; | |||||
APP->window->cursorUnlock(); | APP->window->cursorUnlock(); | ||||
} | } | ||||
@@ -13,6 +13,12 @@ Slider::Slider() { | |||||
} | } | ||||
void Slider::draw(const DrawArgs &args) { | void Slider::draw(const DrawArgs &args) { | ||||
BNDwidgetState state = BND_DEFAULT; | |||||
if (APP->event->hoveredWidget == this) | |||||
state = BND_HOVER; | |||||
if (APP->event->draggedWidget == this) | |||||
state = BND_ACTIVE; | |||||
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() : ""; | ||||
bndSlider(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL); | bndSlider(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL); | ||||
@@ -22,7 +28,6 @@ void Slider::onDragStart(const event::DragStart &e) { | |||||
if (e.button != GLFW_MOUSE_BUTTON_LEFT) | if (e.button != GLFW_MOUSE_BUTTON_LEFT) | ||||
return; | return; | ||||
state = BND_ACTIVE; | |||||
APP->window->cursorLock(); | APP->window->cursorLock(); | ||||
} | } | ||||
@@ -33,7 +38,6 @@ void Slider::onDragMove(const event::DragMove &e) { | |||||
} | } | ||||
void Slider::onDragEnd(const event::DragEnd &e) { | void Slider::onDragEnd(const event::DragEnd &e) { | ||||
state = BND_DEFAULT; | |||||
APP->window->cursorUnlock(); | APP->window->cursorUnlock(); | ||||
} | } | ||||