From dbc5001bd8947731b676742f1329830eba1a6db0 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 18 Sep 2022 13:27:13 -0700 Subject: [PATCH] fail if mouse cursor isn't over the map area --- library/modules/Gui.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index f9e15aac4..56aa09b7f 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -1836,6 +1836,12 @@ df::coord Gui::getMousePos() { df::coord pos; if (gps && gps->mouse_x > -1) { + // return invalid coords if the cursor is not over the map + DwarfmodeDims dims = getDwarfmodeViewDims(); + if (gps->mouse_x < dims.map_x1 || gps->mouse_x > dims.map_x2 || + gps->mouse_y < dims.map_y1 || gps->mouse_y > dims.map_y2) { + return pos; + } pos = getViewportPos(); pos.x += gps->mouse_x - 1; pos.y += gps->mouse_y - 1;