From 5c85d15caa1f40d0a015295c59eaf2ebb73c571b Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 4 Mar 2026 08:46:39 +0000 Subject: [PATCH] Add method to convert point on screen (e.g. mouse) to work area co-ordinates --- riscos_toolbox/objects/window.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/riscos_toolbox/objects/window.py b/riscos_toolbox/objects/window.py index 77e74b8..f3ae06b 100644 --- a/riscos_toolbox/objects/window.py +++ b/riscos_toolbox/objects/window.py @@ -171,6 +171,26 @@ def set_toolbar_id(self, tool_bar, window_id): swi.swi('Toolbox_ObjectMiscOp', swi_fmt, tool_bar, self.id, Window.SetToolBars, window_id) + def screen_to_work_area(self, point): + """Returns the point translated to work area co-ordinates of the window.""" + + class WindowState(ctypes.Structure): + _fields_ = [ + ("window_handle", ctypes.c_int32), + ("visible", BBox), + ("scroll", Point), + ("behind", ctypes.c_int32), + ("flags", ctypes.c_uint32) + ] + + state = WindowState() + state.window_handle = self.wimp_handle + swi.swi("Wimp_GetWindowState", ".I", ctypes.addressof(state)) + + return Point(point.x - state.visible.min.x + state.scroll.x, + point.y - state.visible.max.y + state.scroll.y) + + class WindowAboutToBeShownEvent(AboutToBeShownEvent): event_id = Window.AboutToBeShown