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 zcmeAS@N?(olHy`uVBq!ia0y~yU=UznV36QoV_;zTyr7ncfq{XsILO_JVcj{ImkbPy z?w&4=Ar`$$rx^Mla*$}7e|VNh1V?j5uvCQ4U6a^9yvHUUyu05~{pOv!KiGSI$(LkE zWJV~=N{Hmpx#fD!k$>lIHKp3=X65&P-}zlTea?@XeG^0`6kFWUf3!U01h2(yk*U_n z*>4x${uSTkroZ^&=?Q07vE7yWP*ly*Aiq@ViGPFD$^M{8JMtW5HV3?1d^>8rY1Pg0 znC)&t&I0E?ES_?GHgj!9mzEm$X`3qRtG6omPYH>5#bEDs{l908p8%gu@zc7WpI!4E zMd!)zGjbea^o&{lo@9OT;7)z%;t7Cz9T10aI$M1)8!ne@XM8P0SqnAD=(SkpF2FolKo-j zyfeo6t4o_=&oG?RTjncTH<63ErRJ9Q7p?9Wvz!|AkI8g=eipTGDgy%pgQu&X%Q~lo FCIFMetC0Wz 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!ia0y~yU=UznV36QoV_;zTyr7ncfq{XsILO_JVcj{Immo1u z7sn8b-m6pA@*Oe|aod0UV1na=lSfqKnjdja@P3duqv`q$<_SFQN1Ja*D+DRrKH?MNWyxS`}9JpaR`B9II50hk0{nvoaXm$yGVIWQCZ9_C>QM`>%}c8+Pqe znWr$v<8QeSw|&sJxgvWuH9a@2J5+kuCt+pNvY(3^gG7a@Pv>Z{7fW!y`&5##z9~7r RoPmLX!PC{xWt~$(698m9d2Ijy 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; +}