From d73750401189ea0784450abab984c5f40230cc65 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sun, 27 Jan 2019 07:48:23 -0500 Subject: [PATCH] Add intro message when the rack is empty. Round zoom level to nearest percent. --- include/app/RackScrollWidget.hpp | 1 + include/app/RackWidget.hpp | 1 + src/app/RackScrollWidget.cpp | 18 ++++++++++++++++++ src/app/RackWidget.cpp | 4 ++++ src/app/Scene.cpp | 2 +- src/app/Toolbar.cpp | 10 +++++----- src/engine/Engine.cpp | 11 +++++++++++ 7 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/app/RackScrollWidget.hpp b/include/app/RackScrollWidget.hpp index 1945c12b..687d499a 100644 --- a/include/app/RackScrollWidget.hpp +++ b/include/app/RackScrollWidget.hpp @@ -8,6 +8,7 @@ namespace rack { struct RackScrollWidget : ScrollWidget { void step() override; + void draw(NVGcontext *vg) override; }; diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index e1bd5f9b..4f47eed6 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -50,6 +50,7 @@ struct RackWidget : OpaqueWidget { /** Moves a module to the closest non-colliding position */ bool requestModuleBoxNearest(ModuleWidget *mw, math::Rect requestedBox); ModuleWidget *getModule(int moduleId); + bool isEmpty(); // Cable methods diff --git a/src/app/RackScrollWidget.cpp b/src/app/RackScrollWidget.cpp index 277cab8a..704bb214 100644 --- a/src/app/RackScrollWidget.cpp +++ b/src/app/RackScrollWidget.cpp @@ -27,4 +27,22 @@ void RackScrollWidget::step() { } +void RackScrollWidget::draw(NVGcontext *vg) { + ScrollWidget::draw(vg); + + if (app()->scene->rackWidget->isEmpty()) { + math::Rect b; + b.size = math::Vec(600, 300); + b.pos = box.size.minus(b.size).div(2); + NVGcolor bg = nvgRGBAf(0, 0, 0, 0.4); + bndInnerBox(vg, b.pos.x, b.pos.y, b.size.x, b.size.y, + 0, 0, 0, 0, bg, bg); + + NVGcolor fg = nvgRGBAf(1, 1, 1, 0.25); + std::string text = "Right-click or press Enter to add modules"; + bndIconLabelValue(vg, b.pos.x, b.pos.y + 80, b.size.x, b.size.y, -1, fg, BND_CENTER, 80, text.c_str(), NULL); + } +} + + } // namespace rack diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 171dca9c..26920483 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -416,6 +416,10 @@ ModuleWidget *RackWidget::getModule(int moduleId) { return NULL; } +bool RackWidget::isEmpty() { + return moduleContainer->children.empty(); +} + void RackWidget::clearCables() { for (Widget *w : cableContainer->children) { CableWidget *cw = dynamic_cast(w); diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 2461eb57..bdac4c87 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -64,7 +64,7 @@ void Scene::step() { // Set zoom every few frames if (app()->window->frame % 10 == 0) - zoomWidget->setZoom(settings::zoom); + zoomWidget->setZoom(std::round(settings::zoom * 100) / 100); // Request latest version from server if (!devMode && checkVersion && !checkedVersion) { diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index 4d626618..0ce6fa43 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -187,8 +187,8 @@ struct ZoomQuantity : Quantity { float getMinValue() override {return 0.25;} float getMaxValue() override {return 2.0;} float getDefaultValue() override {return 1.0;} - float getDisplayValue() override {return getValue() * 100.0;} - void setDisplayValue(float displayValue) override {setValue(displayValue / 100.0);} + float getDisplayValue() override {return std::round(getValue() * 100);} + void setDisplayValue(float displayValue) override {setValue(displayValue / 100);} std::string getLabel() override {return "Zoom";} std::string getUnit() override {return "%";} }; @@ -202,8 +202,8 @@ struct CableOpacityQuantity : Quantity { return settings::cableOpacity; } float getDefaultValue() override {return 0.5;} - float getDisplayValue() override {return getValue() * 100.0;} - void setDisplayValue(float displayValue) override {setValue(displayValue / 100.0);} + float getDisplayValue() override {return getValue() * 100;} + void setDisplayValue(float displayValue) override {setValue(displayValue / 100);} std::string getLabel() override {return "Cable opacity";} std::string getUnit() override {return "%";} }; @@ -225,7 +225,7 @@ struct CableTensionQuantity : Quantity { struct PowerMeterItem : MenuItem { PowerMeterItem() { - text = "Power meter"; + text = "CPU meter"; rightText = CHECKMARK(settings::powerMeter); } void onAction(const event::Action &e) override { diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 6c2c16e3..6c0c05ce 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -1,6 +1,7 @@ #include "engine/Engine.hpp" #include "settings.hpp" #include "system.hpp" +#include "random.hpp" #include #include @@ -150,6 +151,16 @@ static void Engine_step(Engine *engine) { } } +#if 0 + if (random::u32() % 1000 == 0 && settings::powerMeter) { + float cpuTotal = 0.f; + for (Module *module : engine->modules) { + cpuTotal += module->cpuTime; + } + DEBUG("%fus %f%% CPU", cpuTotal * 1e6, cpuTotal * engine->internal->sampleRate * 100); + } +#endif + // Step cables for (Cable *cable : engine->cables) { cable->step();