From c3a13dc112469b2d9eeeb1a04c2ccb0d5d42764a Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 2 Oct 2017 01:38:03 -0400 Subject: [PATCH] Added arrow keys to move --- include/widgets.hpp | 1 + src/widgets/ScrollWidget.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/widgets.hpp b/include/widgets.hpp index 4c12fabc..1487f2d2 100644 --- a/include/widgets.hpp +++ b/include/widgets.hpp @@ -382,6 +382,7 @@ struct ScrollWidget : OpaqueWidget { ScrollWidget(); void step(); + Widget *onMouseMove(Vec pos, Vec mouseRel); bool onScrollOpaque(Vec scrollRel); }; diff --git a/src/widgets/ScrollWidget.cpp b/src/widgets/ScrollWidget.cpp index 4c0f8d52..b976a0e9 100644 --- a/src/widgets/ScrollWidget.cpp +++ b/src/widgets/ScrollWidget.cpp @@ -35,6 +35,23 @@ void ScrollWidget::step() { Widget::step(); } +Widget *ScrollWidget::onMouseMove(Vec pos, Vec mouseRel) { + const float arrowSpeed = 50.0; + if (glfwGetKey(gWindow, GLFW_KEY_LEFT) == GLFW_PRESS) { + offset = offset.minus(Vec(1, 0).mult(arrowSpeed)); + } + if (glfwGetKey(gWindow, GLFW_KEY_RIGHT) == GLFW_PRESS) { + offset = offset.minus(Vec(-1, 0).mult(arrowSpeed)); + } + if (glfwGetKey(gWindow, GLFW_KEY_UP) == GLFW_PRESS) { + offset = offset.minus(Vec(0, 1).mult(arrowSpeed)); + } + if (glfwGetKey(gWindow, GLFW_KEY_DOWN) == GLFW_PRESS) { + offset = offset.minus(Vec(0, -1).mult(arrowSpeed)); + } + return OpaqueWidget::onMouseMove(pos, mouseRel); +} + bool ScrollWidget::onScrollOpaque(Vec scrollRel) { offset = offset.minus(scrollRel); return true;