|
|
@ -4,6 +4,8 @@ local _ENV = mkmodule('gui')
|
|
|
|
|
|
|
|
|
|
|
|
local dscreen = dfhack.screen
|
|
|
|
local dscreen = dfhack.screen
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
USE_GRAPHICS = dscreen.inGraphicsMode()
|
|
|
|
|
|
|
|
|
|
|
|
CLEAR_PEN = {ch=32,fg=0,bg=0}
|
|
|
|
CLEAR_PEN = {ch=32,fg=0,bg=0}
|
|
|
|
|
|
|
|
|
|
|
|
function simulateInput(screen,...)
|
|
|
|
function simulateInput(screen,...)
|
|
|
@ -52,6 +54,9 @@ function inset(rect,dx1,dy1,dx2,dy2)
|
|
|
|
rect.x2-(dx2 or dx1), rect.y2-(dy2 or dy1)
|
|
|
|
rect.x2-(dx2 or dx1), rect.y2-(dy2 or dy1)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function is_in_rect(rect,x,y)
|
|
|
|
|
|
|
|
return x and y and x >= rect.x1 and x <= rect.x2 and y >= rect.y1 and y <= rect.y2
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function to_pen(default, pen, bg, bold)
|
|
|
|
local function to_pen(default, pen, bg, bold)
|
|
|
|
if pen == nil then
|
|
|
|
if pen == nil then
|
|
|
@ -201,10 +206,17 @@ end
|
|
|
|
-- Base screen object --
|
|
|
|
-- Base screen object --
|
|
|
|
------------------------
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
|
|
|
|
Screen = defclass(Screen, dfhack.screen)
|
|
|
|
Screen = defclass(Screen)
|
|
|
|
|
|
|
|
|
|
|
|
Screen.text_input_mode = false
|
|
|
|
Screen.text_input_mode = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:init()
|
|
|
|
|
|
|
|
self:updateLayout()
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Screen.isDismissed = dscreen.isDismissed
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:isShown()
|
|
|
|
function Screen:isShown()
|
|
|
|
return self._native ~= nil
|
|
|
|
return self._native ~= nil
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -213,6 +225,18 @@ function Screen:isActive()
|
|
|
|
return self:isShown() and not self:isDismissed()
|
|
|
|
return self:isShown() and not self:isDismissed()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:invalidate()
|
|
|
|
|
|
|
|
dscreen.invalidate()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:getWindowSize()
|
|
|
|
|
|
|
|
return dscreen.getWindowSize()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:getMousePos()
|
|
|
|
|
|
|
|
return dscreen.getMousePos()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:renderParent()
|
|
|
|
function Screen:renderParent()
|
|
|
|
if self._native and self._native.parent then
|
|
|
|
if self._native and self._native.parent then
|
|
|
|
self._native.parent:render()
|
|
|
|
self._native.parent:render()
|
|
|
@ -241,6 +265,7 @@ function Screen:onAboutToShow()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:onShow()
|
|
|
|
function Screen:onShow()
|
|
|
|
|
|
|
|
self:updateLayout()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:dismiss()
|
|
|
|
function Screen:dismiss()
|
|
|
@ -252,6 +277,13 @@ end
|
|
|
|
function Screen:onDismiss()
|
|
|
|
function Screen:onDismiss()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:onResize(w,h)
|
|
|
|
|
|
|
|
self:updateLayout()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screen:updateLayout()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
------------------------
|
|
|
|
------------------------
|
|
|
|
-- Framed screen object --
|
|
|
|
-- Framed screen object --
|
|
|
|
------------------------
|
|
|
|
------------------------
|
|
|
@ -318,7 +350,8 @@ local function hint_coord(gap,hint)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function FramedScreen:updateFrameSize(sw,sh)
|
|
|
|
function FramedScreen:updateFrameSize()
|
|
|
|
|
|
|
|
local sw, sh = dscreen.getWindowSize()
|
|
|
|
local iw, ih = sw-2, sh-2
|
|
|
|
local iw, ih = sw-2, sh-2
|
|
|
|
local width = math.min(self.frame_width or iw, iw)
|
|
|
|
local width = math.min(self.frame_width or iw, iw)
|
|
|
|
local height = math.min(self.frame_height or ih, ih)
|
|
|
|
local height = math.min(self.frame_height or ih, ih)
|
|
|
@ -328,8 +361,21 @@ function FramedScreen:updateFrameSize(sw,sh)
|
|
|
|
self.frame_opaque = (gw == 0 and gh == 0)
|
|
|
|
self.frame_opaque = (gw == 0 and gh == 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function FramedScreen:onResize(w,h)
|
|
|
|
function FramedScreen:updateLayout()
|
|
|
|
self:updateFrameSize(w,h)
|
|
|
|
self:updateFrameSize()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function FramedScreen:getWindowSize()
|
|
|
|
|
|
|
|
local rect = self.frame_rect
|
|
|
|
|
|
|
|
return rect.width, rect.height
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function FramedScreen:getMousePos()
|
|
|
|
|
|
|
|
local rect = self.frame_rect
|
|
|
|
|
|
|
|
local x,y = dscreen.getMousePos()
|
|
|
|
|
|
|
|
if is_in_rect(rect,x,y) then
|
|
|
|
|
|
|
|
return x-rect.x1, y-rect.y1
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function FramedScreen:onRender()
|
|
|
|
function FramedScreen:onRender()
|
|
|
@ -348,4 +394,7 @@ function FramedScreen:onRender()
|
|
|
|
self:onRenderBody(Painter.new(rect))
|
|
|
|
self:onRenderBody(Painter.new(rect))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function FramedScreen:onRenderBody(dc)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return _ENV
|
|
|
|
return _ENV
|
|
|
|