From a9f4c0e50d6a757cc2ffa435b9f239e0e5133b00 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 6 Jun 2018 23:21:03 -0400 Subject: [PATCH] Add the rest of the toolbar icons, remove File menu --- res/icons/030-feed.svg | 58 --------- res/icons/037-file-empty.svg | 58 --------- res/icons/099-floppy-disk.svg | 58 --------- res/icons/167-meter.svg | 58 --------- res/icons/LICENSE.md | 13 +- ...49-folder-open.svg => noun_1084369_cc.svg} | 40 +++--- res/icons/noun_1240789_cc.svg | 47 +++++++ res/icons/noun_1343811_cc.svg | 71 +++++++++++ res/icons/noun_1343816_cc.svg | 71 +++++++++++ res/icons/noun_146097_cc.svg | 56 +++++++++ res/icons/noun_1745061_cc.svg | 57 +++++++++ res/icons/noun_305536_cc.svg | 62 ++++++++++ res/icons/noun_31859_cc.svg | 47 +++++++ src/app/ModuleWidget.cpp | 15 ++- src/app/RackWidget.cpp | 3 + src/app/Toolbar.cpp | 116 +++++++++--------- src/engine.cpp | 12 +- src/ui/Tooltip.cpp | 5 +- 18 files changed, 530 insertions(+), 317 deletions(-) delete mode 100755 res/icons/030-feed.svg delete mode 100755 res/icons/037-file-empty.svg delete mode 100755 res/icons/099-floppy-disk.svg delete mode 100755 res/icons/167-meter.svg rename res/icons/{049-folder-open.svg => noun_1084369_cc.svg} (60%) mode change 100755 => 100644 create mode 100644 res/icons/noun_1240789_cc.svg create mode 100644 res/icons/noun_1343811_cc.svg create mode 100644 res/icons/noun_1343816_cc.svg create mode 100644 res/icons/noun_146097_cc.svg create mode 100644 res/icons/noun_1745061_cc.svg create mode 100644 res/icons/noun_305536_cc.svg create mode 100644 res/icons/noun_31859_cc.svg diff --git a/res/icons/030-feed.svg b/res/icons/030-feed.svg deleted file mode 100755 index 76680d66..00000000 --- a/res/icons/030-feed.svg +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff --git a/res/icons/037-file-empty.svg b/res/icons/037-file-empty.svg deleted file mode 100755 index 0202e211..00000000 --- a/res/icons/037-file-empty.svg +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff --git a/res/icons/099-floppy-disk.svg b/res/icons/099-floppy-disk.svg deleted file mode 100755 index df43a937..00000000 --- a/res/icons/099-floppy-disk.svg +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff --git a/res/icons/167-meter.svg b/res/icons/167-meter.svg deleted file mode 100755 index 67a044ca..00000000 --- a/res/icons/167-meter.svg +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - diff --git a/res/icons/LICENSE.md b/res/icons/LICENSE.md index b1944854..704a7f4b 100644 --- a/res/icons/LICENSE.md +++ b/res/icons/LICENSE.md @@ -1,2 +1,11 @@ -SVG icons in this directory are licensed under the CC BY 4.0 License by IcoMoon.io. -https://icomoon.io/ \ No newline at end of file +All icons are licensed under CC BY 3.0. +https://creativecommons.org/licenses/by/3.0/ +https://thenounproject.com/ + +Paper by Madeleine Bennett from the Noun Project +Folder by Icon Solid from the Noun Project +Save by Landan Lloyd from the Noun Project +Cat by Nabilauzwa from the Noun Project +Stopwatch by Arthur Shlain from the Noun Project +Sound by Gregor Cresnar from the Noun Project +Refresh by un·delivered from the Noun Project diff --git a/res/icons/049-folder-open.svg b/res/icons/noun_1084369_cc.svg old mode 100755 new mode 100644 similarity index 60% rename from res/icons/049-folder-open.svg rename to res/icons/noun_1084369_cc.svg index ea3dd33f..ed8bd940 --- a/res/icons/049-folder-open.svg +++ b/res/icons/noun_1084369_cc.svg @@ -1,6 +1,4 @@ - - + id="metadata59"> image/svg+xml + Cycles + id="defs57" /> + inkscape:current-layer="svg53" /> + Cycles + d="M 9.0117134,7.367368 11.174158,5.206575 a 4.1778634,4.1778634 0 1 0 0.728524,4.460353 h 1.90804 0.01652 q -0.0413,0.15033 -0.09416,0.297357 A 6,6 0 1 1 12.462704,3.919681 l 1.473568,-1.473568 v 4.921255 z" + id="path47" + inkscape:connector-curvature="0" + style="stroke-width:0.16519824;fill:#b4b4b4;fill-opacity:1" /> diff --git a/res/icons/noun_1240789_cc.svg b/res/icons/noun_1240789_cc.svg new file mode 100644 index 00000000..f984277a --- /dev/null +++ b/res/icons/noun_1240789_cc.svg @@ -0,0 +1,47 @@ + +image/svg+xml111all111all \ No newline at end of file diff --git a/res/icons/noun_1343811_cc.svg b/res/icons/noun_1343811_cc.svg new file mode 100644 index 00000000..4765bdeb --- /dev/null +++ b/res/icons/noun_1343811_cc.svg @@ -0,0 +1,71 @@ + + + + + + image/svg+xml + + 7.3 + + + + + + 7.3 + Created with Sketch. + + + + + + diff --git a/res/icons/noun_1343816_cc.svg b/res/icons/noun_1343816_cc.svg new file mode 100644 index 00000000..d3aa67c5 --- /dev/null +++ b/res/icons/noun_1343816_cc.svg @@ -0,0 +1,71 @@ + + + + + + image/svg+xml + + 8.3 + + + + + + 8.3 + Created with Sketch. + + + + + + diff --git a/res/icons/noun_146097_cc.svg b/res/icons/noun_146097_cc.svg new file mode 100644 index 00000000..749d0c11 --- /dev/null +++ b/res/icons/noun_146097_cc.svg @@ -0,0 +1,56 @@ + +image/svg+xml \ No newline at end of file diff --git a/res/icons/noun_1745061_cc.svg b/res/icons/noun_1745061_cc.svg new file mode 100644 index 00000000..aa226944 --- /dev/null +++ b/res/icons/noun_1745061_cc.svg @@ -0,0 +1,57 @@ + +image/svg+xml \ No newline at end of file diff --git a/res/icons/noun_305536_cc.svg b/res/icons/noun_305536_cc.svg new file mode 100644 index 00000000..1ee24be8 --- /dev/null +++ b/res/icons/noun_305536_cc.svg @@ -0,0 +1,62 @@ + +image/svg+xml \ No newline at end of file diff --git a/res/icons/noun_31859_cc.svg b/res/icons/noun_31859_cc.svg new file mode 100644 index 00000000..ff873c99 --- /dev/null +++ b/res/icons/noun_31859_cc.svg @@ -0,0 +1,47 @@ + +image/svg+xml \ No newline at end of file diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 3eb3efce..861a099f 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -190,7 +190,20 @@ void ModuleWidget::draw(NVGcontext *vg) { Widget::draw(vg); // CPU meter - if (gCpuMeters && module) { + if (module && gCpuMeters) { + nvgBeginPath(vg); + nvgRect(vg, + 0, box.size.y - 20, + 55, 20); + nvgFillColor(vg, nvgRGBAf(0, 0, 0, 0.5)); + nvgFill(vg); + + std::string cpuText = stringf("%.0f mS", module->cpuTime * 1000.f); + nvgFontFaceId(vg, gGuiFont->handle); + nvgFontSize(vg, 12); + nvgFillColor(vg, nvgRGBf(1, 1, 1)); + nvgText(vg, 10.0, box.size.y - 6.0, cpuText.c_str(), NULL); + float p = clamp(module->cpuTime, 0.f, 1.f); nvgBeginPath(vg); nvgRect(vg, diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index fbdcb519..f68e630d 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -165,6 +165,9 @@ void RackWidget::revert() { } void RackWidget::disconnect() { + if (!osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK_CANCEL, "Clear all patch cables?")) + return; + for (Widget *w : moduleContainer->children) { ModuleWidget *moduleWidget = dynamic_cast(w); assert(moduleWidget); diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index ee944473..e42b9d7f 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -8,24 +8,31 @@ namespace rack { struct TooltipIconButton : IconButton { + Tooltip *tooltip = NULL; std::string tooltipText; void onMouseEnter(EventMouseEnter &e) override { - TooltipOverlay *overlay = new TooltipOverlay(); - Tooltip *tooltip = new Tooltip(); - tooltip->box.pos = getAbsoluteOffset(Vec(0, BND_WIDGET_HEIGHT)); - tooltip->text = tooltipText; - overlay->addChild(tooltip); - gScene->setOverlay(overlay); + if (!tooltip) { + tooltip = new Tooltip(); + tooltip->box.pos = getAbsoluteOffset(Vec(0, BND_WIDGET_HEIGHT)); + tooltip->text = tooltipText; + gScene->addChild(tooltip); + } + IconButton::onMouseEnter(e); } void onMouseLeave(EventMouseLeave &e) override { - gScene->setOverlay(NULL); + if (tooltip) { + gScene->removeChild(tooltip); + delete tooltip; + tooltip = NULL; + } + IconButton::onMouseLeave(e); } }; struct NewButton : TooltipIconButton { NewButton() { - setSVG(SVG::load(assetGlobal("res/icons/037-file-empty.svg"))); - tooltipText = "New patch (" WINDOW_MOD_KEY_NAME "+N)"; + setSVG(SVG::load(assetGlobal("res/icons/noun_146097_cc.svg"))); + tooltipText = "New (" WINDOW_MOD_KEY_NAME "+N)"; } void onAction(EventAction &e) override { gRackWidget->reset(); @@ -34,8 +41,8 @@ struct NewButton : TooltipIconButton { struct OpenButton : TooltipIconButton { OpenButton() { - setSVG(SVG::load(assetGlobal("res/icons/049-folder-open.svg"))); - tooltipText = "Open patch (" WINDOW_MOD_KEY_NAME "+O)"; + setSVG(SVG::load(assetGlobal("res/icons/noun_31859_cc.svg"))); + tooltipText = "Open (" WINDOW_MOD_KEY_NAME "+O)"; } void onAction(EventAction &e) override { gRackWidget->openDialog(); @@ -44,18 +51,48 @@ struct OpenButton : TooltipIconButton { struct SaveButton : TooltipIconButton { SaveButton() { - setSVG(SVG::load(assetGlobal("res/icons/099-floppy-disk.svg"))); - tooltipText = "Save patch (" WINDOW_MOD_KEY_NAME "+S)"; + setSVG(SVG::load(assetGlobal("res/icons/noun_1343816_cc.svg"))); + tooltipText = "Save (" WINDOW_MOD_KEY_NAME "+S)"; } void onAction(EventAction &e) override { gRackWidget->saveDialog(); } }; +struct SaveAsButton : TooltipIconButton { + SaveAsButton() { + setSVG(SVG::load(assetGlobal("res/icons/noun_1343811_cc.svg"))); + tooltipText = "Save as (" WINDOW_MOD_KEY_NAME "+Shift+S)"; + } + void onAction(EventAction &e) override { + gRackWidget->saveAsDialog(); + } +}; + +struct RevertButton : TooltipIconButton { + RevertButton() { + setSVG(SVG::load(assetGlobal("res/icons/noun_1084369_cc.svg"))); + tooltipText = "Revert"; + } + void onAction(EventAction &e) override { + gRackWidget->revert(); + } +}; + +struct DisconnectCablesButton : TooltipIconButton { + DisconnectCablesButton() { + setSVG(SVG::load(assetGlobal("res/icons/noun_1745061_cc.svg"))); + tooltipText = "Disconnect cables"; + } + void onAction(EventAction &e) override { + gRackWidget->disconnect(); + } +}; + struct MeterButton : TooltipIconButton { MeterButton() { - setSVG(SVG::load(assetGlobal("res/icons/167-meter.svg"))); - tooltipText = "Toggle CPU meter\nSee manual for mV definition"; + setSVG(SVG::load(assetGlobal("res/icons/noun_305536_cc.svg"))); + tooltipText = "Toggle power meter (see manual for explanation)"; } void onAction(EventAction &e) override { gCpuMeters ^= true; @@ -78,7 +115,7 @@ struct SampleRateItem : MenuItem { struct SampleRateButton : TooltipIconButton { SampleRateButton() { - setSVG(SVG::load(assetGlobal("res/icons/030-feed.svg"))); + setSVG(SVG::load(assetGlobal("res/icons/noun_1240789_cc.svg"))); tooltipText = "Internal sample rate"; } void onAction(EventAction &e) override { @@ -86,6 +123,8 @@ struct SampleRateButton : TooltipIconButton { menu->box.pos = getAbsoluteOffset(Vec(0, box.size.y)); menu->box.size.x = box.size.x; + menu->addChild(MenuLabel::create("Internal sample rate")); + EnginePauseItem *pauseItem = new EnginePauseItem(); pauseItem->text = gPaused ? "Resume engine" : "Pause engine"; menu->addChild(pauseItem); @@ -103,38 +142,6 @@ struct SampleRateButton : TooltipIconButton { -struct DisconnectItem : MenuItem { - void onAction(EventAction &e) override { - gRackWidget->disconnect(); - } -}; - -struct SaveAsItem : MenuItem { - void onAction(EventAction &e) override { - gRackWidget->saveAsDialog(); - } -}; - -struct RevertItem : MenuItem { - void onAction(EventAction &e) override { - gRackWidget->revert(); - } -}; - -struct FileChoice : ChoiceButton { - void onAction(EventAction &e) override { - Menu *menu = gScene->createMenu(); - menu->box.pos = getAbsoluteOffset(Vec(0, box.size.y)); - menu->box.size.x = box.size.x; - - menu->addChild(MenuItem::create("Disconnect cables")); - menu->addChild(MenuItem::create("Save as", WINDOW_MOD_KEY_NAME "+Shift+S")); - menu->addChild(MenuItem::create("Revert")); - } -}; - - - Toolbar::Toolbar() { box.size.y = BND_WIDGET_HEIGHT + 2*5; @@ -146,13 +153,9 @@ Toolbar::Toolbar() { layout->addChild(new NewButton()); layout->addChild(new OpenButton()); layout->addChild(new SaveButton()); - layout->addChild(new SampleRateButton()); - layout->addChild(new MeterButton()); - - ChoiceButton *fileChoice = new FileChoice(); - fileChoice->box.size.x = 100; - fileChoice->text = "File"; - layout->addChild(fileChoice); + layout->addChild(new SaveAsButton()); + layout->addChild(new RevertButton()); + layout->addChild(new DisconnectCablesButton()); wireOpacitySlider = new Slider(); wireOpacitySlider->box.size.x = 150; @@ -171,6 +174,9 @@ Toolbar::Toolbar() { wireTensionSlider->setDefaultValue(0.5); layout->addChild(wireTensionSlider); + layout->addChild(new SampleRateButton()); + layout->addChild(new MeterButton()); + struct ZoomSlider : Slider { void onAction(EventAction &e) override { Slider::onAction(e); diff --git a/src/engine.cpp b/src/engine.cpp index 9c1a9ce4..2b1594d3 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -20,7 +20,7 @@ std::vector gWires; bool gCpuMeters = false; static bool running = false; -static float sampleRate; +static float sampleRate = 44100.f; static float sampleTime; static std::mutex mutex; @@ -92,17 +92,17 @@ static void engineStep() { std::chrono::high_resolution_clock::time_point startTime; if (gCpuMeters) { startTime = std::chrono::high_resolution_clock::now(); - } - module->step(); + module->step(); - if (gCpuMeters) { auto stopTime = std::chrono::high_resolution_clock::now(); float cpuTime = std::chrono::duration(stopTime - startTime).count() * sampleRate; - module->cpuTime += (cpuTime - module->cpuTime) * sampleTime * 10.f; + module->cpuTime += (cpuTime - module->cpuTime) * sampleTime / 0.25f; + } + else { + module->step(); } - // TODO skip this step when plug lights are disabled // Step ports for (Input &input : module->inputs) { if (input.active) { diff --git a/src/ui/Tooltip.cpp b/src/ui/Tooltip.cpp index f65c68bc..47f6c440 100644 --- a/src/ui/Tooltip.cpp +++ b/src/ui/Tooltip.cpp @@ -10,9 +10,8 @@ Tooltip::Tooltip() { void Tooltip::draw(NVGcontext *vg) { // Wrap size to contents - float bounds[4]; - nvgTextBounds(gVg, 0.0, 0.0, text.c_str(), NULL, bounds); - box.size = Vec(bounds[2], BND_WIDGET_HEIGHT); + box.size.x = bndLabelWidth(vg, -1, text.c_str()); + box.size.y = bndLabelHeight(vg, -1, text.c_str(), INFINITY); bndTooltipBackground(vg, 0.0, 0.0, box.size.x, box.size.y); bndMenuLabel(vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str());