Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local gui = {}
- local component = require("component")
- local gpu = component.gpu
- local event = require("event")
- --Функция создаёт кнопку. Возвращает обьект кнопки (если это нельзя назвать обьектом, не бейте, я новичок).
- function gui.createButton(x, y, sizeX, sizeY, buttonColor, buttonText, textColor)
- local objButton = {X = x, Y = y, dX = sizeX, dY = sizeY}
- textX = x+sizeX/5
- textY = y+sizeY/2
- oldBg = gpu.setBackground(buttonColor)
- gpu.fill(x, y, sizeX, sizeY, " ")
- oldFg = gpu.setForeground(textColor)
- gpu.set(textX, textY, buttonText)
- gpu.setForeground(oldFg)
- gpu.setBackground(oldBg)
- return objButton
- end
- --Функция отслеживает нажатие ЛКМ и, если позиция курсора соответствует кнопке, возвращает true
- function gui.buttonPressed(objButton)
- local _, _, cX, cY, _, _ = event.pull("touch")
- local aX, aY
- aX = objButton.X + objButton.dX
- aY = objButton.Y + objButton.dY
- if cX >= objButton.X and cX <= aX and cY >= objButton.Y and cY <= aY then
- return true
- end
- end
- --Создаёт окно
- function gui.createWindow(windowColor, windowName)
- local windowX, windowY = gpu.getResolution()
- gpu.setBackground(windowColor)
- gpu.fill(1, 1, windowX, windowY, " ")
- gpu.setBackground(0x505050)
- gpu.setForeground(0xFFFFFF)
- gpu.fill(1, 1, windowX, windowY/15, " ")
- gpu.set(3, 1, windowName)
- gpu.setBackground(0x000000)
- end
- return gui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement