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
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
13
DebugInstrument = Group:extend
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
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.
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},
42
-- A recommended number of pixels to inset content or otherwise use
43
-- as spacing, for consistency. You can ignore this if you like.
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.
52
-- Recommended font, for consistency.
54
-- Property: outerFrame
55
-- The <Fill> used to draw the outer frame of the instrument.
57
-- Property: innerFrame
58
-- The <Fill> used to draw the inner frame and background of the instrument.
61
-- The <Fill> used to draw the background of the title bar.
64
-- The <Text> used to draw the instrument title on the title bar.
66
new = function (self, obj)
67
obj = self:extend(obj or {})
69
if obj.width == 'wide' then
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}})
81
if obj.onNew then obj:onNew() end
86
-- Tells the instrument to resize itself to match the dimensions passed.
89
-- x - x coordinate in pixels
90
-- y - y coordinate in pixels
91
-- width - width in pixels
92
-- height - height in pixels
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
103
self.innerFrame.x = x
104
self.innerFrame.y = y
105
self.innerFrame.width = width
106
self.innerFrame.height = height
110
self.titleBar.width = width
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
119
if self.onResize then
120
self:onResize(x, y + self.titleBarHeight, width, height - self.titleBarHeight)
124
-- Method: totalHeight
125
-- Returns the total height of the instrument, including the title bar.
131
-- pixel height, 0 if no display wanted, or '*' (for maximum height available)
133
totalHeight = function (self)
134
if self.contentHeight == 0 or self.contentHeight == '*' then
135
return self.contentHeight
137
return self.contentHeight + self.titleBarHeight
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)
149
love.graphics.setScissor(sx, sy, sw, sh)
151
love.graphics.setScissor()
157
DebugInstrumentButton = Button:extend
162
new = function (self, obj)
163
obj = self:extend(obj or {})
165
obj.background = Fill:new
167
width = self.width, height = self.height,
168
fill = {0, 0, 0, 64},
169
border = {255, 255, 255}
174
width = self.width, height = self.height,
177
font = DebugInstrument.font,
185
onMouseEnter = function (self)
186
self.background.fill = { 128, 128, 128, 200 }
189
onMouseExit = function (self)
190
self.background.fill = {0, 0, 0, 64 }