add Gui::getMousePos() that always gets map coords

develop
Myk Taylor 2022-09-18 08:19:02 -07:00
parent 3b89f482d1
commit 215a5b0a24
No known key found for this signature in database
4 changed files with 19 additions and 34 deletions

@ -126,10 +126,11 @@ namespace DFHack
DFHACK_EXPORT void showAutoAnnouncement(df::announcement_type type, df::coord pos, std::string message, int color = 7, bool bright = true, df::unit *unit1 = NULL, df::unit *unit2 = NULL); DFHACK_EXPORT void showAutoAnnouncement(df::announcement_type type, df::coord pos, std::string message, int color = 7, bool bright = true, df::unit *unit1 = NULL, df::unit *unit2 = NULL);
/* /*
* Cursor and window coords * Cursor and window map coords
*/ */
DFHACK_EXPORT df::coord getViewportPos(); DFHACK_EXPORT df::coord getViewportPos();
DFHACK_EXPORT df::coord getCursorPos(); DFHACK_EXPORT df::coord getCursorPos();
DFHACK_EXPORT df::coord getMousePos();
static const int AREA_MAP_WIDTH = 23; static const int AREA_MAP_WIDTH = 23;
static const int MENU_WIDTH = 30; static const int MENU_WIDTH = 30;
@ -162,8 +163,6 @@ namespace DFHack
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);
DFHACK_EXPORT bool setDesignationCoords (const int32_t x, const int32_t y, const int32_t z); DFHACK_EXPORT bool setDesignationCoords (const int32_t x, const int32_t y, const int32_t z);
DFHACK_EXPORT bool getMousePos (int32_t & x, int32_t & y);
// The distance from the z-level of the tile at map coordinates (x, y) to the closest ground z-level below // The distance from the z-level of the tile at map coordinates (x, y) to the closest ground z-level below
// Defaults to 0, unless overriden by plugins // Defaults to 0, unless overriden by plugins
DFHACK_EXPORT int getDepthAt (int32_t x, int32_t y); DFHACK_EXPORT int getDepthAt (int32_t x, int32_t y);

@ -1831,17 +1831,16 @@ bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t
return true; return true;
} }
bool Gui::getMousePos (int32_t & x, int32_t & y) // returns the map coordinates that the mouse cursor is over
df::coord Gui::getMousePos()
{ {
if (gps) { df::coord pos;
x = gps->mouse_x; if (gps && gps->mouse_x > -1) {
y = gps->mouse_y; pos = getViewportPos();
} pos.x += gps->mouse_x - 1;
else { pos.y += gps->mouse_y - 1;
x = -1;
y = -1;
} }
return (x == -1) ? false : true; return pos;
} }
int getDepthAt_default (int32_t x, int32_t y) int getDepthAt_default (int32_t x, int32_t y)

@ -135,13 +135,12 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
last_designation[2] = desig_z; last_designation[2] = desig_z;
out.print("Designation: %d %d %d\n",desig_x, desig_y, desig_z); out.print("Designation: %d %d %d\n",desig_x, desig_y, desig_z);
} }
int mouse_x, mouse_y; df:coord mousePos = Gui::getMousePos();
Gui::getMousePos(mouse_x,mouse_y); if(mousePos.x != last_mouse[0] || mousePos.y != last_mouse[1])
if(mouse_x != last_mouse[0] || mouse_y != last_mouse[1])
{ {
last_mouse[0] = mouse_x; last_mouse[0] = mousePos.x;
last_mouse[1] = mouse_y; last_mouse[1] = mousePos.y;
out.print("Mouse: %d %d\n",mouse_x, mouse_y); out.print("Mouse: %d %d\n",mousePos.x, mousePos.y);
} }
} }
return CR_OK; return CR_OK;

@ -53,23 +53,11 @@ static enum { None, Left, Right } drag_mode;
static df::coord get_mouse_pos(int32_t &mx, int32_t &my) static df::coord get_mouse_pos(int32_t &mx, int32_t &my)
{ {
df::coord pos; df::coord pos = Gui::getMousePos();
pos.x = -30000; pos.z -= Gui::getDepthAt(pos.x, pos.y);
if (!enabler->tracking_on)
return pos;
if (!Gui::getMousePos(mx, my))
return pos;
int32_t vx, vy, vz;
if (!Gui::getViewCoords(vx, vy, vz))
return pos;
pos.x = vx + mx - 1;
pos.y = vy + my - 1;
pos.z = vz - Gui::getDepthAt(mx, my);
mx = pos.x;
my = pos.y;
return pos; return pos;
} }