#300 graphics alias functions

This commit is contained in:
Mikayla Fischler 2023-08-30 21:11:57 -04:00
parent 048714817e
commit 3afc765f72
33 changed files with 402 additions and 387 deletions

View File

@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")
local core = {}
core.version = "1.1.1"
core.version = "1.1.2"
core.flasher = flasher
core.events = events
@ -35,11 +35,7 @@ core.TEXT_ALIGN = {
---@param even? boolean whether to pad width extra to account for rectangular pixels, defaults to false
---@return graphics_border
function core.border(width, color, even)
return {
width = width,
color = color,
even = even or false -- convert nil to false
}
return { width = width, color = color, even = even or false }
end
---@class graphics_frame
@ -56,12 +52,7 @@ end
---@param h integer
---@return graphics_frame
function core.gframe(x, y, w, h)
return {
x = x,
y = y,
w = w,
h = h
}
return { x = x, y = y, w = w, h = h }
end
---@class cpair

View File

@ -166,6 +166,31 @@ function element.new(args, child_offset_x, child_offset_y)
self.bounds.x2 = self.position.x + f.w - 1
self.bounds.y1 = self.position.y
self.bounds.y2 = self.position.y + f.h - 1
-- alias functions
-- window set cursor position
---@param x integer
---@param y integer
function protected.w_set_cur(x, y) protected.window.setCursorPos(x, y) end
-- set background color
---@param c color
function protected.w_set_bkg(c) protected.window.setBackgroundColor(c) end
-- set foreground (text) color
---@param c color
function protected.w_set_fgd(c) protected.window.setTextColor(c) end
-- write text
---@param str string
function protected.w_write(str) protected.window.write(str) end
-- blit text
---@param str string
---@param fg string
---@param bg string
function protected.w_blit(str, fg, bg) protected.window.blit(str, fg, bg) end
end
-- check if a coordinate relative to the parent is within the bounds of this element

View File

@ -36,49 +36,49 @@ local function waiting(args)
if state >= 0 and state < 7 then
-- top
e.window.setCursorPos(1 + math.floor(state / 2), 1)
e.w_set_cur(1 + math.floor(state / 2), 1)
if state % 2 == 0 then
e.window.blit("\x8f", blit_fg, blit_bg)
e.w_blit("\x8f", blit_fg, blit_bg)
else
e.window.blit("\x8a\x85", blit_fg_2x, blit_bg_2x)
e.w_blit("\x8a\x85", blit_fg_2x, blit_bg_2x)
end
-- bottom
e.window.setCursorPos(4 - math.ceil(state / 2), 3)
e.w_set_cur(4 - math.ceil(state / 2), 3)
if state % 2 == 0 then
e.window.blit("\x8f", blit_fg, blit_bg)
e.w_blit("\x8f", blit_fg, blit_bg)
else
e.window.blit("\x8a\x85", blit_fg_2x, blit_bg_2x)
e.w_blit("\x8a\x85", blit_fg_2x, blit_bg_2x)
end
else
local st = state - 7
-- right
if st % 3 == 0 then
e.window.setCursorPos(4, 1 + math.floor(st / 3))
e.window.blit("\x83", blit_bg, blit_fg)
e.w_set_cur(4, 1 + math.floor(st / 3))
e.w_blit("\x83", blit_bg, blit_fg)
elseif st % 3 == 1 then
e.window.setCursorPos(4, 1 + math.floor(st / 3))
e.window.blit("\x8f", blit_bg, blit_fg)
e.window.setCursorPos(4, 2 + math.floor(st / 3))
e.window.blit("\x83", blit_fg, blit_bg)
e.w_set_cur(4, 1 + math.floor(st / 3))
e.w_blit("\x8f", blit_bg, blit_fg)
e.w_set_cur(4, 2 + math.floor(st / 3))
e.w_blit("\x83", blit_fg, blit_bg)
else
e.window.setCursorPos(4, 2 + math.floor(st / 3))
e.window.blit("\x8f", blit_fg, blit_bg)
e.w_set_cur(4, 2 + math.floor(st / 3))
e.w_blit("\x8f", blit_fg, blit_bg)
end
-- left
if st % 3 == 0 then
e.window.setCursorPos(1, 3 - math.floor(st / 3))
e.window.blit("\x83", blit_fg, blit_bg)
e.window.setCursorPos(1, 2 - math.floor(st / 3))
e.window.blit("\x8f", blit_bg, blit_fg)
e.w_set_cur(1, 3 - math.floor(st / 3))
e.w_blit("\x83", blit_fg, blit_bg)
e.w_set_cur(1, 2 - math.floor(st / 3))
e.w_blit("\x8f", blit_bg, blit_fg)
elseif st % 3 == 1 then
e.window.setCursorPos(1, 2 - math.floor(st / 3))
e.window.blit("\x83", blit_bg, blit_fg)
e.w_set_cur(1, 2 - math.floor(st / 3))
e.w_blit("\x83", blit_bg, blit_fg)
else
e.window.setCursorPos(1, 2 - math.floor(st / 3))
e.window.blit("\x8f", blit_fg, blit_bg)
e.w_set_cur(1, 2 - math.floor(st / 3))
e.w_blit("\x8f", blit_fg, blit_bg)
end
end

View File

@ -25,8 +25,8 @@ local function colormap(args)
local e = element.new(args)
-- draw color map
e.window.setCursorPos(1, 1)
e.window.blit(spaces, bkg, bkg)
e.w_set_cur(1, 1)
e.w_blit(spaces, bkg, bkg)
return e.complete()
end

View File

@ -36,9 +36,8 @@ local function app_button(args)
local e = element.new(args)
-- write app title, centered
e.window.setCursorPos(1, 4)
e.window.setCursorPos(math.floor((e.frame.w - string.len(args.title)) / 2) + 1, 4)
e.window.write(args.title)
e.w_set_cur(math.floor((e.frame.w - string.len(args.title)) / 2) + 1, 4)
e.w_write(args.title)
-- draw the app button
local function draw()
@ -51,36 +50,36 @@ local function app_button(args)
end
-- draw icon
e.window.setCursorPos(1, 1)
e.window.setTextColor(fgd)
e.window.setBackgroundColor(bkg)
e.window.write("\x9f\x83\x83\x83")
e.window.setTextColor(bkg)
e.window.setBackgroundColor(fgd)
e.window.write("\x90")
e.window.setTextColor(fgd)
e.window.setBackgroundColor(bkg)
e.window.setCursorPos(1, 2)
e.window.write("\x95 ")
e.window.setTextColor(bkg)
e.window.setBackgroundColor(fgd)
e.window.write("\x95")
e.window.setCursorPos(1, 3)
e.window.write("\x82\x8f\x8f\x8f\x81")
e.w_set_cur(1, 1)
e.w_set_fgd(fgd)
e.w_set_bkg(bkg)
e.w_write("\x9f\x83\x83\x83")
e.w_set_fgd(bkg)
e.w_set_bkg(fgd)
e.w_write("\x90")
e.w_set_fgd(fgd)
e.w_set_bkg(bkg)
e.w_set_cur(1, 2)
e.w_write("\x95 ")
e.w_set_fgd(bkg)
e.w_set_bkg(fgd)
e.w_write("\x95")
e.w_set_cur(1, 3)
e.w_write("\x82\x8f\x8f\x8f\x81")
-- write the icon text
e.window.setCursorPos(3, 2)
e.window.setTextColor(fgd)
e.window.setBackgroundColor(bkg)
e.window.write(args.text)
e.w_set_cur(3, 2)
e.w_set_fgd(fgd)
e.w_set_bkg(bkg)
e.w_write(args.text)
end
-- draw the app button as pressed (if active_fg_bg set)
local function show_pressed()
if e.enabled and args.active_fg_bg ~= nil then
e.value = true
e.window.setTextColor(args.active_fg_bg.fgd)
e.window.setBackgroundColor(args.active_fg_bg.bkg)
e.w_set_fgd(args.active_fg_bg.fgd)
e.w_set_bkg(args.active_fg_bg.bkg)
draw()
end
end
@ -89,8 +88,8 @@ local function app_button(args)
local function show_unpressed()
if e.enabled and args.active_fg_bg ~= nil then
e.value = false
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
draw()
end
end

View File

@ -32,24 +32,24 @@ local function checkbox(args)
-- show the button state
local function draw()
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if e.value then
-- show as selected
e.window.setTextColor(args.box_fg_bg.bkg)
e.window.setBackgroundColor(args.box_fg_bg.fgd)
e.window.write("\x88")
e.window.setTextColor(args.box_fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.window.write("\x95")
e.w_set_fgd(args.box_fg_bg.bkg)
e.w_set_bkg(args.box_fg_bg.fgd)
e.w_write("\x88")
e.w_set_fgd(args.box_fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
e.w_write("\x95")
else
-- show as unselected
e.window.setTextColor(e.fg_bg.bkg)
e.window.setBackgroundColor(args.box_fg_bg.bkg)
e.window.write("\x88")
e.window.setTextColor(args.box_fg_bg.bkg)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.window.write("\x95")
e.w_set_fgd(e.fg_bg.bkg)
e.w_set_bkg(args.box_fg_bg.bkg)
e.w_write("\x88")
e.w_set_fgd(args.box_fg_bg.bkg)
e.w_set_bkg(e.fg_bg.bkg)
e.w_write("\x95")
end
end
@ -71,10 +71,10 @@ local function checkbox(args)
end
-- write label text
e.window.setCursorPos(3, 1)
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.window.write(args.label)
e.w_set_cur(3, 1)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
e.w_write(args.label)
-- initial draw
draw()

View File

@ -33,35 +33,35 @@ local function hazard_button(args)
local e = element.new(args)
-- write the button text
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_cur(3, 2)
e.w_write(args.text)
-- draw border
---@param accent color accent color
local function draw_border(accent)
-- top
e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 1)
e.window.write("\x99" .. string.rep("\x89", args.width - 2) .. "\x99")
e.w_set_fgd(accent)
e.w_set_bkg(args.fg_bg.bkg)
e.w_set_cur(1, 1)
e.w_write("\x99" .. string.rep("\x89", args.width - 2) .. "\x99")
-- center left
e.window.setCursorPos(1, 2)
e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(accent)
e.window.write("\x99")
e.w_set_cur(1, 2)
e.w_set_fgd(args.fg_bg.bkg)
e.w_set_bkg(accent)
e.w_write("\x99")
-- center right
e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(accent)
e.window.setCursorPos(args.width, 2)
e.window.write("\x99")
e.w_set_fgd(args.fg_bg.bkg)
e.w_set_bkg(accent)
e.w_set_cur(args.width, 2)
e.w_write("\x99")
-- bottom
e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 3)
e.window.write("\x99" .. string.rep("\x98", args.width - 2) .. "\x99")
e.w_set_fgd(accent)
e.w_set_bkg(args.fg_bg.bkg)
e.w_set_cur(1, 3)
e.w_write("\x99" .. string.rep("\x98", args.width - 2) .. "\x99")
end
-- on request timeout: recursively calls itself to double flash button text
@ -72,9 +72,9 @@ local function hazard_button(args)
if n == 0 then
-- go back off
e.window.setTextColor(args.fg_bg.fgd)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.fg_bg.fgd)
e.w_set_cur(3, 2)
e.w_write(args.text)
end
if n >= 4 then
@ -82,18 +82,18 @@ local function hazard_button(args)
elseif n % 2 == 0 then
-- toggle text color on after 0.25 seconds
tcd.dispatch(0.25, function ()
e.window.setTextColor(args.accent)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.accent)
e.w_set_cur(3, 2)
e.w_write(args.text)
on_timeout(n + 1)
on_timeout(n + 1)
end)
elseif n % 1 then
-- toggle text color off after 0.25 seconds
tcd.dispatch(0.25, function ()
e.window.setTextColor(args.fg_bg.fgd)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.fg_bg.fgd)
e.w_set_cur(3, 2)
e.w_write(args.text)
on_timeout(n + 1)
end)
end
@ -101,9 +101,9 @@ local function hazard_button(args)
-- blink routine for success indication
local function on_success()
e.window.setTextColor(args.fg_bg.fgd)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.fg_bg.fgd)
e.w_set_cur(3, 2)
e.w_write(args.text)
end
-- blink routine for failure indication
@ -114,9 +114,9 @@ local function hazard_button(args)
if n == 0 then
-- go back off
e.window.setTextColor(args.fg_bg.fgd)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.fg_bg.fgd)
e.w_set_cur(3, 2)
e.w_write(args.text)
end
if n >= 2 then
@ -124,17 +124,17 @@ local function hazard_button(args)
elseif n % 2 == 0 then
-- toggle text color on after 0.5 seconds
tcd.dispatch(0.5, function ()
e.window.setTextColor(args.accent)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.accent)
e.w_set_cur(3, 2)
e.w_write(args.text)
on_failure(n + 1)
end)
elseif n % 1 then
-- toggle text color off after 0.25 seconds
tcd.dispatch(0.25, function ()
e.window.setTextColor(args.fg_bg.fgd)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.fg_bg.fgd)
e.w_set_cur(3, 2)
e.w_write(args.text)
on_failure(n + 1)
end)
end
@ -146,9 +146,9 @@ local function hazard_button(args)
if e.enabled then
if core.events.was_clicked(event.type) then
-- change text color to indicate clicked
e.window.setTextColor(args.accent)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.accent)
e.w_set_cur(3, 2)
e.w_write(args.text)
-- abort any other callbacks
tcd.abort(on_timeout)
@ -181,18 +181,18 @@ local function hazard_button(args)
function e.disable()
if args.dis_colors then
draw_border(args.dis_colors.color_a)
e.window.setTextColor(args.dis_colors.color_b)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.dis_colors.color_b)
e.w_set_cur(3, 2)
e.w_write(args.text)
end
end
-- show the button as enabled
function e.enable()
draw_border(args.accent)
e.window.setTextColor(args.fg_bg.fgd)
e.window.setCursorPos(3, 2)
e.window.write(args.text)
e.w_set_fgd(args.fg_bg.fgd)
e.w_set_cur(3, 2)
e.w_write(args.text)
end
-- initial draw of border

