From 87eeb02f5c62457f5f103ccb9f86badffe03107d Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 12 Apr 2021 20:34:50 -0400 Subject: [PATCH] Rename new Widget methods. Add Rogan3PSWhite fg/bg test. --- include/componentlibrary.hpp | 8 + include/svg.hpp | 1 + include/widget/SvgWidget.hpp | 2 +- include/widget/Widget.hpp | 13 +- res/ComponentLibrary/Rogan3PSWhite-bg.svg | 31 ++ res/ComponentLibrary/Rogan3PSWhite-fg.svg | 31 ++ res/ComponentLibrary/Rogan3PSWhite.svg | 474 ++-------------------- src/widget/SvgWidget.cpp | 9 +- src/widget/Widget.cpp | 4 +- 9 files changed, 121 insertions(+), 452 deletions(-) create mode 100644 res/ComponentLibrary/Rogan3PSWhite-bg.svg create mode 100644 res/ComponentLibrary/Rogan3PSWhite-fg.svg diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index c6889830..c43e3f56 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -341,6 +341,14 @@ struct Rogan3PSGreen : Rogan { struct Rogan3PSWhite : Rogan { Rogan3PSWhite() { setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSWhite.svg"))); + + widget::SvgWidget* bg = new widget::SvgWidget; + bg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSWhite-bg.svg"))); + fb->addChildBelow(bg, tw); + + widget::SvgWidget* fg = new widget::SvgWidget; + fg->setSvg(Svg::load(asset::system("res/ComponentLibrary/Rogan3PSWhite-fg.svg"))); + fb->addChildAbove(fg, tw); } }; diff --git a/include/svg.hpp b/include/svg.hpp index 2a71a99d..615e18fe 100644 --- a/include/svg.hpp +++ b/include/svg.hpp @@ -11,6 +11,7 @@ namespace rack { +/** Arbitrary DPI, standardized for Rack. */ static const float SVG_DPI = 75.f; static const float MM_PER_IN = 25.4f; diff --git a/include/widget/SvgWidget.hpp b/include/widget/SvgWidget.hpp index 799b64cd..356dca5d 100644 --- a/include/widget/SvgWidget.hpp +++ b/include/widget/SvgWidget.hpp @@ -11,7 +11,7 @@ namespace widget { struct SvgWidget : Widget { std::shared_ptr svg; - /** Sets the box size to the svg image size */ + /** Sets the box size to the SVG image size */ void wrap(); /** Sets and wraps the SVG */ diff --git a/include/widget/Widget.hpp b/include/widget/Widget.hpp index 35144a54..4682e197 100644 --- a/include/widget/Widget.hpp +++ b/include/widget/Widget.hpp @@ -99,14 +99,21 @@ struct Widget : WeakBase { return NULL; } + /** Checks if the given widget is a child of `this` widget. + */ bool hasChild(Widget* child); - /** Adds widget to list of children. + /** Adds widget to the top of the children. Gives ownership of widget to this widget instance. */ void addChild(Widget* child); + /** Adds widget to the bottom of the children. + */ void addChildBottom(Widget* child); - void addChildBefore(Widget* child, Widget* sibling); - void addChildAfter(Widget* child, Widget* sibling); + /** Adds widget directly below another widget. + The sibling widget must already be a child of `this` widget. + */ + void addChildBelow(Widget* child, Widget* sibling); + void addChildAbove(Widget* child, Widget* sibling); /** Removes widget from list of children if it exists. Does not delete widget but transfers ownership to caller */ diff --git a/res/ComponentLibrary/Rogan3PSWhite-bg.svg b/res/ComponentLibrary/Rogan3PSWhite-bg.svg new file mode 100644 index 00000000..6c06a1d9 --- /dev/null +++ b/res/ComponentLibrary/Rogan3PSWhite-bg.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/ComponentLibrary/Rogan3PSWhite-fg.svg b/res/ComponentLibrary/Rogan3PSWhite-fg.svg new file mode 100644 index 00000000..8096737c --- /dev/null +++ b/res/ComponentLibrary/Rogan3PSWhite-fg.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/ComponentLibrary/Rogan3PSWhite.svg b/res/ComponentLibrary/Rogan3PSWhite.svg index d2fe80c1..30350d9f 100644 --- a/res/ComponentLibrary/Rogan3PSWhite.svg +++ b/res/ComponentLibrary/Rogan3PSWhite.svg @@ -1,443 +1,31 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/widget/SvgWidget.cpp b/src/widget/SvgWidget.cpp index ee42c25d..8208bac7 100644 --- a/src/widget/SvgWidget.cpp +++ b/src/widget/SvgWidget.cpp @@ -21,9 +21,12 @@ void SvgWidget::setSvg(std::shared_ptr svg) { } void SvgWidget::draw(const DrawArgs& args) { - if (svg && svg->handle) { - svgDraw(args.vg, svg->handle); - } + if (!svg) + return; + if (!svg->handle) + return; + + svgDraw(args.vg, svg->handle); } diff --git a/src/widget/Widget.cpp b/src/widget/Widget.cpp index 4194c63b..4c0597c9 100644 --- a/src/widget/Widget.cpp +++ b/src/widget/Widget.cpp @@ -177,7 +177,7 @@ void Widget::addChildBottom(Widget* child) { } -void Widget::addChildBefore(Widget* child, Widget* sibling) { +void Widget::addChildBelow(Widget* child, Widget* sibling) { assert(child); assert(!child->parent); auto it = std::find(children.begin(), children.end(), sibling); @@ -191,7 +191,7 @@ void Widget::addChildBefore(Widget* child, Widget* sibling) { } -void Widget::addChildAfter(Widget* child, Widget* sibling) { +void Widget::addChildAbove(Widget* child, Widget* sibling) { assert(child); assert(!child->parent); auto it = std::find(children.begin(), children.end(), sibling);