mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
72 lines
1.7 KiB
Lua
72 lines
1.7 KiB
Lua
local lg = love.graphics
|
|
|
|
local path = string.sub(..., 1, string.len(...) - string.len("/elements/box"))
|
|
local class = require(path .. "/lib/middleclass")
|
|
local element = require(path .. "/elements/element")
|
|
|
|
local box = class("pop.box", element)
|
|
|
|
function box:initialize(pop, parent, background)
|
|
element.initialize(self, pop, parent)
|
|
|
|
self.background = background or false
|
|
end
|
|
|
|
function box:draw() --NOTE these ifs are probably wrong
|
|
if self.background then
|
|
if type(self.background) == "table" then
|
|
lg.setColor(self.background)
|
|
lg.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
else
|
|
lg.setColor(255, 255, 255, 255)
|
|
local w, h = self.background:getDimensions()
|
|
-- scale!
|
|
w = self.w/w
|
|
h = self.h/h
|
|
lg.draw(self.background, self.x, self.y, 0, w, h)
|
|
end
|
|
end
|
|
|
|
return self
|
|
end
|
|
|
|
function box:debugDraw()
|
|
lg.setLineWidth(0.5)
|
|
lg.setColor(0, 0, 0, 100)
|
|
lg.rectangle("fill", self.x, self.y, self.w, self.h)
|
|
lg.setColor(0, 0, 200, 200)
|
|
lg.rectangle("line", self.x, self.y, self.w, self.h)
|
|
lg.setColor(200, 200, 255, 255)
|
|
lg.print("b", self.x, self.y)
|
|
end
|
|
|
|
function box:setBackground(background)
|
|
self.background = background
|
|
|
|
return self
|
|
end
|
|
|
|
function box:getBackground()
|
|
return self.background
|
|
end
|
|
|
|
function box:setColor(r, g, b, a)
|
|
self.background = {r, g, b, a}
|
|
|
|
if not a then
|
|
self.background[4] = 255
|
|
end
|
|
|
|
return self
|
|
end
|
|
|
|
function box:getColor()
|
|
if type(self.background) == "table" then
|
|
return self.background[1], self.background[1], self.background[3], self.background[4]
|
|
else
|
|
error("This box doesn't have a color.")
|
|
end
|
|
end
|
|
|
|
return box
|