bzr branch
http://9ix.org/bzr/ld27
1
by Josh C
zoetrope 1.4 |
1 |
-- Class: Fill |
2 |
-- A fill paints a rectangle of a solid color and border. |
|
3 |
-- Either fill or border are optional. |
|
4 |
-- |
|
5 |
-- Extends: |
|
6 |
-- <Sprite> |
|
7 |
||
8 |
Fill = Sprite:extend{ |
|
9 |
-- Property: fill |
|
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 |
|
12 |
-- onscreen. |
|
13 |
fill = { 255, 255, 255, 255 }, |
|
14 |
||
15 |
-- Property: border |
|
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). |
|
19 |
border = nil, |
|
20 |
||
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 |
|
25 |
||
26 |
if STRICT then |
|
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') |
|
32 |
end |
|
33 |
||
34 |
-- rotate and scale |
|
35 |
||
36 |
local scaleX = self.scale * self.distort.x |
|
37 |
local scaleY = self.scale * self.distort.y |
|
38 |
||
39 |
if scaleX ~= 1 or scaleY ~= 1 or self.rotation ~= 0 then |
|
40 |
love.graphics.push() |
|
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)) |
|
45 |
end |
|
46 |
||
47 |
-- draw fill and border |
|
48 |
||
49 |
if self.fill then |
|
50 |
local fillAlpha = self.fill[4] or 255 |
|
51 |
||
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) |
|
56 |
||
57 |
love.graphics.rectangle('fill', x, y, self.width, self.height) |
|
58 |
end |
|
59 |
||
60 |
if self.border then |
|
61 |
local borderAlpha = self.border[4] or 255 |
|
62 |
||
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) |
|
67 |
||
68 |
love.graphics.rectangle('line', x, y, self.width, self.height) |
|
69 |
end |
|
70 |
||
71 |
-- reset color and rotation |
|
72 |
||
73 |
love.graphics.setColor(255, 255, 255, 255) |
|
74 |
||
75 |
if scaleX ~= 1 or scaleY ~= 1 or self.rotation ~= 0 then |
|
76 |
love.graphics.pop() |
|
77 |
end |
|
78 |
end, |
|
79 |
||
80 |
__tostring = function (self) |
|
81 |
local result = 'Fill (x: ' .. self.x .. ', y: ' .. self.y .. |
|
82 |
', w: ' .. self.width .. ', h: ' .. self.height .. ', ' |
|
83 |
||
84 |
if self.fill then |
|
85 |
result = result .. 'fill {' .. table.concat(self.fill, ', ') .. '}, ' |
|
86 |
else |
|
87 |
result = result .. 'no fill, ' |
|
88 |
end |
|
89 |
||
90 |
if self.border then |
|
91 |
result = result .. 'border {' .. table.concat(self.border, ', ') .. '}, ' |
|
92 |
else |
|
93 |
result = result .. 'no border, ' |
|
94 |
end |
|
95 |
||
96 |
if self.active then |
|
97 |
result = result .. 'active, ' |
|
98 |
else |
|
99 |
result = result .. 'inactive, ' |
|
100 |
end |
|
101 |
||
102 |
if self.visible then |
|
103 |
result = result .. 'visible, ' |
|
104 |
else |
|
105 |
result = result .. 'invisible, ' |
|
106 |
end |
|
107 |
||
108 |
if self.solid then |
|
109 |
result = result .. 'solid' |
|
110 |
else |
|
111 |
result = result .. 'not solid' |
|
112 |
end |
|
113 |
||
114 |
return result .. ')' |
|
115 |
end |
|
116 |
} |