View File

@ -75,19 +75,19 @@ local function multi_button(args)
for i = 1, #args.options do
local opt = args.options[i] ---@type button_option
e.window.setCursorPos(opt._start_x, 1)
e.w_set_cur(opt._start_x, 1)
if e.value == i then
-- show as pressed
e.window.setTextColor(opt.active_fg_bg.fgd)
e.window.setBackgroundColor(opt.active_fg_bg.bkg)
e.w_set_fgd(opt.active_fg_bg.fgd)
e.w_set_bkg(opt.active_fg_bg.bkg)
else
-- show as unpressed
e.window.setTextColor(opt.fg_bg.fgd)
e.window.setBackgroundColor(opt.fg_bg.bkg)
e.w_set_fgd(opt.fg_bg.fgd)
e.w_set_bkg(opt.fg_bg.bkg)
end
e.window.write(util.pad(opt.text, button_width))
e.w_write(util.pad(opt.text, button_width))
end
end

View File

@ -48,16 +48,16 @@ local function push_button(args)
e.window.clear()
-- write the button text
e.window.setCursorPos(h_pad, v_pad)
e.window.write(args.text)
e.w_set_cur(h_pad, v_pad)
e.w_write(args.text)
end
-- draw the button as pressed (if active_fg_bg set)
local function show_pressed()
if e.enabled and args.active_fg_bg ~= nil then
e.value = true
e.window.setTextColor(args.active_fg_bg.fgd)
e.window.setBackgroundColor(args.active_fg_bg.bkg)
e.w_set_fgd(args.active_fg_bg.fgd)
e.w_set_bkg(args.active_fg_bg.bkg)
draw()
end
end
@ -66,8 +66,8 @@ local function push_button(args)
local function show_unpressed()
if e.enabled and args.active_fg_bg ~= nil then
e.value = false
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
draw()
end
end
@ -102,8 +102,8 @@ local function push_button(args)
function e.enable()
if args.dis_fg_bg ~= nil then
e.value = false
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
draw()
end
end
@ -112,8 +112,8 @@ local function push_button(args)
function e.disable()
if args.dis_fg_bg ~= nil then
e.value = false
e.window.setTextColor(args.dis_fg_bg.fgd)
e.window.setBackgroundColor(args.dis_fg_bg.bkg)
e.w_set_fgd(args.dis_fg_bg.fgd)
e.w_set_bkg(args.dis_fg_bg.bkg)
draw()
end
end

