ReiLuaGui basics done.
This commit is contained in:
95
examples/resources/lib/color.lua
Normal file
95
examples/resources/lib/color.lua
Normal file
@@ -0,0 +1,95 @@
|
||||
Color = {}
|
||||
Color.meta = {
|
||||
__index = Color,
|
||||
__tostring = function( r )
|
||||
return "{"..tostring( r.r )..", "..tostring( r.g )..", "..tostring( r.b )..", "..tostring( r.a ).."}"
|
||||
end,
|
||||
-- __add = function( v1, v2 )
|
||||
-- return Vector2:new( v1.x + v2.x, v1.y + v2.y )
|
||||
-- end,
|
||||
-- __sub = function( v1, v2 )
|
||||
-- return Vector2:new( v1.x - v2.x, v1.y - v2.y )
|
||||
-- end,
|
||||
-- __mul = function( v1, v2 )
|
||||
-- return Vector2:new( v1.x * v2.x, v1.y * v2.y )
|
||||
-- end,
|
||||
-- __div = function( v1, v2 )
|
||||
-- return Vector2:new( v1.x / v2.x, v1.y / v2.y )
|
||||
-- end,
|
||||
-- __mod = function( v, value )
|
||||
-- return Vector2:new( math.fmod( v.x, value ), math.fmod( v.y, value ) )
|
||||
-- end,
|
||||
-- __pow = function( v, value )
|
||||
-- return Vector2:new( v.x ^ value, v.y ^ value )
|
||||
-- end,
|
||||
-- __unm = function( v )
|
||||
-- return Vector2:new( -v.x, -v.y )
|
||||
-- end,
|
||||
-- __idiv = function( v, value )
|
||||
-- return Vector2:new( v.x // value, v.y // value )
|
||||
-- end,
|
||||
-- __len = function( v )
|
||||
-- local len = 0
|
||||
|
||||
-- for _, _ in pairs( v ) do
|
||||
-- len = len + 1
|
||||
-- end
|
||||
|
||||
-- return len
|
||||
-- end,
|
||||
-- __eq = function( v1, v2 )
|
||||
-- return v1.x == v2.x and v1.y == v2.y
|
||||
-- end,
|
||||
}
|
||||
|
||||
function Color:new( r, g, b, a )
|
||||
if type( r ) == "table" then
|
||||
r, g, b, a = table.unpack( r )
|
||||
elseif type( r ) == "nil" then
|
||||
r, g, b, a = 0, 0, 0, 255
|
||||
end
|
||||
|
||||
if a == nil then
|
||||
a = 255
|
||||
end
|
||||
|
||||
local o = {
|
||||
r = r,
|
||||
g = g,
|
||||
b = b,
|
||||
a = a,
|
||||
}
|
||||
setmetatable( o, Color.meta )
|
||||
return o
|
||||
end
|
||||
|
||||
function Color:set( r, g, b, a )
|
||||
if type( r ) == "table" then
|
||||
r, g, b, a = table.unpack( r )
|
||||
elseif type( r ) == "nil" then
|
||||
r, g, b, a = 0, 0, 0, 0
|
||||
end
|
||||
|
||||
if a == nil then
|
||||
a = 255
|
||||
end
|
||||
|
||||
self.r = r
|
||||
self.g = g
|
||||
self.b = b
|
||||
self.a = a
|
||||
end
|
||||
|
||||
function Color:arr()
|
||||
return { self.r, self.g, self.b, self.a }
|
||||
end
|
||||
|
||||
function Color:unpack()
|
||||
return self.r, self.g, self.b, self.a
|
||||
end
|
||||
|
||||
function Color:clone()
|
||||
return Color:new( self.r, self.g, self.b, self.a )
|
||||
end
|
||||
|
||||
return Color
|
||||
Reference in New Issue
Block a user