From 07f8fad7876047aeec46b1d6ba61565a236772fa Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 28 Dec 2022 16:00:10 -0800 Subject: [PATCH] implement Gui::getMousePos and Gui::getDepthAt --- library/modules/Gui.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 4b600a661..71a166b89 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -61,6 +61,7 @@ using namespace DFHack; #include "df/general_ref.h" #include "df/global_objects.h" #include "df/graphic.h" +#include "df/graphic_viewportst.h" #include "df/historical_figure.h" #include "df/interfacest.h" #include "df/item_corpsepiecest.h" @@ -2151,16 +2152,24 @@ df::coord Gui::getMousePos() df::coord pos; if (gps && gps->precise_mouse_x > -1) { pos = getViewportPos(); -/* TODO: understand how this changes for v50 - pos.x += gps->mouse_x_pixel / tile_width; - pos.y += gps->mouse_y_pixel / tile_height; -*/ + int32_t map_tile_pixels = gps->viewport_zoom_factor >> 2; + pos.x += gps->precise_mouse_x / map_tile_pixels; + pos.y += gps->precise_mouse_y / map_tile_pixels; } return pos; } int getDepthAt_default (int32_t x, int32_t y) { + auto &main_vp = gps->main_viewport; + if (x < 0 || x >= main_vp->dim_x || y < 0 || y >= main_vp->dim_y) + return 0; + const size_t num_viewports = gps->viewport.size(); + const size_t index = (x * main_vp->dim_y) + y; + for (int depth = 0; depth < num_viewports; ++depth) { + if (gps->viewport[depth]->screentexpos_background[index]) + return depth; + } return 0; }