add getCursorCoords overload for df::coord

and factor out active cursor detection
develop
myk002 2021-05-15 12:05:00 -07:00
parent 95d97b929e
commit aff5c9bf35
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 16 additions and 2 deletions

@ -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 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 (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 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); DFHACK_EXPORT bool getDesignationCoords (int32_t &x, int32_t &y, int32_t &z);

@ -648,13 +648,18 @@ bool Gui::item_details_hotkey(df::viewscreen *top)
return !!strict_virtual_cast<df::viewscreen_itemst>(top); return !!strict_virtual_cast<df::viewscreen_itemst>(top);
} }
static bool has_cursor()
{
return df::global::cursor && df::global::cursor->x != -30000;
}
bool Gui::cursor_hotkey(df::viewscreen *top) bool Gui::cursor_hotkey(df::viewscreen *top)
{ {
if (!dwarfmode_hotkey(top)) if (!dwarfmode_hotkey(top))
return false; return false;
// Also require the cursor. // Also require the cursor.
if (!df::global::cursor || df::global::cursor->x == -30000) if (!has_cursor())
return false; return false;
return true; return true;
@ -1788,7 +1793,15 @@ bool Gui::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
x = df::global::cursor->x; x = df::global::cursor->x;
y = df::global::cursor->y; y = df::global::cursor->y;
z = df::global::cursor->z; 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? //FIXME: confine writing of coords to map bounds?