2023-04-12 16:40:13 +00:00
|
|
|
--
|
|
|
|
-- Graphics Rendering Control
|
|
|
|
--
|
|
|
|
|
2023-04-21 18:53:28 +00:00
|
|
|
local main_view = require("pocket.ui.main")
|
|
|
|
local style = require("pocket.ui.style")
|
2023-04-12 16:40:13 +00:00
|
|
|
|
2023-04-21 18:53:28 +00:00
|
|
|
local flasher = require("graphics.flasher")
|
|
|
|
|
|
|
|
local DisplayBox = require("graphics.elements.displaybox")
|
2023-04-12 16:40:13 +00:00
|
|
|
|
|
|
|
local renderer = {}
|
|
|
|
|
|
|
|
local ui = {
|
2023-04-21 18:53:28 +00:00
|
|
|
display = nil
|
2023-04-12 16:40:13 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 03:00:27 +00:00
|
|
|
-- start the pocket GUI
|
2023-04-12 16:40:13 +00:00
|
|
|
function renderer.start_ui()
|
2023-04-21 18:53:28 +00:00
|
|
|
if ui.display == nil then
|
2023-04-12 16:40:13 +00:00
|
|
|
-- reset screen
|
|
|
|
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-21 18:53:28 +00:00
|
|
|
-- init front panel view
|
|
|
|
ui.display = DisplayBox{window=term.current(),fg_bg=style.root}
|
|
|
|
main_view(ui.display)
|
|
|
|
|
2023-04-12 16:40:13 +00:00
|
|
|
-- start flasher callback task
|
|
|
|
flasher.run()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- close out the UI
|
|
|
|
function renderer.close_ui()
|
2023-04-21 18:53:28 +00:00
|
|
|
if ui.display ~= nil then
|
2023-04-22 03:43:28 +00:00
|
|
|
-- stop blinking indicators
|
|
|
|
flasher.clear()
|
|
|
|
|
2023-04-12 16:40:13 +00:00
|
|
|
-- hide to stop animation callbacks
|
2023-04-21 18:53:28 +00:00
|
|
|
ui.display.hide()
|
2023-04-12 16:40:13 +00:00
|
|
|
|
2023-04-22 03:43:28 +00:00
|
|
|
-- clear root UI elements
|
|
|
|
ui.display = nil
|
2023-04-12 16:40:13 +00:00
|
|
|
|
2023-04-22 03:43:28 +00:00
|
|
|
-- 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-12 16:40:13 +00:00
|
|
|
|
2023-04-22 03:43:28 +00:00
|
|
|
-- reset terminal
|
|
|
|
term.setTextColor(colors.white)
|
|
|
|
term.setBackgroundColor(colors.black)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1, 1)
|
|
|
|
end
|
2023-04-12 16:40:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- is the UI ready?
|
|
|
|
---@nodiscard
|
|
|
|
---@return boolean ready
|
2023-04-21 18:53:28 +00:00
|
|
|
function renderer.ui_ready() return ui.display ~= nil end
|
2023-04-12 16:40:13 +00:00
|
|
|
|
|
|
|
-- handle a mouse event
|
2023-05-11 23:55:02 +00:00
|
|
|
---@param event mouse_interaction|nil
|
2023-04-12 16:40:13 +00:00
|
|
|
function renderer.handle_mouse(event)
|
2023-05-11 23:55:02 +00:00
|
|
|
if ui.display ~= nil and event ~= nil then
|
2023-04-21 18:53:28 +00:00
|
|
|
ui.display.handle_mouse(event)
|
|
|
|
end
|
2023-04-12 16:40:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return renderer
|