Browse Source

Add SVGPanel

tags/v0.3.2
Andrew Belt 7 years ago
parent
commit
d297586f98
5 changed files with 50 additions and 2 deletions
  1. +8
    -0
      include/app.hpp
  2. +1
    -0
      include/widgets.hpp
  3. +20
    -0
      src/app/PanelBorder.cpp
  4. +19
    -0
      src/app/SVGPanel.cpp
  5. +2
    -2
      src/widgets/FramebufferWidget.cpp

+ 8
- 0
include/app.hpp View File

@@ -121,6 +121,14 @@ struct Panel : TransparentWidget {
void draw(NVGcontext *vg);
};

struct PanelBorder : TransparentWidget {
void draw(NVGcontext *vg);
};

struct SVGPanel : FramebufferWidget {
void addBackground(std::shared_ptr<SVG> svg);
};

////////////////////
// params
////////////////////


+ 1
- 0
include/widgets.hpp View File

@@ -198,6 +198,7 @@ struct FramebufferWidget : virtual Widget {
This prevents cutting the rendered SVG off on the box edges.
*/
Vec padding;
float oversample = 2.0;
/** The root object in the framebuffer scene
The FramebufferWidget owns the pointer
*/


+ 20
- 0
src/app/PanelBorder.cpp View File

@@ -0,0 +1,20 @@
#include "app.hpp"


namespace rack {

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

NVGcolor borderColor = nvgRGB(0xac, 0xac, 0xac);

// Border
nvgBeginPath(vg);
nvgRect(vg, 0.5, 0.5, box.size.x - 1, box.size.y - 1);
nvgStrokeColor(vg, borderColor);
nvgStrokeWidth(vg, 1.0);
nvgStroke(vg);
}

} // namespace rack

+ 19
- 0
src/app/SVGPanel.cpp View File

@@ -0,0 +1,19 @@
#include "app.hpp"


namespace rack {


void SVGPanel::addBackground(std::shared_ptr<SVG> svg) {
SVGWidget *sw = new SVGWidget();
sw->wrap();
sw->svg = svg;
addChild(sw);

PanelBorder *pb = new PanelBorder();
sw->box.size = box.size;
addChild(pb);
}


} // namespace rack

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

@@ -39,7 +39,7 @@ void FramebufferWidget::step() {
if (dirty) {
internal->box.pos = padding.neg();
internal->box.size = box.size.plus(padding.mult(2));
Vec fbSize = internal->box.size.mult(gPixelRatio);
Vec fbSize = internal->box.size.mult(gPixelRatio * oversample);
// assert(fbSize.isFinite());

internal->setFramebuffer(NULL);
@@ -54,7 +54,7 @@ void FramebufferWidget::step() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
nvgBeginFrame(gVg, fbSize.x, fbSize.y, gPixelRatio);

nvgScale(gVg, gPixelRatio, gPixelRatio);
nvgScale(gVg, gPixelRatio * oversample, gPixelRatio * oversample);
nvgTranslate(gVg, padding.x, padding.y);
Widget::draw(gVg);



Loading…
Cancel
Save