Entry-point for File drops from GLFW into Field
| 12 | * Entry-point for File drops from GLFW into Field |
| 13 | */ |
| 14 | public 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 | } |
nothing calls this directly
no test coverage detected