From d297586f9893c7612432d9abd879d99221740949 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 15 Sep 2017 08:08:35 -0400 Subject: [PATCH] Add SVGPanel --- include/app.hpp | 8 ++++++++ include/widgets.hpp | 1 + src/app/PanelBorder.cpp | 20 ++++++++++++++++++++ src/app/SVGPanel.cpp | 19 +++++++++++++++++++ src/widgets/FramebufferWidget.cpp | 4 ++-- 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/app/PanelBorder.cpp create mode 100644 src/app/SVGPanel.cpp diff --git a/include/app.hpp b/include/app.hpp index 48c5606a..a6cf7616 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -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); +}; + //////////////////// // params //////////////////// diff --git a/include/widgets.hpp b/include/widgets.hpp index 816fc933..becdee84 100644 --- a/include/widgets.hpp +++ b/include/widgets.hpp @@ -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 */ diff --git a/src/app/PanelBorder.cpp b/src/app/PanelBorder.cpp new file mode 100644 index 00000000..aea68159 --- /dev/null +++ b/src/app/PanelBorder.cpp @@ -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 diff --git a/src/app/SVGPanel.cpp b/src/app/SVGPanel.cpp new file mode 100644 index 00000000..b77760c0 --- /dev/null +++ b/src/app/SVGPanel.cpp @@ -0,0 +1,19 @@ +#include "app.hpp" + + +namespace rack { + + +void SVGPanel::addBackground(std::shared_ptr 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 diff --git a/src/widgets/FramebufferWidget.cpp b/src/widgets/FramebufferWidget.cpp index 390ffee9..1fa13656 100644 --- a/src/widgets/FramebufferWidget.cpp +++ b/src/widgets/FramebufferWidget.cpp @@ -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);