Advertisement
Solomeister

minecraft openos gui creation

Dec 19th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. local gui = {}
  2. local component = require("component")
  3. local gpu = component.gpu
  4. local event = require("event")
  5.  
  6.  
  7. --Функция создаёт кнопку. Возвращает обьект кнопки (если это нельзя назвать обьектом, не бейте, я новичок).
  8. function gui.createButton(x, y, sizeX, sizeY, buttonColor, buttonText, textColor)
  9.     local objButton = {X = x, Y = y, dX = sizeX, dY = sizeY}
  10.     textX = x+sizeX/5
  11.     textY = y+sizeY/2
  12.     oldBg = gpu.setBackground(buttonColor)
  13.     gpu.fill(x, y, sizeX, sizeY, " ")
  14.     oldFg = gpu.setForeground(textColor)
  15.     gpu.set(textX, textY, buttonText)
  16.     gpu.setForeground(oldFg)
  17.     gpu.setBackground(oldBg)
  18.     return objButton
  19. end
  20.  
  21. --Функция отслеживает нажатие ЛКМ и, если позиция курсора соответствует кнопке, возвращает true
  22. function gui.buttonPressed(objButton)
  23.     local _, _, cX, cY, _, _ = event.pull("touch")
  24.     local aX, aY
  25.     aX = objButton.X + objButton.dX
  26.     aY = objButton.Y + objButton.dY
  27.     if cX >= objButton.X and cX <= aX and cY >= objButton.Y and cY <= aY then
  28.         return true
  29.     end
  30. end
  31. --Создаёт окно
  32. function gui.createWindow(windowColor, windowName)
  33.     local windowX, windowY = gpu.getResolution()
  34.     gpu.setBackground(windowColor)
  35.     gpu.fill(1, 1, windowX, windowY, " ")
  36.     gpu.setBackground(0x505050)
  37.     gpu.setForeground(0xFFFFFF)
  38.     gpu.fill(1, 1, windowX, windowY/15, " ")
  39.     gpu.set(3, 1, windowName)
  40.     gpu.setBackground(0x000000)
  41.  end
  42. return gui
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement