From 26922a95d34c9634f247d480034ec05f0c5347e7 Mon Sep 17 00:00:00 2001 From: Pascal <engelerp@phys.ethz.ch> Date: Thu, 27 Jul 2023 09:41:50 +0200 Subject: [PATCH] Added zoom shortcuts f1 f2 f3 --- gui/include/input_state.hpp | 3 +++ gui/src/input_state.cpp | 15 ++++++++++++ gui/src/main.cpp | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/gui/include/input_state.hpp b/gui/include/input_state.hpp index 3fdc915..a5bab2c 100644 --- a/gui/include/input_state.hpp +++ b/gui/include/input_state.hpp @@ -17,6 +17,9 @@ public: static bool b_click; static bool s_click; static bool g_click; + static bool f1_click; + static bool f2_click; + static bool f3_click; //mouse position static float mpos_x; diff --git a/gui/src/input_state.cpp b/gui/src/input_state.cpp index d31a575..f45f072 100644 --- a/gui/src/input_state.cpp +++ b/gui/src/input_state.cpp @@ -19,6 +19,9 @@ bool InputState::should_quit = false; bool InputState::b_click = false; bool InputState::s_click = false; bool InputState::g_click = false; +bool InputState::f1_click = false; +bool InputState::f2_click = false; +bool InputState::f3_click = false; void InputState::update(const unsigned width, const unsigned height) { //reset relative data @@ -30,6 +33,9 @@ void InputState::update(const unsigned width, const unsigned height) { b_click = false; s_click = false; g_click = false; + f1_click = false; + f2_click = false; + f3_click = false; SDL_Event event; while (SDL_PollEvent(&event)) { @@ -144,6 +150,15 @@ void InputState::update(const unsigned width, const unsigned height) { if (event.key.keysym.sym == SDLK_s) { s_click = true; } + if (event.key.keysym.sym == SDLK_F1) { + f1_click = true; + } + if (event.key.keysym.sym == SDLK_F2) { + f2_click = true; + } + if (event.key.keysym.sym == SDLK_F3) { + f3_click = true; + } break; case SDL_KEYUP: if (event.key.keysym.sym == SDLK_SPACE) { diff --git a/gui/src/main.cpp b/gui/src/main.cpp index 5e86b98..249b8e3 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -139,6 +139,7 @@ int main(int argc, char** argv) { #ifndef NDEBUG std::cout << "Zooming" << std::endl; #endif + std::cout << "Zooming " << InputState::mwheelmot_y << std::endl; //calculate position of mouse cursor in real world glm::vec2 m_real_world = camera.GetWorldXyFromMouse(InputState::mpos_x, InputState::mpos_y); //move camera to position pointed to by cursor @@ -148,6 +149,51 @@ int main(int argc, char** argv) { //process zoom (keep only this for central zoom) camera.ProcessMouseZoom(InputState::mwheelmot_y); } + else if (InputState::f1_click) { + //zoom 25 + //calculate position of mouse cursor in real world + glm::vec2 m_real_world = camera.GetWorldXyFromMouse(InputState::mpos_x, InputState::mpos_y); + //reset view and selection + camera.SetCameraView(eye, lookAt, upVector); + //move camera to position pointed to by cursor + camera.MoveTo(m_real_world); + //move mouse to screen center (doesn't visually work in remote desktop) + SDL_WarpMouseInWindow(infra.window(), WIDTH / 2, HEIGHT / 2); + //zoom to desired level + for (int i = 0; i < 25; ++i) { + camera.ProcessMouseZoom(1); + } + } + else if (InputState::f2_click) { + //zoom 40 + //calculate position of mouse cursor in real world + glm::vec2 m_real_world = camera.GetWorldXyFromMouse(InputState::mpos_x, InputState::mpos_y); + //reset view and selection + camera.SetCameraView(eye, lookAt, upVector); + //move camera to position pointed to by cursor + camera.MoveTo(m_real_world); + //move mouse to screen center (doesn't visually work in remote desktop) + SDL_WarpMouseInWindow(infra.window(), WIDTH / 2, HEIGHT / 2); + //zoom to desired level + for (int i = 0; i < 40; ++i) { + camera.ProcessMouseZoom(1); + } + } + else if (InputState::f3_click) { + //zoom 50 + //calculate position of mouse cursor in real world + glm::vec2 m_real_world = camera.GetWorldXyFromMouse(InputState::mpos_x, InputState::mpos_y); + //reset view and selection + camera.SetCameraView(eye, lookAt, upVector); + //move camera to position pointed to by cursor + camera.MoveTo(m_real_world); + //move mouse to screen center (doesn't visually work in remote desktop) + SDL_WarpMouseInWindow(infra.window(), WIDTH / 2, HEIGHT / 2); + //zoom to desired level + for (int i = 0; i < 50; ++i) { + camera.ProcessMouseZoom(1); + } + } SelectionManager::hoveredIndex = bottom_metal.selectObject(InputState::umpos_x, HEIGHT - InputState::umpos_y, projection, view, model); if (SelectionManager::hoveredIndex != -1) { SelectionManager::hoveredLayerName = bottom_metal.name(); -- GitLab