From d4cbaca3c01e05fbd240ac60799da4fe13ef187b Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Mon, 11 Nov 2019 11:09:03 +0200 Subject: [PATCH] Keyboard and mouse scroll controls --- applications/gui/src/screen.cpp | 28 +++++++++++++++++++++++++--- applications/gui/src/screen.hpp | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/applications/gui/src/screen.cpp b/applications/gui/src/screen.cpp index 28487057c..ab205ae2b 100644 --- a/applications/gui/src/screen.cpp +++ b/applications/gui/src/screen.cpp @@ -368,11 +368,28 @@ void ftl::gui::Screen::setActiveCamera(ftl::gui::Camera *cam) { } } +bool ftl::gui::Screen::scrollEvent(const Eigen::Vector2i &p, const Eigen::Vector2f &rel) { + if (nanogui::Screen::scrollEvent(p, rel)) { + return true; + } else { + zoom_ += zoom_ * 0.1f * rel[1]; + return true; + } +} + bool ftl::gui::Screen::mouseMotionEvent(const Eigen::Vector2i &p, const Eigen::Vector2i &rel, int button, int modifiers) { if (nanogui::Screen::mouseMotionEvent(p, rel, button, modifiers)) { return true; } else { - if (camera_) camera_->mouseMovement(rel[0], rel[1], button); + if (camera_) { + LOG(INFO) << "BUTTON = " << button << ", MOD = " << modifiers; + if (button == 1) { + camera_->mouseMovement(rel[0], rel[1], button); + } else if (button == 2) { + pos_x_ += rel[0]; + pos_y_ += -rel[1]; + } + } } return true; // TODO: return statement was missing; is true correct? } @@ -381,7 +398,10 @@ bool ftl::gui::Screen::mouseButtonEvent(const nanogui::Vector2i &p, int button, if (nanogui::Screen::mouseButtonEvent(p, button, down, modifiers)) { return true; } else { - if (camera_ && down) { + if (!camera_) return false; + + //ol movable = camera_->source()->hasCapabilities(ftl::rgbd::kCapMovable); + if (button == 0 && down) { Eigen::Vector2f screenSize = size().cast<float>(); auto mScale = (screenSize.cwiseQuotient(imageSize).minCoeff()); Eigen::Vector2f scaleFactor = mScale * imageSize.cwiseQuotient(screenSize); @@ -405,8 +425,10 @@ bool ftl::gui::Screen::mouseButtonEvent(const nanogui::Vector2i &p, int button, //lookPoint_ = Eigen::Vector3f(worldPos[0],worldPos[1],worldPos[2]); //LOG(INFO) << "Depth at click = " << -camPos[2]; return true; + } else { + } - return false; + return false; } } diff --git a/applications/gui/src/screen.hpp b/applications/gui/src/screen.hpp index ecdbf7c91..a195f4ccd 100644 --- a/applications/gui/src/screen.hpp +++ b/applications/gui/src/screen.hpp @@ -29,6 +29,7 @@ class Screen : public nanogui::Screen { ~Screen(); bool mouseMotionEvent(const Eigen::Vector2i &p, const Eigen::Vector2i &rel, int button, int modifiers); + bool scrollEvent(const Eigen::Vector2i &p, const Eigen::Vector2f &rel); bool mouseButtonEvent(const nanogui::Vector2i &p, int button, bool down, int modifiers); bool keyboardEvent(int key, int scancode, int action, int modifiers); -- GitLab