From b90f9bd31275f03808332ed63c9a955ebc4f42af Mon Sep 17 00:00:00 2001 From: camierjs Date: Fri, 30 Jan 2026 10:30:25 -0800 Subject: [PATCH 1/2] Enable q/Q key mode --- lib/aux_vis.cpp | 3 ++- lib/aux_vis.hpp | 2 +- lib/glwindow.hpp | 7 +++++-- lib/window.cpp | 6 ++++++ lib/window.hpp | 4 ++++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/aux_vis.cpp b/lib/aux_vis.cpp index 8c886ade..6e597a6f 100644 --- a/lib/aux_vis.cpp +++ b/lib/aux_vis.cpp @@ -1356,8 +1356,9 @@ void KeyCtrlP() #endif } -void KeyQPressed() +void KeyQPressed(SDL_Keymod state) { + if (state & KMOD_SHIFT) { return Window::SwitchSolution(); } wnd->signalQuit(); visualize = 0; } diff --git a/lib/aux_vis.hpp b/lib/aux_vis.hpp index 98f48cb0..eb68471e 100644 --- a/lib/aux_vis.hpp +++ b/lib/aux_vis.hpp @@ -68,7 +68,7 @@ void TouchPinch(SDL_MultiGestureEvent & e); void KeyCtrlP(); void KeyS(); -void KeyQPressed(); +void KeyQPressed(SDL_Keymod); void ToggleThreads(); void ThreadsPauseFunc(SDL_Keymod); void ThreadsStop(); diff --git a/lib/glwindow.hpp b/lib/glwindow.hpp index b0da9d50..8110c657 100644 --- a/lib/glwindow.hpp +++ b/lib/glwindow.hpp @@ -95,11 +95,14 @@ class GLWindow void setOnIdle(IdleDelegate func) { onIdle = func; } void setOnExpose(Delegate func) { onExpose = func; } - void setOnKeyDown(SDL_Keycode key, Delegate func) + void setOnKeyDown(SDL_Keycode key, KeyDelegate func) { + onKeyDown[key] = [func](SDL_Keymod) { func(SDL_GetModState()); }; + } + + void setOnKeyDown(SDL_Keycode key, Delegate func) { onKeyDown[key] = [func](SDL_Keymod) { func(); }; } - void setOnKeyDown(SDL_Keycode key, KeyDelegate func) { onKeyDown[key] = func; } void setOnMouseDown(SDL_Mousebutton btn, MouseDelegate func) { onMouseDown[btn] = func; } void setOnMouseUp(SDL_Mousebutton btn, MouseDelegate func) { onMouseUp[btn] = func; } diff --git a/lib/window.cpp b/lib/window.cpp index 3b850b15..cf30d1c4 100644 --- a/lib/window.cpp +++ b/lib/window.cpp @@ -270,3 +270,9 @@ void Window::SwitchQuadSolution() locwin->SwitchQuadSolution((DataState::QuadSolution)iqs); SendExposeEvent(); } + +void Window::SwitchSolution() +{ + if (locwin->data_state.cgrid_f) { SwitchComplexSolution(); } + if (locwin->data_state.quad_f) { SwitchQuadSolution(); } +} \ No newline at end of file diff --git a/lib/window.hpp b/lib/window.hpp index 9e81cc06..feb2a7f9 100644 --- a/lib/window.hpp +++ b/lib/window.hpp @@ -93,6 +93,10 @@ struct Window /// @note: Use with caution when the update is compatible /// @see SetNewMeshAndSolution() void ResetMeshAndSolution(DataState &ss); + +public: + /// Switch the function representation for key handlers + static void SwitchSolution(); }; #endif // GLVIS_WINDOW_HPP From e7967e493e0a84e7db314cbb61c0068be5b9275d Mon Sep 17 00:00:00 2001 From: camierjs Date: Fri, 30 Jan 2026 10:31:25 -0800 Subject: [PATCH 2/2] Style and EOF --- lib/glwindow.hpp | 3 ++- lib/window.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/glwindow.hpp b/lib/glwindow.hpp index 8110c657..c9abd6ff 100644 --- a/lib/glwindow.hpp +++ b/lib/glwindow.hpp @@ -100,7 +100,8 @@ class GLWindow onKeyDown[key] = [func](SDL_Keymod) { func(SDL_GetModState()); }; } - void setOnKeyDown(SDL_Keycode key, Delegate func) { + void setOnKeyDown(SDL_Keycode key, Delegate func) + { onKeyDown[key] = [func](SDL_Keymod) { func(); }; } diff --git a/lib/window.cpp b/lib/window.cpp index cf30d1c4..b2e42132 100644 --- a/lib/window.cpp +++ b/lib/window.cpp @@ -275,4 +275,4 @@ void Window::SwitchSolution() { if (locwin->data_state.cgrid_f) { SwitchComplexSolution(); } if (locwin->data_state.quad_f) { SwitchQuadSolution(); } -} \ No newline at end of file +}