From 9d7024232c4b9b09e758b7758bd1384b78a34ffd Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 19 Dec 2018 08:11:41 -0500 Subject: [PATCH] Put ui.hpp in namespace, clean up --- include/context.hpp | 2 ++ include/helpers.hpp | 1 - include/settings.hpp | 2 -- include/ui.hpp | 9 +++++---- src/app/LedDisplay.cpp | 1 - src/app/ModuleWidget.cpp | 1 - src/main.cpp | 12 ++++++------ src/settings.cpp | 17 +++++++---------- src/ui.cpp | 13 ++++++------- 9 files changed, 26 insertions(+), 32 deletions(-) diff --git a/include/context.hpp b/include/context.hpp index 4c565c99..a41cf1d9 100644 --- a/include/context.hpp +++ b/include/context.hpp @@ -19,6 +19,8 @@ struct Context { Scene *scene = NULL; Engine *engine = NULL; Window *window = NULL; + + bool skipLoadOnLaunch = false; }; diff --git a/include/helpers.hpp b/include/helpers.hpp index a7d415b2..05a65444 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -141,7 +141,6 @@ TMenuItem *createMenuItem(std::string text, std::string rightText = "") { return o; } -// TODO Reevaluate this. Does it belong here? inline Menu *createMenu() { Menu *o = new Menu; o->box.pos = context()->window->mousePos; diff --git a/include/settings.hpp b/include/settings.hpp index c05d67de..d9e043ef 100644 --- a/include/settings.hpp +++ b/include/settings.hpp @@ -6,8 +6,6 @@ namespace rack { namespace settings { -extern bool gSkipAutosaveOnLaunch; - void save(std::string filename); void load(std::string filename); diff --git a/include/ui.hpp b/include/ui.hpp index f5038991..95003fa0 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -1,15 +1,16 @@ #pragma once #include "ui/common.hpp" #include "color.hpp" -#include "window.hpp" namespace rack { +namespace ui { -void uiInit(); -void uiDestroy(); -void uiSetTheme(NVGcolor bg, NVGcolor fg); +void init(); +void destroy(); +void setTheme(NVGcolor bg, NVGcolor fg); +} // namespace ui } // namespace rack diff --git a/src/app/LedDisplay.cpp b/src/app/LedDisplay.cpp index 504dae7f..1bf09af2 100644 --- a/src/app/LedDisplay.cpp +++ b/src/app/LedDisplay.cpp @@ -3,7 +3,6 @@ #include "window.hpp" #include "event.hpp" #include "context.hpp" -#include "ui.hpp" namespace rack { diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 39642065..6db87558 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -6,7 +6,6 @@ #include "app/Scene.hpp" #include "helpers.hpp" #include "context.hpp" -#include "ui.hpp" #include "osdialog.h" diff --git a/src/main.cpp b/src/main.cpp index 5d64ddc5..1c95a110 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) { bridgeInit(); keyboard::init(); gamepad::init(); - uiInit(); + ui::init(); plugin::init(devMode); // Log environment @@ -90,11 +90,11 @@ int main(int argc, char *argv[]) { if (patchFile.empty()) { // To prevent launch crashes, if Rack crashes between now and 15 seconds from now, the "skipAutosaveOnLaunch" property will remain in settings.json, so that in the next launch, the broken autosave will not be loaded. - bool oldSkipAutosaveOnLaunch = settings::gSkipAutosaveOnLaunch; - settings::gSkipAutosaveOnLaunch = true; + bool oldSkipLoadOnLaunch = context()->skipLoadOnLaunch; + context()->skipLoadOnLaunch = true; settings::save(asset::user("settings.json")); - settings::gSkipAutosaveOnLaunch = false; - if (oldSkipAutosaveOnLaunch && osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, "Rack has recovered from a crash, possibly caused by a faulty module in your patch. Clear your patch and start over?")) { + context()->skipLoadOnLaunch = false; + if (oldSkipLoadOnLaunch && osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, "Rack has recovered from a crash, possibly caused by a faulty module in your patch. Clear your patch and start over?")) { context()->scene->rackWidget->lastPath = ""; } else { @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) { // Destroy environment plugin::destroy(); - uiDestroy(); + ui::destroy(); bridgeDestroy(); midiDestroy(); logger::destroy(); diff --git a/src/settings.cpp b/src/settings.cpp index fc249dbf..4b87131f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -13,9 +13,6 @@ namespace rack { namespace settings { -bool gSkipAutosaveOnLaunch = false; - - static json_t *settingsToJson() { // root json_t *rootJ = json_object(); @@ -63,9 +60,9 @@ static json_t *settingsToJson() { json_t *lastPathJ = json_string(context()->scene->rackWidget->lastPath.c_str()); json_object_set_new(rootJ, "lastPath", lastPathJ); - // skipAutosaveOnLaunch - if (gSkipAutosaveOnLaunch) { - json_object_set_new(rootJ, "skipAutosaveOnLaunch", json_true()); + // skipLoadOnLaunch + if (context()->skipLoadOnLaunch) { + json_object_set_new(rootJ, "skipLoadOnLaunch", json_true()); } // moduleBrowser @@ -135,10 +132,10 @@ static void settingsFromJson(json_t *rootJ) { if (lastPathJ) context()->scene->rackWidget->lastPath = json_string_value(lastPathJ); - // skipAutosaveOnLaunch - json_t *skipAutosaveOnLaunchJ = json_object_get(rootJ, "skipAutosaveOnLaunch"); - if (skipAutosaveOnLaunchJ) - gSkipAutosaveOnLaunch = json_boolean_value(skipAutosaveOnLaunchJ); + // skipLoadOnLaunch + json_t *skipLoadOnLaunchJ = json_object_get(rootJ, "skipLoadOnLaunch"); + if (skipLoadOnLaunchJ) + context()->skipLoadOnLaunch = json_boolean_value(skipLoadOnLaunchJ); // moduleBrowser json_t *moduleBrowserJ = json_object_get(rootJ, "moduleBrowser"); diff --git a/src/ui.cpp b/src/ui.cpp index 3b0f1755..08164cd8 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -2,16 +2,17 @@ namespace rack { +namespace ui { -void uiInit(){ - uiSetTheme(nvgRGB(0x33, 0x33, 0x33), nvgRGB(0xf0, 0xf0, 0xf0)); +void init(){ + setTheme(nvgRGB(0x33, 0x33, 0x33), nvgRGB(0xf0, 0xf0, 0xf0)); } -void uiDestroy() { +void destroy() { } -void uiSetTheme(NVGcolor bg, NVGcolor fg) { +void setTheme(NVGcolor bg, NVGcolor fg) { // Assume dark background and light foreground BNDwidgetTheme w; @@ -58,7 +59,5 @@ void uiSetTheme(NVGcolor bg, NVGcolor fg) { } -std::shared_ptr gGuiFont; - - +} // namespace ui } // namespace rack