View File

@ -56,28 +56,28 @@ local function radio_button(args)
for i = 1, #args.options do
local opt = args.options[i] ---@type string
e.window.setCursorPos(1, i)
e.w_set_cur(1, i)
if e.value == i then
-- show as selected
e.window.setTextColor(args.radio_colors.color_a)
e.window.setBackgroundColor(args.radio_bg)
e.w_set_fgd(args.radio_colors.color_a)
e.w_set_bkg(args.radio_bg)
else
-- show as unselected
e.window.setTextColor(args.radio_colors.color_b)
e.window.setBackgroundColor(args.radio_bg)
e.w_set_fgd(args.radio_colors.color_b)
e.w_set_bkg(args.radio_bg)
end
e.window.write("\x88")
e.w_write("\x88")
e.window.setTextColor(args.radio_bg)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.window.write("\x95")
e.w_set_fgd(args.radio_bg)
e.w_set_bkg(e.fg_bg.bkg)
e.w_write("\x95")
-- write button text
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.window.write(opt)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
e.w_write(opt)
end
end

View File

@ -52,27 +52,27 @@ local function sidebar(args)
local y = ((i - 1) * 3) + 1
e.window.setCursorPos(1, y)
e.w_set_cur(1, y)
if pressed and i == pressed_idx then
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
else
e.window.setTextColor(tab.color.fgd)
e.window.setBackgroundColor(tab.color.bkg)
e.w_set_fgd(tab.color.fgd)
e.w_set_bkg(tab.color.bkg)
end
e.window.write(" ")
e.window.setCursorPos(1, y + 1)
e.w_write(" ")
e.w_set_cur(1, y + 1)
if e.value == i then
-- show as selected
e.window.write(" " .. tab.char .. "\x10")
e.w_write(" " .. tab.char .. "\x10")
else
-- show as unselected
e.window.write(" " .. tab.char .. " ")
e.w_write(" " .. tab.char .. " ")
end
e.window.setCursorPos(1, y + 2)
e.window.write(" ")
e.w_set_cur(1, y + 2)
e.w_write(" ")
end
end

View File

@ -58,17 +58,17 @@ local function spinbox(args)
-- draw the arrows
local function draw_arrows(color)
e.window.setBackgroundColor(args.arrow_fg_bg.bkg)
e.window.setTextColor(color)
e.window.setCursorPos(1, 1)
e.window.write(string.rep("\x1e", wn_prec))
e.window.setCursorPos(1, 3)
e.window.write(string.rep("\x1f", wn_prec))
e.w_set_bkg(args.arrow_fg_bg.bkg)
e.w_set_fgd(color)
e.w_set_cur(1, 1)
e.w_write(string.rep("\x1e", wn_prec))
e.w_set_cur(1, 3)
e.w_write(string.rep("\x1f", wn_prec))
if fr_prec > 0 then
e.window.setCursorPos(1 + wn_prec, 1)
e.window.write(" " .. string.rep("\x1e", fr_prec))
e.window.setCursorPos(1 + wn_prec, 3)
e.window.write(" " .. string.rep("\x1f", fr_prec))
e.w_set_cur(1 + wn_prec, 1)
e.w_write(" " .. string.rep("\x1e", fr_prec))
e.w_set_cur(1 + wn_prec, 3)
e.w_write(" " .. string.rep("\x1f", fr_prec))
end
end
@ -119,10 +119,10 @@ local function spinbox(args)
end
-- draw
e.window.setBackgroundColor(e.fg_bg.bkg)
e.window.setTextColor(e.fg_bg.fgd)
e.window.setCursorPos(1, 2)
e.window.write(util.sprintf(fmt, e.value))
e.w_set_bkg(e.fg_bg.bkg)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_cur(1, 2)
e.w_write(util.sprintf(fmt, e.value))
end
-- init with the default value

View File

@ -47,20 +47,20 @@ local function switch_button(args)
local function draw_state()
if e.value then
-- show as pressed
e.window.setTextColor(args.active_fg_bg.fgd)
e.window.setBackgroundColor(args.active_fg_bg.bkg)
e.w_set_fgd(args.active_fg_bg.fgd)
e.w_set_bkg(args.active_fg_bg.bkg)
else
-- show as unpressed
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
end
-- clear to redraw background
e.window.clear()
-- write the button text
e.window.setCursorPos(h_pad, v_pad)
e.window.write(args.text)
e.w_set_cur(h_pad, v_pad)
e.w_write(args.text)
end
-- initial draw

View File

@ -71,17 +71,17 @@ local function tabbar(args)
for i = 1, #args.tabs do
local tab = args.tabs[i] ---@type tabbar_tab
e.window.setCursorPos(tab._start_x, 1)
e.w_set_cur(tab._start_x, 1)
if e.value == i then
e.window.setTextColor(tab.color.fgd)
e.window.setBackgroundColor(tab.color.bkg)
e.w_set_fgd(tab.color.fgd)
e.w_set_bkg(tab.color.bkg)
else
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
end
e.window.write(util.pad(tab.name, button_width))
e.w_write(util.pad(tab.name, button_width))
end
end

View File

@ -53,17 +53,17 @@ local function alarm_indicator_light(args)
-- called by flasher when enabled
local function flash_callback()
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if flash_on then
if e.value == 2 then
e.window.blit(" \x95", "0" .. c2, c2 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c2, c2 .. e.fg_bg.blit_bkg)
end
else
if e.value == 3 then
e.window.blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
else
e.window.blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
end
end
@ -76,7 +76,7 @@ local function alarm_indicator_light(args)
local was_off = e.value ~= 2
e.value = new_state
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if args.flash then
if was_off and (new_state == 2) then
@ -87,17 +87,17 @@ local function alarm_indicator_light(args)
flasher.stop(flash_callback)
if new_state == 3 then
e.window.blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
else
e.window.blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
end
end
elseif new_state == 2 then
e.window.blit(" \x95", "0" .. c2, c2 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c2, c2 .. e.fg_bg.blit_bkg)
elseif new_state == 3 then
e.window.blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
else
e.window.blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
end
end
@ -107,7 +107,7 @@ local function alarm_indicator_light(args)
-- write label and initial indicator light
e.on_update(1)
e.window.write(args.label)
e.w_write(args.label)
return e.complete()
end

View File

@ -47,25 +47,25 @@ local function core_map(args)
-- create coordinate grid and frame
local function draw_frame()
e.window.setTextColor(colors.white)
e.w_set_fgd(colors.white)
for x = 0, (inner_width - 1) do
e.window.setCursorPos(x + start_x, 1)
e.window.write(util.sprintf("%X", x))
e.w_set_cur(x + start_x, 1)
e.w_write(util.sprintf("%X", x))
end
for y = 0, (inner_height - 1) do
e.window.setCursorPos(1, y + start_y)
e.window.write(util.sprintf("%X", y))
e.w_set_cur(1, y + start_y)
e.w_write(util.sprintf("%X", y))
end
-- even out bottom edge
e.window.setTextColor(e.fg_bg.bkg)
e.window.setBackgroundColor(args.parent.get_fg_bg().bkg)
e.window.setCursorPos(1, e.frame.h)
e.window.write(string.rep("\x8f", e.frame.w))
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_fgd(e.fg_bg.bkg)
e.w_set_bkg(args.parent.get_fg_bg().bkg)
e.w_set_cur(1, e.frame.h)
e.w_write(string.rep("\x8f", e.frame.w))
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
end
-- draw the core
@ -102,13 +102,13 @@ local function core_map(args)
-- draw pattern
for y = start_y, inner_height + (start_y - 1) do
e.window.setCursorPos(start_x, y)
e.w_set_cur(start_x, y)
for _ = 1, inner_width do
if alternator then
i = i + 1
e.window.blit("\x07", text_c, back_c)
e.w_blit("\x07", text_c, back_c)
else
e.window.blit("\x07", "7", "8")
e.w_blit("\x07", "7", "8")
end
alternator = not alternator

View File

@ -37,12 +37,12 @@ local function data(args)
-- label color
if args.lu_colors ~= nil then
e.window.setTextColor(args.lu_colors.color_a)
e.w_set_fgd(args.lu_colors.color_a)
end
-- write label
e.window.setCursorPos(1, 1)
e.window.write(args.label)
e.w_set_cur(1, 1)
e.w_write(args.label)
local value_color = e.fg_bg.fgd
local label_len = string.len(args.label)
@ -60,25 +60,25 @@ local function data(args)
e.value = value
-- clear old data and label
e.window.setCursorPos(data_start, 1)
e.window.write(util.spaces(clear_width))
e.w_set_cur(data_start, 1)
e.w_write(util.spaces(clear_width))
-- write data
local data_str = util.sprintf(args.format, value)
e.window.setCursorPos(data_start, 1)
e.window.setTextColor(value_color)
e.w_set_cur(data_start, 1)
e.w_set_fgd(value_color)
if args.commas then
e.window.write(util.comma_format(data_str))
e.w_write(util.comma_format(data_str))
else
e.window.write(data_str)
e.w_write(data_str)
end
-- write label
if args.unit ~= nil then
if args.lu_colors ~= nil then
e.window.setTextColor(args.lu_colors.color_b)
e.w_set_fgd(args.lu_colors.color_b)
end
e.window.write(" " .. args.unit)
e.w_write(" " .. args.unit)
end
end

View File

