From 212404c664d1f6a349db744ef544e64d17c13d7b Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 16 May 2019 13:08:35 -0400 Subject: [PATCH] Add Widget::addChildBottom(). Change ModuleWidget::setPanel behavior. Improve event docstrings. Temporarily disable glibc 2.23 header on Linux. --- helper.py | 2 +- include/app/ModuleWidget.hpp | 3 +-- include/event.hpp | 22 +++++++++++----------- include/plugin/Model.hpp | 2 +- include/plugin/Plugin.hpp | 4 ++-- include/rack0.hpp | 2 +- include/widget/Widget.hpp | 1 + plugin.mk | 2 +- src/Core/Blank.cpp | 5 ----- src/app/ModuleWidget.cpp | 19 ++++++++++++++----- src/widget/Widget.cpp | 10 ++++++++++ 11 files changed, 43 insertions(+), 29 deletions(-) diff --git a/helper.py b/helper.py index 39e4ca0b..ffc65087 100755 --- a/helper.py +++ b/helper.py @@ -211,7 +211,7 @@ def create_module(slug, panel_filename=None, source_filename=None): with open(manifest_filename, "w") as f: json.dump(manifest, f, indent=" ") - print(f"Added {slug} to plugin.json") + print(f"Added {slug} to {manifest_filename}") # Check filenames if panel_filename and source_filename: diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index 0127215d..f0a010f6 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -4,7 +4,6 @@ #include "ui/Menu.hpp" #include "app/PortWidget.hpp" #include "app/ParamWidget.hpp" -#include "app/SvgPanel.hpp" #include "plugin/Model.hpp" #include "engine/Module.hpp" @@ -19,7 +18,7 @@ struct ModuleWidget : widget::OpaqueWidget { /** Owned. */ engine::Module *module = NULL; - SvgPanel *panel = NULL; + widget::Widget *panel = NULL; /** Note that the indexes of these vectors do not necessarily correspond with the indexes of `Module::params` etc. */ std::vector params; diff --git a/include/event.hpp b/include/event.hpp index f8953dcb..7a716b89 100644 --- a/include/event.hpp +++ b/include/event.hpp @@ -145,7 +145,7 @@ struct Button : Base, PositionBase { /** Occurs when the left mouse button is pressed a second time on the same Widget within a time duration. -Must set the Button target to receive this event. +Must consume the Button event (on left button press) to receive this event. */ struct DoubleClick : Base { }; @@ -175,28 +175,28 @@ struct HoverScroll : Base, PositionBase { /** Occurs when a Widget begins consuming the Hover event. -Must set the Hover target to receive this event. +Must consume the Hover event to receive this event. */ struct Enter : Base { }; /** Occurs when a different Widget is entered. -Must set the Hover target to receive this event. +Must consume the Hover event (when a Widget is entered) to receive this event. */ struct Leave : Base { }; /** Occurs when a Widget begins consuming the Button press event for the left mouse button. -Must set the Button target to receive this event. +Must consume the Button event (on left button press) to receive this event. */ struct Select : Base { }; /** Occurs when a different Widget is selected. -Must set the Button target to receive this event. +Must consume the Button event (on left button press, when the Widget is selected) to receive this event. */ struct Deselect : Base { }; @@ -222,21 +222,21 @@ struct DragBase : Base { }; /** Occurs when a Widget begins being dragged. -Must set the Button target to receive this event. +Must consume the Button event (on press) to receive this event. */ struct DragStart : DragBase { }; /** Occurs when a Widget stops being dragged by releasing the mouse button. -Must set the Button target to receive this event. +Must consume the Button event (on press, when the Widget drag begins) to receive this event. */ struct DragEnd : DragBase { }; /** Occurs every frame on the dragged Widget. -Must set the Button target to receive this event. +Must consume the Button event (on press, when the Widget drag begins) to receive this event. */ struct DragMove : DragBase { /** Change in mouse position since the last frame. Can be zero. */ @@ -255,7 +255,7 @@ struct DragHover : DragBase, PositionBase { }; /** Occurs when the mouse enters a Widget while dragging. -Must set the DragHover target to receive this event. +Must consume the DragHover event to receive this event. */ struct DragEnter : DragBase { /** The dragged widget */ @@ -264,7 +264,7 @@ struct DragEnter : DragBase { /** Occurs when the mouse leaves a Widget while dragging. -Must set the DragHover target to receive this event. +Must consume the DragHover event (when the Widget is entered) to receive this event. */ struct DragLeave : DragBase { /** The dragged widget */ @@ -273,7 +273,7 @@ struct DragLeave : DragBase { /** Occurs when the mouse button is released over a Widget while dragging. -Must set the Button target to receive this event. +Must consume the Button event (on release) to receive this event. */ struct DragDrop : DragBase { /** The dragged widget */ diff --git a/include/plugin/Model.hpp b/include/plugin/Model.hpp index 32fa4422..d7157d65 100644 --- a/include/plugin/Model.hpp +++ b/include/plugin/Model.hpp @@ -25,7 +25,7 @@ struct Model { Plugin *plugin = NULL; std::vector presetPaths; - /** Must be unique. Used for saving patches. Never change this. + /** Must be unique. Used for saving patches. Never change this after releasing your module. The model slug must be unique within your plugin, but it doesn't need to be unique among different plugins. */ std::string slug; diff --git a/include/plugin/Plugin.hpp b/include/plugin/Plugin.hpp index a681b481..1e61d7a7 100644 --- a/include/plugin/Plugin.hpp +++ b/include/plugin/Plugin.hpp @@ -15,12 +15,12 @@ struct Model; struct Plugin { /** A list of the models available by this plugin, add with addModel() */ std::vector models; - /** The file path of the plugin's directory */ + /** The file path to the plugin's directory */ std::string path; /** OS-dependent library handle */ void *handle = NULL; - /** Must be unique. Used for saving patches. Never change this. + /** Must be unique. Used for saving patches. Never change this after releasing your plugin. To guarantee uniqueness, it is a good idea to prefix the slug by your "company name" if available, e.g. "MyCompany-MyPlugin" */ std::string slug; diff --git a/include/rack0.hpp b/include/rack0.hpp index ad05d544..02f4a9dd 100644 --- a/include/rack0.hpp +++ b/include/rack0.hpp @@ -44,8 +44,8 @@ DEPRECATED inline float chopf(float x, float eps) {return chop(x, eps);} DEPRECATED inline float rescalef(float x, float a, float b, float yMin, float yMax) {return math::rescale(x, a, b, yMin, yMax);} DEPRECATED inline float crossf(float a, float b, float frac) {return crossfade(a, b, frac);} DEPRECATED inline float interpf(const float *p, float x) {return interpolateLinear(p, x);} -DEPRECATED inline void cmultf(float *cr, float *ci, float ar, float ai, float br, float bi) {return complexMult(cr, ci, ar, ai, br, bi);} DEPRECATED inline void complexMult(float *cr, float *ci, float ar, float ai, float br, float bi) {complexMult(ar, ai, br, bi, cr, ci);} +DEPRECATED inline void cmultf(float *cr, float *ci, float ar, float ai, float br, float bi) {return complexMult(ar, ai, br, bi, cr, ci);} //////////////////// // random diff --git a/include/widget/Widget.hpp b/include/widget/Widget.hpp index 3a74a8e5..e9fd5f70 100644 --- a/include/widget/Widget.hpp +++ b/include/widget/Widget.hpp @@ -71,6 +71,7 @@ struct Widget { Gives ownership of widget to this widget instance. */ void addChild(Widget *child); + void addChildBottom(Widget *child); /** Removes widget from list of children if it exists. Does not delete widget but transfers ownership to caller */ diff --git a/plugin.mk b/plugin.mk index d95ed734..04ee8d34 100644 --- a/plugin.mk +++ b/plugin.mk @@ -24,7 +24,7 @@ ifdef ARCH_LIN TARGET := plugin.so RACK_USER_DIR ?= $(HOME)/.Rack # Link to glibc 2.23 - FLAGS += -include $(RACK_DIR)/include/force_link_glibc_2.23.h +# FLAGS += -include $(RACK_DIR)/include/force_link_glibc_2.23.h endif ifdef ARCH_MAC diff --git a/src/Core/Blank.cpp b/src/Core/Blank.cpp index eb864d83..097500db 100644 --- a/src/Core/Blank.cpp +++ b/src/Core/Blank.cpp @@ -99,11 +99,6 @@ struct BlankWidget : ModuleWidget { setModule(module); box.size = Vec(RACK_GRID_WIDTH * 10, RACK_GRID_HEIGHT); - // Delete SvgPanel - removeChild(panel); - delete panel; - panel = NULL; - blankPanel = new BlankPanel; addChild(blankPanel); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index dbca8c7f..76f057c1 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -2,6 +2,7 @@ #include "app/Scene.hpp" #include "engine/Engine.hpp" #include "plugin/Plugin.hpp" +#include "app/SvgPanel.hpp" #include "system.hpp" #include "asset.hpp" #include "helpers.hpp" @@ -242,9 +243,6 @@ struct ModuleDeleteItem : ui::MenuItem { ModuleWidget::ModuleWidget() { box.size = math::Vec(0, RACK_GRID_HEIGHT); - - panel = new SvgPanel; - addChild(panel); } ModuleWidget::~ModuleWidget() { @@ -424,8 +422,19 @@ void ModuleWidget::setModule(engine::Module *module) { } void ModuleWidget::setPanel(std::shared_ptr svg) { - assert(panel); - panel->setBackground(svg); + // Remove existing panel + if (panel) { + removeChild(panel); + delete panel; + panel = NULL; + } + + // Create SvgPanel + SvgPanel *svgPanel = new SvgPanel; + svgPanel->setBackground(svg); + panel = svgPanel; + addChildBottom(panel); + // Set ModuleWidget size based on panel box.size.x = std::round(panel->box.size.x / RACK_GRID_WIDTH) * RACK_GRID_WIDTH; } diff --git a/src/widget/Widget.cpp b/src/widget/Widget.cpp index 201d9464..f2a7b346 100644 --- a/src/widget/Widget.cpp +++ b/src/widget/Widget.cpp @@ -94,6 +94,16 @@ void Widget::addChild(Widget *child) { child->onAdd(eAdd); } +void Widget::addChildBottom(Widget *child) { + assert(child); + assert(!child->parent); + child->parent = this; + children.push_front(child); + // event::Add + event::Add eAdd; + child->onAdd(eAdd); +} + void Widget::removeChild(Widget *child) { assert(child); // Make sure `this` is the child's parent