77 lines
1.9 KiB
Lua
77 lines
1.9 KiB
Lua
ui = {}
|
|
|
|
function ui.spacer(container, x, y)
|
|
local width = container.width or 0
|
|
local height = container.height or 0
|
|
return x + width, y + height
|
|
end
|
|
function ui.opaque(container, x, y)
|
|
local material = container.material
|
|
local width = container.width
|
|
local height = container.height
|
|
if type(material) == "IMaterial" then -- FIXME Type name might be wrong
|
|
elseif type(material) == "string" then
|
|
material = Material(material)
|
|
else
|
|
error("Received non meterial object in ui.render.opaque call")
|
|
end
|
|
surface.SetMaterial(material)
|
|
surface.DrawTexturedRect(x, y, width, height)
|
|
return x+width,y+height
|
|
end
|
|
|
|
function ui.color(container, x, y)
|
|
local width = container.width or 0
|
|
local height = container.height or 0
|
|
surface.SetDrawColor(container.r or 255, container.g or 255,
|
|
container.b or 255, container.a or 255)
|
|
surface.DrawRect(x, y, width, height)
|
|
return x + width, y + height
|
|
end
|
|
|
|
function ui.label(container, x, y)
|
|
surface.SetFont("DermaDefault")
|
|
surface.SetTextColor(255,255,255)
|
|
surface.SetTextPos(x,y)
|
|
surface.DrawText(container.text)
|
|
-- 13 is the font size of DermaDefault
|
|
local width = #container.text * 6
|
|
return x+width,y + 13
|
|
end
|
|
|
|
function ui.layer(container, x, y)
|
|
local ret1 = {}
|
|
local ret2 = {}
|
|
ret1.x, ret1.y = ui.handle(container[1], x, y)
|
|
ret2.x, ret2.y = ui.handle(container[2], x, y)
|
|
return math.max(ret1.x,ret2.x), math.max(ret1.y, ret2.y)
|
|
end
|
|
|
|
function ui.horizontal(container, x, y)
|
|
local bigy = y
|
|
for i, v in ipairs(container) do
|
|
local ret = {}
|
|
ret.x, ret.y = ui.handle(v,x,y)
|
|
if ret.y > bigy then bigy = ret.y end
|
|
x = ret.x
|
|
end
|
|
return x,bigy
|
|
end
|
|
|
|
function ui.vertical(container, x, y)
|
|
local bigx = x
|
|
for i, v in ipairs(container) do
|
|
local ret = {}
|
|
ret.x, ret.y = ui.handle(v,x,y)
|
|
if ret.x > bigx then bigx = ret.x end
|
|
y = ret.y
|
|
end
|
|
return bigx,y
|
|
end
|
|
|
|
function ui.handle(container, x, y)
|
|
name = container["name"]
|
|
x, y = ui[name](container, x, y)
|
|
return x, y
|
|
end
|