-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGRTopView.sc
93 lines (73 loc) · 2.27 KB
/
GRTopView.sc
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
GRTopView : GRContainerView {
var
pointsPressedBySource
;
*new { |numCols, numRows, enabled=true|
^super.new(nil, nil, numCols, numRows, enabled, true).initGRTopView;
}
initGRTopView {
pointsPressedBySource = Array.fill2D(numCols, numRows) { Array.new }
}
*newDetached { |numCols, numRows, enabled=true| // same as *new, this is just to override superclass version
^this.new(numCols, numRows, enabled);
}
*newDisabled { |numCols, numRows|
^this.new(numCols, numRows, false);
}
// Parent - Child
setParentReference { |argParent, argOrigin|
Error("a % may not be added as a child to another view".format(this)).throw
}
// Button events and state
isPressedBySourceAt { |source, point|
^pointsPressedBySource[point.x][point.y].includes(source)
}
isReleasedBySourceAt { |source, point|
^this.isPressedBySourceAt(source, point).not
}
isPressedByOneSourceAt { |point|
^pointsPressedBySource[point.x][point.y].size == 1
}
isNotPressedByAnySourceAt { |point|
^pointsPressedBySource[point.x][point.y].isEmpty
}
press { |point|
Error("not available in %".format(this.class)).throw
}
release { |point|
Error("not available in %".format(this.class)).throw
}
handleViewButtonEvent { |source, point, pressed|
if (enabled) {
if (GRCommon.traceButtonEvents) {
"in % - button % at % (source: [%]) received.".format(
thisMethod,
if (pressed, "press", "release"),
point,
source
).postln
};
if (pressed) {
if (this.isReleasedBySourceAt(source, point)) {
pointsPressedBySource[point.x][point.y] = pointsPressedBySource[point.x][point.y].add(source);
if (GRCommon.traceButtonEvents) {
"in % - source [%] not referenced in array - reference was added.".format(thisMethod, source).postln
};
if (this.isPressedByOneSourceAt(point)) {
super.handleViewButtonEvent(source, point, true)
}
}
} {
if (this.isPressedBySourceAt(source, point)) {
pointsPressedBySource[point.x][point.y].remove(source);
if (GRCommon.traceButtonEvents) {
"in % - source [%] referenced in array - reference was removed.".format(thisMethod, source).postln
};
if (this.isNotPressedByAnySourceAt(point)) {
super.handleViewButtonEvent(source, point, false)
}
}
}
}
}
}