Merge pull request #2531 from myk002/myk_gooey

Baby GUI steps
develop
Myk 2022-12-29 22:25:54 -08:00 committed by GitHub
commit 4d74f7c727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 14 deletions

@ -1121,7 +1121,8 @@ Other
* ``dfhack.gui.getDepthAt(x, y)``
Returns 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 overridden by plugins.
the closest rendered ground z-level below. Defaults to 0, unless overridden by
plugins.
Job module
----------
@ -2161,7 +2162,14 @@ Functions:
* ``dfhack.screen.getMousePos()``
Returns *x,y* of the tile the mouse is over.
Returns *x,y* of the UI interface tile the mouse is over, with the upper left
corner being ``0,0``. To get the map tile coordinate that the mouse is over,
see ``dfhack.gui.getMousePos()``.
* ``dfhack.screen.getMousePixels()``
Returns *x,y* of the screen coordinates the mouse is over in pixels, with the
upper left corner being ``0,0``.
* ``dfhack.screen.inGraphicsMode()``
@ -3632,11 +3640,6 @@ considered stable.
Misc
----
* ``USE_GRAPHICS``
Contains the value of ``dfhack.screen.inGraphicsMode()``, which cannot be
changed without restarting the game and thus is constant during the session.
* ``CLEAR_PEN``
The black pen used to clear the screen.

@ -2373,6 +2373,11 @@ static int screen_getMousePos(lua_State *L)
return Lua::PushPosXY(L, Screen::getMousePos());
}
static int screen_getMousePixels(lua_State *L)
{
return Lua::PushPosXY(L, Screen::getMousePixels());
}
static int screen_getWindowSize(lua_State *L)
{
return Lua::PushPosXY(L, Screen::getWindowSize());
@ -2563,6 +2568,7 @@ static int screen_zoom(lua_State *L)
static const luaL_Reg dfhack_screen_funcs[] = {
{ "getMousePos", screen_getMousePos },
{ "getMousePixels", screen_getMousePixels },
{ "getWindowSize", screen_getWindowSize },
{ "paintTile", screen_paintTile },
{ "readTile", screen_readTile },

@ -7,8 +7,6 @@ local utils = require('utils')
local dscreen = dfhack.screen
local getval = utils.getval
USE_GRAPHICS = dscreen.inGraphicsMode()
local to_pen = dfhack.pen.parse
CLEAR_PEN = to_pen{tile=909, ch=32, fg=0, bg=0}

@ -988,7 +988,7 @@ function render_text(obj,dc,x0,y0,pen,dpen,disabled)
if token.tile then
x = x + 1
if dc then
dc:char(nil, token.tile)
dc:tile(nil, token.tile)
end
end

@ -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,31 @@ 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;
*/
if (Screen::inGraphicsMode()) {
int32_t map_tile_pixels = gps->viewport_zoom_factor / 4;
pos.x += gps->precise_mouse_x / map_tile_pixels;
pos.y += gps->precise_mouse_y / map_tile_pixels;
} else {
pos.x += gps->mouse_x;
pos.y += gps->mouse_y;
}
}
if (!Maps::isValidTilePos(pos.x, pos.y, pos.z))
return df::coord();
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 (size_t depth = 0; depth < num_viewports; ++depth) {
if (gps->viewport[depth]->screentexpos_background[index])
return depth;
}
return 0;
}