Merge pull request #2576 from myk002/myk_pin

use an actual pin texture for ZScreen pins
develop
Myk 2023-01-09 23:49:50 -08:00 committed by GitHub
commit e1b63d8600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 17 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

@ -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 }
};

@ -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();
}
}

@ -721,6 +721,13 @@ function ZScreen:onInput(keys)
end
if ZScreen.super.onInput(self, keys) then
-- ensure underlying DF screens don't also react to handled clicks
if keys._MOUSE_L_DOWN then
df.global.enabler.mouse_lbut_down = 0
end
if keys._MOUSE_R_DOWN then
df.global.enabler.mouse_rbut_down = 0
end
return
end
@ -729,7 +736,8 @@ function ZScreen:onInput(keys)
return
end
if not self.locked and (keys.LEAVESCREEN or keys._MOUSE_R_DOWN) then
if (self:isMouseOver() or not self.locked)
and (keys.LEAVESCREEN or keys._MOUSE_R_DOWN) then
self:dismiss()
-- ensure underlying DF screens don't also react to the click
df.global.enabler.mouse_rbut_down = 0
@ -818,9 +826,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

@ -272,10 +272,30 @@ local function Panel_on_double_click(self)
Panel_update_frame(self, frame, true)
end
local function panel_is_on_pin(self)
local frame_rect = self.frame_rect
local x,y = dscreen.getMousePos()
return (x == frame_rect.x2-2 or x == frame_rect.x2-1)
and (y == frame_rect.y1-1 or y == frame_rect.y1)
end
local function panel_is_pinnable(self)
return self.lockable and self.parent_view and self.parent_view.toggleLocked
end
function Panel:getMouseFramePos()
local x,y = Panel.super.getMouseFramePos(self)
if x then return x, y end
if panel_is_pinnable(self) and panel_is_on_pin(self) then
local frame_rect = self.frame_rect
return frame_rect.width - 3, 0
end
end
function Panel:onInput(keys)
if self.kbd_get_pos then
if keys.SELECT or keys.LEAVESCREEN then
Panel_end_drag(self, keys.LEAVESCREEN and self.saved_frame or nil,
if keys.SELECT or keys.LEAVESCREEN or keys._MOUSE_R_DOWN then
Panel_end_drag(self, not keys.SELECT and self.saved_frame or nil,
not not keys.SELECT)
return true
end
@ -300,7 +320,13 @@ function Panel:onInput(keys)
end
return true
end
if self:inputToSubviews(keys) then
if panel_is_pinnable(self) and keys._MOUSE_L_DOWN then
if panel_is_on_pin(self) then
self.parent_view:toggleLocked()
return true
end
end
if Panel.super.onInput(self, keys) then
return true
end
if not keys._MOUSE_L_DOWN then return end
@ -498,17 +524,6 @@ Window.ATTRS {
lockable = true,
}
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
self.parent_view:toggleLocked()
end
end
return Window.super.onInput(self, keys)
end
-------------------
-- ResizingPanel --
-------------------

@ -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;
}