Browse Source

Save draw state before each child is drawn, so widgets draw at (0, 0)

instead of box.pos.
tags/v0.3.0
Andrew Belt 8 years ago
parent
commit
ef6dc2ff67
19 changed files with 28 additions and 41 deletions
  1. +3
    -0
      src/gui.cpp
  2. +1
    -1
      src/widgets/Button.cpp
  3. +1
    -1
      src/widgets/ChoiceButton.cpp
  4. +1
    -1
      src/widgets/Label.cpp
  5. +1
    -2
      src/widgets/Light.cpp
  6. +1
    -1
      src/widgets/Menu.cpp
  7. +1
    -1
      src/widgets/MenuItem.cpp
  8. +1
    -1
      src/widgets/MenuLabel.cpp
  9. +4
    -4
      src/widgets/ModuleWidget.cpp
  10. +2
    -2
      src/widgets/Panel.cpp
  11. +0
    -13
      src/widgets/RackScene.cpp
  12. +2
    -2
      src/widgets/RackWidget.cpp
  13. +1
    -1
      src/widgets/RadioButton.cpp
  14. +1
    -1
      src/widgets/ScrollBar.cpp
  15. +1
    -1
      src/widgets/Slider.cpp
  16. +2
    -4
      src/widgets/SpriteWidget.cpp
  17. +2
    -2
      src/widgets/Toolbar.cpp
  18. +2
    -2
      src/widgets/Widget.cpp
  19. +1
    -1
      src/widgets/WireWidget.cpp

+ 3
- 0
src/gui.cpp View File

@@ -165,7 +165,10 @@ void renderGui() {


nvgBeginFrame(vg, width, height, 1.0); nvgBeginFrame(vg, width, height, 1.0);


nvgSave(vg);
gScene->draw(vg); gScene->draw(vg);
nvgRestore(vg);

nvgEndFrame(vg); nvgEndFrame(vg);
glfwSwapBuffers(window); glfwSwapBuffers(window);
} }


+ 1
- 1
src/widgets/Button.cpp View File

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


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


void Button::onMouseEnter() { void Button::onMouseEnter() {


+ 1
- 1
src/widgets/ChoiceButton.cpp View File

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


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






+ 1
- 1
src/widgets/Label.cpp View File

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


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






+ 1
- 2
src/widgets/Light.cpp View File

@@ -6,11 +6,10 @@ namespace rack {


void Light::draw(NVGcontext *vg) { void Light::draw(NVGcontext *vg) {
NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5); NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5);
Vec c = box.getCenter();
Vec r = box.size.div(2.0); Vec r = box.size.div(2.0);


nvgBeginPath(vg); nvgBeginPath(vg);
nvgEllipse(vg, c.x, c.y, r.x - 1.0, r.y - 1.0);
nvgEllipse(vg, r.x, r.y, r.x - 1.0, r.y - 1.0);
nvgFillColor(vg, color); nvgFillColor(vg, color);
nvgFill(vg); nvgFill(vg);




+ 1
- 1
src/widgets/Menu.cpp View File

@@ -23,7 +23,7 @@ void Menu::draw(NVGcontext *vg) {
child->box.size.x = box.size.x; child->box.size.x = box.size.x;
} }


bndMenuBackground(vg, box.pos.x, box.pos.y, box.size.x, box.size.y, BND_CORNER_NONE);
bndMenuBackground(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE);


Widget::draw(vg); Widget::draw(vg);
} }


+ 1
- 1
src/widgets/MenuItem.cpp View File

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


void MenuItem::draw(NVGcontext *vg) { void MenuItem::draw(NVGcontext *vg) {
bndMenuItem(vg, box.pos.x, box.pos.y, box.size.x, box.size.y, state, -1, text.c_str());
bndMenuItem(vg, 0.0, 0.0, box.size.x, box.size.y, state, -1, text.c_str());
} }


