/ld27

To get this branch, use:
bzr branch http://9ix.org/bzr/ld27

« back to all changes in this revision

Viewing changes to zoetrope/debug/instrument.lua

  • Committer: Josh C
  • Date: 2013-08-25 00:16:36 UTC
  • Revision ID: josh@9ix.org-20130825001636-xoivc9byo1mdx0fu
1 goal in each maze

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
--
2
 
--              Responsible for setting the dimensions of all member sprites. Receives
3
 
--              x, y, width, and height arguments. This *must* be defined in order for
4
 
--              an instrument to be drawn properly. You do not need to resize the built-in
5
 
--              frame, titleBar, and title properties in this handler -- that is taken care
6
 
--              of for you.
7
 
--
8
 
--              An instrument is guaranteed to receive this event at least once before it
9
 
--              appears onscreen, so there is no need to set up dimensions of sprites anywhere
10
 
--              but here.
11
 
--
12
 
 
13
 
DebugInstrument = Group:extend
14
 
{
15
 
        -- Property: contentHeight
16
 
        -- Set by the instrument to indicate how much vertical space it wants.
17
 
        -- Changing this causes the debugger to recalculate layout for all instruments.
18
 
        -- A '*' indicates that it wants all available space. If the instrument
19
 
        -- doesn't want to be considered for layout, then it should set its visible
20
 
        -- property to false.
21
 
        contentHeight = 0,
22
 
 
23
 
        -- Property: width
24
 
        -- Should be either 'wide' or 'narrow', *not* a pixel width. This must
25
 
        -- be set when the instrument is created, and cannot be changed.
26
 
        width = 'narrow',
27
 
 
28
 
        -- Property: innerBorderColor
29
 
        -- Property: outerBorderColor
30
 
        -- Property: backgroundColor
31
 
        -- Property: titleBarColor
32
 
        -- Property: titleColor
33
 
        -- Color properties to customize appearance. These must be set when the
34
 
        -- instrument is created, and cannot be changed.
35
 
        outerBorderColor = {0, 0, 0},
36
 
        innerBorderColor = {255, 255, 255},
37
 
        backgroundColor = {0, 0, 0, 200},
38
 
        titleBarColor = {255, 255, 255},
39
 
        titleColor = {0, 0, 0},
40
 
 
41
 
        -- Property: spacing
42
 
        -- A recommended number of pixels to inset content or otherwise use
43
 
        -- as spacing, for consistency. You can ignore this if you like.
44
 
        spacing = 5,
45
 
 
46
 
        -- Property: titleBarHeight
47
 
        -- How tall the title bar should be. This must be set when the instrument
48
 
        -- is created, and cannot be changed.
49
 
        titleBarHeight = 20,
50
 
 
51
 
        -- Property: font
52
 
        -- Recommended font, for consistency.
53
 
 
54
 
        -- Property: outerFrame
55
 
        -- The <Fill> used to draw the outer frame of the instrument.
56
 
 
57
 
        -- Property: innerFrame
58
 
        -- The <Fill> used to draw the inner frame and background of the instrument.
59
 
 
60
 
        -- Property: titleBar
61
 
        -- The <Fill> used to draw the background of the title bar.
62
 
 
63
 
        -- Property: title
64
 
        -- The <Text> used to draw the instrument title on the title bar.
65
 
 
66
 
        new = function (self, obj)
67
 
                obj = self:extend(obj or {})
68
 
 
69
 
                if obj.width == 'wide' then
70
 
                        obj.font = 12
71
 
                else
72
 
                        obj.font = 11
73
 
                end
74
 
 
75
 
                obj.outerFrame = obj:add(Fill:new{ width = 0, height = 0, border = obj.outerBorderColor, fill = {0, 0, 0, 0} })
76
 
                obj.innerFrame = obj:add(Fill:new{ width = 0, height = 0, border = obj.innerBorderColor, fill = obj.backgroundColor })
77
 
                obj.titleBar = obj:add(Fill:new{ width = 0, height = obj.titleBarHeight, fill = obj.titlebarColor })
78
 
                obj.title = obj:add(Text:new{ width = 0, height = 0, fill = obj.titlebarColor, font = obj.font,
79
 
                                      tint = {obj.titleColor[1] / 255, obj.titleColor[2] / 255, obj.titleColor[3] / 255}})
80
 
 
81
 
                if obj.onNew then obj:onNew() end
82
 
                return obj
83
 
        end,
84
 
 
85
 
        -- Method: resize
86
 
        -- Tells the instrument to resize itself to match the dimensions passed.
87
 
        --
88
 
        -- Arguments:
89
 
        --              x - x coordinate in pixels
90
 
        --              y - y coordinate in pixels
91
 
        --              width - width in pixels
92
 
        --              height - height in pixels
93
 
        --
94
 
        -- Returns:
95
 
        --              nothing
96
 
 
97
 
        resize = function (self, x, y, width, height)
98
 
                self.outerFrame.x = x - 1
99
 
                self.outerFrame.y = y - 1
100
 
                self.outerFrame.width = width + 2
101
 
                self.outerFrame.height = height + 2
102
 
 
103
 
                self.innerFrame.x = x
104
 
                self.innerFrame.y = y
105
 
                self.innerFrame.width = width
106
 
                self.innerFrame.height = height
107
 
 
108
 
                self.titleBar.x = x
109
 
                self.titleBar.y = y
110
 
                self.titleBar.width = width
111
 
 
112
 
                local titleHeight = self.title._fontObj:getHeight()
113
 
                local titleInset = (self.titleBarHeight - titleHeight) / 2
114
 
                self.title.x = self.titleBar.x + titleInset
115
 
                self.title.y = self.titleBar.y + titleInset
116
 
                self.title.width = width - titleInset * 2
117
 
                self.title.height = titleHeight
118
 
 
119
 
                if self.onResize then
120
 
                        self:onResize(x, y + self.titleBarHeight, width, height - self.titleBarHeight)
121
 
                end
122
 
        end,
123
 
 
124
 
        -- Method: totalHeight
125
 
        -- Returns the total height of the instrument, including the title bar.
126
 
        -- 
127
 
        -- Arguments:
128
 
        --              none
129
 
        --
130
 
        -- Returns:
131
 
        --              pixel height, 0 if no display wanted, or '*' (for maximum height available)
132
 
 
133
 
        totalHeight = function (self)
134
 
                if self.contentHeight == 0 or self.contentHeight == '*' then
135
 
                        return self.contentHeight
136
 
                else
137
 
                        return self.contentHeight + self.titleBarHeight
138
 
                end
139
 
        end,
140
 
 
141
 
        draw = function (self, x, y)
142
 
                local sx, sy, sw, sh = love.graphics.getScissor()
143
 
                love.graphics.setScissor(the.app.inset.x + self.outerFrame.x - 1,
144
 
                                         the.app.inset.y + self.outerFrame.y - 1,
145
 
                                         self.outerFrame.width + 2, self.outerFrame.height + 2)
146
 
                Group.draw(self, x, y)
147
 
 
148
 
                if sx and sy then
149
 
                        love.graphics.setScissor(sx, sy, sw, sh)
150
 
                else
151
 
                        love.graphics.setScissor()
152
 
                end
153
 
        end
154
 
}
155
 
 
156
 
 
157
 
DebugInstrumentButton = Button:extend
158
 
{
159
 
        width = 75,
160
 
        height = 25,
161
 
 
162
 
        new = function (self, obj)
163
 
                obj = self:extend(obj or {})
164
 
 
165
 
                obj.background = Fill:new
166
 
                {
167
 
                        width = self.width, height = self.height,
168
 
                        fill = {0, 0, 0, 64},
169
 
                        border = {255, 255, 255}
170
 
                }
171
 
 
172
 
                obj.label = Text:new
173
 
                {
174
 
                        width = self.width, height = self.height,
175
 
                        align = 'center',
176
 
                        y = 5,
177
 
                        font = DebugInstrument.font,
178
 
                        text = obj.label
179
 
                }
180
 
 
181
 
                Button.new(obj)
182
 
                return obj
183
 
        end,
184
 
 
185
 
        onMouseEnter = function (self)
186
 
                self.background.fill = { 128, 128, 128, 200 }
187
 
        end,
188
 
 
189
 
        onMouseExit = function (self)
190
 
                self.background.fill = {0, 0, 0, 64 }
191
 
        end
192
 
}