@ -87,16 +87,16 @@ local function hbar(args)
-- draw bar
for y = 1, e.frame.h do
e.window.setCursorPos(1, y)
e.w_set_cur(1, y)
-- intentionally swapped fgd/bkg since we use spaces as fill, but they are the opposite
e.window.blit(spaces, bkg, fgd)
e.w_blit(spaces, bkg, fgd)
end
end
-- update percentage
if args.show_percent then
e.window.setCursorPos(bar_width + 2, math.max(1, math.ceil(e.frame.h / 2)))
e.window.write(util.sprintf("%3.0f%%", fraction * 100))
e.w_set_cur(bar_width + 2, math.max(1, math.ceil(e.frame.h / 2)))
e.w_write(util.sprintf("%3.0f%%", fraction * 100))
end
end

View File

@ -48,16 +48,16 @@ local function icon(args)
end
-- write label and initial indicator light
e.window.setCursorPos(5, 1)
e.window.write(args.label)
e.w_set_cur(5, 1)
e.w_write(args.label)
-- on state change
---@param new_state integer indicator state
function e.on_update(new_state)
local blit_cmd = state_blit_cmds[new_state]
e.value = new_state
e.window.setCursorPos(1, 1)
e.window.blit(blit_cmd.text, blit_cmd.fgd, blit_cmd.bkg)
e.w_set_cur(1, 1)
e.w_blit(blit_cmd.text, blit_cmd.fgd, blit_cmd.bkg)
end
-- set indicator state

View File

@ -44,12 +44,12 @@ local function indicator_led(args)
-- called by flasher when enabled
local function flash_callback()
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if flash_on then
e.window.blit("\x8c", args.colors.blit_a, e.fg_bg.blit_bkg)
e.w_blit("\x8c", args.colors.blit_a, e.fg_bg.blit_bkg)
else
e.window.blit("\x8c", args.colors.blit_b, e.fg_bg.blit_bkg)
e.w_blit("\x8c", args.colors.blit_b, e.fg_bg.blit_bkg)
end
flash_on = not flash_on
@ -61,8 +61,8 @@ local function indicator_led(args)
flash_on = true
flasher.start(flash_callback, args.period)
else
e.window.setCursorPos(1, 1)
e.window.blit("\x8c", args.colors.blit_a, e.fg_bg.blit_bkg)
e.w_set_cur(1, 1)
e.w_blit("\x8c", args.colors.blit_a, e.fg_bg.blit_bkg)
end
end
@ -73,8 +73,8 @@ local function indicator_led(args)
flasher.stop(flash_callback)
end
e.window.setCursorPos(1, 1)
e.window.blit("\x8c", args.colors.blit_b, e.fg_bg.blit_bkg)
e.w_set_cur(1, 1)
e.w_blit("\x8c", args.colors.blit_b, e.fg_bg.blit_bkg)
end
-- on state change
@ -91,8 +91,8 @@ local function indicator_led(args)
-- write label and initial indicator light
e.on_update(false)
if string.len(args.label) > 0 then
e.window.setCursorPos(3, 1)
e.window.write(args.label)
e.w_set_cur(3, 1)
e.w_write(args.label)
end
return e.complete()

View File

@ -56,16 +56,16 @@ local function indicator_led_pair(args)
-- called by flasher when enabled
local function flash_callback()
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if flash_on then
if e.value == 2 then
e.window.blit("\x8c", c1, e.fg_bg.blit_bkg)
e.w_blit("\x8c", c1, e.fg_bg.blit_bkg)
elseif e.value == 3 then
e.window.blit("\x8c", c2, e.fg_bg.blit_bkg)
e.w_blit("\x8c", c2, e.fg_bg.blit_bkg)
end
else
e.window.blit("\x8c", co, e.fg_bg.blit_bkg)
e.w_blit("\x8c", co, e.fg_bg.blit_bkg)
end
flash_on = not flash_on
@ -77,7 +77,7 @@ local function indicator_led_pair(args)
local was_off = e.value <= 1
e.value = new_state
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if args.flash then
if was_off and (new_state > 1) then
@ -87,14 +87,14 @@ local function indicator_led_pair(args)
flash_on = false
flasher.stop(flash_callback)
e.window.blit("\x8c", co, e.fg_bg.blit_bkg)
e.w_blit("\x8c", co, e.fg_bg.blit_bkg)
end
elseif new_state == 2 then
e.window.blit("\x8c", c1, e.fg_bg.blit_bkg)
e.w_blit("\x8c", c1, e.fg_bg.blit_bkg)
elseif new_state == 3 then
e.window.blit("\x8c", c2, e.fg_bg.blit_bkg)
e.w_blit("\x8c", c2, e.fg_bg.blit_bkg)
else
e.window.blit("\x8c", co, e.fg_bg.blit_bkg)
e.w_blit("\x8c", co, e.fg_bg.blit_bkg)
end
end
@ -105,8 +105,8 @@ local function indicator_led_pair(args)
-- write label and initial indicator light
e.on_update(1)
if string.len(args.label) > 0 then
e.window.setCursorPos(3, 1)
e.window.write(args.label)
e.w_set_cur(3, 1)
e.w_write(args.label)
end
return e.complete()

View File

@ -37,9 +37,9 @@ local function indicator_led_rgb(args)
---@param new_state integer indicator state
function e.on_update(new_state)
e.value = new_state
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if type(args.colors[new_state]) == "number" then
e.window.blit("\x8c", colors.toBlit(args.colors[new_state]), e.fg_bg.blit_bkg)
e.w_blit("\x8c", colors.toBlit(args.colors[new_state]), e.fg_bg.blit_bkg)
end
end
@ -50,8 +50,8 @@ local function indicator_led_rgb(args)
-- write label and initial indicator light
e.on_update(1)
if string.len(args.label) > 0 then
e.window.setCursorPos(3, 1)
e.window.write(args.label)
e.w_set_cur(3, 1)
e.w_write(args.label)
end
return e.complete()

View File

