2022-09-10 14:42:56 +00:00
|
|
|
-- Loading/Waiting Animation Graphics Element
|
|
|
|
|
|
|
|
local tcd = require("scada-common.tcallbackdsp")
|
|
|
|
|
|
|
|
local element = require("graphics.element")
|
|
|
|
|
|
|
|
---@class waiting_args
|
|
|
|
---@field parent graphics_element
|
|
|
|
---@field id? string element id
|
|
|
|
---@field x? integer 1 if omitted
|
|
|
|
---@field y? integer 1 if omitted
|
|
|
|
---@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
|
|
|
|
e.window.setCursorPos(1 + math.floor(state / 2), 1)
|
|
|
|
if state % 2 == 0 then
|
|
|
|
e.window.blit("\x8f", blit_fg, blit_bg)
|
|
|
|
else
|
|
|
|
e.window.blit("\x8a\x85", blit_fg_2x, blit_bg_2x)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- bottom
|
|
|
|
e.window.setCursorPos(4 - math.ceil(state / 2), 3)
|
|
|
|
if state % 2 == 0 then
|
|
|
|
e.window.blit("\x8f", blit_fg, blit_bg)
|
|
|
|
else
|
|
|
|
e.window.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)
|
|
|
|
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)
|
|
|
|
else
|
|
|
|
e.window.setCursorPos(4, 2 + math.floor(st / 3))
|
|
|
|
e.window.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)
|
|
|
|
elseif st % 3 == 1 then
|
|
|
|
e.window.setCursorPos(1, 2 - math.floor(st / 3))
|
|
|
|
e.window.blit("\x83", blit_bg, blit_fg)
|
|
|
|
else
|
|
|
|
e.window.setCursorPos(1, 2 - math.floor(st / 3))
|
|
|
|
e.window.blit("\x8f", blit_fg, blit_bg)
|
|
|
|
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
|