/ld26-basecode

To get this branch, use:
bzr branch http://9ix.org/bzr/ld26-basecode
1 by Josh C
zoetrope 1.4
1
-- Class: Subview
2
-- A subview is a view that steals lives inside a parent view. It's useful for
3
-- things like a pause overlay or inventory screen, which don't interact with a main view
4
-- directly and are useful when they're sectioned off into their own world.
5
--
6
-- A subview should not interact much with its parent view, if at all. It's important
7
-- to, if a subview calls a method on its parent, that it set the.view to the parent,
8
-- and then restore it to itself afterwards.
9
--
10
-- A subview is modal, meaning that although the parent view is visible underneath
11
-- its subview, it does not receive any update-related events. If you want to display
12
-- something on top of a view while it still is visible and updating, use a <Group>
13
-- instead.
14
--
15
-- Events:
16
--		onActivate - Called when the subview activates.
17
--		onDeactivate - Called when the subview deactivates.
18
--
19
-- Extends:
20
--		<View>
21
22
Subview = View:extend
23
{
24
	-- Property: drawParent
25
	-- Draw the parent view underneath this one? Defaults to true.
26
	drawParent = true,
27
28
	-- Property: activated
29
	-- Is this subview currently visible and active? This property is read-only.
30
	-- To change the status of the subview, use either the <activate()> or
31
	-- <deactivate()> methods.
32
	activated = false,
33
34
	-- Method: activate
35
	-- Shows the subview.
36
	-- 
37
	-- Arguments:
38
	--		none
39
	--
40
	-- Returns:
41
	--		nothing
42
43
	activate = function (self)
44
		if the.view == self then
45
			if STRICT then
46
				local info = debug.getinfo(2, 'Sl')
47
				print('Warning: treid to activate an already active subview (' ..
48
					  info.short_src .. ', line ' .. info.currentline .. ')')
49
			end
50
51
			return
52
		end
53
54
		self.parentView = the.view
55
		the.app.view = self
56
		self.activated = true
57
		if self.onActivate then self:onActivate() end
58
	end,
59
60
	-- Method: deactivate
61
	-- Hides the subview.
62
	-- 
63
	-- Arguments:
64
	--		none
65
	--
66
	-- Returns:
67
	--		nothing
68
69
	deactivate = function (self)
70
		the.app.view = self.parentView
71
		self.activated = false
72
		if self.onDeactivate then self:onDeactivate() end
73
	end,
74
75
	draw = function (self, x, y)
76
		if self.drawParent and self.parentView then self.parentView:draw(x, y) end
77
		View.draw(self, x, y)
78
	end
79
}