From 5e0378cb5ac5c6d399f8f25b87feabf43edaa9e7 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 11 May 2019 15:58:12 -0400 Subject: [PATCH] Clean up app namespace. --- include/app/AudioWidget.hpp | 8 +------- include/app/CableWidget.hpp | 1 + include/app/CircularShadow.hpp | 1 + include/app/LightWidget.hpp | 1 + include/app/MidiWidget.hpp | 8 +------- include/app/ModuleLightWidget.hpp | 1 + include/app/ModuleWidget.hpp | 9 +++++---- include/app/MultiLightWidget.hpp | 1 + include/app/Scene.hpp | 4 ++-- include/app/SvgKnob.hpp | 3 ++- include/app/common.hpp | 6 +++--- src/Core/Blank.cpp | 12 +++++++++--- src/app/AudioWidget.cpp | 1 - src/app/Knob.cpp | 6 ++++++ src/app/MidiWidget.cpp | 1 - src/app/ModuleWidget.cpp | 28 ++++++++++++++-------------- src/app/PortWidget.cpp | 14 +++++++++++++- src/app/Switch.cpp | 3 +++ src/app/common.cpp | 15 +++++++++++++++ 19 files changed, 79 insertions(+), 44 deletions(-) create mode 100644 src/app/common.cpp diff --git a/include/app/AudioWidget.hpp b/include/app/AudioWidget.hpp index f2e1b340..6ee2a540 100644 --- a/include/app/AudioWidget.hpp +++ b/include/app/AudioWidget.hpp @@ -1,16 +1,10 @@ #pragma once #include "app/common.hpp" #include "app/LedDisplay.hpp" +#include "audio.hpp" namespace rack { - - -namespace audio { - struct Port; -} - - namespace app { diff --git a/include/app/CableWidget.hpp b/include/app/CableWidget.hpp index 83f2e5c7..198057e4 100644 --- a/include/app/CableWidget.hpp +++ b/include/app/CableWidget.hpp @@ -16,6 +16,7 @@ struct CableWidget : widget::OpaqueWidget { PortWidget *inputPort = NULL; PortWidget *hoveredOutputPort = NULL; PortWidget *hoveredInputPort = NULL; + /** Owned. */ engine::Cable *cable; NVGcolor color; diff --git a/include/app/CircularShadow.hpp b/include/app/CircularShadow.hpp index 5041d74b..06099d30 100644 --- a/include/app/CircularShadow.hpp +++ b/include/app/CircularShadow.hpp @@ -10,6 +10,7 @@ namespace app { struct CircularShadow : widget::TransparentWidget { float blurRadius; float opacity; + CircularShadow(); void draw(const DrawArgs &args) override; }; diff --git a/include/app/LightWidget.hpp b/include/app/LightWidget.hpp index ff76e5d6..e26a2234 100644 --- a/include/app/LightWidget.hpp +++ b/include/app/LightWidget.hpp @@ -11,6 +11,7 @@ struct LightWidget : widget::TransparentWidget { NVGcolor bgColor = nvgRGBA(0, 0, 0, 0); NVGcolor color = nvgRGBA(0, 0, 0, 0); NVGcolor borderColor = nvgRGBA(0, 0, 0, 0); + void draw(const DrawArgs &args) override; virtual void drawLight(const DrawArgs &args); virtual void drawHalo(const DrawArgs &args); diff --git a/include/app/MidiWidget.hpp b/include/app/MidiWidget.hpp index cb9c391f..707b2ff8 100644 --- a/include/app/MidiWidget.hpp +++ b/include/app/MidiWidget.hpp @@ -1,16 +1,10 @@ #pragma once #include "app/common.hpp" #include "app/LedDisplay.hpp" +#include "midi.hpp" namespace rack { - - -namespace midi { - struct Port; -} - - namespace app { diff --git a/include/app/ModuleLightWidget.hpp b/include/app/ModuleLightWidget.hpp index c82b9596..b702c2ea 100644 --- a/include/app/ModuleLightWidget.hpp +++ b/include/app/ModuleLightWidget.hpp @@ -14,6 +14,7 @@ Will access firstLightId, firstLightId + 1, etc. for each added color struct ModuleLightWidget : MultiLightWidget { engine::Module *module = NULL; int firstLightId; + void step() override; }; diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index a60dcb02..0127215d 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -4,6 +4,7 @@ #include "ui/Menu.hpp" #include "app/PortWidget.hpp" #include "app/ParamWidget.hpp" +#include "app/SvgPanel.hpp" #include "plugin/Model.hpp" #include "engine/Module.hpp" @@ -15,11 +16,11 @@ namespace app { /** Manages an engine::Module in the rack. */ struct ModuleWidget : widget::OpaqueWidget { plugin::Model *model = NULL; - /** Owns the module pointer */ + /** Owned. */ engine::Module *module = NULL; - widget::Widget *panel = NULL; - /** Note that the indexes of these vectors might not correspond with the indexes of `Module::params` etc. + SvgPanel *panel = NULL; + /** Note that the indexes of these vectors do not necessarily correspond with the indexes of `Module::params` etc. */ std::vector params; std::vector outputs; @@ -29,7 +30,7 @@ struct ModuleWidget : widget::OpaqueWidget { math::Vec oldPos; ModuleWidget(); - DEPRECATED ModuleWidget(engine::Module *module) { + DEPRECATED ModuleWidget(engine::Module *module) : ModuleWidget() { setModule(module); } ~ModuleWidget(); diff --git a/include/app/MultiLightWidget.hpp b/include/app/MultiLightWidget.hpp index 9411bbab..52f1fd7f 100644 --- a/include/app/MultiLightWidget.hpp +++ b/include/app/MultiLightWidget.hpp @@ -11,6 +11,7 @@ namespace app { struct MultiLightWidget : LightWidget { /** Colors of each value state */ std::vector baseColors; + void addBaseColor(NVGcolor baseColor); /** Sets the color to a linear combination of the baseColors with the given weights */ void setBrightnesses(const std::vector &brightnesses); diff --git a/include/app/Scene.hpp b/include/app/Scene.hpp index 11d86094..ecd953c9 100644 --- a/include/app/Scene.hpp +++ b/include/app/Scene.hpp @@ -17,13 +17,13 @@ struct Scene : widget::OpaqueWidget { MenuBar *menuBar; widget::Widget *moduleBrowser; + double lastAutoSaveTime = 0.0; + // Version checking bool checkVersion = true; bool checkedVersion = false; std::string latestVersion; - double lastAutoSaveTime = 0.0; - Scene(); ~Scene(); void step() override; diff --git a/include/app/SvgKnob.hpp b/include/app/SvgKnob.hpp index 9e5698da..3bb6d48e 100644 --- a/include/app/SvgKnob.hpp +++ b/include/app/SvgKnob.hpp @@ -18,7 +18,8 @@ struct SvgKnob : Knob { widget::TransformWidget *tw; widget::SvgWidget *sw; /** Angles in radians */ - float minAngle, maxAngle; + float minAngle = 0.f; + float maxAngle = M_PI; SvgKnob(); void setSvg(std::shared_ptr svg); diff --git a/include/app/common.hpp b/include/app/common.hpp index 433271f0..3695a86b 100644 --- a/include/app/common.hpp +++ b/include/app/common.hpp @@ -12,9 +12,9 @@ namespace rack { namespace app { -static const char APP_NAME[] = "VCV Rack"; -static const char APP_VERSION[] = TOSTRING(VERSION); -static const char API_URL[] = "https://api.vcvrack.com"; +extern const char APP_NAME[]; +extern const char APP_VERSION[]; +extern const char API_URL[]; static const float SVG_DPI = 75.0; static const float MM_PER_IN = 25.4; diff --git a/src/Core/Blank.cpp b/src/Core/Blank.cpp index 82c78904..eb864d83 100644 --- a/src/Core/Blank.cpp +++ b/src/Core/Blank.cpp @@ -93,13 +93,19 @@ struct BlankWidget : ModuleWidget { Widget *topRightScrew; Widget *bottomRightScrew; Widget *rightHandle; + BlankPanel *blankPanel; BlankWidget(Module *module) { setModule(module); box.size = Vec(RACK_GRID_WIDTH * 10, RACK_GRID_HEIGHT); - panel = new BlankPanel; - addChild(panel); + // Delete SvgPanel + removeChild(panel); + delete panel; + panel = NULL; + + blankPanel = new BlankPanel; + addChild(blankPanel); ModuleResizeHandle *leftHandle = new ModuleResizeHandle; ModuleResizeHandle *rightHandle = new ModuleResizeHandle; @@ -117,7 +123,7 @@ struct BlankWidget : ModuleWidget { } void step() override { - panel->box.size = box.size; + blankPanel->box.size = box.size; topRightScrew->box.pos.x = box.size.x - 30; bottomRightScrew->box.pos.x = box.size.x - 30; if (box.size.x < RACK_GRID_WIDTH * 6) { diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index e0994f75..8b56a20a 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -1,5 +1,4 @@ #include "app/AudioWidget.hpp" -#include "audio.hpp" #include "helpers.hpp" diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index 4c61d5a8..a3f7514c 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -43,6 +43,9 @@ void Knob::onDragStart(const event::DragStart &e) { } void Knob::onDragEnd(const event::DragEnd &e) { + if (e.button != GLFW_MOUSE_BUTTON_LEFT) + return; + APP->window->cursorUnlock(); if (paramQuantity) { @@ -66,6 +69,9 @@ void Knob::onDragEnd(const event::DragEnd &e) { } void Knob::onDragMove(const event::DragMove &e) { + if (e.button != GLFW_MOUSE_BUTTON_LEFT) + return; + if (paramQuantity) { float range; if (paramQuantity->isBounded()) { diff --git a/src/app/MidiWidget.cpp b/src/app/MidiWidget.cpp index 02d93b23..a4a1c1d4 100644 --- a/src/app/MidiWidget.cpp +++ b/src/app/MidiWidget.cpp @@ -1,5 +1,4 @@ #include "app/MidiWidget.hpp" -#include "midi.hpp" #include "helpers.hpp" diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 4b6321f4..dbca8c7f 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -1,6 +1,5 @@ #include "app/ModuleWidget.hpp" #include "app/Scene.hpp" -#include "app/SvgPanel.hpp" #include "engine/Engine.hpp" #include "plugin/Plugin.hpp" #include "system.hpp" @@ -243,6 +242,9 @@ struct ModuleDeleteItem : ui::MenuItem { ModuleWidget::ModuleWidget() { box.size = math::Vec(0, RACK_GRID_HEIGHT); + + panel = new SvgPanel; + addChild(panel); } ModuleWidget::~ModuleWidget() { @@ -311,7 +313,7 @@ void ModuleWidget::onButton(const event::Button &e) { if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) { createContextMenu(); - e.consume(NULL); + e.consume(this); } } @@ -390,6 +392,9 @@ void ModuleWidget::onDragStart(const event::DragStart &e) { } void ModuleWidget::onDragEnd(const event::DragEnd &e) { + if (e.button != GLFW_MOUSE_BUTTON_LEFT) + return; + history::ComplexAction *h = APP->scene->rack->getModuleDragAction(); if (!h) { delete h; @@ -399,6 +404,9 @@ void ModuleWidget::onDragEnd(const event::DragEnd &e) { } void ModuleWidget::onDragMove(const event::DragMove &e) { + if (e.button != GLFW_MOUSE_BUTTON_LEFT) + return; + if (!settings::lockModules) { math::Vec pos = APP->scene->rack->mousePos.minus(dragPos); if ((APP->window->getMods() & RACK_MOD_MASK) == RACK_MOD_CTRL) @@ -416,18 +424,10 @@ void ModuleWidget::setModule(engine::Module *module) { } void ModuleWidget::setPanel(std::shared_ptr svg) { - // Remove old panel - if (panel) { - removeChild(panel); - delete panel; - panel = NULL; - } - - SvgPanel *svgPanel = new SvgPanel; - svgPanel->setBackground(svg); - addChild(svgPanel); - box.size.x = std::round(svgPanel->box.size.x / RACK_GRID_WIDTH) * RACK_GRID_WIDTH; - panel = svgPanel; + assert(panel); + panel->setBackground(svg); + // Set ModuleWidget size based on panel + box.size.x = std::round(panel->box.size.x / RACK_GRID_WIDTH) * RACK_GRID_WIDTH; } void ModuleWidget::addParam(ParamWidget *param) { diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index 14fcc6a9..3c356cce 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -74,7 +74,7 @@ void PortWidget::onButton(const event::Button &e) { delete cw; } - e.consume(NULL); + e.consume(this); } } @@ -135,6 +135,9 @@ void PortWidget::onDragStart(const event::DragStart &e) { } void PortWidget::onDragEnd(const event::DragEnd &e) { + if (e.button != GLFW_MOUSE_BUTTON_LEFT) + return; + CableWidget *cw = APP->scene->rack->releaseIncompleteCable(); if (cw->isComplete()) { APP->scene->rack->addCable(cw); @@ -150,6 +153,9 @@ void PortWidget::onDragEnd(const event::DragEnd &e) { } void PortWidget::onDragDrop(const event::DragDrop &e) { + if (e.button != GLFW_MOUSE_BUTTON_LEFT) + return; + // Reject ports if this is an input port and something is already plugged into it if (type == INPUT) { if (APP->scene->rack->getTopCable(this)) @@ -167,6 +173,9 @@ void PortWidget::onDragDrop(const event::DragDrop &e) { } void PortWidget::onDragEnter(const event::DragEnter &e) { + if (e.button != GLFW_MOUSE_BUTTON_LEFT) + return; + // Reject ports if this is an input port and something is already plugged into it if (type == INPUT) { if (APP->scene->rack->getTopCable(this)) @@ -183,6 +192,9 @@ void PortWidget::onDragEnter(const event::DragEnter &e) { } void PortWidget::onDragLeave(const event::DragLeave &e) { + if (e.button != GLFW_MOUSE_BUTTON_LEFT) + return; + PortWidget *originPort = dynamic_cast(e.origin); if (!originPort) return; diff --git a/src/app/Switch.cpp b/src/app/Switch.cpp index b92ea96f..c855dc11 100644 --- a/src/app/Switch.cpp +++ b/src/app/Switch.cpp @@ -67,6 +67,9 @@ void Switch::onDragStart(const event::DragStart &e) { } void Switch::onDragEnd(const event::DragEnd &e) { + if (e.button != GLFW_MOUSE_BUTTON_LEFT) + return; + if (momentary) { momentaryReleased = true; } diff --git a/src/app/common.cpp b/src/app/common.cpp new file mode 100644 index 00000000..e56db1ee --- /dev/null +++ b/src/app/common.cpp @@ -0,0 +1,15 @@ +#include "app/common.hpp" + + +namespace rack { +namespace app { + + +const char APP_NAME[] = "VCV Rack"; +const char APP_VERSION[] = TOSTRING(VERSION); +const char API_URL[] = "https://api.vcvrack.com"; + + + +} // namespace app +} // namespace rack