86 lines
2.3 KiB
Lua
86 lines
2.3 KiB
Lua
--@include render_devices/render_device.txt
|
|
--@include elements/root.txt
|
|
|
|
require("render_devices/render_device.txt")
|
|
require("elements/root.txt")
|
|
|
|
GUI = class("GUI")
|
|
|
|
GUI.static.fonts = {
|
|
main = render.createFont("Roboto", 16, 400, true),
|
|
mainBold = render.createFont("Roboto", 16, 700, true),
|
|
icons = render.createFont("Segoe MDL2 Assets", 16, 400, true, false, false, false, false, true)
|
|
}
|
|
|
|
function GUI:initialize(renderDevice)
|
|
checkVarClass(renderDevice, RenderDevice)
|
|
|
|
self.renderDevice = renderDevice
|
|
self._root = ERoot:new()
|
|
self._root:setSize(renderDevice:getSize())
|
|
|
|
hook.add("inputPressed", "gui_inputPressed", function(key)
|
|
local keyName = input.getKeyName(key)
|
|
|
|
if key >= 107 and key <= 111 then
|
|
local x, y = input.getCursorPos()
|
|
|
|
self._root:_postEvent("MOUSE_PRESSED", x, y, key, keyName)
|
|
else
|
|
self._root:_postEvent("BUTTON_PRESSED", x, y, key, keyName)
|
|
end
|
|
end)
|
|
|
|
hook.add("inputReleased", "gui_inputReleased", function(key)
|
|
local keyName = input.getKeyName(key)
|
|
|
|
if key >= 107 and key <= 111 then
|
|
local x, y = input.getCursorPos()
|
|
|
|
self._root:_postEvent("MOUSE_RELEASED", x, y, key, keyName)
|
|
else
|
|
self._root:_postEvent("BUTTON_RELEASED", x, y, key, keyName)
|
|
end
|
|
end)
|
|
|
|
self._lastMouseX = 0
|
|
self._lastMouseY = 0
|
|
hook.add("think", "gui_think", function()
|
|
if not hasPermission("input") then
|
|
return
|
|
end
|
|
|
|
if input.getCursorVisible then
|
|
local x, y = input.getCursorPos()
|
|
|
|
if x ~= self._lastMouseX or y ~= self._lastMouseY then
|
|
self._lastMouseX = x
|
|
self._lastMouseY = y
|
|
|
|
self._root:_postEvent("MOUSE_MOVED", x, y)
|
|
end
|
|
end
|
|
|
|
self._root:_postEvent("THINK")
|
|
end)
|
|
|
|
renderDevice.render = function()
|
|
self._root:_postEvent("PAINT")
|
|
end
|
|
end
|
|
|
|
function GUI:getRoot()
|
|
return self._root
|
|
end
|
|
|
|
function GUI:add(element)
|
|
self._root:addChild(element)
|
|
end
|
|
|
|
function GUI:setVisible(state)
|
|
self._root:setVisible(state)
|
|
end
|
|
|
|
function GUI:isVisible()
|
|
self._root:isVisible()
|
|
end |