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

Class Drops

src/main/java/fieldbox/boxes/Drops.java:14–51  ·  view source on GitHub ↗

Entry-point for File drops from GLFW into Field

Source from the content-addressed store, hash-verified

12 * Entry-point for File drops from GLFW into Field
13 */
14public class Drops {
15
16 static public final Dict.Prop<Map<String, OnDrop>> onDrop = new Dict.Prop<>("onDrop").type()
17 .toCanon().autoConstructs(() -> new IdempotencyMap<OnDrop>(OnDrop.class));
18
19 public void dispatch(Box root, Window.Event<Window.Drop> drop) {
20
21 Box startAt = Intersects.startAt(drop.after.mouseState, root);
22
23 startAt.find(onDrop, startAt.upwards()).flatMap(x -> x.values()
24 .stream())
25 .forEach(x -> x.onDrop(drop));
26
27 if (!drop.properties.isTrue(Window.consumed, false))
28 startAt.find(onDrop, startAt.downwards())
29 .flatMap(x -> x.values().stream())
30 .forEach(x -> x.onDrop(drop));
31 }
32
33 private boolean intersectsWith(Box x, Vec2 position) {
34 Rect f = x.properties.get(Box.frame);
35 if (f == null) return false;
36 return f.intersects(position.get());
37 }
38
39 private Box selection(Box root) {
40 return root.breadthFirst(root.both())
41 .filter(x -> x.properties.isTrue(Mouse.isSelected, false) && x.properties.has(Box.frame) && x.properties.has(Box.name) && !x.properties.isTrue(Mouse.isSticky, false))
42 .findFirst()
43 .orElse(root);
44 }
45
46 public interface OnDrop {
47 void onDrop(Window.Event<Window.Drop> drop);
48 }
49
50
51}

Callers

nothing calls this directly

Calls 3

autoConstructsMethod · 0.80
toCanonMethod · 0.80
typeMethod · 0.80

Tested by

no test coverage detected