From aff5c9bf35448a1a6ba93c8ade2e4d083b4af0d7 Mon Sep 17 00:00:00 2001 From: myk002 Date: Sat, 15 May 2021 12:05:00 -0700 Subject: [PATCH] add getCursorCoords overload for df::coord and factor out active cursor detection --- library/include/modules/Gui.h | 1 + library/modules/Gui.cpp | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/library/include/modules/Gui.h b/library/include/modules/Gui.h index 819ad1558..455032fea 100644 --- a/library/include/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -156,6 +156,7 @@ namespace DFHack DFHACK_EXPORT bool setViewCoords (const int32_t x, const int32_t y, const int32_t z); DFHACK_EXPORT bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z); + DFHACK_EXPORT bool getCursorCoords (df::coord &pos); DFHACK_EXPORT bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z); DFHACK_EXPORT bool getDesignationCoords (int32_t &x, int32_t &y, int32_t &z); diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 3ba851438..04225e111 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -648,13 +648,18 @@ bool Gui::item_details_hotkey(df::viewscreen *top) return !!strict_virtual_cast(top); } +static bool has_cursor() +{ + return df::global::cursor && df::global::cursor->x != -30000; +} + bool Gui::cursor_hotkey(df::viewscreen *top) { if (!dwarfmode_hotkey(top)) return false; // Also require the cursor. - if (!df::global::cursor || df::global::cursor->x == -30000) + if (!has_cursor()) return false; return true; @@ -1788,7 +1793,15 @@ bool Gui::getCursorCoords (int32_t &x, int32_t &y, int32_t &z) x = df::global::cursor->x; y = df::global::cursor->y; z = df::global::cursor->z; - return (x == -30000) ? false : true; + return has_cursor(); +} + +bool Gui::getCursorCoords (df::coord &pos) +{ + pos.x = df::global::cursor->x; + pos.y = df::global::cursor->y; + pos.z = df::global::cursor->z; + return has_cursor(); } //FIXME: confine writing of coords to map bounds?