From 04be72fc5447aeddba4fcb80968bb8e3c0ee619d Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 4 Aug 2021 12:38:00 -0400 Subject: [PATCH] Handle arrow key scrolling in Scene instead of RackScrollWidget in case the mouse is not hovering the RackScrollWidget. --- src/app/RackScrollWidget.cpp | 30 ------------------------------ src/app/Scene.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/app/RackScrollWidget.cpp b/src/app/RackScrollWidget.cpp index aecc0cf4..c80dfee1 100644 --- a/src/app/RackScrollWidget.cpp +++ b/src/app/RackScrollWidget.cpp @@ -110,36 +110,6 @@ void RackScrollWidget::draw(const DrawArgs& args) { void RackScrollWidget::onHoverKey(const HoverKeyEvent& e) { ScrollWidget::onHoverKey(e); - if (e.isConsumed()) - return; - - // Scroll with arrow keys - float arrowSpeed = 32.f; - if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) - arrowSpeed /= 4.f; - if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) - arrowSpeed *= 4.f; - if ((e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) - arrowSpeed /= 16.f; - - if (e.action == RACK_HELD) { - if (e.key == GLFW_KEY_LEFT) { - offset.x -= arrowSpeed; - e.consume(this); - } - if (e.key == GLFW_KEY_RIGHT) { - offset.x += arrowSpeed; - e.consume(this); - } - if (e.key == GLFW_KEY_UP) { - offset.y -= arrowSpeed; - e.consume(this); - } - if (e.key == GLFW_KEY_DOWN) { - offset.y += arrowSpeed; - e.consume(this); - } - } } diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index b5fb84b0..29220da0 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -238,6 +238,34 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { e.consume(this); } } + + // Scroll RackScrollWidget with arrow keys + if (e.action == RACK_HELD) { + float arrowSpeed = 32.f; + if ((e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) + arrowSpeed /= 4.f; + if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) + arrowSpeed *= 4.f; + if ((e.mods & RACK_MOD_MASK) == (RACK_MOD_CTRL | GLFW_MOD_SHIFT)) + arrowSpeed /= 16.f; + + if (e.key == GLFW_KEY_LEFT) { + rackScroll->offset.x -= arrowSpeed; + e.consume(this); + } + if (e.key == GLFW_KEY_RIGHT) { + rackScroll->offset.x += arrowSpeed; + e.consume(this); + } + if (e.key == GLFW_KEY_UP) { + rackScroll->offset.y -= arrowSpeed; + e.consume(this); + } + if (e.key == GLFW_KEY_DOWN) { + rackScroll->offset.y += arrowSpeed; + e.consume(this); + } + } } void Scene::onPathDrop(const PathDropEvent& e) {