Browse Source

Clean up ui namespace. Remove blendish state from ui classes.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
076f8b1965
10 changed files with 37 additions and 31 deletions
  1. +0
    -3
      include/ui/Button.hpp
  2. +2
    -3
      include/ui/RadioButton.hpp
  3. +0
    -1
      include/ui/ScrollBar.hpp
  4. +0
    -1
      include/ui/Slider.hpp
  5. +5
    -0
      src/app/MenuBar.cpp
  6. +7
    -10
      src/ui/Button.cpp
  7. +7
    -0
      src/ui/ChoiceButton.cpp
  8. +4
    -9
      src/ui/RadioButton.cpp
  9. +6
    -2
      src/ui/ScrollBar.cpp
  10. +6
    -2
      src/ui/Slider.cpp

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

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


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

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



+ 0
- 1
include/ui/ScrollBar.hpp View File

@@ -14,7 +14,6 @@ struct ScrollBar : widget::OpaqueWidget {
HORIZONTAL
};
Orientation orientation;
BNDwidgetState state = BND_DEFAULT;
float offset = 0.0;
float size = 0.0;



+ 0
- 1
include/ui/Slider.hpp View File

@@ -10,7 +10,6 @@ namespace ui {


struct Slider : widget::OpaqueWidget {
BNDwidgetState state = BND_DEFAULT;
/** Not owned. */
Quantity *quantity = NULL;



+ 5
- 0
src/app/MenuBar.cpp View File

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


+ 7
- 10
src/ui/Button.cpp View File

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


+ 7
- 0
src/ui/ChoiceButton.cpp View File

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



+ 4
- 9
src/ui/RadioButton.cpp View File

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


+ 6
- 2
src/ui/ScrollBar.cpp View File

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



+ 6
- 2
src/ui/Slider.cpp View File

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



Loading…
Cancel
Save