graphics library refactoring and bugfixes

This commit is contained in:
Mikayla Fischler
2022-06-16 11:19:32 -04:00
parent b628472d81
commit 971657c3d2
10 changed files with 85 additions and 49 deletions

View File

@@ -3,6 +3,8 @@
--
local core = require("graphics.core")
local log = require("scada-common.log")
local util = require("scada-common.util")
local element = {}
@@ -20,11 +22,15 @@ local element = {}
---@param args graphics_args_generic arguments
function element.new(args)
local self = {
elem_type = debug.getinfo(2).name,
p_window = nil, ---@type table
position = { x = 1, y = 1 },
bounds = { x1 = 1, y1 = 1, x2 = 1, y2 = 1}
}
---@fixme remove debug
log.dmesg("new " .. self.elem_type)
local protected = {
window = nil, ---@type table
fg_bg = core.graphics.cpair(colors.white, colors.black),
@@ -34,7 +40,10 @@ function element.new(args)
-- SETUP --
-- get the parent window
self.p_window = args.window or args.parent.window()
self.p_window = args.window
if self.p_window == nil and args.parent ~= nil then
self.p_window = args.parent.window()
end
-- check window
assert(self.p_window, "graphics.element: no parent window provided")
@@ -63,14 +72,18 @@ function element.new(args)
local f = protected.frame
protected.window = window.create(self.p_window, f.x, f.y, f.w, f.h, true)
-- init display box
-- init colors
if args.fg_bg ~= nil then
protected.window.setBackgroundColor(args.fg_bg.bkg)
protected.window.setTextColor(args.fg_bg.fgd)
protected.window.clear()
protected.fg_bg = args.fg_bg
elseif args.parent ~= nil then
protected.fg_bg = args.parent.get_fg_bg()
end
-- set colors
protected.window.setBackgroundColor(protected.fg_bg.bkg)
protected.window.setTextColor(protected.fg_bg.fgd)
protected.window.clear()
-- record position
self.position.x, self.position.y = protected.window.getPosition()
@@ -107,6 +120,9 @@ function element.new(args)
-- get the window object
function public.window() return protected.window end
-- get the foreground/background colors
function public.get_fg_bg() return protected.fg_bg end
-- handle a monitor touch
---@param event monitor_touch monitor touch event
function public.handle_touch(event)