Browse Source

Move ui header implementations to source files.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
1a26bac9b1
29 changed files with 392 additions and 280 deletions
  1. +1
    -0
      include/app/PortWidget.hpp
  2. +0
    -1
      include/rack.hpp
  3. +8
    -39
      include/ui/Button.hpp
  4. +1
    -3
      include/ui/ChoiceButton.hpp
  5. +2
    -16
      include/ui/IconButton.hpp
  6. +2
    -25
      include/ui/Label.hpp
  7. +1
    -15
      include/ui/List.hpp
  8. +1
    -3
      include/ui/MenuEntry.hpp
  9. +2
    -12
      include/ui/MenuLabel.hpp
  10. +2
    -13
      include/ui/MenuSeparator.hpp
  11. +1
    -6
      include/ui/PasswordField.hpp
  12. +5
    -14
      include/ui/ProgressBar.hpp
  13. +8
    -44
      include/ui/RadioButton.hpp
  14. +7
    -38
      include/ui/Slider.hpp
  15. +0
    -13
      include/ui/WindowOverlay.hpp
  16. +0
    -23
      include/ui/WindowWidget.hpp
  17. +16
    -15
      src/app/PortWidget.cpp
  18. +48
    -0
      src/ui/Button.cpp
  19. +12
    -0
      src/ui/ChoiceButton.cpp
  20. +25
    -0
      src/ui/IconButton.cpp
  21. +34
    -0
      src/ui/Label.cpp
  22. +24
    -0
      src/ui/List.cpp
  23. +12
    -0
      src/ui/MenuEntry.cpp
  24. +21
    -0
      src/ui/MenuLabel.cpp
  25. +22
    -0
      src/ui/MenuSeparator.cpp
  26. +15
    -0
      src/ui/PasswordField.cpp
  27. +23
    -0
      src/ui/ProgressBar.cpp
  28. +52
    -0
      src/ui/RadioButton.cpp
  29. +47
    -0
      src/ui/Slider.cpp

+ 1
- 0
include/app/PortWidget.hpp View File

@@ -29,6 +29,7 @@ struct PortWidget : OpaqueWidget {
void onDragDrop(const event::DragDrop &e) override;
void onDragEnter(const event::DragEnter &e) override;
void onDragLeave(const event::DragLeave &e) override;
void setHovered();
};




+ 0
- 1
include/rack.hpp View File

@@ -37,7 +37,6 @@
#include "ui/IconButton.hpp"
#include "ui/ChoiceButton.hpp"
#include "ui/RadioButton.hpp"
#include "ui/WindowWidget.hpp"
#include "ui/ProgressBar.hpp"

#include "app/AudioWidget.hpp"


+ 8
- 39
include/ui/Button.hpp View File

@@ -13,45 +13,14 @@ struct Button : OpaqueWidget {
/** Optional, owned. Tracks the pressed state of the button.*/
Quantity *quantity = NULL;

Button() {
box.size.y = BND_WIDGET_HEIGHT;
}

~Button() {
if (quantity)
delete quantity;
}

void draw(NVGcontext *vg) override {
bndToolButton(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str());
}

void onEnter(const event::Enter &e) override {
state = BND_HOVER;
}

void onLeave(const event::Leave &e) override {
state = BND_DEFAULT;
}

void onDragStart(const event::DragStart &e) override {
state = BND_ACTIVE;
if (quantity)
quantity->setMax();
}

void onDragEnd(const event::DragEnd &e) override {
state = BND_HOVER;
if (quantity)
quantity->setMin();
}

void onDragDrop(const event::DragDrop &e) override {
if (e.origin == this) {
event::Action eAction;
onAction(eAction);
}
}
Button();
~Button();
void draw(NVGcontext *vg) 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;
};




+ 1
- 3
include/ui/ChoiceButton.hpp View File

