|
|
@ -40,12 +40,153 @@ function simulateInput(screen,...)
|
|
|
|
dscreen._doSimulateInput(screen, keys)
|
|
|
|
dscreen._doSimulateInput(screen, keys)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
Screen = defclass(Screen, dfhack.screen)
|
|
|
|
function mkdims_xy(x1,y1,x2,y2)
|
|
|
|
|
|
|
|
return { x1=x1, y1=y1, x2=x2, y2=y2, width=x2-x1+1, height=y2-y1+1 }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function mkdims_wh(x1,y1,w,h)
|
|
|
|
|
|
|
|
return { x1=x1, y1=y1, x2=x1+w-1, y2=y1+h-1, width=w, height=h }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function inset(rect,dx1,dy1,dx2,dy2)
|
|
|
|
|
|
|
|
return mkdims_xy(
|
|
|
|
|
|
|
|
rect.x1+dx1, rect.y1+dy1,
|
|
|
|
|
|
|
|
rect.x2-(dx2 or dx1), rect.y2-(dy2 or dy1)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function to_pen(pen, default)
|
|
|
|
|
|
|
|
if pen == nil then
|
|
|
|
|
|
|
|
return default or {}
|
|
|
|
|
|
|
|
elseif type(pen) ~= 'table' then
|
|
|
|
|
|
|
|
return {fg=pen}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return pen
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
-- Clipped painter object --
|
|
|
|
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Painter = defclass(Painter, nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter.new(rect, pen)
|
|
|
|
|
|
|
|
rect = rect or {}
|
|
|
|
|
|
|
|
local sw, sh = dscreen.getWindowSize()
|
|
|
|
|
|
|
|
local self = mkdims_xy(
|
|
|
|
|
|
|
|
math.max(rect.x1 or 0, 0),
|
|
|
|
|
|
|
|
math.max(rect.y1 or 0, 0),
|
|
|
|
|
|
|
|
math.min(rect.x2 or sw-1, sw-1),
|
|
|
|
|
|
|
|
math.min(rect.y2 or sh-1, sh-1)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
self.cur_pen = to_pen(pen or COLOR_GREY)
|
|
|
|
|
|
|
|
self.x = self.x1
|
|
|
|
|
|
|
|
self.y = self.y1
|
|
|
|
|
|
|
|
return mkinstance(Painter, self)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Screen.new(attrs)
|
|
|
|
function Painter:setRect(x1,y1,x2,y2)
|
|
|
|
return mkinstance(Screen, attrs)
|
|
|
|
local rect = mkdims_xy(x1,y1,x2,y2)
|
|
|
|
|
|
|
|
self.x1 = rect.x1
|
|
|
|
|
|
|
|
self.y1 = rect.y1
|
|
|
|
|
|
|
|
self.x2 = rect.x2
|
|
|
|
|
|
|
|
self.y2 = rect.y2
|
|
|
|
|
|
|
|
self.width = rect.width
|
|
|
|
|
|
|
|
self.height = rect.height
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:isValidPos()
|
|
|
|
|
|
|
|
return self.x >= self.x1 and self.x <= self.x2 and self.y >= self.y1 and self.y <= self.y2
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:inset(dx1,dy1,dx2,dy1)
|
|
|
|
|
|
|
|
self:setRect(
|
|
|
|
|
|
|
|
self.x1+dx1, self.y1+dy1,
|
|
|
|
|
|
|
|
self.x2-(dx2 or dx1), self.y2-(dy2 or dy1)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:seek(x,y)
|
|
|
|
|
|
|
|
if x then self.x = self.x1 + x end
|
|
|
|
|
|
|
|
if y then self.y = self.y1 + y end
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:advance(dx,dy)
|
|
|
|
|
|
|
|
if dx then self.x = self.x + dx end
|
|
|
|
|
|
|
|
if dy then self.y = self.y + dy end
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:newline(dx)
|
|
|
|
|
|
|
|
self.y = self.y + 1
|
|
|
|
|
|
|
|
self.x = self.x1 + (dx or 0)
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:pen(pen)
|
|
|
|
|
|
|
|
self.cur_pen = to_pen(pen, self.cur_pen)
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:clear()
|
|
|
|
|
|
|
|
dscreen.fillRect(CLEAR_PEN, self.x1, self.y1, self.x2, self.y2)
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:fill(x1,y1,x2,y2,pen)
|
|
|
|
|
|
|
|
if type(x1) == 'table' then
|
|
|
|
|
|
|
|
x1, y1, x2, y2, pen = x1.x1, x1.y1, x1.x2, x1.y2, x2
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
x1 = math.max(x1,self.x1)
|
|
|
|
|
|
|
|
y1 = math.max(y1,self.y1)
|
|
|
|
|
|
|
|
x2 = math.min(x2,self.x2)
|
|
|
|
|
|
|
|
y2 = math.min(y2,self.y2)
|
|
|
|
|
|
|
|
dscreen.fillRect(to_pen(pen, self.cur_pen),x1,y1,x2,y2)
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:char(char,pen)
|
|
|
|
|
|
|
|
if self:isValidPos() then
|
|
|
|
|
|
|
|
dscreen.paintTile(to_pen(pen, self.cur_pen), self.x, self.y, char)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return self:advance(1, nil)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:tile(char,tile,pen)
|
|
|
|
|
|
|
|
if self:isValidPos() then
|
|
|
|
|
|
|
|
dscreen.paintTile(to_pen(pen, self.cur_pen), self.x, self.y, char, tile)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return self:advance(1, nil)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Painter:string(text,pen)
|
|
|
|
|
|
|
|
if self.y >= self.y1 and self.y <= self.y2 then
|
|
|
|
|
|
|
|
local dx = 0
|
|
|
|
|
|
|
|
if self.x < self.x1 then
|
|
|
|
|
|
|
|
dx = self.x1 - self.x
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local len = #text
|
|
|
|
|
|
|
|
if self.x + len - 1 > self.x2 then
|
|
|
|
|
|
|
|
len = self.x2 - self.x + 1
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if len > dx then
|
|
|
|
|
|
|
|
dscreen.paintString(
|
|
|
|
|
|
|
|
to_pen(pen, self.cur_pen),
|
|
|
|
|
|
|
|
self.x+dx, self.y,
|
|
|
|
|
|
|
|
string.sub(text,dx+1,len)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return self:advance(#text, nil)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
-- Base screen object --
|
|
|
|
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Screen = defclass(Screen, dfhack.screen)
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:isShown()
|
|
|
|
function Screen:isShown()
|
|
|
|
return self._native ~= nil
|
|
|
|
return self._native ~= nil
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -68,6 +209,22 @@ function Screen:inputToParent(...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:show()
|
|
|
|
|
|
|
|
if self._native then
|
|
|
|
|
|
|
|
error("This screen is already on display")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
self:onAboutToShow()
|
|
|
|
|
|
|
|
if dscreen.show(self) then
|
|
|
|
|
|
|
|
self:onShown()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:onAboutToShow()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:onShown()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function paint_border(x1,y1,x2,y2,color,title)
|
|
|
|
function paint_border(x1,y1,x2,y2,color,title)
|
|
|
|
local pen = { ch = ' ', fg = COLOR_BLACK, bg = color }
|
|
|
|
local pen = { ch = ' ', fg = COLOR_BLACK, bg = color }
|
|
|
|
dscreen.fillRect(pen,x1,y1,x2,y1)
|
|
|
|
dscreen.fillRect(pen,x1,y1,x2,y1)
|
|
|
@ -92,13 +249,6 @@ local function hint_coord(gap,hint)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function mkdims_xy(x1,y1,x2,y2)
|
|
|
|
|
|
|
|
return { x1=x1, y1=y1, x2=x2, y2=y2, width=x2-x1+1, height=y2-y1+1 }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function mkdims_wh(x1,y1,w,h)
|
|
|
|
|
|
|
|
return { x1=x1, y1=y1, x2=x1+w-1, y2=y1+h-1, width=w, height=h }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:renderFrame(color,title,width,height,xhint,yhint)
|
|
|
|
function Screen:renderFrame(color,title,width,height,xhint,yhint)
|
|
|
|
local sw, sh = dscreen.getWindowSize()
|
|
|
|
local sw, sh = dscreen.getWindowSize()
|
|
|
|
local iw, ih = sw-2, sh-2
|
|
|
|
local iw, ih = sw-2, sh-2
|
|
|
@ -116,7 +266,8 @@ function Screen:renderFrame(color,title,width,height,xhint,yhint)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
paint_border(x1,y1,x2,y2,color,title)
|
|
|
|
paint_border(x1,y1,x2,y2,color,title)
|
|
|
|
return x1+1,y1+1,width,height,x2-1,y2-1
|
|
|
|
|
|
|
|
|
|
|
|
return Painter.new(mkdims_wh(x1+1,y1+1,width,height))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return _ENV
|
|
|
|
return _ENV
|
|
|
|