MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / Chorder

Method Chorder

src/main/java/fieldbox/boxes/plugins/Chorder.java:62–142  ·  view source on GitHub ↗
(Box root)

Source from the content-addressed store, hash-verified

60
61 static public final Dict.Prop<Boolean> nox = new Dict.Prop<>("_nox").type()
62 .toCanon()
63 .doc("'NO eXecution. Set to prevent option-clicking from running this box");
64
65
66 public Chorder(Box root_unused) {
67
68 properties.put(Planes.plane, "__always__");
69
70 properties.putToMap(Mouse.onMouseDown, "__chorder__", (e, button) -> {
71 if (button != 0) return null;
72 if (!e.after.keyboardState.isAltDown()) return null;
73 if (e.after.keyboardState.isShiftDown()) return null;
74 if (e.after.keyboardState.isSuperDown()) return null;
75 if (e.after.keyboardState.isControlDown()) return null;
76
77 Optional<Drawing> drawing = this.find(Drawing.drawing, both())
78 .findFirst();
79 Vec2 point = new Vec2(e.after.mx, e.after.my);
80
81 Stream<Pair<Box, Rect>> fr = breadthFirst(both()).map(b -> new Pair<>(b, frame(b)))
82 .filter(b -> !b.first.properties.isTrue(nox, false))
83 .filter(b -> b.second != null);
84
85 List<Pair<Box, Rect>> frames = fr.collect(Collectors.toList());
86
87 Optional<Pair<Box, Rect>> hit = frames.stream()
88 .filter(b -> !b.first.properties.isTrue(Box.hidden, false))
89 .filter(b -> b.second.intersects(point))
90 .filter(b -> !b.first.properties.isTrue(nox, false))
91 .sorted((a, b) -> Float.compare(order(a.second), order(b.second)))
92 .findFirst();
93
94 if (hit.isPresent()) {
95 return executeNowAt(e, point, hit.get().first);
96 }
97
98 // we have an execution chord
99
100 return chordAt(frames, point, e);
101 });
102
103 this.properties.put(begin, box -> {
104 try {
105 return ThreadSync2.callInMainThreadAndWait(() -> {
106
107 Execution ex = getExecution(box, Execution.code);
108 if (ex != null)
109 ex.support(box, Execution.code).begin(box, getInitiator(box));
110
111 return () -> box.properties.computeIfAbsent(IsExecuting.executionCount, (k) -> 0) > 0;
112 });
113 } catch (Exception e) {
114 return () -> false;
115 }
116
117 });
118 this.properties.put(beginAgain, box ->
119 {

Callers

nothing calls this directly

Calls 15

frameMethod · 0.95
onMethod · 0.95
orderMethod · 0.95
executeNowAtMethod · 0.95
chordAtMethod · 0.95
supportMethod · 0.95
getInitiatorMethod · 0.95
dirtyMethod · 0.95
putToMapMethod · 0.80
isAltDownMethod · 0.80
isShiftDownMethod · 0.80

Tested by

no test coverage detected