-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclickGesture.sj
70 lines (65 loc) · 2.2 KB
/
clickGesture.sj
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
enum clickState (
none
entered
pressed
)
#clickable(
onClickGestureEnter(element : '#element)'void
onClickGestureLeave(element : '#element)'void
onClickGesturePress(element : '#element)'void
onClickGestureClick(element : '#element)'void
)
clickGesture(
element : empty'weak #element
clickable : empty'weak #clickable
rect := rect()
_state := clickState.none
getState() { _state }
fireMouseEvent(mouseEvent : 'mouseEvent)'bool {
ifValid e : heap element {
if rect.containsPoint(mouseEvent.point) {
switch mouseEvent.eventType {
mouseEventType.up {
_state = clickState.none
mouse_release(e)
clickable?.onClickGestureClick(e)
false
}
mouseEventType.down {
_state = clickState.pressed
mouse_capture(e)
clickable?.onClickGesturePress(e)
false
}
mouseEventType.move {
if _state == clickState.none {
if mouseEvent.isLeftDown {
_state = clickState.pressed
} else {
_state = clickState.entered
}
clickable?.onClickGestureEnter(e)
}
!mouse_hasCapture(e)
}
default {
true
}
}
} else {
if _state == clickState.entered || _state == clickState.pressed {
clickable?.onClickGestureLeave(e)
_state = clickState.none
}
if mouseEvent.eventType == mouseEventType.up && mouse_hasCapture(e) {
mouse_release(e)
false
} else {
!mouse_hasCapture(e)
}
}
} elseEmpty {
true
}
}
) { this }