@ -44,12 +44,12 @@ local function indicator_light(args)
-- called by flasher when enabled
local function flash_callback()
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if flash_on then
e.window.blit(" \x95", "0" .. args.colors.blit_a, args.colors.blit_a .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. args.colors.blit_a, args.colors.blit_a .. e.fg_bg.blit_bkg)
else
e.window.blit(" \x95", "0" .. args.colors.blit_b, args.colors.blit_b .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. args.colors.blit_b, args.colors.blit_b .. e.fg_bg.blit_bkg)
end
flash_on = not flash_on
@ -61,8 +61,8 @@ local function indicator_light(args)
flash_on = true
flasher.start(flash_callback, args.period)
else
e.window.setCursorPos(1, 1)
e.window.blit(" \x95", "0" .. args.colors.blit_a, args.colors.blit_a .. e.fg_bg.blit_bkg)
e.w_set_cur(1, 1)
e.w_blit(" \x95", "0" .. args.colors.blit_a, args.colors.blit_a .. e.fg_bg.blit_bkg)
end
end
@ -73,8 +73,8 @@ local function indicator_light(args)
flasher.stop(flash_callback)
end
e.window.setCursorPos(1, 1)
e.window.blit(" \x95", "0" .. args.colors.blit_b, args.colors.blit_b .. e.fg_bg.blit_bkg)
e.w_set_cur(1, 1)
e.w_blit(" \x95", "0" .. args.colors.blit_b, args.colors.blit_b .. e.fg_bg.blit_bkg)
end
-- on state change
@ -90,8 +90,8 @@ local function indicator_light(args)
-- write label and initial indicator light
e.on_update(false)
e.window.setCursorPos(3, 1)
e.window.write(args.label)
e.w_set_cur(3, 1)
e.w_write(args.label)
return e.complete()
end

View File

@ -34,12 +34,12 @@ local function power(args)
-- label color
if args.lu_colors ~= nil then
e.window.setTextColor(args.lu_colors.color_a)
e.w_set_fgd(args.lu_colors.color_a)
end
-- write label
e.window.setCursorPos(1, 1)
e.window.write(args.label)
e.w_set_cur(1, 1)
e.w_write(args.label)
local data_start = string.len(args.label) + 2
if string.len(args.label) == 0 then data_start = 1 end
@ -52,13 +52,13 @@ local function power(args)
local data_str, unit = util.power_format(value, false, args.format)
-- write data
e.window.setCursorPos(data_start, 1)
e.window.setTextColor(e.fg_bg.fgd)
e.window.write(util.comma_format(data_str))
e.w_set_cur(data_start, 1)
e.w_set_fgd(e.fg_bg.fgd)
e.w_write(util.comma_format(data_str))
-- write unit
if args.lu_colors ~= nil then
e.window.setTextColor(args.lu_colors.color_b)
e.w_set_fgd(args.lu_colors.color_b)
end
-- append per tick if rate is set
@ -70,7 +70,7 @@ local function power(args)
if unit == "FE" then unit = "FE " end
end
e.window.write(" " .. unit)
e.w_write(" " .. unit)
end
-- set the value

View File

@ -36,12 +36,12 @@ local function rad(args)
-- label color
if args.lu_colors ~= nil then
e.window.setTextColor(args.lu_colors.color_a)
e.w_set_fgd(args.lu_colors.color_a)
end
-- write label
e.window.setCursorPos(1, 1)
e.window.write(args.label)
e.w_set_cur(1, 1)
e.w_write(args.label)
local label_len = string.len(args.label)
local data_start = 1
@ -58,24 +58,24 @@ local function rad(args)
e.value = value.radiation
-- clear old data and label
e.window.setCursorPos(data_start, 1)
e.window.write(util.spaces(clear_width))
e.w_set_cur(data_start, 1)
e.w_write(util.spaces(clear_width))
-- write data
local data_str = util.sprintf(args.format, e.value)
e.window.setCursorPos(data_start, 1)
e.window.setTextColor(e.fg_bg.fgd)
e.w_set_cur(data_start, 1)
e.w_set_fgd(e.fg_bg.fgd)
if args.commas then
e.window.write(util.comma_format(data_str))
e.w_write(util.comma_format(data_str))
else
e.window.write(data_str)
e.w_write(data_str)
end
-- write unit
if args.lu_colors ~= nil then
e.window.setTextColor(args.lu_colors.color_b)
e.w_set_fgd(args.lu_colors.color_b)
end
e.window.write(" " .. value.unit)
e.w_write(" " .. value.unit)
end
-- set the value

View File

@ -64,8 +64,8 @@ local function state_indicator(args)
function e.on_update(new_state)
local blit_cmd = state_blit_cmds[new_state]
e.value = new_state
e.window.setCursorPos(1, 1)
e.window.blit(blit_cmd.text, blit_cmd.fgd, blit_cmd.bkg)
e.w_set_cur(1, 1)
e.w_blit(blit_cmd.text, blit_cmd.fgd, blit_cmd.bkg)
end
-- set indicator state

View File

@ -56,16 +56,16 @@ local function tristate_indicator_light(args)
-- called by flasher when enabled
local function flash_callback()
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if flash_on then
if e.value == 2 then
e.window.blit(" \x95", "0" .. c2, c2 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c2, c2 .. e.fg_bg.blit_bkg)
elseif e.value == 3 then
e.window.blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
end
else
e.window.blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
end
flash_on = not flash_on
@ -77,7 +77,7 @@ local function tristate_indicator_light(args)
local was_off = e.value <= 1
e.value = new_state
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
if args.flash then
if was_off and (new_state > 1) then
@ -87,14 +87,14 @@ local function tristate_indicator_light(args)
flash_on = false
flasher.stop(flash_callback)
e.window.blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
end
elseif new_state == 2 then
e.window.blit(" \x95", "0" .. c2, c2 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c2, c2 .. e.fg_bg.blit_bkg)
elseif new_state == 3 then
e.window.blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c3, c3 .. e.fg_bg.blit_bkg)
else
e.window.blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
e.w_blit(" \x95", "0" .. c1, c1 .. e.fg_bg.blit_bkg)
end
end
@ -104,7 +104,7 @@ local function tristate_indicator_light(args)
-- write label and initial indicator light
e.on_update(1)
e.window.write(args.label)
e.w_write(args.label)
return e.complete()
end

View File

@ -56,28 +56,28 @@ local function vbar(args)
local y = e.frame.h
-- start at base of vertical bar
e.window.setCursorPos(1, y)
e.w_set_cur(1, y)
-- fill percentage
for _ = 1, num_bars / 3 do
e.window.blit(spaces, bkg, fgd)
e.w_blit(spaces, bkg, fgd)
y = y - 1
e.window.setCursorPos(1, y)
e.w_set_cur(1, y)
end
-- add fractional bar if needed
if num_bars % 3 == 1 then
e.window.blit(one_third, bkg, fgd)
e.w_blit(one_third, bkg, fgd)
y = y - 1
elseif num_bars % 3 == 2 then
e.window.blit(two_thirds, bkg, fgd)
e.w_blit(two_thirds, bkg, fgd)
y = y - 1
end
-- fill the rest blank
while y > 0 do
e.window.setCursorPos(1, y)
e.window.blit(spaces, fgd, bkg)
e.w_set_cur(1, y)
e.w_blit(spaces, fgd, bkg)
y = y - 1
end
end

