diff --git a/include/ui/Button.hpp b/include/ui/Button.hpp index 2a287dbb..5e07ec5e 100644 --- a/include/ui/Button.hpp +++ b/include/ui/Button.hpp @@ -10,14 +10,11 @@ namespace ui { struct Button : widget::OpaqueWidget { std::string text; - BNDwidgetState state = BND_DEFAULT; /** Not owned. Tracks the pressed state of the button.*/ Quantity *quantity = NULL; Button(); 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 onDragEnd(const event::DragEnd &e) override; void onDragDrop(const event::DragDrop &e) override; diff --git a/include/ui/RadioButton.hpp b/include/ui/RadioButton.hpp index 7fceb76d..5034c55b 100644 --- a/include/ui/RadioButton.hpp +++ b/include/ui/RadioButton.hpp @@ -2,6 +2,8 @@ #include "ui/common.hpp" #include "widget/OpaqueWidget.hpp" #include "Quantity.hpp" +#include "app.hpp" +#include "event.hpp" namespace rack { @@ -9,14 +11,11 @@ namespace ui { struct RadioButton : widget::OpaqueWidget { - BNDwidgetState state = BND_DEFAULT; /** Not owned. */ Quantity *quantity = NULL; RadioButton(); 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; }; diff --git a/include/ui/ScrollBar.hpp b/include/ui/ScrollBar.hpp index 3c6d4908..b4a52a6e 100644 --- a/include/ui/ScrollBar.hpp +++ b/include/ui/ScrollBar.hpp @@ -14,7 +14,6 @@ struct ScrollBar : widget::OpaqueWidget { HORIZONTAL }; Orientation orientation; - BNDwidgetState state = BND_DEFAULT; float offset = 0.0; float size = 0.0; diff --git a/include/ui/Slider.hpp b/include/ui/Slider.hpp index 009c8d7d..3c3cc0af 100644 --- a/include/ui/Slider.hpp +++ b/include/ui/Slider.hpp @@ -10,7 +10,6 @@ namespace ui { struct Slider : widget::OpaqueWidget { - BNDwidgetState state = BND_DEFAULT; /** Not owned. */ Quantity *quantity = NULL; diff --git a/src/app/MenuBar.cpp b/src/app/MenuBar.cpp index c2b4c77b..f73301ab 100644 --- a/src/app/MenuBar.cpp +++ b/src/app/MenuBar.cpp @@ -28,6 +28,11 @@ struct MenuButton : ui::Button { Widget::step(); } 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()); } }; diff --git a/src/ui/Button.cpp b/src/ui/Button.cpp index 7682b5fe..ec4577b0 100644 --- a/src/ui/Button.cpp +++ b/src/ui/Button.cpp @@ -1,4 +1,6 @@ #include "ui/Button.hpp" +#include "app.hpp" +#include "event.hpp" namespace rack { @@ -10,28 +12,23 @@ Button::Button() { } 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()); } -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) { if (e.button != GLFW_MOUSE_BUTTON_LEFT) return; - state = BND_ACTIVE; if (quantity) quantity->setMax(); } void Button::onDragEnd(const event::DragEnd &e) { - state = BND_HOVER; if (quantity) quantity->setMin(); } diff --git a/src/ui/ChoiceButton.cpp b/src/ui/ChoiceButton.cpp index 9894dbbd..f93eb1dc 100644 --- a/src/ui/ChoiceButton.cpp +++ b/src/ui/ChoiceButton.cpp @@ -1,4 +1,6 @@ #include "ui/ChoiceButton.hpp" +#include "app.hpp" +#include "event.hpp" namespace rack { @@ -6,6 +8,11 @@ namespace ui { 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()); } diff --git a/src/ui/RadioButton.cpp b/src/ui/RadioButton.cpp index 206b2d98..a9dda3d9 100644 --- a/src/ui/RadioButton.cpp +++ b/src/ui/RadioButton.cpp @@ -10,7 +10,10 @@ RadioButton::RadioButton() { } 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; if (quantity) { 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()); } -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) { if (e.origin == this) { if (quantity) { diff --git a/src/ui/ScrollBar.cpp b/src/ui/ScrollBar.cpp index 0072da3a..4654d39c 100644 --- a/src/ui/ScrollBar.cpp +++ b/src/ui/ScrollBar.cpp @@ -13,6 +13,12 @@ ScrollBar::ScrollBar() { } 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); } @@ -20,7 +26,6 @@ void ScrollBar::onDragStart(const event::DragStart &e) { if (e.button != GLFW_MOUSE_BUTTON_LEFT) return; - state = BND_ACTIVE; APP->window->cursorLock(); } @@ -36,7 +41,6 @@ void ScrollBar::onDragMove(const event::DragMove &e) { } void ScrollBar::onDragEnd(const event::DragEnd &e) { - state = BND_DEFAULT; APP->window->cursorUnlock(); } diff --git a/src/ui/Slider.cpp b/src/ui/Slider.cpp index 2333053c..fcc2efba 100644 --- a/src/ui/Slider.cpp +++ b/src/ui/Slider.cpp @@ -13,6 +13,12 @@ Slider::Slider() { } 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; 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); @@ -22,7 +28,6 @@ void Slider::onDragStart(const event::DragStart &e) { if (e.button != GLFW_MOUSE_BUTTON_LEFT) return; - state = BND_ACTIVE; APP->window->cursorLock(); } @@ -33,7 +38,6 @@ void Slider::onDragMove(const event::DragMove &e) { } void Slider::onDragEnd(const event::DragEnd &e) { - state = BND_DEFAULT; APP->window->cursorUnlock(); }