2
-- A fill paints a rectangle of a solid color and border.
3
-- Either fill or border are optional.
10
-- A table of color values in RGBA order. Each value should fall
11
-- between 0 and 255. The fill sprite fills this color in its bounds
13
fill = { 255, 255, 255, 255 },
16
-- A table of color values in RGBA order. Each value should fall
17
-- between 0 and 255. The fill sprite draws the border in this color
18
-- after filling in a color (if any).
21
draw = function (self, x, y)
22
x = math.floor(x or self.x)
23
y = math.floor(y or self.y)
24
if not self.visible or self.alpha <= 0 then return end
27
assert(type(x) == 'number', 'visible fill does not have a numeric x property')
28
assert(type(y) == 'number', 'visible fill does not have a numeric y property')
29
assert(type(self.width) == 'number', 'visible fill does not have a numeric width property')
30
assert(type(self.height) == 'number', 'visible fill does not have a numeric height property')
31
assert(self.fill or self.border, 'visible fill does not have a fill or border property')
36
local scaleX = self.scale * self.distort.x
37
local scaleY = self.scale * self.distort.y
39
if scaleX ~= 1 or scaleY ~= 1 or self.rotation ~= 0 then
41
love.graphics.translate(x + self.width / 2, y + self.height / 2)
42
love.graphics.scale(scaleX, scaleY)
43
love.graphics.rotate(self.rotation)
44
love.graphics.translate(- (x + self.width / 2), - (y + self.height / 2))
47
-- draw fill and border
50
local fillAlpha = self.fill[4] or 255
52
love.graphics.setColor(self.fill[1] * self.tint[1],
53
self.fill[2] * self.tint[2],
54
self.fill[3] * self.tint[3],
55
fillAlpha * self.alpha)
57
love.graphics.rectangle('fill', x, y, self.width, self.height)
61
local borderAlpha = self.border[4] or 255
63
love.graphics.setColor(self.border[1] * self.tint[1],
64
self.border[2] * self.tint[2],
65
self.border[3] * self.tint[3],
66
borderAlpha * self.alpha)
68
love.graphics.rectangle('line', x, y, self.width, self.height)
71
-- reset color and rotation
73
love.graphics.setColor(255, 255, 255, 255)
75
if scaleX ~= 1 or scaleY ~= 1 or self.rotation ~= 0 then
80
__tostring = function (self)
81
local result = 'Fill (x: ' .. self.x .. ', y: ' .. self.y ..
82
', w: ' .. self.width .. ', h: ' .. self.height .. ', '
85
result = result .. 'fill {' .. table.concat(self.fill, ', ') .. '}, '
87
result = result .. 'no fill, '
91
result = result .. 'border {' .. table.concat(self.border, ', ') .. '}, '
93
result = result .. 'no border, '
97
result = result .. 'active, '
99
result = result .. 'inactive, '
103
result = result .. 'visible, '
105
result = result .. 'invisible, '
109
result = result .. 'solid'
111
result = result .. 'not solid'