From bc2a4ff140a249c113fe3e4d805392c182c1334a Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 21 Jan 2025 00:37:36 -0700 Subject: [PATCH] Restore mouse support to orbits window The old mouse code worked by faking up key presses for all the mouse movements. We want to move away from this style of mouse handling and move towards handling mouse events directly. The orbit window handling would block waiting for keyboard input through the cursor. Our indirect method of handling mouse events updates the cursor position, so add a flag on the Cursor object that unblocks waiting for a key press if the position was updated externally. This unblocks the Cursor key press code once and allows the orbits window to continue. --- libid/engine/jiim.cpp | 14 +++++++------- libid/include/ui/editpal.h | 1 + libid/ui/editpal.cpp | 4 +++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libid/engine/jiim.cpp b/libid/engine/jiim.cpp index 495919779..e8d1618ed 100644 --- a/libid/engine/jiim.cpp +++ b/libid/engine/jiim.cpp @@ -1194,7 +1194,13 @@ bool InverseJulia::iterate() { bool still{true}; bool mouse_updated{}; - if (m_actively_computing) + if (s_cursor.get_x() != g_col || s_cursor.get_y() != g_row) + { + g_col = s_cursor.get_x(); + g_row = s_cursor.get_y(); + mouse_updated = true; + } + if (m_actively_computing || mouse_updated) { s_cursor.check_blink(); } @@ -1202,12 +1208,6 @@ bool InverseJulia::iterate() { s_cursor.wait_key(); } - if (s_cursor.get_x() != g_col || s_cursor.get_y() != g_row) - { - g_col = s_cursor.get_x(); - g_row = s_cursor.get_y(); - mouse_updated = true; - } if (driver_key_pressed() || m_first_time || mouse_updated) { m_first_time = false; diff --git a/libid/include/ui/editpal.h b/libid/include/ui/editpal.h index d444f00f6..051301cfd 100644 --- a/libid/include/ui/editpal.h +++ b/libid/include/ui/editpal.h @@ -53,6 +53,7 @@ class CrossHairCursor int m_hidden; // >0 if mouse hidden long m_last_blink; bool m_blink; + bool m_pos_updated{}; char m_top[CURSOR_SIZE]; // save line segments here char m_bottom[CURSOR_SIZE]; char m_left[CURSOR_SIZE]; diff --git a/libid/ui/editpal.cpp b/libid/ui/editpal.cpp index 889ef6adb..98f602a12 100644 --- a/libid/ui/editpal.cpp +++ b/libid/ui/editpal.cpp @@ -1101,6 +1101,7 @@ void CrossHairCursor::set_pos(int x, int y) m_x = x; m_y = y; + m_pos_updated = true; if (!m_hidden) { @@ -1170,10 +1171,11 @@ void CrossHairCursor::check_blink() int CrossHairCursor::wait_key() { - while (!driver_wait_key_pressed(true)) + while (!driver_wait_key_pressed(true) && !m_pos_updated) { check_blink(); } + m_pos_updated = false; return driver_key_pressed(); }