From 768c95ecb6f3458f81536c901e1bb4cded7aaecc Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 16 Dec 2022 11:53:44 -0800 Subject: [PATCH] absorb Putnam's work on Screen --- library/include/modules/Screen.h | 1 + library/modules/Screen.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/library/include/modules/Screen.h b/library/include/modules/Screen.h index 9be09fa67..347df1011 100644 --- a/library/include/modules/Screen.h +++ b/library/include/modules/Screen.h @@ -178,6 +178,7 @@ namespace DFHack }; DFHACK_EXPORT df::coord2d getMousePos(); + DFHACK_EXPORT df::coord2d getMousePixels(); DFHACK_EXPORT df::coord2d getWindowSize(); inline rect2d getScreenRect() { diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index 60967d771..38611e5ce 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -79,12 +79,23 @@ using std::string; // returns text grid coordinates, even if the game map is scaled differently df::coord2d Screen::getMousePos() { - int32_t a, b, r, f; - if (!enabler || !enabler->renderer->get_mouse_coords(&a, &b, &r, &f)) { + int32_t pixelx = 0, pixely = 0, tilex = 0, tiley = 0; + if (!enabler || !enabler->renderer->get_mouse_coords( + &pixelx, &pixely, &tilex, &tiley)) { return df::coord2d(-1, -1); } - std::cerr << "a,b,r,f = " << a << ", " << b << ", " << r << ", " << f << std::endl; - return df::coord2d(-1, -1); + return df::coord2d(tilex, tiley); +} + +// returns the screen pixel coordinates +df::coord2d Screen::getMousePixels() +{ + int32_t pixelx = 0, pixely = 0, tilex = 0, tiley = 0; + if (!enabler || !enabler->renderer->get_mouse_coords( + &pixelx, &pixely, &tilex, &tiley)) { + return df::coord2d(-1, -1); + } + return df::coord2d(pixelx, pixely); } df::coord2d Screen::getWindowSize()