2022-09-10 14:42:56 +00:00
|
|
|
-- Loading/Waiting Animation Graphics Element
|
|
|
|
|
2023-06-03 21:40:57 +00:00
|
|
|
local tcd = require("scada-common.tcd")
|
2022-09-10 14:42:56 +00:00
|
|
|
|
|
|
|
local element = require("graphics.element")
|
|
|
|
|
|
|
|
---@class waiting_args
|
|
|
|
---@field parent graphics_element
|
|
|
|
---@field id? string element id
|
|
|
|
---@field x? integer 1 if omitted
|
2023-07-10 03:42:44 +00:00
|
|
|
---@field y? integer auto incremented if omitted
|
2022-09-10 14:42:56 +00:00
|
|
|
---@field fg_bg? cpair foreground/background colors
|
2023-05-25 21:40:16 +00:00
|
|
|
---@field hidden? boolean true to hide on initial draw
|
2022-09-10 14:42:56 +00:00
|
|
|
|
|
|
|
-- new waiting animation element
|
|
|
|
---@param args waiting_args
|
|
|
|
---@return graphics_element element, element_id id
|
|
|
|
local function waiting(args)
|
|
|
|
local state = 0
|
2022-09-10 19:14:48 +00:00
|
|
|
local run_animation = false
|
2022-09-10 14:42:56 +00:00
|
|
|
|
|
|
|
args.width = 4
|
|
|
|
args.height = 3
|
|
|
|
|
|
|
|
-- create new graphics element base object
|
|
|
|
local e = element.new(args)
|
|
|
|
|
|
|
|
local blit_fg = e.fg_bg.blit_fgd
|
|
|
|
local blit_bg = e.fg_bg.blit_bkg
|
|
|
|
local blit_fg_2x = e.fg_bg.blit_fgd .. e.fg_bg.blit_fgd
|
|
|
|
local blit_bg_2x = e.fg_bg.blit_bkg .. e.fg_bg.blit_bkg
|
|
|
|
|
2022-09-10 19:14:48 +00:00
|
|
|
-- tick the animation
|
|
|
|
local function animate()
|
2022-09-10 14:42:56 +00:00
|
|
|
e.window.clear()
|
|
|
|
|
|
|
|
if state >= 0 and state < 7 then
|
|
|
|
-- top
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_set_cur(1 + math.floor(state / 2), 1)
|
2022-09-10 14:42:56 +00:00
|
|
|
if state % 2 == 0 then
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_blit("\x8f", blit_fg, blit_bg)
|
2022-09-10 14:42:56 +00:00
|
|
|
else
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_blit("\x8a\x85", blit_fg_2x, blit_bg_2x)
|
2022-09-10 14:42:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- bottom
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_set_cur(4 - math.ceil(state / 2), 3)
|
2022-09-10 14:42:56 +00:00
|
|
|
if state % 2 == 0 then
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_blit("\x8f", blit_fg, blit_bg)
|
2022-09-10 14:42:56 +00:00
|
|
|
else
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_blit("\x8a\x85", blit_fg_2x, blit_bg_2x)
|
2022-09-10 14:42:56 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
local st = state - 7
|
|
|
|
|
|
|
|
-- right
|
|
|
|
if st % 3 == 0 then
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_set_cur(4, 1 + math.floor(st / 3))
|
|
|
|
e.w_blit("\x83", blit_bg, blit_fg)
|
2022-09-10 14:42:56 +00:00
|
|
|
elseif st % 3 == 1 then
|
2023-08-31 01:11:57 +00:00
|
|
|
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)
|
2022-09-10 14:42:56 +00:00
|
|
|
else
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_set_cur(4, 2 + math.floor(st / 3))
|
|
|
|
e.w_blit("\x8f", blit_fg, blit_bg)
|
2022-09-10 14:42:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- left
|
|
|
|
if st % 3 == 0 then
|
2023-08-31 01:11:57 +00:00
|
|
|
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)
|
2022-09-10 14:42:56 +00:00
|
|
|
elseif st % 3 == 1 then
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_set_cur(1, 2 - math.floor(st / 3))
|
|
|
|
e.w_blit("\x83", blit_bg, blit_fg)
|
2022-09-10 14:42:56 +00:00
|
|
|
else
|
2023-08-31 01:11:57 +00:00
|
|
|
e.w_set_cur(1, 2 - math.floor(st / 3))
|
|
|
|
e.w_blit("\x8f", blit_fg, blit_bg)
|
2022-09-10 14:42:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
state = state + 1
|
|
|
|
if state >= 12 then state = 0 end
|
|
|
|
|
2022-09-10 19:14:48 +00:00
|
|
|
if run_animation then
|
2023-04-12 16:40:13 +00:00
|
|
|
tcd.dispatch_unique(0.15, animate)
|
2022-09-10 19:14:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- start the animation
|
|
|
|
function e.start_anim()
|
|
|
|
run_animation = true
|
|
|
|
animate()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- stop the animation
|
|
|
|
function e.stop_anim()
|
|
|
|
run_animation = false
|
2022-09-10 14:42:56 +00:00
|
|
|
end
|
|
|
|
|
2022-09-10 19:14:48 +00:00
|
|
|
e.start_anim()
|
2022-09-10 14:42:56 +00:00
|
|
|
|
2023-05-30 23:51:10 +00:00
|
|
|
return e.complete()
|
2022-09-10 14:42:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return waiting
|