View File

@ -63,34 +63,34 @@ local function listbox(args)
-- draw up/down arrows
if pressed_arrow == 1 then
e.window.setTextColor(active_fg_bg.fgd)
e.window.setBackgroundColor(active_fg_bg.bkg)
e.window.setCursorPos(e.frame.w, 1)
e.window.write("\x1e")
e.window.setTextColor(nav_fg_bg.fgd)
e.window.setBackgroundColor(nav_fg_bg.bkg)
e.window.setCursorPos(e.frame.w, e.frame.h)
e.window.write("\x1f")
e.w_set_fgd(active_fg_bg.fgd)
e.w_set_bkg(active_fg_bg.bkg)
e.w_set_cur(e.frame.w, 1)
e.w_write("\x1e")
e.w_set_fgd(nav_fg_bg.fgd)
e.w_set_bkg(nav_fg_bg.bkg)
e.w_set_cur(e.frame.w, e.frame.h)
e.w_write("\x1f")
elseif pressed_arrow == -1 then
e.window.setTextColor(nav_fg_bg.fgd)
e.window.setBackgroundColor(nav_fg_bg.bkg)
e.window.setCursorPos(e.frame.w, 1)
e.window.write("\x1e")
e.window.setTextColor(active_fg_bg.fgd)
e.window.setBackgroundColor(active_fg_bg.bkg)
e.window.setCursorPos(e.frame.w, e.frame.h)
e.window.write("\x1f")
e.w_set_fgd(nav_fg_bg.fgd)
e.w_set_bkg(nav_fg_bg.bkg)
e.w_set_cur(e.frame.w, 1)
e.w_write("\x1e")
e.w_set_fgd(active_fg_bg.fgd)
e.w_set_bkg(active_fg_bg.bkg)
e.w_set_cur(e.frame.w, e.frame.h)
e.w_write("\x1f")
else
e.window.setTextColor(nav_fg_bg.fgd)
e.window.setBackgroundColor(nav_fg_bg.bkg)
e.window.setCursorPos(e.frame.w, 1)
e.window.write("\x1e")
e.window.setCursorPos(e.frame.w, e.frame.h)
e.window.write("\x1f")
e.w_set_fgd(nav_fg_bg.fgd)
e.w_set_bkg(nav_fg_bg.bkg)
e.w_set_cur(e.frame.w, 1)
e.w_write("\x1e")
e.w_set_cur(e.frame.w, e.frame.h)
e.w_write("\x1f")
end
e.window.setTextColor(e.fg_bg.fgd)
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_fgd(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.bkg)
end
-- render the scroll bar and re-cacluate height & bounds
@ -115,23 +115,23 @@ local function listbox(args)
for i = 2, e.frame.h - 1 do
if (i >= offset and i < (bar_height + offset)) and (bar_height ~= max_bar_height) then
if args.nav_fg_bg ~= nil then
e.window.setBackgroundColor(args.nav_fg_bg.fgd)
e.w_set_bkg(args.nav_fg_bg.fgd)
else
e.window.setBackgroundColor(e.fg_bg.fgd)
e.w_set_bkg(e.fg_bg.fgd)
end
else
if args.nav_fg_bg ~= nil then
e.window.setBackgroundColor(args.nav_fg_bg.bkg)
e.w_set_bkg(args.nav_fg_bg.bkg)
else
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_bkg(e.fg_bg.bkg)
end
end
e.window.setCursorPos(e.frame.w, i)
e.window.write(" ")
e.w_set_cur(e.frame.w, i)
e.w_write(" ")
end
e.window.setBackgroundColor(e.fg_bg.bkg)
e.w_set_bkg(e.fg_bg.bkg)
end
-- update item y positions and move elements

View File

@ -73,7 +73,7 @@ local function pipenet(args)
y_step = util.trinary(pipe.y1 == pipe.y2, 0, y_step)
end
e.window.setCursorPos(x, y)
e.w_set_cur(x, y)
local c = core.cpair(pipe.color, e.fg_bg.bkg)
@ -84,24 +84,24 @@ local function pipenet(args)
if i == pipe.w then
-- corner
if y_step > 0 then
e.window.blit("\x93", c.blit_bkg, c.blit_fgd)
e.w_blit("\x93", c.blit_bkg, c.blit_fgd)
else
e.window.blit("\x8e", c.blit_fgd, c.blit_bkg)
e.w_blit("\x8e", c.blit_fgd, c.blit_bkg)
end
else
e.window.blit("\x8c", c.blit_fgd, c.blit_bkg)
e.w_blit("\x8c", c.blit_fgd, c.blit_bkg)
end
else
if i == pipe.w and y_step > 0 then
-- corner
e.window.blit(" ", c.blit_bkg, c.blit_fgd)
e.w_blit(" ", c.blit_bkg, c.blit_fgd)
else
e.window.blit("\x8f", c.blit_fgd, c.blit_bkg)
e.w_blit("\x8f", c.blit_fgd, c.blit_bkg)
end
end
x = x + x_step
e.window.setCursorPos(x, y)
e.w_set_cur(x, y)
end
-- back up one
@ -109,12 +109,12 @@ local function pipenet(args)
for _ = 1, pipe.h - 1 do
y = y + y_step
e.window.setCursorPos(x, y)
e.w_set_cur(x, y)
if pipe.thin then
e.window.blit("\x95", c.blit_bkg, c.blit_fgd)
e.w_blit("\x95", c.blit_bkg, c.blit_fgd)
else
e.window.blit(" ", c.blit_bkg, c.blit_fgd)
e.w_blit(" ", c.blit_bkg, c.blit_fgd)
end
end
else
@ -124,26 +124,26 @@ local function pipenet(args)
if i == pipe.h then
-- corner
if y_step < 0 then
e.window.blit("\x97", c.blit_bkg, c.blit_fgd)
e.w_blit("\x97", c.blit_bkg, c.blit_fgd)
elseif y_step > 0 then
e.window.blit("\x8d", c.blit_fgd, c.blit_bkg)
e.w_blit("\x8d", c.blit_fgd, c.blit_bkg)
else
e.window.blit("\x8c", c.blit_fgd, c.blit_bkg)
e.w_blit("\x8c", c.blit_fgd, c.blit_bkg)
end
else
e.window.blit("\x95", c.blit_fgd, c.blit_bkg)
e.w_blit("\x95", c.blit_fgd, c.blit_bkg)
end
else
if i == pipe.h and y_step < 0 then
-- corner
e.window.blit("\x83", c.blit_bkg, c.blit_fgd)
e.w_blit("\x83", c.blit_bkg, c.blit_fgd)
else
e.window.blit(" ", c.blit_bkg, c.blit_fgd)
e.w_blit(" ", c.blit_bkg, c.blit_fgd)
end
end
y = y + y_step
e.window.setCursorPos(x, y)
e.w_set_cur(x, y)
end
-- back up one
@ -151,12 +151,12 @@ local function pipenet(args)
for _ = 1, pipe.w - 1 do
x = x + x_step
e.window.setCursorPos(x, y)
e.w_set_cur(x, y)
if pipe.thin then
e.window.blit("\x8c", c.blit_fgd, c.blit_bkg)
e.w_blit("\x8c", c.blit_fgd, c.blit_bkg)
else
e.window.blit("\x83", c.blit_bkg, c.blit_fgd)
e.w_blit("\x83", c.blit_bkg, c.blit_fgd)
end
end
end
@ -298,12 +298,12 @@ local function pipenet(args)
end
end
e.window.setCursorPos(x, y)
e.w_set_cur(x, y)
if invert then
e.window.blit(char, entry.bg, entry.fg)
e.w_blit(char, entry.bg, entry.fg)
else
e.window.blit(char, entry.fg, entry.bg)
e.w_blit(char, entry.fg, entry.bg)
end
end
end