void MenuItem::onMouseEnter() { void MenuItem::onMouseEnter() {


+ 1
- 1
src/widgets/MenuLabel.cpp View File

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


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






+ 4
- 4
src/widgets/ModuleWidget.cpp View File

@@ -99,7 +99,7 @@ void ModuleWidget::cloneParams(ModuleWidget *source) {


void ModuleWidget::draw(NVGcontext *vg) { void ModuleWidget::draw(NVGcontext *vg) {
Widget::draw(vg); Widget::draw(vg);
bndBevel(vg, box.pos.x, box.pos.y, box.size.x, box.size.y);
bndBevel(vg, 0.0, 0.0, box.size.x, box.size.y);


// CPU usage text // CPU usage text
if (dynamic_cast<RackScene*>(gScene)->toolbar->cpuUsageButton->value != 0.0) { if (dynamic_cast<RackScene*>(gScene)->toolbar->cpuUsageButton->value != 0.0) {
@@ -108,17 +108,17 @@ void ModuleWidget::draw(NVGcontext *vg) {


nvgSave(vg); nvgSave(vg);
nvgBeginPath(vg); nvgBeginPath(vg);
nvgRect(vg, box.pos.x, box.pos.y, box.size.x, BND_WIDGET_HEIGHT);
nvgRect(vg, 0.0, 0.0, box.size.x, BND_WIDGET_HEIGHT);
nvgFillColor(vg, nvgRGBf(0.0, 0.0, 0.0)); nvgFillColor(vg, nvgRGBf(0.0, 0.0, 0.0));
nvgFill(vg); nvgFill(vg);


nvgBeginPath(vg); nvgBeginPath(vg);
cpuTime = clampf(cpuTime, 0.0, 1.0); cpuTime = clampf(cpuTime, 0.0, 1.0);
nvgRect(vg, box.pos.x, box.pos.y, box.size.x * cpuTime, BND_WIDGET_HEIGHT);
nvgRect(vg, 0.0, 0.0, box.size.x * cpuTime, BND_WIDGET_HEIGHT);
nvgFillColor(vg, nvgHSL(0.33 * cubic(1.0 - cpuTime), 1.0, 0.4)); nvgFillColor(vg, nvgHSL(0.33 * cubic(1.0 - cpuTime), 1.0, 0.4));
nvgFill(vg); nvgFill(vg);


bndMenuItem(vg, box.pos.x, box.pos.y, box.size.x, BND_WIDGET_HEIGHT, BND_DEFAULT, -1, text.c_str());
bndMenuItem(vg, 0.0, 0.0, box.size.x, BND_WIDGET_HEIGHT, BND_DEFAULT, -1, text.c_str());
nvgRestore(vg); nvgRestore(vg);
} }
} }


+ 2
- 2
src/widgets/Panel.cpp View File

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


void Panel::draw(NVGcontext *vg) { void Panel::draw(NVGcontext *vg) {
nvgBeginPath(vg); nvgBeginPath(vg);
nvgRect(vg, box.pos.x, box.pos.y, box.size.x, box.size.y);
nvgRect(vg, 0.0, 0.0, box.size.x, box.size.y);


// Background color // Background color
nvgFillColor(vg, backgroundColor); nvgFillColor(vg, backgroundColor);
@@ -15,7 +15,7 @@ void Panel::draw(NVGcontext *vg) {
if (backgroundImage) { if (backgroundImage) {
int width, height; int width, height;
nvgImageSize(vg, backgroundImage->handle, &width, &height); nvgImageSize(vg, backgroundImage->handle, &width, &height);
NVGpaint paint = nvgImagePattern(vg, box.pos.x, box.pos.y, width, height, 0.0, backgroundImage->handle, 1.0);
NVGpaint paint = nvgImagePattern(vg, 0.0, 0.0, width, height, 0.0, backgroundImage->handle, 1.0);
nvgFillPaint(vg, paint); nvgFillPaint(vg, paint);
nvgFill(vg); nvgFill(vg);
} }


+ 0
- 13
src/widgets/RackScene.cpp View File

@@ -27,19 +27,6 @@ void RackScene::step() {


void RackScene::draw(NVGcontext *vg) { void RackScene::draw(NVGcontext *vg) {
Scene::draw(vg); Scene::draw(vg);

// // Draw custom stuff here
// static std::shared_ptr<SVG> svg;
// if (!svg)
// svg = SVG::load("res/ComponentLibrary/CL1362.svg");

// for (float y = 0.0; y < 1000.0; y += 200.0)
// for (float x = 0.0; x < 1000.0; x += 200.0) {
// nvgSave(vg);
// nvgTranslate(vg, x, y);
// drawSVG(vg, svg->handle);
// nvgRestore(vg);
// }
} }






+ 2
- 2
src/widgets/RackWidget.cpp View File

@@ -289,7 +289,7 @@ void RackWidget::step() {


void RackWidget::draw(NVGcontext *vg) { void RackWidget::draw(NVGcontext *vg) {
nvgBeginPath(vg); nvgBeginPath(vg);
nvgRect(vg, box.pos.x, box.pos.y, box.size.x, box.size.y);
nvgRect(vg, 0.0, 0.0, box.size.x, box.size.y);


// Background color // Background color
nvgFillColor(vg, nvgRGBf(0.2, 0.2, 0.2)); nvgFillColor(vg, nvgRGBf(0.2, 0.2, 0.2));
@@ -299,7 +299,7 @@ void RackWidget::draw(NVGcontext *vg) {
{ {
int imageWidth, imageHeight; int imageWidth, imageHeight;
nvgImageSize(vg, railsImage->handle, &imageWidth, &imageHeight); nvgImageSize(vg, railsImage->handle, &imageWidth, &imageHeight);
NVGpaint paint = nvgImagePattern(vg, box.pos.x, box.pos.y, imageWidth, imageHeight, 0.0, railsImage->handle, 1.0);
NVGpaint paint = nvgImagePattern(vg, 0.0, 0.0, imageWidth, imageHeight, 0.0, railsImage->handle, 1.0);
nvgFillPaint(vg, paint); nvgFillPaint(vg, paint);
nvgFill(vg); nvgFill(vg);
} }


+ 1
- 1
src/widgets/RadioButton.cpp View File

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


void RadioButton::draw(NVGcontext *vg) { void RadioButton::draw(NVGcontext *vg) {
bndRadioButton(vg, box.pos.x, box.pos.y, box.size.x, box.size.y, BND_CORNER_NONE, value == 0.0 ? state : BND_ACTIVE, -1, label.c_str());
bndRadioButton(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, value == 0.0 ? state : BND_ACTIVE, -1, label.c_str());
} }


void RadioButton::onMouseEnter() { void RadioButton::onMouseEnter() {


+ 1
- 1
src/widgets/ScrollBar.cpp View File

@@ -10,7 +10,7 @@ void ScrollBar::draw(NVGcontext *vg) {
float offset = containerOffset / maxOffset; float offset = containerOffset / maxOffset;
float size = boxSize / containerSize; float size = boxSize / containerSize;
size = clampf(size, 0.0, 1.0); size = clampf(size, 0.0, 1.0);
bndScrollBar(vg, box.pos.x, box.pos.y, box.size.x, box.size.y, state, offset, size);
bndScrollBar(vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size);
} }


void ScrollBar::move(float delta) { void ScrollBar::move(float delta) {


+ 1
- 1
src/widgets/Slider.cpp View File

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


void Slider::draw(NVGcontext *vg) { void Slider::draw(NVGcontext *vg) {
float progress = mapf(value, minValue, maxValue, 0.0, 1.0); float progress = mapf(value, minValue, maxValue, 0.0, 1.0);
bndSlider(vg, box.pos.x, box.pos.y, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, getText().c_str(), NULL);
bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, getText().c_str(), NULL);
} }


void Slider::onDragStart() { void Slider::onDragStart() {


+ 2
- 4
src/widgets/SpriteWidget.cpp View File

@@ -4,8 +4,6 @@
namespace rack { namespace rack {


void SpriteWidget::draw(NVGcontext *vg) { void SpriteWidget::draw(NVGcontext *vg) {
Vec pos = box.pos.plus(spriteOffset);

int width, height; int width, height;
nvgImageSize(vg, spriteImage->handle, &width, &height); nvgImageSize(vg, spriteImage->handle, &width, &height);
int stride = width / spriteSize.x; int stride = width / spriteSize.x;
@@ -14,10 +12,10 @@ void SpriteWidget::draw(NVGcontext *vg) {
return; return;
} }
Vec offset = Vec((index % stride) * spriteSize.x, (index / stride) * spriteSize.y); Vec offset = Vec((index % stride) * spriteSize.x, (index / stride) * spriteSize.y);
NVGpaint paint = nvgImagePattern(vg, pos.x - offset.x, pos.y - offset.y, width, height, 0.0, spriteImage->handle, 1.0);
NVGpaint paint = nvgImagePattern(vg, spriteOffset.x - offset.x, spriteOffset.y - offset.y, width, height, 0.0, spriteImage->handle, 1.0);
nvgFillPaint(vg, paint); nvgFillPaint(vg, paint);
nvgBeginPath(vg); nvgBeginPath(vg);
nvgRect(vg, pos.x, pos.y, spriteSize.x, spriteSize.y);
nvgRect(vg, spriteOffset.x, spriteOffset.y, spriteSize.x, spriteSize.y);
nvgFill(vg); nvgFill(vg);
} }




+ 2
- 2
src/widgets/Toolbar.cpp View File

@@ -165,8 +165,8 @@ Toolbar::Toolbar() {
} }


void Toolbar::draw(NVGcontext *vg) { void Toolbar::draw(NVGcontext *vg) {
bndBackground(vg, box.pos.x, box.pos.y, box.size.x, box.size.y);
bndBevel(vg, box.pos.x, box.pos.y, box.size.x, box.size.y);
bndBackground(vg, 0.0, 0.0, box.size.x, box.size.y);
bndBevel(vg, 0.0, 0.0, box.size.x, box.size.y);


Widget::draw(vg); Widget::draw(vg);
} }


+ 2
- 2
src/widgets/Widget.cpp View File

@@ -69,12 +69,12 @@ void Widget::step() {
} }


void Widget::draw(NVGcontext *vg) { void Widget::draw(NVGcontext *vg) {
nvgTranslate(vg, box.pos.x, box.pos.y);
for (Widget *child : children) { for (Widget *child : children) {
nvgSave(vg); nvgSave(vg);
nvgTranslate(vg, child->box.pos.x, child->box.pos.y);
child->draw(vg); child->draw(vg);
nvgRestore(vg);
} }
nvgRestore(vg);
} }


Widget *Widget::onMouseDown(Vec pos, int button) { Widget *Widget::onMouseDown(Vec pos, int button) {


+ 1
- 1
src/widgets/WireWidget.cpp View File

@@ -120,7 +120,7 @@ void WireWidget::updateWire() {
} }


void WireWidget::draw(NVGcontext *vg) { void WireWidget::draw(NVGcontext *vg) {
Vec absolutePos = getAbsolutePos();
Vec absolutePos = getAbsolutePos().minus(box.pos);
float opacity = dynamic_cast<RackScene*>(gScene)->toolbar->wireOpacitySlider->value / 100.0; float opacity = dynamic_cast<RackScene*>(gScene)->toolbar->wireOpacitySlider->value / 100.0;
float tension = dynamic_cast<RackScene*>(gScene)->toolbar->wireTensionSlider->value; float tension = dynamic_cast<RackScene*>(gScene)->toolbar->wireTensionSlider->value;




Loading…
Cancel
Save