@@ -7,9 +7,7 @@ namespace rack {


struct ChoiceButton : Button {
void draw(NVGcontext *vg) override {
bndChoiceButton(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str());
}
void draw(NVGcontext *vg) override;
};




+ 2
- 16
include/ui/IconButton.hpp View File

@@ -12,22 +12,8 @@ struct IconButton : Button {
FramebufferWidget *fw;
SVGWidget *sw;

IconButton() {
box.size.x = BND_TOOL_WIDTH;

fw = new FramebufferWidget;
fw->oversample = 2;
addChild(fw);

sw = new SVGWidget;
sw->box.pos = math::Vec(2, 2);
fw->addChild(sw);
}

void setSVG(std::shared_ptr<SVG> svg) {
sw->setSVG(svg);
fw->dirty = true;
}
IconButton();
void setSVG(std::shared_ptr<SVG> svg);
};




+ 2
- 25
include/ui/Label.hpp View File

@@ -18,31 +18,8 @@ struct Label : virtual Widget {
NVGcolor color;
Alignment alignment = LEFT_ALIGNMENT;

Label() {
box.size.y = BND_WIDGET_HEIGHT;
fontSize = 13;
color = bndGetTheme()->regularTheme.textColor;
}

void draw(NVGcontext *vg) override {
// TODO
// Custom font sizes do not work with right or center alignment
float x;
switch (alignment) {
default:
case LEFT_ALIGNMENT: {
x = 0.0;
} break;
case RIGHT_ALIGNMENT: {
x = box.size.x - bndLabelWidth(vg, -1, text.c_str());
} break;
case CENTER_ALIGNMENT: {
x = (box.size.x - bndLabelWidth(vg, -1, text.c_str())) / 2.0;
} break;
}

bndIconLabelValue(vg, x, 0.0, box.size.x, box.size.y, -1, color, BND_LEFT, fontSize, text.c_str(), NULL);
}
Label();
void draw(NVGcontext *vg) override;
};




+ 1
- 15
include/ui/List.hpp View File

@@ -7,21 +7,7 @@ namespace rack {


struct List : OpaqueWidget {
void step() override {
Widget::step();

// Set positions of children
box.size.y = 0.0;
for (Widget *child : children) {
if (!child->visible)
continue;
// Increment height, set position of child
child->box.pos = math::Vec(0.0, box.size.y);
box.size.y += child->box.size.y;
// Resize width of child
child->box.size.x = box.size.x;
}
}
void step() override;
};




+ 1
- 3
include/ui/MenuEntry.hpp View File

@@ -7,9 +7,7 @@ namespace rack {


struct MenuEntry : OpaqueWidget {
MenuEntry() {
box.size = math::Vec(0, BND_WIDGET_HEIGHT);
}
MenuEntry();
};




+ 2
- 12
include/ui/MenuLabel.hpp View File

@@ -1,7 +1,6 @@
#pragma once
#include "ui/common.hpp"
#include "ui/MenuEntry.hpp"
#include "app.hpp"


namespace rack {
@@ -10,17 +9,8 @@ namespace rack {
struct MenuLabel : MenuEntry {
std::string text;

void draw(NVGcontext *vg) override {
bndMenuLabel(vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str());
}

void step() override {
// Add 10 more pixels because Retina measurements are sometimes too small
const float rightPadding = 10.0;
// HACK use app()->window->vg from the window.
box.size.x = bndLabelWidth(app()->window->vg, -1, text.c_str()) + rightPadding;
Widget::step();
}
void draw(NVGcontext *vg) override;
void step() override;
};




+ 2
- 13
include/ui/MenuSeparator.hpp View File

@@ -7,19 +7,8 @@ namespace rack {


struct MenuSeparator : MenuEntry {
MenuSeparator() {
box.size.y = BND_WIDGET_HEIGHT / 2;
}

void draw(NVGcontext *vg) override {
nvgBeginPath(vg);
const float margin = 8.0;
nvgMoveTo(vg, margin, box.size.y / 2.0);
nvgLineTo(vg, box.size.x - margin, box.size.y / 2.0);
nvgStrokeWidth(vg, 1.0);
nvgStrokeColor(vg, color::alpha(bndGetTheme()->menuTheme.textColor, 0.25));
nvgStroke(vg);
}
MenuSeparator();
void draw(NVGcontext *vg) override;
};




+ 1
- 6
include/ui/PasswordField.hpp View File

@@ -7,12 +7,7 @@ namespace rack {


struct PasswordField : TextField {
void draw(NVGcontext *vg) override {
std::string textTmp = text;
text = std::string(textTmp.size(), '*');
TextField::draw(vg);
text = textTmp;
}
void draw(NVGcontext *vg) override;
};




+ 5
- 14
include/ui/ProgressBar.hpp View File

@@ -1,5 +1,7 @@
#pragma once
#include "ui/common.hpp"
#include "widgets/Widget.hpp"
#include "ui/Quantity.hpp"


namespace rack {
@@ -8,20 +10,9 @@ namespace rack {
struct ProgressBar : virtual Widget {
Quantity *quantity = NULL;

ProgressBar() {
box.size.y = BND_WIDGET_HEIGHT;
}

~ProgressBar() {
if (quantity)
delete quantity;
}

void draw(NVGcontext *vg) override {
float progress = quantity ? quantity->getScaledValue() : 0.f;
std::string text = quantity ? quantity->getString() : "";
bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL, BND_DEFAULT, progress, text.c_str(), NULL);
}
ProgressBar();
~ProgressBar();
void draw(NVGcontext *vg) override;
};




+ 8
- 44
include/ui/RadioButton.hpp View File

@@ -1,6 +1,7 @@
#pragma once
#include "widgets/OpaqueWidget.hpp"
#include "ui/common.hpp"
#include "widgets/OpaqueWidget.hpp"
#include "ui/Quantity.hpp"


namespace rack {
@@ -10,49 +11,12 @@ struct RadioButton : OpaqueWidget {
BNDwidgetState state = BND_DEFAULT;
Quantity *quantity = NULL;

RadioButton() {
box.size.y = BND_WIDGET_HEIGHT;
}

~RadioButton() {
if (quantity)
delete quantity;
}

void draw(NVGcontext *vg) override {
std::string label;
if (quantity)
label = quantity->getLabel();
bndRadioButton(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, label.c_str());
}

void onEnter(const event::Enter &e) override {
if (state != BND_ACTIVE)
state = BND_HOVER;
}

void onLeave(const event::Leave &e) override {
if (state != BND_ACTIVE)
state = BND_DEFAULT;
}

void onDragDrop(const event::DragDrop &e) override {
if (e.origin == this) {
if (state == BND_ACTIVE) {
state = BND_HOVER;
if (quantity)
quantity->setMin();
}
else {
state = BND_ACTIVE;
if (quantity)
quantity->setMax();
}

event::Action eAction;
onAction(eAction);
}
}
RadioButton();
~RadioButton();
void draw(NVGcontext *vg) override;
void onEnter(const event::Enter &e) override;
void onLeave(const event::Leave &e) override;
void onDragDrop(const event::DragDrop &e) override;
};




+ 7
- 38
include/ui/Slider.hpp View File

@@ -15,44 +15,13 @@ struct Slider : OpaqueWidget {
BNDwidgetState state = BND_DEFAULT;
Quantity *quantity = NULL;

Slider() {
box.size.y = BND_WIDGET_HEIGHT;
}

~Slider() {
if (quantity)
delete quantity;
}

void draw(NVGcontext *vg) override {
float progress = quantity ? quantity->getScaledValue() : 0.f;
std::string text = quantity ? quantity->getString() : "";
bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL);
}

void onDragStart(const event::DragStart &e) override {
state = BND_ACTIVE;
app()->window->cursorLock();
}

void onDragMove(const event::DragMove &e) override {
if (quantity) {
quantity->moveScaledValue(SLIDER_SENSITIVITY * e.mouseDelta.x);
}
}

void onDragEnd(const event::DragEnd &e) override {
state = BND_DEFAULT;
app()->window->cursorUnlock();
}

void onButton(const event::Button &e) override {
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) {
if (quantity)
quantity->reset();
}
e.consume(this);
}
Slider();
~Slider();
void draw(NVGcontext *vg) override;
void onDragStart(const event::DragStart &e) override;
void onDragMove(const event::DragMove &e) override;
void onDragEnd(const event::DragEnd &e) override;
void onButton(const event::Button &e) override;
};




+ 0
- 13
include/ui/WindowOverlay.hpp View File

@@ -1,13 +0,0 @@
#pragma once
#include "widgets/OpaqueWidget.hpp"
#include "ui/common.hpp"


namespace rack {


struct WindowOverlay : OpaqueWidget {
};


} // namespace rack

+ 0
- 23
include/ui/WindowWidget.hpp View File

@@ -1,23 +0,0 @@
#pragma once
#include "widgets/OpaqueWidget.hpp"
#include "ui/common.hpp"


namespace rack {


struct WindowWidget : OpaqueWidget {
std::string title;

void draw(NVGcontext *vg) override {
bndNodeBackground(vg, 0.0, 0.0, box.size.x, box.size.y, BND_DEFAULT, -1, title.c_str(), bndGetTheme()->backgroundColor);
Widget::draw(vg);
}

void onDragMove(const event::DragMove &e) override {
box.pos = box.pos.plus(e.mouseDelta);
}
};


} // namespace rack

+ 16
- 15
src/app/PortWidget.cpp View File

@@ -99,10 +99,7 @@ void PortWidget::onDragDrop(const event::DragDrop &e) {
if (!originPort)
return;

// Fake onDragEnter because onDragLeave is triggered immediately before this one
event::DragEnter eDragEnter;
eDragEnter.origin = e.origin;
onDragEnter(eDragEnter);
setHovered();
}

void PortWidget::onDragEnter(const event::DragEnter &e) {
@@ -110,17 +107,7 @@ void PortWidget::onDragEnter(const event::DragEnter &e) {
if (!originPort)
return;

// Reject ports if this is an input port and something is already plugged into it
if (type == INPUT) {
CableWidget *topCable = app()->scene->rackWidget->cableContainer->getTopCable(this);
if (topCable)
return;
}

CableWidget *activeCable = app()->scene->rackWidget->cableContainer->activeCable;
if (activeCable) {
(type == INPUT ? activeCable->hoveredInputPort : activeCable->hoveredOutputPort) = this;
}
setHovered();
}

void PortWidget::onDragLeave(const event::DragLeave &e) {
@@ -134,5 +121,19 @@ void PortWidget::onDragLeave(const event::DragLeave &e) {
}
}

void PortWidget::setHovered() {
// Reject ports if this is an input port and something is already plugged into it
if (type == INPUT) {
CableWidget *topCable = app()->scene->rackWidget->cableContainer->getTopCable(this);
if (topCable)
return;
}

CableWidget *activeCable = app()->scene->rackWidget->cableContainer->activeCable;
if (activeCable) {
(type == INPUT ? activeCable->hoveredInputPort : activeCable->hoveredOutputPort) = this;
}
}


} // namespace rack

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

@@ -0,0 +1,48 @@
#include "ui/Button.hpp"


namespace rack {


Button::Button() {
box.size.y = BND_WIDGET_HEIGHT;
}

Button::~Button() {
if (quantity)
delete quantity;
}

void Button::draw(NVGcontext *vg) {
bndToolButton(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) {
state = BND_ACTIVE;
if (quantity)
quantity->setMax();
}

void Button::onDragEnd(const event::DragEnd &e) {
state = BND_HOVER;
if (quantity)
quantity->setMin();
}

void Button::onDragDrop(const event::DragDrop &e) {
if (e.origin == this) {
event::Action eAction;
onAction(eAction);
}
}


} // namespace rack

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

@@ -0,0 +1,12 @@
#include "ui/ChoiceButton.hpp"


namespace rack {


void ChoiceButton::draw(NVGcontext *vg) {
bndChoiceButton(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str());
}


} // namespace rack

+ 25
- 0
src/ui/IconButton.cpp View File

@@ -0,0 +1,25 @@
#include "ui/IconButton.hpp"


namespace rack {


IconButton::IconButton() {
box.size.x = BND_TOOL_WIDTH;

fw = new FramebufferWidget;
fw->oversample = 2;
addChild(fw);

sw = new 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 rack

+ 34
- 0
src/ui/Label.cpp View File

@@ -0,0 +1,34 @@
#include "ui/Label.hpp"


namespace rack {


Label::Label() {
box.size.y = BND_WIDGET_HEIGHT;
fontSize = 13;
color = bndGetTheme()->regularTheme.textColor;
}

void Label::draw(NVGcontext *vg) {
// TODO
// Custom font sizes do not work with right or center alignment
float x;
switch (alignment) {
default:
case LEFT_ALIGNMENT: {
x = 0.0;
} break;
case RIGHT_ALIGNMENT: {
x = box.size.x - bndLabelWidth(vg, -1, text.c_str());
} break;
case CENTER_ALIGNMENT: {
x = (box.size.x - bndLabelWidth(vg, -1, text.c_str())) / 2.0;
} break;
}

bndIconLabelValue(vg, x, 0.0, box.size.x, box.size.y, -1, color, BND_LEFT, fontSize, text.c_str(), NULL);
}


} // namespace rack

+ 24
- 0
src/ui/List.cpp View File

@@ -0,0 +1,24 @@
#include "ui/List.hpp"


namespace rack {


void List::step() {
Widget::step();

// Set positions of children
box.size.y = 0.0;
for (Widget *child : children) {
if (!child->visible)
continue;
// Increment height, set position of child
child->box.pos = math::Vec(0.0, box.size.y);
box.size.y += child->box.size.y;
// Resize width of child
child->box.size.x = box.size.x;
}
}


} // namespace rack

+ 12
- 0
src/ui/MenuEntry.cpp View File

@@ -0,0 +1,12 @@
#include "ui/MenuEntry.hpp"


namespace rack {


MenuEntry::MenuEntry() {
box.size = math::Vec(0, BND_WIDGET_HEIGHT);
}


} // namespace rack

+ 21
- 0
src/ui/MenuLabel.cpp View File

@@ -0,0 +1,21 @@
#include "ui/MenuLabel.hpp"
#include "app.hpp"


namespace rack {


void MenuLabel::draw(NVGcontext *vg) {
bndMenuLabel(vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str());
}

void MenuLabel::step() {
// Add 10 more pixels because Retina measurements are sometimes too small
const float rightPadding = 10.0;
// HACK use app()->window->vg from the window.
box.size.x = bndLabelWidth(app()->window->vg, -1, text.c_str()) + rightPadding;
Widget::step();
}


} // namespace rack

+ 22
- 0
src/ui/MenuSeparator.cpp View File

@@ -0,0 +1,22 @@
#include "ui/MenuSeparator.hpp"


namespace rack {


MenuSeparator::MenuSeparator() {
box.size.y = BND_WIDGET_HEIGHT / 2;
}

void MenuSeparator::draw(NVGcontext *vg) {
nvgBeginPath(vg);
const float margin = 8.0;
nvgMoveTo(vg, margin, box.size.y / 2.0);
nvgLineTo(vg, box.size.x - margin, box.size.y / 2.0);
nvgStrokeWidth(vg, 1.0);
nvgStrokeColor(vg, color::alpha(bndGetTheme()->menuTheme.textColor, 0.25));
nvgStroke(vg);
}


} // namespace rack

+ 15
- 0
src/ui/PasswordField.cpp View File

@@ -0,0 +1,15 @@
#include "ui/PasswordField.hpp"


namespace rack {


void PasswordField::draw(NVGcontext *vg) {
std::string textTmp = text;
text = std::string(textTmp.size(), '*');
TextField::draw(vg);
text = textTmp;
}


} // namespace rack

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

@@ -0,0 +1,23 @@
#include "ui/ProgressBar.hpp"


namespace rack {


ProgressBar::ProgressBar() {
box.size.y = BND_WIDGET_HEIGHT;
}

ProgressBar::~ProgressBar() {
if (quantity)
delete quantity;
}

void ProgressBar::draw(NVGcontext *vg) {
float progress = quantity ? quantity->getScaledValue() : 0.f;
std::string text = quantity ? quantity->getString() : "";
bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_ALL, BND_DEFAULT, progress, text.c_str(), NULL);
}


} // namespace rack

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

@@ -0,0 +1,52 @@
#include "ui/RadioButton.hpp"


namespace rack {


RadioButton::RadioButton() {
box.size.y = BND_WIDGET_HEIGHT;
}

RadioButton::~RadioButton() {
if (quantity)
delete quantity;
}

void RadioButton::draw(NVGcontext *vg) {
std::string label;
if (quantity)
label = quantity->getLabel();
bndRadioButton(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) {
if (state != BND_ACTIVE)
state = BND_HOVER;
}

void RadioButton::onLeave(const event::Leave &e) {
if (state != BND_ACTIVE)
state = BND_DEFAULT;
}

void RadioButton::onDragDrop(const event::DragDrop &e) {
if (e.origin == this) {
if (state == BND_ACTIVE) {
state = BND_HOVER;
if (quantity)
quantity->setMin();
}
else {
state = BND_ACTIVE;
if (quantity)
quantity->setMax();
}

event::Action eAction;
onAction(eAction);
}
}


} // namespace rack

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

@@ -0,0 +1,47 @@
#include "ui/Slider.hpp"


namespace rack {


Slider::Slider() {
box.size.y = BND_WIDGET_HEIGHT;
}

Slider::~Slider() {
if (quantity)
delete quantity;
}

void Slider::draw(NVGcontext *vg) {
float progress = quantity ? quantity->getScaledValue() : 0.f;
std::string text = quantity ? quantity->getString() : "";
bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL);
}

void Slider::onDragStart(const event::DragStart &e) {
state = BND_ACTIVE;
app()->window->cursorLock();
}

void Slider::onDragMove(const event::DragMove &e) {
if (quantity) {
quantity->moveScaledValue(SLIDER_SENSITIVITY * e.mouseDelta.x);
}
}

void Slider::onDragEnd(const event::DragEnd &e) {
state = BND_DEFAULT;
app()->window->cursorUnlock();
}

void Slider::onButton(const event::Button &e) {
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) {
if (quantity)
quantity->reset();
}
e.consume(this);
}


} // namespace rack

Loading…
Cancel
Save