From 661e93bb2494cdb456ae9290f10ba79f5beadff2 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 31 Oct 2017 08:03:56 -0400 Subject: [PATCH] Remove old panel if ModuleWidget::setPanel is called multiple times, move in2px and mm2px to widgets.hpp --- include/app.hpp | 2 ++ include/rack.hpp | 9 --------- include/widgets.hpp | 9 +++++++++ src/app/ModuleWidget.cpp | 8 +++++++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/app.hpp b/include/app.hpp index a252ab14..0f6e5bba 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -14,6 +14,7 @@ struct Wire; struct RackWidget; struct ParamWidget; struct Port; +struct SVGPanel; //////////////////// // module @@ -31,6 +32,7 @@ struct ModuleWidget : OpaqueWidget { /** Owns the module pointer */ Module *module = NULL; + SVGPanel *panel = NULL; std::vector inputs; std::vector outputs; std::vector params; diff --git a/include/rack.hpp b/include/rack.hpp index 6b1595b7..9593d29f 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -18,15 +18,6 @@ namespace rack { //////////////////// -inline Vec in2px(Vec inches) { - return inches.mult(SVG_DPI); -} - -inline Vec mm2px(Vec millimeters) { - return millimeters.mult(SVG_DPI / 25.4); -} - - template Model *createModel(std::string manufacturerSlug, std::string manufacturerName, std::string slug, std::string name) { struct TModel : Model { diff --git a/include/widgets.hpp b/include/widgets.hpp index 9e974c61..18d7321d 100644 --- a/include/widgets.hpp +++ b/include/widgets.hpp @@ -16,6 +16,15 @@ namespace rack { +inline Vec in2px(Vec inches) { + return inches.mult(SVG_DPI); +} + +inline Vec mm2px(Vec millimeters) { + return millimeters.mult(SVG_DPI / 25.4); +} + + //////////////////// // resources //////////////////// diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 07eed233..695fe0e9 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -43,7 +43,13 @@ void ModuleWidget::addParam(ParamWidget *param) { } void ModuleWidget::setPanel(std::shared_ptr svg) { - SVGPanel *panel = new SVGPanel(); + // Remove old panel + if (panel) { + removeChild(panel); + panel = NULL; + } + + panel = new SVGPanel(); panel->setBackground(svg); addChild(panel);