Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- kernel.lua
- local window = require("window")
- local windowManager = {
- windows = {},
- nextWindowId = 1
- }
- function windowManager.addWindow(x, y, width, height, title)
- local win = window.create(x, y, width, height, title)
- table.insert(windowManager.windows, win)
- return win
- end
- function windowManager.drawAll()
- term.setBackgroundColour(colours.black)
- term.clear()
- -- Сортируем окна по zIndex
- table.sort(windowManager.windows, function(a, b) return a.zIndex < b.zIndex end)
- for _, win in ipairs(windowManager.windows) do
- if win.active and not win.minimized then
- window.draw(win)
- end
- end
- end
- function windowManager.handleEvents()
- while true do
- windowManager.drawAll()
- local event = {os.pullEvent()}
- -- Обрабатываем события для всех окон (сверху вниз)
- local handled = false
- for i = #windowManager.windows, 1, -1 do
- local win = windowManager.windows[i]
- if win.active then
- handled = window.handleEvent(win, event, windowManager.windows)
- if handled then break end
- end
- end
- -- Глобальные горячие клавиши
- if not handled and event[1] == "key" then
- if event[2] == keys.q then
- term.clear()
- term.setCursorPos(1, 1)
- print("Shutting down...")
- return
- elseif event[2] == keys.n then
- local win = windowManager.addWindow(
- math.random(5, 15),
- math.random(3, 10),
- math.random(20, 40),
- math.random(10, 20),
- "Window " .. windowManager.nextWindowId
- )
- windowManager.nextWindowId = windowManager.nextWindowId + 1
- -- Заполняем окно тестовым содержимым
- window.setBackgroundColour(win, colours.blue)
- window.setTextColour(win, colours.white)
- window.setCursorPos(win, 3, 3)
- window.write(win, "Hello from Window " .. (windowManager.nextWindowId - 1))
- end
- end
- end
- end
- -- Инициализация и запуск
- local function init()
- term.clear()
- term.setCursorPos(1, 1)
- print("MyOS v0.3 (Native Windows)")
- print("Press: n-new window, q-quit")
- -- Запускаем менеджер окон
- windowManager.handleEvents()
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement