#118 graphics cleanup

This commit is contained in:
Mikayla Fischler 2023-02-24 19:50:01 -05:00
parent 225ed7baa1
commit 38ac552613
18 changed files with 43 additions and 11 deletions

View File

@ -16,6 +16,7 @@ local events = {}
---@field y integer ---@field y integer
-- create a new touch event definition -- create a new touch event definition
---@nodiscard
---@param monitor string ---@param monitor string
---@param x integer ---@param x integer
---@param y integer ---@param y integer
@ -32,7 +33,7 @@ core.events = events
local graphics = {} local graphics = {}
---@alias TEXT_ALIGN integer ---@enum TEXT_ALIGN
graphics.TEXT_ALIGN = { graphics.TEXT_ALIGN = {
LEFT = 1, LEFT = 1,
CENTER = 2, CENTER = 2,
@ -47,6 +48,7 @@ graphics.TEXT_ALIGN = {
---@alias element_id string|integer ---@alias element_id string|integer
-- create a new border definition -- create a new border definition
---@nodiscard
---@param width integer border width ---@param width integer border width
---@param color color border color ---@param color color border color
---@param even? boolean whether to pad width extra to account for rectangular pixels, defaults to false ---@param even? boolean whether to pad width extra to account for rectangular pixels, defaults to false
@ -66,6 +68,7 @@ end
---@field h integer ---@field h integer
-- create a new graphics frame definition -- create a new graphics frame definition
---@nodiscard
---@param x integer ---@param x integer
---@param y integer ---@param y integer
---@param w integer ---@param w integer
@ -91,6 +94,7 @@ end
---@field blit_bkg string ---@field blit_bkg string
-- create a new color pair definition -- create a new color pair definition
---@nodiscard
---@param a color ---@param a color
---@param b color ---@param b color
---@return cpair ---@return cpair
@ -120,9 +124,9 @@ end
---@field thin boolean true for 1 subpixel, false (default) for 2 ---@field thin boolean true for 1 subpixel, false (default) for 2
---@field align_tr boolean false to align bottom left (default), true to align top right ---@field align_tr boolean false to align bottom left (default), true to align top right
-- create a new pipe -- create a new pipe<br>
--
-- note: pipe coordinate origin is (0, 0) -- note: pipe coordinate origin is (0, 0)
---@nodiscard
---@param x1 integer starting x, origin is 0 ---@param x1 integer starting x, origin is 0
---@param y1 integer starting y, origin is 0 ---@param y1 integer starting y, origin is 0
---@param x2 integer ending x, origin is 0 ---@param x2 integer ending x, origin is 0

View File

@ -47,6 +47,7 @@ local element = {}
---|tiling_args ---|tiling_args
-- a base graphics element, should not be created on its own -- a base graphics element, should not be created on its own
---@nodiscard
---@param args graphics_args arguments ---@param args graphics_args arguments
function element.new(args) function element.new(args)
local self = { local self = {
@ -172,6 +173,7 @@ function element.new(args)
end end
-- get value -- get value
---@nodiscard
function protected.get_value() function protected.get_value()
return protected.value return protected.value
end end
@ -218,6 +220,7 @@ function element.new(args)
end end
-- get public interface -- get public interface
---@nodiscard
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
function protected.get() return public, self.id end function protected.get() return public, self.id end
@ -246,11 +249,13 @@ function element.new(args)
---------------------- ----------------------
-- get the window object -- get the window object
---@nodiscard
function public.window() return protected.window end function public.window() return protected.window end
-- CHILD ELEMENTS -- -- CHILD ELEMENTS --
-- add a child element -- add a child element
---@nodiscard
---@param key string|nil id ---@param key string|nil id
---@param child graphics_template ---@param child graphics_template
---@return integer|string key ---@return integer|string key
@ -271,6 +276,7 @@ function element.new(args)
end end
-- get a child element -- get a child element
---@nodiscard
---@return graphics_element ---@return graphics_element
function public.get_child(key) return self.children[key] end function public.get_child(key) return self.children[key] end
@ -279,6 +285,7 @@ function element.new(args)
function public.remove(key) self.children[key] = nil end function public.remove(key) self.children[key] = nil end
-- attempt to get a child element by ID (does not include this element itself) -- attempt to get a child element by ID (does not include this element itself)
---@nodiscard
---@param id element_id ---@param id element_id
---@return graphics_element|nil element ---@return graphics_element|nil element
function public.get_element_by_id(id) function public.get_element_by_id(id)
@ -297,39 +304,49 @@ function element.new(args)
-- AUTO-PLACEMENT -- -- AUTO-PLACEMENT --
-- skip a line for automatically placed elements -- skip a line for automatically placed elements
function public.line_break() self.next_y = self.next_y + 1 end function public.line_break()
self.next_y = self.next_y + 1
end
-- PROPERTIES -- -- PROPERTIES --
-- get the foreground/background colors -- get the foreground/background colors
---@nodiscard
---@return cpair fg_bg ---@return cpair fg_bg
function public.get_fg_bg() return protected.fg_bg end function public.get_fg_bg()
return protected.fg_bg
end
-- get element x -- get element x
---@nodiscard
---@return integer x ---@return integer x
function public.get_x() function public.get_x()
return protected.frame.x return protected.frame.x
end end
-- get element y -- get element y
---@nodiscard
---@return integer y ---@return integer y
function public.get_y() function public.get_y()
return protected.frame.y return protected.frame.y
end end
-- get element width -- get element width
---@nodiscard
---@return integer width ---@return integer width
function public.width() function public.width()
return protected.frame.w return protected.frame.w
end end
-- get element height -- get element height
---@nodiscard
---@return integer height ---@return integer height
function public.height() function public.height()
return protected.frame.h return protected.frame.h
end end
-- get the element value -- get the element value
---@nodiscard
---@return any value ---@return any value
function public.get_value() function public.get_value()
return protected.get_value() return protected.get_value()

View File

@ -12,6 +12,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new root display box -- new root display box
---@nodiscard
---@param args displaybox_args ---@param args displaybox_args
local function displaybox(args) local function displaybox(args)
-- create new graphics element base object -- create new graphics element base object

View File

@ -13,6 +13,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new div element -- new div element
---@nodiscard
---@param args div_args ---@param args div_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function div(args) local function div(args)

View File

@ -20,6 +20,7 @@ local flasher = require("graphics.flasher")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new alarm indicator light -- new alarm indicator light
---@nodiscard
---@param args alarm_indicator_light ---@param args alarm_indicator_light
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function alarm_indicator_light(args) local function alarm_indicator_light(args)

View File

@ -14,6 +14,7 @@ local element = require("graphics.element")
---@field y? integer 1 if omitted ---@field y? integer 1 if omitted
-- new core map box -- new core map box
---@nodiscard
---@param args core_map_args ---@param args core_map_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function core_map(args) local function core_map(args)

View File

@ -19,6 +19,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new data indicator -- new data indicator
---@nodiscard
---@param args data_indicator_args ---@param args data_indicator_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function data(args) local function data(args)

View File

@ -17,6 +17,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new horizontal bar -- new horizontal bar
---@nodiscard
---@param args hbar_args ---@param args hbar_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function hbar(args) local function hbar(args)

View File

@ -20,6 +20,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new icon indicator -- new icon indicator
---@nodiscard
---@param args icon_indicator_args ---@param args icon_indicator_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function icon(args) local function icon(args)

View File

@ -18,6 +18,7 @@ local flasher = require("graphics.flasher")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new indicator light -- new indicator light
---@nodiscard
---@param args indicator_light_args ---@param args indicator_light_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function indicator_light(args) local function indicator_light(args)

View File

@ -18,6 +18,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new power indicator -- new power indicator
---@nodiscard
---@param args power_indicator_args ---@param args power_indicator_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function power(args) local function power(args)

View File

@ -19,6 +19,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new radiation indicator -- new radiation indicator
---@nodiscard
---@param args rad_indicator_args ---@param args rad_indicator_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function rad(args) local function rad(args)

View File

@ -20,6 +20,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new state indicator -- new state indicator
---@nodiscard
---@param args state_indicator_args ---@param args state_indicator_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function state_indicator(args) local function state_indicator(args)

View File

@ -20,6 +20,7 @@ local flasher = require("graphics.flasher")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new tri-state indicator light -- new tri-state indicator light
---@nodiscard
---@param args tristate_indicator_light_args ---@param args tristate_indicator_light_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function tristate_indicator_light(args) local function tristate_indicator_light(args)

View File

@ -15,6 +15,7 @@ local element = require("graphics.element")
---@field fg_bg? cpair foreground/background colors ---@field fg_bg? cpair foreground/background colors
-- new vertical bar -- new vertical bar
---@nodiscard
---@param args vbar_args ---@param args vbar_args
---@return graphics_element element, element_id id ---@return graphics_element element, element_id id
local function vbar(args) local function vbar(args)

View File

@ -144,7 +144,7 @@ local function rectangle(args)
e.window.blit(spaces, blit_fg, blit_bg_top_bot) e.window.blit(spaces, blit_fg, blit_bg_top_bot)
end end
else else
if (args.thin == true) then if args.thin == true then
e.window.blit(p_s, blit_fg_sides, blit_bg_sides) e.window.blit(p_s, blit_fg_sides, blit_bg_sides)
else else
e.window.blit(p_s, blit_fg, blit_bg_sides) e.window.blit(p_s, blit_fg, blit_bg_sides)

View File

@ -60,7 +60,7 @@ local function tiling(args)
-- create pattern -- create pattern
for y = start_y, inner_height + (start_y - 1) do for y = start_y, inner_height + (start_y - 1) do
e.window.setCursorPos(start_x, y) e.window.setCursorPos(start_x, y)
for x = 1, inner_width do for _ = 1, inner_width do
if alternator then if alternator then
if even then if even then
e.window.blit(" ", "00", fill_a .. fill_a) e.window.blit(" ", "00", fill_a .. fill_a)

View File

@ -21,8 +21,7 @@ local active = false
local registry = { {}, {}, {} } -- one registry table per period local registry = { {}, {}, {} } -- one registry table per period
local callback_counter = 0 local callback_counter = 0
-- blink registered indicators -- blink registered indicators<br>
--
-- this assumes it is called every 250ms, it does no checking of time on its own -- this assumes it is called every 250ms, it does no checking of time on its own
local function callback_250ms() local function callback_250ms()
if active then if active then
@ -55,8 +54,7 @@ function flasher.clear()
registry = { {}, {}, {} } registry = { {}, {}, {} }
end end
-- register a function to be called on the selected blink period -- register a function to be called on the selected blink period<br>
--
-- times are not strictly enforced, but all with a given period will be set at the same time -- times are not strictly enforced, but all with a given period will be set at the same time
---@param f function function to call each period ---@param f function function to call each period
---@param period PERIOD time period option (1, 2, or 3) ---@param period PERIOD time period option (1, 2, or 3)