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;