From b17a19125c657061ab978e92ad42c320392b952a Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Mon, 11 Nov 2019 10:50:49 +0200
Subject: [PATCH] Zoom and pan in GUI

---
 applications/gui/src/screen.cpp | 18 ++++++++++++++++--
 applications/gui/src/screen.hpp |  3 +++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/applications/gui/src/screen.cpp b/applications/gui/src/screen.cpp
index 3b2aae1aa..28487057c 100644
--- a/applications/gui/src/screen.cpp
+++ b/applications/gui/src/screen.cpp
@@ -72,6 +72,20 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl
 	has_vr_ = vr::VR_IsHmdPresent();
 	#endif
 
+	zoom_ = root_->value("zoom", 1.0f);
+	root_->on("zoom", [this](const ftl::config::Event &e) {
+		zoom_ = root_->value("zoom", 1.0f);
+	});
+
+	pos_x_ = root_->value("position_x", 0.0f);
+	root_->on("position_x", [this](const ftl::config::Event &e) {
+		pos_x_ = root_->value("position_x", 0.0f);
+	});
+	pos_y_ = root_->value("position_y", 0.0f);
+	root_->on("position_y", [this](const ftl::config::Event &e) {
+		pos_y_ = root_->value("position_y", 0.0f);
+	});
+
 	setSize(Vector2i(1280,720));
 
 	toolbuttheme = new Theme(*theme());
@@ -446,9 +460,9 @@ void ftl::gui::Screen::draw(NVGcontext *ctx) {
 		#endif
 
 		if (mImageID < std::numeric_limits<unsigned int>::max() && imageSize[0] > 0) {
-			auto mScale = (screenSize.cwiseQuotient(imageSize).minCoeff());
+			auto mScale = (screenSize.cwiseQuotient(imageSize).minCoeff()) * zoom_;
 			Vector2f scaleFactor = mScale * imageSize.cwiseQuotient(screenSize);
-			Vector2f positionInScreen(0.0f, 0.0f);
+			Vector2f positionInScreen(pos_x_, pos_y_);
 			auto mOffset = (screenSize - (screenSize.cwiseProduct(scaleFactor))) / 2;
 			Vector2f positionAfterOffset = positionInScreen + mOffset;
 			Vector2f imagePosition = positionAfterOffset.cwiseQuotient(screenSize);
diff --git a/applications/gui/src/screen.hpp b/applications/gui/src/screen.hpp
index a0ac39d06..ecdbf7c91 100644
--- a/applications/gui/src/screen.hpp
+++ b/applications/gui/src/screen.hpp
@@ -92,6 +92,9 @@ class Screen : public nanogui::Screen {
 	ftl::Configurable *root_;
 	std::string status_;
 	ftl::gui::Camera *camera_;
+	float zoom_;
+	float pos_x_;
+	float pos_y_;
 
 	GLuint leftEye_;
 	GLuint rightEye_;
-- 
GitLab