From 52d41865ef08740c490932b59ed0462b524d5d85 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 19 Sep 2017 21:48:05 -0400 Subject: [PATCH] Add allowCursorLock setting for touch screens and tablets Prevent MomentarySwitch from randomizing --- include/app.hpp | 3 +++ include/gui.hpp | 1 + src/app/ModuleWidget.cpp | 2 +- src/app/ParamWidget.cpp | 5 +++++ src/gui.cpp | 14 ++++++++++---- src/settings.cpp | 10 ++++++++++ src/widgets/SVGWidget.cpp | 6 ++++-- 7 files changed, 34 insertions(+), 7 deletions(-) diff --git a/include/app.hpp b/include/app.hpp index 98998762..b1d97b65 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -146,6 +146,7 @@ struct ParamWidget : OpaqueWidget, QuantityWidget { json_t *toJson(); void fromJson(json_t *root); + virtual void randomize(); void onMouseDownOpaque(int button); void onChange(); }; @@ -227,6 +228,8 @@ struct ToggleSwitch : virtual Switch { /** A switch that is turned on when held */ struct MomentarySwitch : virtual Switch { + /** Don't randomize state */ + void randomize() {} void onDragStart() { setValue(maxValue); } diff --git a/include/gui.hpp b/include/gui.hpp index 78138cea..9262a08c 100644 --- a/include/gui.hpp +++ b/include/gui.hpp @@ -19,6 +19,7 @@ extern GLFWwindow *gWindow; extern NVGcontext *gVg; extern std::shared_ptr gGuiFont; extern float gPixelRatio; +extern bool gAllowCursorLock; void guiInit(); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 1847d425..c638063c 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -115,7 +115,7 @@ void ModuleWidget::initialize() { void ModuleWidget::randomize() { for (ParamWidget *param : params) { - param->setValue(rescalef(randomf(), 0.0, 1.0, param->minValue, param->maxValue)); + param->randomize(); } if (module) { module->randomize(); diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index 50e11f09..c13c1b45 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -4,6 +4,7 @@ namespace rack { + json_t *ParamWidget::toJson() { json_t *paramJ = json_real(value); return paramJ; @@ -13,6 +14,10 @@ void ParamWidget::fromJson(json_t *rootJ) { setValue(json_number_value(rootJ)); } +void ParamWidget::randomize() { + setValue(rescalef(randomf(), 0.0, 1.0, minValue, maxValue)); +} + void ParamWidget::onMouseDownOpaque(int button) { if (button == 1) { setValue(defaultValue); diff --git a/src/gui.cpp b/src/gui.cpp index dac180f8..de7d1d69 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -14,6 +14,7 @@ #define BLENDISH_IMPLEMENTATION #include "../ext/oui-blendish/blendish.h" #define NANOSVG_IMPLEMENTATION +#define NANOSVG_ALL_COLOR_KEYWORDS #include "../ext/nanosvg/src/nanosvg.h" #ifdef ARCH_MAC @@ -24,9 +25,10 @@ namespace rack { GLFWwindow *gWindow = NULL; -std::shared_ptr gGuiFont; NVGcontext *gVg = NULL; +std::shared_ptr gGuiFont; float gPixelRatio = 0.0; +bool gAllowCursorLock = true; void windowSizeCallback(GLFWwindow* window, int width, int height) { @@ -307,15 +309,19 @@ void guiClose() { } void guiCursorLock() { + if (gAllowCursorLock) { #ifdef ARCH_MAC - glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); #else - glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED); + glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED); #endif + } } void guiCursorUnlock() { - glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + if (gAllowCursorLock) { + glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + } } bool guiIsModPressed() { diff --git a/src/settings.cpp b/src/settings.cpp index 6a79e951..e8151d7f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,5 +1,6 @@ #include "settings.hpp" #include "app.hpp" +#include "gui.hpp" #include "plugin.hpp" #include @@ -25,6 +26,10 @@ static json_t *settingsToJson() { json_t *tensionJ = json_real(tension); json_object_set_new(rootJ, "wireTension", tensionJ); + // allowCursorLock + json_t *allowCursorLockJ = json_boolean(gAllowCursorLock); + json_object_set_new(rootJ, "allowCursorLock", allowCursorLockJ); + return rootJ; } @@ -43,6 +48,11 @@ static void settingsFromJson(json_t *rootJ) { json_t *tensionJ = json_object_get(rootJ, "wireTension"); if (tensionJ) dynamic_cast(gScene)->toolbar->wireTensionSlider->value = json_number_value(tensionJ); + + // allowCursorLock + json_t *allowCursorLockJ = json_object_get(rootJ, "allowCursorLock"); + if (allowCursorLockJ) + gAllowCursorLock = json_is_true(allowCursorLockJ); } diff --git a/src/widgets/SVGWidget.cpp b/src/widgets/SVGWidget.cpp index e71afaa8..56a7834f 100644 --- a/src/widgets/SVGWidget.cpp +++ b/src/widgets/SVGWidget.cpp @@ -44,8 +44,10 @@ static void drawSVG(NVGcontext *vg, NSVGimage *svg) { if (path->closed) nvgClosePath(vg); - if (path->next) - nvgPathWinding(vg, NVG_HOLE); + // if () + // nvgPathWinding(vg, NVG_SOLID); + // else + // nvgPathWinding(vg, NVG_HOLE); } // Fill shape