2023-04-07 02:10:33 +00:00
|
|
|
--
|
|
|
|
-- Graphics Rendering Control
|
|
|
|
--
|
|
|
|
|
|
|
|
local style = require("reactor-plc.panel.style")
|
|
|
|
local panel_view = require("reactor-plc.panel.front_panel")
|
|
|
|
|
2023-04-08 20:49:54 +00:00
|
|
|
local flasher = require("graphics.flasher")
|
|
|
|
|
2023-04-07 02:10:33 +00:00
|
|
|
local renderer = {}
|
|
|
|
|
|
|
|
local ui = {
|
|
|
|
view = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
-- start the UI
|
2023-04-08 20:49:54 +00:00
|
|
|
function renderer.start_ui()
|
2023-04-07 02:10:33 +00:00
|
|
|
if ui.view == nil then
|
2023-04-08 20:49:54 +00:00
|
|
|
-- reset terminal
|
2023-04-07 02:10:33 +00:00
|
|
|
term.setTextColor(colors.white)
|
|
|
|
term.setBackgroundColor(colors.black)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1, 1)
|
|
|
|
|
|
|
|
-- set overridden colors
|
|
|
|
for i = 1, #style.colors do
|
|
|
|
term.setPaletteColor(style.colors[i].c, style.colors[i].hex)
|
|
|
|
end
|
|
|
|
|
2023-04-08 20:49:54 +00:00
|
|
|
-- start flasher callback task
|
|
|
|
flasher.run()
|
|
|
|
|
2023-04-07 02:10:33 +00:00
|
|
|
-- init front panel view
|
2023-04-08 20:49:54 +00:00
|
|
|
ui.view = panel_view(term.current())
|
2023-04-07 02:10:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- close out the UI
|
|
|
|
function renderer.close_ui()
|
2023-04-08 20:49:54 +00:00
|
|
|
-- stop blinking indicators
|
|
|
|
flasher.clear()
|
|
|
|
|
2023-04-07 02:10:33 +00:00
|
|
|
if ui.view ~= nil then
|
|
|
|
-- hide to stop animation callbacks
|
|
|
|
ui.view.hide()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- clear root UI elements
|
|
|
|
ui.view = nil
|
|
|
|
|
|
|
|
-- restore colors
|
|
|
|
for i = 1, #style.colors do
|
|
|
|
local r, g, b = term.nativePaletteColor(style.colors[i].c)
|
|
|
|
term.setPaletteColor(style.colors[i].c, r, g, b)
|
|
|
|
end
|
|
|
|
|
2023-04-08 20:49:54 +00:00
|
|
|
-- reset terminal
|
|
|
|
term.setTextColor(colors.white)
|
|
|
|
term.setBackgroundColor(colors.black)
|
2023-04-07 02:10:33 +00:00
|
|
|
term.clear()
|
2023-04-08 20:49:54 +00:00
|
|
|
term.setCursorPos(1, 1)
|
2023-04-07 02:10:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- is the UI ready?
|
|
|
|
---@nodiscard
|
|
|
|
---@return boolean ready
|
|
|
|
function renderer.ui_ready() return ui.view ~= nil end
|
|
|
|
|
|
|
|
-- handle a touch event
|
2023-04-09 01:35:44 +00:00
|
|
|
---@param event mouse_interaction
|
|
|
|
function renderer.handle_mouse(event)
|
|
|
|
ui.view.handle_mouse(event)
|
2023-04-07 02:10:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return renderer
|