I'm using Lua, as I am under the impression that GCC isn't compatible with small soft compilers.
I've been using the pre embark screen as my test bed.
I've been messing around with various approaches, and my code is doing anything as it's purely experimenting to see what might work. I'm currently calling Screen:renderParent() every time the 'm' key is pressed and nothing else, after a starting state of putting up a DFHack "transparent" frame (the clearing of the innards removed from an overriding onRenderFrame(), a label, and a Grid widget that doesn't actually render anything at all at the moment).
renderParent() gives odd results, as random parts of the screen gets blanked out at random calls. When I did sent an 'm' on to the parent DF correctly moved the embark frame, but did not clear out the old one and parts get overwritten but with the old contents still displayed (flickering between two results when F1/F2 becomes available, for instance).
local gui = require 'gui'
local dialog = require 'gui.dialogs'
local widgets = require 'gui.widgets'
local guiScript = require 'gui.script'
local x = 0
local y = 0
local pen = {ch = 'X',
fg = COLOR_BLACK,
bg = COLOR_YELLOW,
bold = false,
tile = nil,
tile_color = false,
tile_fg = nil,
tile_bg = nil}
--================================================================
-- The Grid widget defines an pen supporting X/Y character display grid supporting display of
-- a grid larger than the frame allows through a panning viewport. The init function requires
-- the specification of the width and height attributes that defines the grid dimensions.
-- The grid coordinates are 0 based.
--
Grid = defclass (Grid, widgets.Widget)
Grid.ATTRS =
{width = DEFAULT_NIL,
height = DEFAULT_NIL}
--================================================================
function Grid:init ()
if type (self.width) ~= 'number' or
type (self.height) ~= 'number' or
self.width < 0 or
self.height < 0 then
error ("Grid widgets have to have their width and height set permanently on initiation")
return
end
self.grid = dfhack.penarray.new (self.width, self.height)
self.background_grid = dfhack.penarray.new (self.width, self.height)
self.viewport = {x1 = 0,
x2 = self.frame.w - 1,
y1 = 0,
y2 = self.frame.h - 1}
if false then
dfhack.println (dfhack.screen.doGetTile (1, 1))
for i = self.frame.l, self.frame.r do
for k = self.frame.t, self.frame.b do
self.background_grid:set_tile (i,
k,
dfhack.screen.getTile (self.viewport.x1 + i - self.frame.l,
self.viewport.y1 + k - self.frame.t))
end
end
end
end
--================================================================
function Grid:panTo (x, y)
local x_size = self.viewport.x2 - self.viewport.x1 + 1
local y_size = self.viewport.y2 - self.viewport.y1 + 1
self.viewport.x1 = x
if self.viewport.x1 + x_size > self.width then
self.viewport.x1 = self.width - x_size
end
if self.viewport.x1 < 0 then
self.viewport.x1 = 0
end
self.viewport.x2 = self.viewport.x1 + x_size - 1
self.viewport.y1 = y
if self.viewport.y1 + y_size > self.height then
self.viewport.y1 = self.height - y_size
end
if self.viewport.y1 < 0 then
self.viewport.y1 = 0
end
self.viewport.y2 = self.viewport.y1 + y_size - 1
end
--================================================================
-- Pans the viewport in the X and Y dimensions the number of steps specified by the parameters.
-- It will stop the panning at 0, however, and will not pan outside of the grid (a grid smaller)
-- than the frame will still have non grid parts in the frame, of course).
--
function Grid:pan (x, y)
self:panTo (self.viewport.x1 + x, self.viewport.y1 + y)
end
--================================================================
function Grid:panCenter (x, y)
self:panTo (x - math.floor ((self.viewport.x2 - self.viewport.x1 + 1) / 2),
y - math.floor ((self.viewport.y2 - self.viewport.y1 + 1) / 2))
end
--================================================================
-- Assigns a value to the specified grid (not frame) coordinates. The 'pen'
-- parameter has to be a DFHack 'pen' table or object.
--
function Grid:set (x, y, pen)
if x < 0 or x >= self.width then
error ("Grid:set error: x out of bounds " .. tostring (x) .. " vs 0 - " .. tostring (self.width - 1))
return
elseif y < 0 or y >= self.height then
error ("Grid:set error: y out of bounds " .. tostring (y) .. " vs 0 - " .. tostring (self.height - 1))
return
end
self.grid:set_tile (x, y, pen)
end
--================================================================
function Grid:reset (x, y)
if x < 0 or x >= self.width then
error ("Grid:set error: x out of bounds " .. tostring (x) .. " vs 0 - " .. tostring (self.width - 1))
return
elseif y < 0 or y >= self.height then
error ("Grid:set error: y out of bounds " .. tostring (y) .. " vs 0 - " .. tostring (self.height - 1))
return
end
self.grid:set_tile (x, y, self.background_grid:get_tile (x, y))
end
--================================================================
-- Returns the data at position x, y in the grid.
--
function Grid:get (x, y)
if x < 0 or x >= self.width then
error ("Grid:set error: x out of bounds " .. tostring (x) .. " vs 0 - " .. tostring (self.width - 1))
return
elseif y < 0 or y >= self.height then
error ("Grid:set error: y out of bounds " .. tostring (y) .. " vs 0 - " .. tostring (self.height - 1))
return
else
return self.grid:get_tile (x, y)
end
end
--================================================================
-- Renders the contents within the viewport into the frame.
--
function Grid:onRenderBody (dc)
local pen
for i = self.frame.l, self.frame.l + self.frame.w - 1 do
for k = self.frame.t, self.frame.t + self.frame.h - 1 do
pen = self.grid:get_tile (self.viewport.x1 + i - self.frame.l,
self.viewport.y1 + k - self.frame.t)
if pen.ch ~= 0 then
dfhack.screen.paintTile (pen, i, k, pen.ch)
end
end
end
end
--================================================================
function hy ()
local Main_Page = {}
local persist_screen
Ui = defclass (Ui, gui.FramedScreen)
Ui.ATTRS = {
frame_style = gui.GREY_LINE_FRAME,
frame_title = "Transparent Overlay"
}
--============================================================
function Ui:onRenderFrame (dc, rect)
local x1,y1,x2,y2 = rect.x1, rect.y1, rect.x2, rect.y2
gui.paint_frame (x1, y1, x2, y2, self.frame_style, self.frame_title)
end
--============================================================
function Ui:clear ()
end
--============================================================
function Ui:onHelp ()
self.subviews.pages:setSelected (7)
end
--============================================================
function Ui:init ()
self.stack = {}
self.item_count = 0
self.keys = {}
Main_Page.Background =
widgets.Label {text = {{text = "BACKGROUND",
pen = COLOR_LIGHTBLUE}},
frame = {l = 0, t = 0, y_align = 0}}
Main_Page.Grid = Grid {frame = {l = 1,
t = 2,
w = 16,
h = 16},
width = 16,
height = 16,
visible = true}
local mainPage = widgets.Panel {
subviews = {Main_Page.Background,
Main_Page.Grid}}
local pages = widgets.Pages
{subviews = {mainPage},view_id = "pages",
}
pages:setSelected (1)
self:addviews {pages}
end
--============================================================
function Ui:onInput (keys)
if keys.LEAVESCREEN_ALL then
self:dismiss ()
end
if keys.LEAVESCREEN then
self:dismiss ()
end
if keys.CUSTOM_M then
if y ~= 0 then
Main_Page.Grid:reset (x, y)
end
y = y + 1
if y > 16 then
y = 16
end
-- Main_Page.Grid:set (x, y, pen)
-- local screen = dfhack.gui.getCurViewscreen ()
-- persist_screen:renderParent ()
-- persist_screen:sendInputToParent (df.interface_key.SETUP_LOCAL_Y_MDOWN)
-- screen.parent:feed_key (df.interface_key.SETUP_LOCAL_Y_MDOWN)
persist_screen:renderParent ()
end
end
--============================================================
function Show_Viewer ()
local screen = Ui {}
persist_screen = screen
screen:show ()
end
--============================================================
Show_Viewer ()
end
hy ()