From 6800cc7493a88f1f285595f7714d06e501ff0cdf Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 10 Dec 2019 14:55:07 -0500 Subject: [PATCH] Add back "allowCursorLock" to settings and menu bar. --- include/settings.hpp | 5 ++--- src/app/Knob.cpp | 8 ++++---- src/app/MenuBar.cpp | 13 +++++++++++-- src/settings.cpp | 12 ++++++------ src/window.cpp | 6 ++++++ 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/include/settings.hpp b/include/settings.hpp index d2bd87dc..df1c6ec1 100644 --- a/include/settings.hpp +++ b/include/settings.hpp @@ -27,12 +27,11 @@ extern float zoom; extern bool invertZoom; extern float cableOpacity; extern float cableTension; +extern bool allowCursorLock; enum KnobMode { - KNOB_MODE_LINEAR_LOCKED = 0, KNOB_MODE_LINEAR, - KNOB_MODE_SCALED_LINEAR_LOCKED = 100, KNOB_MODE_SCALED_LINEAR, - KNOB_MODE_ROTARY_ABSOLUTE = 200, + KNOB_MODE_ROTARY_ABSOLUTE, KNOB_MODE_ROTARY_RELATIVE, }; extern KnobMode knobMode; diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index 1c37eaf0..808a3767 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -71,7 +71,7 @@ void Knob::onDragStart(const event::DragStart& e) { } settings::KnobMode km = settings::knobMode; - if (km == settings::KNOB_MODE_LINEAR_LOCKED || km == settings::KNOB_MODE_SCALED_LINEAR_LOCKED) { + if (km == settings::KNOB_MODE_LINEAR || km == settings::KNOB_MODE_SCALED_LINEAR) { APP->window->cursorLock(); } // Only changed for KNOB_MODE_LINEAR_*. @@ -88,7 +88,7 @@ void Knob::onDragEnd(const event::DragEnd& e) { return; settings::KnobMode km = settings::knobMode; - if (km == settings::KNOB_MODE_LINEAR_LOCKED || km == settings::KNOB_MODE_SCALED_LINEAR_LOCKED) { + if (km == settings::KNOB_MODE_LINEAR || km == settings::KNOB_MODE_SCALED_LINEAR) { APP->window->cursorUnlock(); } @@ -115,7 +115,7 @@ void Knob::onDragMove(const event::DragMove& e) { return; settings::KnobMode km = settings::knobMode; - bool linearMode = (km < settings::KNOB_MODE_ROTARY_ABSOLUTE) || forceLinear; + bool linearMode = (km == settings::KNOB_MODE_LINEAR || km == settings::KNOB_MODE_SCALED_LINEAR) || forceLinear; engine::ParamQuantity* pq = getParamQuantity(); if (pq) { @@ -150,7 +150,7 @@ void Knob::onDragMove(const event::DragMove& e) { delta *= rangeRatio; // Scale delta if in scaled linear knob mode - if (km == settings::KNOB_MODE_SCALED_LINEAR_LOCKED || km == settings::KNOB_MODE_SCALED_LINEAR) { + if (km == settings::KNOB_MODE_SCALED_LINEAR) { float deltaY = (horizontal ? -e.mouseDelta.y : -e.mouseDelta.x); const float pixelTau = 200.f; internal->linearScale *= std::pow(2.f, deltaY / pixelTau); diff --git a/src/app/MenuBar.cpp b/src/app/MenuBar.cpp index 57abb33f..f14da2e5 100644 --- a/src/app/MenuBar.cpp +++ b/src/app/MenuBar.cpp @@ -317,6 +317,12 @@ struct ParamTooltipItem : ui::MenuItem { } }; +struct AllowCursorLockItem : ui::MenuItem { + void onAction(const event::Action& e) override { + settings::allowCursorLock ^= true; + } +}; + struct KnobModeValueItem : ui::MenuItem { settings::KnobMode knobMode; void onAction(const event::Action& e) override { @@ -329,9 +335,7 @@ struct KnobModeItem : ui::MenuItem { ui::Menu* menu = new ui::Menu; static const std::vector> knobModes = { - {settings::KNOB_MODE_LINEAR_LOCKED, "Linear (locked cursor)"}, {settings::KNOB_MODE_LINEAR, "Linear"}, - {settings::KNOB_MODE_SCALED_LINEAR_LOCKED, "Scaled linear (locked cursor)"}, {settings::KNOB_MODE_SCALED_LINEAR, "Scaled linear"}, {settings::KNOB_MODE_ROTARY_ABSOLUTE, "Absolute rotary"}, {settings::KNOB_MODE_ROTARY_RELATIVE, "Relative rotary"}, @@ -394,6 +398,11 @@ struct ViewButton : MenuButton { paramTooltipItem->rightText = CHECKMARK(settings::paramTooltip); menu->addChild(paramTooltipItem); + AllowCursorLockItem* allowCursorLockItem = new AllowCursorLockItem; + allowCursorLockItem->text = "Allow cursor lock"; + allowCursorLockItem->rightText = CHECKMARK(settings::allowCursorLock); + menu->addChild(allowCursorLockItem); + KnobModeItem* knobModeItem = new KnobModeItem; knobModeItem->text = "Knob mode"; knobModeItem->rightText = RIGHT_ARROW; diff --git a/src/settings.cpp b/src/settings.cpp index 4781d9b0..dbe92849 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -22,7 +22,8 @@ float zoom = 0.0; bool invertZoom = false; float cableOpacity = 0.5; float cableTension = 0.5; -KnobMode knobMode = KNOB_MODE_LINEAR_LOCKED; +bool allowCursorLock = true; +KnobMode knobMode = KNOB_MODE_LINEAR; float knobLinearSensitivity = 0.001f; float sampleRate = 44100.0; int threadCount = 1; @@ -66,6 +67,8 @@ json_t* toJson() { json_object_set_new(rootJ, "cableTension", json_real(cableTension)); + json_object_set_new(rootJ, "allowCursorLock", json_boolean(allowCursorLock)); + json_object_set_new(rootJ, "knobMode", json_integer((int) knobMode)); json_object_set_new(rootJ, "knobLinearSensitivity", json_real(knobLinearSensitivity)); @@ -144,12 +147,9 @@ void fromJson(json_t* rootJ) { if (cableTensionJ) cableTension = json_number_value(cableTensionJ); - // legacy v1 json_t* allowCursorLockJ = json_object_get(rootJ, "allowCursorLock"); - if (allowCursorLockJ) { - if (json_is_false(allowCursorLockJ)) - knobMode = KNOB_MODE_LINEAR; - } + if (allowCursorLockJ) + allowCursorLock = json_boolean_value(allowCursorLockJ); json_t* knobModeJ = json_object_get(rootJ, "knobMode"); if (knobModeJ) diff --git a/src/window.cpp b/src/window.cpp index fab980bb..979c1f09 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -478,6 +478,9 @@ void Window::close() { } void Window::cursorLock() { + if (!settings::allowCursorLock) + return; + #if defined ARCH_MAC glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); #else @@ -487,6 +490,9 @@ void Window::cursorLock() { } void Window::cursorUnlock() { + if (!settings::allowCursorLock) + return; + glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_NORMAL); internal->ignoreNextMouseDelta = true; }