Fundamental interaction support for FLines when placed on the canvas. FLines can respond to mouse events --- OnMouseEnter and OnMouseExit. Add FLines that support interaction to the "interactiveDrawing" property (signature Map >). Add implementations of Mouse.OnMouseE
| 21 | * FLines can respond to mouse events --- OnMouseEnter and OnMouseExit. Add FLines that support interaction to the "interactiveDrawing" property |
| 22 | * (signature Map<String, Function<Box, FLine>>). Add implementations of Mouse.OnMouseEnter,Mouse.OnMouseExit & Mouse.OnMouseDown to FLine.attributes |
| 23 | * (the shape of the line governs the sense of "enter" and "exit"). See MarkingMenus for an example of the use of this class. |
| 24 | */ |
| 25 | public class FLineInteraction extends Box implements Drawing.Drawer, Mouse.OnMouseDown, Mouse.OnMouseMove { |
| 26 | |
| 27 | static public final Dict.Prop<FLineInteraction> interaction = new Dict.Prop<>("interaction").type().toCanon() |
| 28 | .doc("the FLineInteraction Plugin"); |
| 29 | static public final Dict.Prop<FLine> _interactionTarget = new Dict.Prop<>("_interactionTarget").type().toCanon(); |
| 30 | |
| 31 | static public final Dict.Prop<Cached<FLine, Object, Area>> projectedArea = new Dict.Prop<>("_projectedArea"); |
| 32 | |
| 33 | static public final Dict.Prop<IdempotencyMap<Function<Box, FLine>>> interactiveDrawing = new Dict.Prop<>("interactiveDrawing").type().toCanon().autoConstructs(() -> new IdempotencyMap<>(Function.class)).set(IO.dontCopy, true) |
| 34 | .doc("add lines to this property to make them interactive. onMouseExit and onMouseEnter attributes will be called appropriately. See FLineButton for a helper class."); |
| 35 | |
| 36 | static public final Dict.Prop<Float> interactionOutset = new Dict.Prop<>("interactionOutset").type().toCanon() |
| 37 | .doc("sets how much shapes are outset for the purposes of hovering, clicking and draging").set(Dict.domain, "fline"); |
| 38 | |
| 39 | |
| 40 | static public final Dict.Prop<IdempotencyMap<Supplier<FLine>>> interactiveLines = new Dict.Prop<>("interactiveLines").type().autoConstructs(() -> new IdempotencyMap<>(Supplier.class)).set(IO.dontCopy, true) |
| 41 | .toCanon() |
| 42 | .doc("add lines to this property to make them interactive. onMouseExit and onMouseEnter attributes will be called appropriately. See FLineButton for a helper class."); |
| 43 | |
| 44 | public FLineInteraction(Box root) { |
| 45 | properties.putToList(Drawing.drawers, this); |
| 46 | properties.put(interaction, this); |
| 47 | properties.putToMap(Mouse.onMouseDown, "__flineInteraction__", this); |
| 48 | properties.putToMap(Mouse.onMouseMove, "__flineInteraction__", this); |
| 49 | } |
| 50 | |
| 51 | Set<FLine> all = null; |
| 52 | |
| 53 | @Override |
| 54 | public void draw(DrawingInterface context) { |
| 55 | all = new LinkedHashSet<>(); |
| 56 | this.breadthFirst(this.both()).forEach(x -> { |
| 57 | try { |
| 58 | Rect r = x.properties.get(frame); |
| 59 | { |
| 60 | Map<String, Function<Box, FLine>> drawing = x.properties |
| 61 | .get(interactiveDrawing); |
| 62 | |
| 63 | if (drawing != null && drawing.size() > 0) { |
| 64 | Iterator<Function<Box, FLine>> it = drawing.values().iterator(); |
| 65 | while (it.hasNext()) { |
| 66 | Function<Box, FLine> f = it.next(); |
| 67 | FLine fl = f.apply(x); |
| 68 | if (fl == null) it.remove(); |
| 69 | else all.add(fl); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | { |
| 74 | Map<String, Supplier<FLine>> drawing = x.properties.get(interactiveLines); |
| 75 | |
| 76 | if (drawing != null && drawing.size() > 0) { |
| 77 | Iterator<Supplier<FLine>> it = drawing.values().iterator(); |
| 78 | while (it.hasNext()) { |
| 79 | Supplier<FLine> f = it.next(); |
| 80 | FLine fl = f.get(); |
nothing calls this directly
no test coverage detected