-
Notifications
You must be signed in to change notification settings - Fork 8
/
ActivityZone.moon
47 lines (37 loc) · 1.11 KB
/
ActivityZone.moon
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
class ActivityZone extends Rect
new: ( @resize, @activityCheck ) =>
super!
@active = false
@elements = Stack!
reconfigure: =>
@active = false
addUIElement: ( element ) =>
@elements\insert element
element\activate @active
removeUIElement: ( element ) =>
@elements\remove element
-- bottom-up click propagation does not deal with mouse down/up events.
clickHandler: ( button ) =>
unless @containsPoint Mouse.clickX, Mouse.clickY
return
for _, element in ipairs @elements
-- if clickHandler returns false, the click stops propagating.
if element.clickHandler and element\clickHandler( button ) == false
break
activityCheck: ( displayRequested ) =>
if displayRequested == true
return true
unless Mouse.inWindow
return false
if Mouse.dead
return false
return @containsPoint Mouse.x, Mouse.y
update: ( displayRequested, clickPending ) =>
nowActive = @activityCheck displayRequested
if @active != nowActive
@active = nowActive
for id, element in ipairs @elements
element\activate nowActive
if clickPending != false
@clickHandler clickPending
return nowActive