You can make your own functions that operate in terms of your custom concepts, and use dxDrawRectangle/dxDrawText under the hood for actual drawing. An example:
function getCoords(coordSys, x, y)
if coordSys then
x, y = coordSys.x+x, coordSys.y+y
end
return x, y
end
function makeCoordSystem(parent, x, y)
local finalX, finalY = getCoords(parent, x, y)
return { x = finalX, y = finalY }
end
function drawText(coordSys, text, x, y)
local finalX, finalY = getCoords(coordSys, x, y)
dxDrawText(text, finalX, finalY)
end
function drawRectangle(coordSys, x, y, width, height, color)
local finalX, finalY = getCoords(coordSys, x, y)
dxDrawRectangle(finalX, finalY, width, height, color)
end
This implements a concept of coordinate system, the coordinate offset described by table with keys x and y. With this, you can do:
local onScreenHud = makeCoordSystem(false, x*1200, y*120) -- false means onScreenHud will be placed in absolute coordinates
function drawHUD()
drawRectangle(onScreenHud, 0, 0, x*1400, y*400, tocolor(0, 0, 0, 150))
drawText(onScreenHud, "Text", x*20, y*10)
end
Since makeCoordSystem has parent as first argument, even coordinate systems themselves can be positioned with respect to other coordinate systems:
local someInnerHud = makeCoordSystem(onScreenHud, x*20, x*40)
function drawInnerHUD()
drawText(someInnerHud, "Text in the inner HUD", x*20, y*10)
end
It's all about coming up with the right abstractions. As an example, you could modify this to add width and height properties to coordinate systems, and use them in calculations so you wouldn't have to write x* and y* everywhere.