diff --git a/include/app.hpp b/include/app.hpp index f96e5ac4..e0fd3f53 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -313,6 +313,7 @@ struct Toolbar : OpaqueWidget { Slider *wireOpacitySlider; Slider *wireTensionSlider; RadioButton *cpuUsageButton; + RadioButton *plugLightButton; Toolbar(); void draw(NVGcontext *vg); @@ -327,7 +328,6 @@ struct PluginManagerWidget : Widget { }; struct RackScene : Scene { - Toolbar *toolbar; ScrollWidget *scrollWidget; ZoomWidget *zoomWidget; @@ -345,7 +345,9 @@ extern std::string gApplicationName; extern std::string gApplicationVersion; extern std::string gApiHost; +// Easy access to "singleton" widgets extern RackWidget *gRackWidget; +extern Toolbar *gToolbar; void sceneInit(); void sceneDestroy(); diff --git a/src/app.cpp b/src/app.cpp index 2e827d35..98aec2cb 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -8,6 +8,7 @@ std::string gApplicationVersion = TOSTRING(VERSION); std::string gApiHost = "http://api.vcvrack.com"; RackWidget *gRackWidget = NULL; +Toolbar *gToolbar = NULL; void sceneInit() { diff --git a/src/app/RackScene.cpp b/src/app/RackScene.cpp index 705086e8..b02b5caa 100644 --- a/src/app/RackScene.cpp +++ b/src/app/RackScene.cpp @@ -40,9 +40,9 @@ RackScene::RackScene() { } addChild(scrollWidget); - toolbar = new Toolbar(); - addChild(toolbar); - scrollWidget->box.pos.y = toolbar->box.size.y; + gToolbar = new Toolbar(); + addChild(gToolbar); + scrollWidget->box.pos.y = gToolbar->box.size.y; // Check for new version if (gApplicationVersion != "dev") { @@ -53,7 +53,7 @@ RackScene::RackScene() { void RackScene::step() { // Resize owned descendants - toolbar->box.size.x = box.size.x; + gToolbar->box.size.x = box.size.x; scrollWidget->box.size = box.size.minus(scrollWidget->box.pos); // Resize to be a bit larger than the ScrollWidget viewport diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index d9b95c84..47c754a3 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -395,7 +395,7 @@ struct AddPluginMenuItem : MenuItem { if (!plugin->path.empty()) { UrlItem *item = new UrlItem(); - item->text = "Browse Directory"; + item->text = "Browse directory"; item->url = plugin->path; menu->pushChild(item); } @@ -410,7 +410,7 @@ void RackWidget::onMouseDownOpaque(int button) { Menu *menu = gScene->createMenu(); MenuLabel *menuLabel = new MenuLabel(); - menuLabel->text = "Add Module"; + menuLabel->text = "Add module"; menu->pushChild(menuLabel); for (Plugin *plugin : gPlugins) { AddPluginMenuItem *item = new AddPluginMenuItem(); diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index 4f3eb299..4a421522 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -53,7 +53,7 @@ struct FileChoice : ChoiceButton { menu->pushChild(saveItem); MenuItem *saveAsItem = new SaveAsItem(); - saveAsItem->text = "Save As"; + saveAsItem->text = "Save as"; saveAsItem->rightText = GUI_MOD_KEY_NAME "+Shift+S"; menu->pushChild(saveAsItem); } @@ -82,7 +82,7 @@ struct SampleRateChoice : ChoiceButton { menu->box.size.x = box.size.x; PauseItem *pauseItem = new PauseItem(); - pauseItem->text = gPaused ? "Resume Engine" : "Pause Engine"; + pauseItem->text = gPaused ? "Resume engine" : "Pause engine"; menu->pushChild(pauseItem); float sampleRates[] = {44100, 48000, 88200, 96000, 176400, 192000}; @@ -154,6 +154,17 @@ Toolbar::Toolbar() { xPos += wireTensionSlider->box.size.x; } + xPos += margin; + { + plugLightButton = new RadioButton(); + plugLightButton->box.pos = Vec(xPos, margin); + plugLightButton->box.size.x = 100; + plugLightButton->label = "Plug lights"; + plugLightButton->setValue(1.0); + addChild(plugLightButton); + xPos += plugLightButton->box.size.x; + } + /* xPos += margin; { diff --git a/src/app/WireWidget.cpp b/src/app/WireWidget.cpp index f3c6c315..bfcddc8a 100644 --- a/src/app/WireWidget.cpp +++ b/src/app/WireWidget.cpp @@ -151,8 +151,8 @@ Vec WireWidget::getInputPos() { } void WireWidget::draw(NVGcontext *vg) { - float opacity = dynamic_cast(gScene)->toolbar->wireOpacitySlider->value / 100.0; - float tension = dynamic_cast(gScene)->toolbar->wireTensionSlider->value; + float opacity = gToolbar->wireOpacitySlider->value / 100.0; + float tension = gToolbar->wireTensionSlider->value; // Draw as opaque if an "incomplete" wire if (!(inputPort && outputPort)) @@ -169,19 +169,27 @@ void WireWidget::drawPlugs(NVGcontext *vg) { drawPlug(vg, inputPos, color); // Draw plug light - if (wire) { - Output &output = wire->outputModule->outputs[wire->outputId]; - float value = output.value / 8.0; - outputLight->box.size = Vec(10, 10); - inputLight->box.size = Vec(10, 10); - outputLight->box.pos = outputPos.minus(Vec(5, 5)); - inputLight->box.pos = inputPos.minus(Vec(5, 5)); - outputLight->setValue(value); - inputLight->setValue(value); + if (gToolbar->plugLightButton->value > 0.0) { + if (wire) { + Output &output = wire->outputModule->outputs[wire->outputId]; + float value = output.value / 8.0; + outputLight->box.size = Vec(10, 10); + inputLight->box.size = Vec(10, 10); + outputLight->box.pos = outputPos.minus(Vec(5, 5)); + inputLight->box.pos = inputPos.minus(Vec(5, 5)); + outputLight->setValue(value); + inputLight->setValue(value); + } + else { + outputLight->setValue(0.0); + inputLight->setValue(0.0); + } + outputLight->visible = true; + inputLight->visible = true; } else { - outputLight->setValue(0.0); - inputLight->setValue(0.0); + outputLight->visible = false; + inputLight->visible = false; } Widget::draw(vg); } diff --git a/src/settings.cpp b/src/settings.cpp index c2e5153e..86e622b8 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -18,12 +18,12 @@ static json_t *settingsToJson() { json_object_set_new(rootJ, "token", tokenJ); // opacity - float opacity = dynamic_cast(gScene)->toolbar->wireOpacitySlider->value; + float opacity = gToolbar->wireOpacitySlider->value; json_t *opacityJ = json_real(opacity); json_object_set_new(rootJ, "wireOpacity", opacityJ); // tension - float tension = dynamic_cast(gScene)->toolbar->wireTensionSlider->value; + float tension = gToolbar->wireTensionSlider->value; json_t *tensionJ = json_real(tension); json_object_set_new(rootJ, "wireTension", tensionJ); @@ -36,6 +36,10 @@ static json_t *settingsToJson() { json_t *sampleRateJ = json_real(sampleRate); json_object_set_new(rootJ, "sampleRate", sampleRateJ); + // plugLight + json_t *plugLightJ = json_boolean(gToolbar->plugLightButton->value > 0.0); + json_object_set_new(rootJ, "plugLight", plugLightJ); + return rootJ; } @@ -48,12 +52,12 @@ static void settingsFromJson(json_t *rootJ) { // opacity json_t *opacityJ = json_object_get(rootJ, "wireOpacity"); if (opacityJ) - dynamic_cast(gScene)->toolbar->wireOpacitySlider->value = json_number_value(opacityJ); + gToolbar->wireOpacitySlider->value = json_number_value(opacityJ); // tension json_t *tensionJ = json_object_get(rootJ, "wireTension"); if (tensionJ) - dynamic_cast(gScene)->toolbar->wireTensionSlider->value = json_number_value(tensionJ); + gToolbar->wireTensionSlider->value = json_number_value(tensionJ); // allowCursorLock json_t *allowCursorLockJ = json_object_get(rootJ, "allowCursorLock"); @@ -66,6 +70,11 @@ static void settingsFromJson(json_t *rootJ) { float sampleRate = json_number_value(sampleRateJ); engineSetSampleRate(sampleRate); } + + // plugLight + json_t *plugLightJ = json_object_get(rootJ, "plugLight"); + if (plugLightJ) + gToolbar->plugLightButton->setValue(json_is_true(plugLightJ) ? 1.0 : 0.0); }