View File

@ -56,7 +56,7 @@ local function rectangle(args)
-- draw bordered box if requested
-- element constructor will have drawn basic colored rectangle regardless
if args.border ~= nil then
e.window.setCursorPos(1, 1)
e.w_set_cur(1, 1)
local border_width = offset_x
local border_height = offset_y
@ -127,28 +127,28 @@ local function rectangle(args)
-- draw rectangle with borders
for y = 1, e.frame.h do
e.window.setCursorPos(1, y)
e.w_set_cur(1, y)
-- top border
if y <= border_height then
-- partial pixel fill
if args.border.even and y == border_height then
if args.thin == true then
e.window.blit(p_a, p_inv_bg, p_inv_fg)
e.w_blit(p_a, p_inv_bg, p_inv_fg)
else
local _fg = util.trinary(args.even_inner == true, string.rep(e.fg_bg.blit_bkg, e.frame.w), p_inv_bg)
local _bg = util.trinary(args.even_inner == true, blit_bg_top_bot, p_inv_fg)
if width_x2 % 3 == 1 then
e.window.blit(p_b, _fg, _bg)
e.w_blit(p_b, _fg, _bg)
elseif width_x2 % 3 == 2 then
e.window.blit(p_a, _fg, _bg)
e.w_blit(p_a, _fg, _bg)
else
-- skip line
e.window.blit(spaces, blit_fg, blit_bg_sides)
e.w_blit(spaces, blit_fg, blit_bg_sides)
end
end
else
e.window.blit(spaces, blit_fg, blit_bg_top_bot)
e.w_blit(spaces, blit_fg, blit_bg_top_bot)
end
-- bottom border
elseif y > (e.frame.h - border_width) then
@ -156,31 +156,31 @@ local function rectangle(args)
if args.border.even and y == ((e.frame.h - border_width) + 1) then
if args.thin == true then
if args.even_inner == true then
e.window.blit(p_b, blit_bg_top_bot, string.rep(e.fg_bg.blit_bkg, e.frame.w))
e.w_blit(p_b, blit_bg_top_bot, string.rep(e.fg_bg.blit_bkg, e.frame.w))
else
e.window.blit(p_b, string.rep(e.fg_bg.blit_bkg, e.frame.w), blit_bg_top_bot)
e.w_blit(p_b, string.rep(e.fg_bg.blit_bkg, e.frame.w), blit_bg_top_bot)
end
else
local _fg = util.trinary(args.even_inner == true, blit_bg_top_bot, p_inv_fg)
local _bg = util.trinary(args.even_inner == true, string.rep(e.fg_bg.blit_bkg, e.frame.w), blit_bg_top_bot)
if width_x2 % 3 == 1 then
e.window.blit(p_a, _fg, _bg)
e.w_blit(p_a, _fg, _bg)
elseif width_x2 % 3 == 2 then
e.window.blit(p_b, _fg, _bg)
e.w_blit(p_b, _fg, _bg)
else
-- skip line
e.window.blit(spaces, blit_fg, blit_bg_sides)
e.w_blit(spaces, blit_fg, blit_bg_sides)
end
end
else
e.window.blit(spaces, blit_fg, blit_bg_top_bot)
e.w_blit(spaces, blit_fg, blit_bg_top_bot)
end
else
if args.thin == true then
e.window.blit(p_s, blit_fg_sides, blit_bg_sides)
e.w_blit(p_s, blit_fg_sides, blit_bg_sides)
else
e.window.blit(p_s, blit_fg, blit_bg_sides)
e.w_blit(p_s, blit_fg, blit_bg_sides)
end
end
end

View File

@ -45,14 +45,14 @@ local function textbox(args)
-- use cursor position to align this line
if alignment == TEXT_ALIGN.CENTER then
e.window.setCursorPos(math.floor((e.frame.w - len) / 2) + 1, i)
e.w_set_cur(math.floor((e.frame.w - len) / 2) + 1, i)
elseif alignment == TEXT_ALIGN.RIGHT then
e.window.setCursorPos((e.frame.w - len) + 1, i)
e.w_set_cur((e.frame.w - len) + 1, i)
else
e.window.setCursorPos(1, i)
e.w_set_cur(1, i)
end
e.window.write(lines[i])
e.w_write(lines[i])
end
end

View File

@ -42,7 +42,7 @@ local function tiling(args)
-- border
if args.border_c ~= nil then
e.window.setBackgroundColor(args.border_c)
e.w_set_bkg(args.border_c)
e.window.clear()
start_x = 1 + util.trinary(even, 2, 1)
@ -60,19 +60,19 @@ local function tiling(args)
-- create pattern
for y = start_y, inner_height + (start_y - 1) do
e.window.setCursorPos(start_x, y)
e.w_set_cur(start_x, y)
for _ = 1, inner_width do
if alternator then
if even then
e.window.blit(" ", "00", fill_a .. fill_a)
e.w_blit(" ", "00", fill_a .. fill_a)
else
e.window.blit(" ", "0", fill_a)
e.w_blit(" ", "0", fill_a)
end
else
if even then
e.window.blit(" ", "00", fill_b .. fill_b)
e.w_blit(" ", "00", fill_b .. fill_b)
else
e.window.blit(" ", "0", fill_b)
e.w_blit(" ", "0", fill_b)
end
end