1
-- Class: DebugInstrument
2
-- This is a container that manages the location and size of debug instruments
3
-- onscreen. This also creates a title bar and framed content area.
6
-- Responsible for setting the dimensions of all member sprites. Receives
7
-- x, y, width, and height arguments. This *must* be defined in order for
8
-- an instrument to be drawn properly. You do not need to resize the built-in
9
-- frame, titleBar, and title properties in this handler -- that is taken care
12
-- An instrument is guaranteed to receive this event at least once before it
13
-- appears onscreen, so there is no need to set up dimensions of sprites anywhere
19
DebugInstrument = Group:extend
21
-- Property: contentHeight
22
-- Set by the instrument to indicate how much vertical space it wants.
23
-- Changing this causes the debugger to recalculate layout for all instruments.
24
-- A '*' indicates that it wants all available space. If the instrument
25
-- doesn't want to be considered for layout, then it should set its visible
30
-- Should be either 'wide' or 'narrow', *not* a pixel width. This must
31
-- be set when the instrument is created, and cannot be changed.
34
-- Property: innerBorderColor
35
-- Property: outerBorderColor
36
-- Property: backgroundColor
37
-- Property: titleBarColor
38
-- Property: titleColor
39
-- Color properties to customize appearance. These must be set when the
40
-- instrument is created, and cannot be changed.
41
outerBorderColor = {0, 0, 0},
42
innerBorderColor = {255, 255, 255},
43
backgroundColor = {0, 0, 0, 200},
44
titleBarColor = {255, 255, 255},
45
titleColor = {0, 0, 0},
48
-- A recommended number of pixels to inset content or otherwise use
49
-- as spacing, for consistency. You can ignore this if you like.
52
-- Property: titleBarHeight
53
-- How tall the title bar should be. This must be set when the instrument
54
-- is created, and cannot be changed.
58
-- Recommended font, for consistency.
60
-- Property: outerFrame
61
-- The <Fill> used to draw the outer frame of the instrument.
63
-- Property: innerFrame
64
-- The <Fill> used to draw the inner frame and background of the instrument.
67
-- The <Fill> used to draw the background of the title bar.
70
-- The <Text> used to draw the instrument title on the title bar.
72
new = function (self, obj)
73
obj = self:extend(obj or {})
75
if obj.width == 'wide' then
81
obj.outerFrame = obj:add(Fill:new{ width = 0, height = 0, border = obj.outerBorderColor, fill = {0, 0, 0, 0} })
82
obj.innerFrame = obj:add(Fill:new{ width = 0, height = 0, border = obj.innerBorderColor, fill = obj.backgroundColor })
83
obj.titleBar = obj:add(Fill:new{ width = 0, height = obj.titleBarHeight, fill = obj.titlebarColor })
84
obj.title = obj:add(Text:new{ width = 0, height = 0, fill = obj.titlebarColor, font = obj.font,
85
tint = {obj.titleColor[1] / 255, obj.titleColor[2] / 255, obj.titleColor[3] / 255}})
87
if obj.onNew then obj:onNew() end
92
-- Tells the instrument to resize itself to match the dimensions passed.
95
-- x - x coordinate in pixels
96
-- y - y coordinate in pixels
97
-- width - width in pixels
98
-- height - height in pixels
103
resize = function (self, x, y, width, height)
104
self.outerFrame.x = x - 1
105
self.outerFrame.y = y - 1
106
self.outerFrame.width = width + 2
107
self.outerFrame.height = height + 2
109
self.innerFrame.x = x
110
self.innerFrame.y = y
111
self.innerFrame.width = width
112
self.innerFrame.height = height
116
self.titleBar.width = width
118
local titleHeight = self.title._fontObj:getHeight()
119
local titleInset = (self.titleBarHeight - titleHeight) / 2
120
self.title.x = self.titleBar.x + titleInset
121
self.title.y = self.titleBar.y + titleInset
122
self.title.width = width - titleInset * 2
123
self.title.height = titleHeight
125
if self.onResize then
126
self:onResize(x, y + self.titleBarHeight, width, height - self.titleBarHeight)
130
-- Method: totalHeight
131
-- Returns the total height of the instrument, including the title bar.
137
-- pixel height, 0 if no display wanted, or '*' (for maximum height available)
139
totalHeight = function (self)
140
if self.contentHeight == 0 or self.contentHeight == '*' then
141
return self.contentHeight
143
return self.contentHeight + self.titleBarHeight
147
draw = function (self, x, y)
148
local sx, sy, sw, sh = love.graphics.getScissor()
149
love.graphics.setScissor(the.app.inset.x + self.outerFrame.x - 1,
150
the.app.inset.y + self.outerFrame.y - 1,
151
self.outerFrame.width + 2, self.outerFrame.height + 2)
152
Group.draw(self, x, y)
155
love.graphics.setScissor(sx, sy, sw, sh)
157
love.graphics.setScissor()
162
-- Class: DebugInstrumentButton
163
-- A convenience class to keep the appearance of buttons in instruments consistent.
165
DebugInstrumentButton = Button:extend
170
new = function (self, obj)
171
obj = self:extend(obj or {})
173
obj.background = Fill:new
175
width = self.width, height = self.height,
176
fill = {0, 0, 0, 64},
177
border = {255, 255, 255}
182
width = self.width, height = self.height,
185
font = DebugInstrument.font,
193
onMouseEnter = function (self)
194
self.background.fill = { 128, 128, 128, 200 }
197
onMouseExit = function (self)
198
self.background.fill = {0, 0, 0, 64 }