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
|
-- Class: Subview
-- A subview is a view that steals lives inside a parent view. It's useful for
-- things like a pause overlay or inventory screen, which don't interact with a main view
-- directly and are useful when they're sectioned off into their own world.
--
-- A subview should not interact much with its parent view, if at all. It's important
-- to, if a subview calls a method on its parent, that it set the.view to the parent,
-- and then restore it to itself afterwards.
--
-- A subview is modal, meaning that although the parent view is visible underneath
-- its subview, it does not receive any update-related events. If you want to display
-- something on top of a view while it still is visible and updating, use a <Group>
-- instead.
--
-- Events:
-- onActivate - Called when the subview activates.
-- onDeactivate - Called when the subview deactivates.
--
-- Extends:
-- <View>
Subview = View:extend
{
-- Property: drawParent
-- Draw the parent view underneath this one? Defaults to true.
drawParent = true,
-- Property: activated
-- Is this subview currently visible and active? This property is read-only.
-- To change the status of the subview, use either the <activate()> or
-- <deactivate()> methods.
activated = false,
-- Method: activate
-- Shows the subview.
--
-- Arguments:
-- none
--
-- Returns:
-- nothing
activate = function (self)
if the.view == self then
if STRICT then
local info = debug.getinfo(2, 'Sl')
print('Warning: treid to activate an already active subview (' ..
info.short_src .. ', line ' .. info.currentline .. ')')
end
return
end
self.parentView = the.view
the.app.view = self
self.activated = true
if self.onActivate then self:onActivate() end
end,
-- Method: deactivate
-- Hides the subview.
--
-- Arguments:
-- none
--
-- Returns:
-- nothing
deactivate = function (self)
the.app.view = self.parentView
self.activated = false
if self.onDeactivate then self:onDeactivate() end
end,
draw = function (self, x, y)
if self.drawParent and self.parentView then self.parentView:draw(x, y) end
View.draw(self, x, y)
end
}
|