/ld27

To get this branch, use:
bzr branch /bzr/ld27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
-- Class: DebugInstrument
-- This is a container that manages the location and size of debug instruments
-- onscreen. This also creates a title bar and framed content area.
--
-- Event: onResize
--		Responsible for setting the dimensions of all member sprites. Receives
--		x, y, width, and height arguments. This *must* be defined in order for
--		an instrument to be drawn properly. You do not need to resize the built-in
--		frame, titleBar, and title properties in this handler -- that is taken care
--		of for you.
--
--		An instrument is guaranteed to receive this event at least once before it
--		appears onscreen, so there is no need to set up dimensions of sprites anywhere
--		but here.
--
-- Extends:
-- 		<Group>

DebugInstrument = Group:extend
{
	-- Property: contentHeight
	-- Set by the instrument to indicate how much vertical space it wants.
	-- Changing this causes the debugger to recalculate layout for all instruments.
	-- A '*' indicates that it wants all available space. If the instrument
	-- doesn't want to be considered for layout, then it should set its visible
	-- property to false.
	contentHeight = 0,

	-- Property: width
	-- Should be either 'wide' or 'narrow', *not* a pixel width. This must
	-- be set when the instrument is created, and cannot be changed.
	width = 'narrow',

	-- Property: innerBorderColor
	-- Property: outerBorderColor
	-- Property: backgroundColor
	-- Property: titleBarColor
	-- Property: titleColor
	-- Color properties to customize appearance. These must be set when the
	-- instrument is created, and cannot be changed.
	outerBorderColor = {0, 0, 0},
	innerBorderColor = {255, 255, 255},
	backgroundColor = {0, 0, 0, 200},
	titleBarColor = {255, 255, 255},
	titleColor = {0, 0, 0},

	-- Property: spacing
	-- A recommended number of pixels to inset content or otherwise use
	-- as spacing, for consistency. You can ignore this if you like.
	spacing = 5,

	-- Property: titleBarHeight
	-- How tall the title bar should be. This must be set when the instrument
	-- is created, and cannot be changed.
	titleBarHeight = 20,

	-- Property: font
	-- Recommended font, for consistency.

	-- Property: outerFrame
	-- The <Fill> used to draw the outer frame of the instrument.

	-- Property: innerFrame
	-- The <Fill> used to draw the inner frame and background of the instrument.

	-- Property: titleBar
	-- The <Fill> used to draw the background of the title bar.

	-- Property: title
	-- The <Text> used to draw the instrument title on the title bar.

	new = function (self, obj)
		obj = self:extend(obj or {})

		if obj.width == 'wide' then
			obj.font = 12
		else
			obj.font = 11
		end

		obj.outerFrame = obj:add(Fill:new{ width = 0, height = 0, border = obj.outerBorderColor, fill = {0, 0, 0, 0} })
		obj.innerFrame = obj:add(Fill:new{ width = 0, height = 0, border = obj.innerBorderColor, fill = obj.backgroundColor })
		obj.titleBar = obj:add(Fill:new{ width = 0, height = obj.titleBarHeight, fill = obj.titlebarColor })
		obj.title = obj:add(Text:new{ width = 0, height = 0, fill = obj.titlebarColor, font = obj.font,
		                      tint = {obj.titleColor[1] / 255, obj.titleColor[2] / 255, obj.titleColor[3] / 255}})

		if obj.onNew then obj:onNew() end
		return obj
	end,

	-- Method: resize
	-- Tells the instrument to resize itself to match the dimensions passed.
	--
	-- Arguments:
	--		x - x coordinate in pixels
	--		y - y coordinate in pixels
	--		width - width in pixels
	--		height - height in pixels
	--
	-- Returns:
	--		nothing

	resize = function (self, x, y, width, height)
		self.outerFrame.x = x - 1
		self.outerFrame.y = y - 1
		self.outerFrame.width = width + 2
		self.outerFrame.height = height + 2

		self.innerFrame.x = x
		self.innerFrame.y = y
		self.innerFrame.width = width
		self.innerFrame.height = height

		self.titleBar.x = x
		self.titleBar.y = y
		self.titleBar.width = width

		local titleHeight = self.title._fontObj:getHeight()
		local titleInset = (self.titleBarHeight - titleHeight) / 2
		self.title.x = self.titleBar.x + titleInset
		self.title.y = self.titleBar.y + titleInset
		self.title.width = width - titleInset * 2
		self.title.height = titleHeight

		if self.onResize then
			self:onResize(x, y + self.titleBarHeight, width, height - self.titleBarHeight)
		end
	end,

	-- Method: totalHeight
	-- Returns the total height of the instrument, including the title bar.
	-- 
	-- Arguments:
	--		none
	--
	-- Returns:
	--		pixel height, 0 if no display wanted, or '*' (for maximum height available)

	totalHeight = function (self)
		if self.contentHeight == 0 or self.contentHeight == '*' then
			return self.contentHeight
		else
			return self.contentHeight + self.titleBarHeight
		end
	end,

	draw = function (self, x, y)
		local sx, sy, sw, sh = love.graphics.getScissor()
		love.graphics.setScissor(the.app.inset.x + self.outerFrame.x - 1,
		                         the.app.inset.y + self.outerFrame.y - 1,
		                         self.outerFrame.width + 2, self.outerFrame.height + 2)
		Group.draw(self, x, y)

		if sx and sy then
			love.graphics.setScissor(sx, sy, sw, sh)
		else
			love.graphics.setScissor()
		end
	end
}

-- Class: DebugInstrumentButton
-- A convenience class to keep the appearance of buttons in instruments consistent.

DebugInstrumentButton = Button:extend
{
	width = 75,
	height = 25,

	new = function (self, obj)
		obj = self:extend(obj or {})

		obj.background = Fill:new
		{
			width = self.width, height = self.height,
			fill = {0, 0, 0, 64},
			border = {255, 255, 255}
		}

		obj.label = Text:new
		{
			width = self.width, height = self.height,
			align = 'center',
			y = 5,
			font = DebugInstrument.font,
			text = obj.label
		}

		Button.new(obj)
		return obj
	end,

	onMouseEnter = function (self)
		self.background.fill = { 128, 128, 128, 200 }
	end,

	onMouseExit = function (self)
		self.background.fill = {0, 0, 0, 64 }
	end
}