From 2234328a915a50810ee8654d9cbb0116d47ba771 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 9 Jan 2023 00:47:13 -0800 Subject: [PATCH] use an actual pin texture for ZScreen pins --- data/art/green-pin.png | Bin 0 -> 397 bytes data/art/red-pin.png | Bin 0 -> 313 bytes library/LuaApi.cpp | 2 ++ library/include/modules/Textures.h | 5 +++++ library/lua/gui.lua | 20 ++++++++++++++++++-- library/lua/gui/widgets.lua | 3 ++- library/modules/Textures.cpp | 14 ++++++++++++++ 7 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 data/art/green-pin.png create mode 100644 data/art/red-pin.png diff --git a/data/art/green-pin.png b/data/art/green-pin.png new file mode 100644 index 0000000000000000000000000000000000000000..25d0e696ff266a3def8c1584ac56dd1ac2586f45 GIT binary patch literal 397 zcmV;80doF{P)Px$M@d9MR5*>Llrc}jKp2Lf!x2JUCaQ^ rE~ZTtevt|TgnZg7^eT(!nnHjt#vF+A=31eZ00000NkvXXu0mjflf$c# literal 0 HcmV?d00001 diff --git a/data/art/red-pin.png b/data/art/red-pin.png new file mode 100644 index 0000000000000000000000000000000000000000..763b83e97e88b6bd901d7877702eb71b96731395 GIT binary patch literal 313 zcmeAS@N?(olHy`uVBq!ia0vp^0zfRm!3HEhFR0}KQjEnx?oJHr&dIz4iFvv>hFJ7o zowAnikb#KX{@Vu=93PxKq9WJ)h;xGXgTxt4*KaUS;AubFd_!6xz}a75*MzkaY*Wfo zB87$QZqJ)s{kvGxzK4~^Y29ln&KaD4q8(4!)dM*4# zJ#~R{3)uY4eg6&P4-_I+c)gmr!r4rj>q3} zA8z}gZ*xWVY-)OLT6d`QuusCure!}DHwK9cRiDn$VlS59eD|p&V|`O{d^ynj44$rj JF6*2UngC=xd2Ijy literal 0 HcmV?d00001 diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index fdd19783a..c327efe1b 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1676,6 +1676,8 @@ static const luaL_Reg dfhack_job_funcs[] = { static const LuaWrapper::FunctionReg dfhack_textures_module[] = { WRAPM(Textures, getDfhackLogoTexposStart), + WRAPM(Textures, getGreenPinTexposStart), + WRAPM(Textures, getRedPinTexposStart), { NULL, NULL } }; diff --git a/library/include/modules/Textures.h b/library/include/modules/Textures.h index 2ef172bff..e088ce477 100644 --- a/library/include/modules/Textures.h +++ b/library/include/modules/Textures.h @@ -30,5 +30,10 @@ void cleanup(); */ DFHACK_EXPORT long getDfhackLogoTexposStart(); +/** + * Get the texpos for the UI pin tiles. Each are 2x2 grids. + */ +DFHACK_EXPORT long getGreenPinTexposStart(); +DFHACK_EXPORT long getRedPinTexposStart(); } } diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 661351d31..f83a1b0cd 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -818,9 +818,25 @@ function paint_frame(dc,rect,style,title,show_lock,locked,inactive) if show_lock then if locked and style.locked_pen then - dscreen.paintTile(style.locked_pen, x2-1, y1) + local pin_texpos = dfhack.textures.getGreenPinTexposStart() + if pin_texpos == -1 then + dscreen.paintTile(style.locked_pen, x2-1, y1) + else + dscreen.paintTile(style.locked_pen, x2-2, y1-1, nil, pin_texpos+0) + dscreen.paintTile(style.locked_pen, x2-1, y1-1, nil, pin_texpos+1) + dscreen.paintTile(style.locked_pen, x2-2, y1, nil, pin_texpos+2) + dscreen.paintTile(style.locked_pen, x2-1, y1, nil, pin_texpos+3) + end elseif not locked and style.unlocked_pen then - dscreen.paintTile(style.unlocked_pen, x2-1, y1) + local pin_texpos = dfhack.textures.getRedPinTexposStart() + if pin_texpos == -1 then + dscreen.paintTile(style.unlocked_pen, x2-1, y1) + else + dscreen.paintTile(style.unlocked_pen, x2-2, y1-1, nil, pin_texpos+0) + dscreen.paintTile(style.unlocked_pen, x2-1, y1-1, nil, pin_texpos+1) + dscreen.paintTile(style.unlocked_pen, x2-2, y1, nil, pin_texpos+2) + dscreen.paintTile(style.unlocked_pen, x2-1, y1, nil, pin_texpos+3) + end end end end diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index c5002ddaa..c13757f22 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -502,7 +502,8 @@ function Window:onInput(keys) if keys._MOUSE_L_DOWN and self.parent_view and self.parent_view.toggleLocked then local x,y = dscreen.getMousePos() local frame_rect = self.frame_rect - if x == frame_rect.x2-1 and y == frame_rect.y1 then + if (x == frame_rect.x2-2 or x == frame_rect.x2-1) + and (y == frame_rect.y1-1 or y == frame_rect.y1) then self.parent_view:toggleLocked() end end diff --git a/library/modules/Textures.cpp b/library/modules/Textures.cpp index 70011b627..3ae8658c8 100644 --- a/library/modules/Textures.cpp +++ b/library/modules/Textures.cpp @@ -19,6 +19,8 @@ namespace DFHack { static bool g_loaded = false; static long g_num_dfhack_textures = 0; static long g_dfhack_logo_texpos_start = -1; +static long g_green_pin_texpos_start = -1; +static long g_red_pin_texpos_start = -1; // Converts an arbitrary Surface to something like the display format // (32-bit RGBA), and converts magenta to transparency if convert_magenta is set @@ -111,6 +113,10 @@ void Textures::init(color_ostream &out) { g_num_dfhack_textures = load_textures(out, "hack/data/art/dfhack.png", &g_dfhack_logo_texpos_start); + g_num_dfhack_textures += load_textures(out, "hack/data/art/green-pin.png", + &g_green_pin_texpos_start); + g_num_dfhack_textures += load_textures(out, "hack/data/art/red-pin.png", + &g_red_pin_texpos_start); DEBUG(textures,out).print("loaded %ld textures\n", g_num_dfhack_textures); @@ -146,3 +152,11 @@ void Textures::cleanup() { long Textures::getDfhackLogoTexposStart() { return g_dfhack_logo_texpos_start; } + +long Textures::getGreenPinTexposStart() { + return g_green_pin_texpos_start; +} + +long Textures::getRedPinTexposStart() { + return g_red_pin_texpos_start; +}