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 |
|
35
by Josh C
cluke009 zoetrope + my spritebatch changes |
40 |
local origX = self.origin.x or (self.width / 2) |
41 |
local origY = self.origin.y or (self.height / 2) |
|
42 |
||
1
by Josh C
zoetrope 1.4 |
43 |
love.graphics.push() |
35
by Josh C
cluke009 zoetrope + my spritebatch changes |
44 |
love.graphics.translate(x + origX, y + origY) |
1
by Josh C
zoetrope 1.4 |
45 |
love.graphics.scale(scaleX, scaleY) |
46 |
love.graphics.rotate(self.rotation) |
|
35
by Josh C
cluke009 zoetrope + my spritebatch changes |
47 |
love.graphics.translate(- (x + origX), - (y + origY)) |
1
by Josh C
zoetrope 1.4 |
48 |
end |
49 |
||
50 |
-- draw fill and border |
|
51 |
||
52 |
if self.fill then |
|
53 |
local fillAlpha = self.fill[4] or 255 |
|
54 |
||
55 |
love.graphics.setColor(self.fill[1] * self.tint[1], |
|
56 |
self.fill[2] * self.tint[2], |
|
57 |
self.fill[3] * self.tint[3], |
|
58 |
fillAlpha * self.alpha) |
|
59 |
||
60 |
love.graphics.rectangle('fill', x, y, self.width, self.height) |
|
61 |
end |
|
62 |
||
63 |
if self.border then |
|
64 |
local borderAlpha = self.border[4] or 255 |
|
65 |
||
66 |
love.graphics.setColor(self.border[1] * self.tint[1], |
|
67 |
self.border[2] * self.tint[2], |
|
68 |
self.border[3] * self.tint[3], |
|
69 |
borderAlpha * self.alpha) |
|
70 |
||
71 |
love.graphics.rectangle('line', x, y, self.width, self.height) |
|
72 |
end |
|
73 |
||
74 |
-- reset color and rotation |
|
75 |
||
76 |
love.graphics.setColor(255, 255, 255, 255) |
|
77 |
||
78 |
if scaleX ~= 1 or scaleY ~= 1 or self.rotation ~= 0 then |
|
79 |
love.graphics.pop() |
|
80 |
end |
|
81 |
end, |
|
82 |
||
83 |
__tostring = function (self) |
|
35
by Josh C
cluke009 zoetrope + my spritebatch changes |
84 |
local result = 'Fill (x: ' .. tostring(self.x) .. ', y: ' .. tostring(self.y) .. |
85 |
', w: ' .. tostring(self.width) .. ', h: ' .. tostring(self.height) .. ', ' |
|
1
by Josh C
zoetrope 1.4 |
86 |
|
87 |
if self.fill then |
|
88 |
result = result .. 'fill {' .. table.concat(self.fill, ', ') .. '}, ' |
|
89 |
else |
|
90 |
result = result .. 'no fill, ' |
|
91 |
end |
|
92 |
||
93 |
if self.border then |
|
94 |
result = result .. 'border {' .. table.concat(self.border, ', ') .. '}, ' |
|
95 |
else |
|
96 |
result = result .. 'no border, ' |
|
97 |
end |
|
98 |
||
99 |
if self.active then |
|
100 |
result = result .. 'active, ' |
|
101 |
else |
|
102 |
result = result .. 'inactive, ' |
|
103 |
end |
|
104 |
||
105 |
if self.visible then |
|
106 |
result = result .. 'visible, ' |
|
107 |
else |
|
108 |
result = result .. 'invisible, ' |
|
109 |
end |
|
110 |
||
111 |
if self.solid then |
|
112 |
result = result .. 'solid' |
|
113 |
else |
|
114 |
result = result .. 'not solid' |
|
115 |
end |
|
116 |
||
117 |
return result .. ')' |
|
118 |
end |
|
119 |
} |