forked from Simnation/Main
58 lines
No EOL
2 KiB
Lua
58 lines
No EOL
2 KiB
Lua
UIResRectangle = setmetatable({}, UIResRectangle)
|
|
UIResRectangle.__index = UIResRectangle
|
|
UIResRectangle.__call = function() return "Rectangle" end
|
|
|
|
function UIResRectangle.New(X, Y, Width, Height, R, G, B, A)
|
|
local _UIResRectangle = {
|
|
X = tonumber(X) or 0,
|
|
Y = tonumber(Y) or 0,
|
|
Width = tonumber(Width) or 0,
|
|
Height = tonumber(Height) or 0,
|
|
_Colour = {R = tonumber(R) or 255, G = tonumber(G) or 255, B = tonumber(B) or 255, A = tonumber(A) or 255},
|
|
}
|
|
return setmetatable(_UIResRectangle, UIResRectangle)
|
|
end
|
|
|
|
function UIResRectangle:Position(X, Y)
|
|
if tonumber(X) and tonumber(Y) then
|
|
self.X = tonumber(X)
|
|
self.Y = tonumber(Y)
|
|
else
|
|
return {X = self.X, Y = self.Y}
|
|
end
|
|
end
|
|
|
|
function UIResRectangle:Size(Width, Height)
|
|
if tonumber(Width) and tonumber(Height) then
|
|
self.Width = tonumber(Width)
|
|
self.Height = tonumber(Height)
|
|
else
|
|
return {Width = self.Width, Height = self.Height}
|
|
end
|
|
end
|
|
|
|
function UIResRectangle:Colour(R, G, B, A)
|
|
if tonumber(R) or tonumber(G) or tonumber(B) or tonumber(A) then
|
|
self._Colour.R = tonumber(R) or 255
|
|
self._Colour.B = tonumber(B) or 255
|
|
self._Colour.G = tonumber(G) or 255
|
|
self._Colour.A = tonumber(A) or 255
|
|
else
|
|
return self._Colour
|
|
end
|
|
end
|
|
|
|
function UIResRectangle:Draw()
|
|
local Position = self:Position()
|
|
local Size = self:Size()
|
|
Size.Width, Size.Height = FormatXWYH(Size.Width, Size.Height)
|
|
Position.X, Position.Y = FormatXWYH(Position.X, Position.Y)
|
|
DrawRect(Position.X + Size.Width * 0.5, Position.Y + Size.Height * 0.5, Size.Width, Size.Height, self._Colour.R, self._Colour.G, self._Colour.B, self._Colour.A)
|
|
end
|
|
|
|
function DrawRectangle(X, Y, Width, Height, R, G, B, A)
|
|
X, Y, Width, Height = X or 0, Y or 0, Width or 0, Height or 0
|
|
X, Y = FormatXWYH(X, Y)
|
|
Width, Height = FormatXWYH(Width, Height)
|
|
DrawRect(X + Width * 0.5, Y + Height * 0.5, Width, Height, tonumber(R) or 255, tonumber(G) or 255, tonumber(B) or 255, tonumber(A) or 255)
|
|
end |