## Fundamental drawing support for Boxes This is the ingest side of FLine drawing system --- the Field vector drawing framework. FLines are receptacles for geometry, both lines, tessellated shapes and text, and when added to certain properties of Boxes they will appear inside the FieldBoxWindow.
| 46 | * in the middle, a light grey gradient box, and a construction site selection trim. |
| 47 | */ |
| 48 | public class FLineDrawing extends Box implements Drawing.Drawer { |
| 49 | |
| 50 | static public final Dict.Prop<Map<String, Function<Box, FLine>>> frameDrawing = new Dict.Prop<>("frameDrawing").type() |
| 51 | .toCanon() |
| 52 | .doc("Functions that compute lines to be drawn along with this box") |
| 53 | .set(IO.dontCopy, true) |
| 54 | .set(Dict.readOnly, true).autoConstructs(() -> new IdempotencyMap<Function<Box, FLine>>(Function.class)); |
| 55 | |
| 56 | static public final Dict.Prop<Map<String, Function<Box, FLine>>> appearance = new Dict.Prop<>("frameDrawing").type() |
| 57 | .toCanon() |
| 58 | .doc("set this to a function that returns a list of FLines; it will be called whenever the box is selected or when its frame changes. Boxes with `_.appearance` set don't get the default grey box treatment") |
| 59 | .set(Dict.readOnly, true); |
| 60 | |
| 61 | static public final Dict.Prop<IdempotencyMap<Supplier<FLine>>> lines = new Dict.Prop<>("lines").type() |
| 62 | .toCanon() |
| 63 | .doc("Geometry to be drawn along with this box") |
| 64 | .autoConstructs(() -> new IdempotencyMap<>(Supplier.class).configureResourceLimits(1500, "too many lines in _.lines")) |
| 65 | .set(IO.dontCopy, true) |
| 66 | .set(Dict.readOnly, true); |
| 67 | |
| 68 | static public final Dict.Prop<Vec4> boxBackground = new Dict.Prop<>("boxBackground").type().toCanon().doc("sets the background color of this box. Defaults to `" + Colors.boxBackground1 + "`").autoConstructs(() -> Colors.boxBackground1).set(IO.persistent, true); |
| 69 | static public final Dict.Prop<Vec4> boxOutline = new Dict.Prop<>("boxOutline").type().toCanon().doc("sets the outline color of this box. Defaults to `" + Colors.boxStroke + "`").autoConstructs(() -> Colors.boxStroke).set(IO.persistent, true); |
| 70 | |
| 71 | static { |
| 72 | // accessing 'lines' causes a redraw to happen |
| 73 | lines.getAttributes().putToMap(Missing.watchRead, "drawOnLines", (box, v) -> { |
| 74 | Drawing.dirty(box); |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | static public final Dict.Prop<IdempotencyMap<Supplier<Collection<? extends Supplier<FLine>>>>> bulkLines = new Dict.Prop<>("bulkLines").type() |
| 79 | .toCanon() |
| 80 | .doc("Geometry to be drawn along with this box") |
| 81 | .autoConstructs(() -> new IdempotencyMap<>(Supplier.class)) |
| 82 | .set(IO.dontCopy, true) |
| 83 | .set(Dict.readOnly, true); |
| 84 | |
| 85 | static public final Dict.Prop<String> layer = new Dict.Prop<>("layer").type() |
| 86 | .toCanon() |
| 87 | .doc("which layer to draw to? Defaults to `__main__`, the other alternative right now is `__glass__` to draw on the blur layer above Field"); |
| 88 | |
| 89 | private final Box root; |
| 90 | |
| 91 | static public final Dict.Prop<FunctionOfBox<Boolean>> redraw = new Dict.Prop<>("redraw").type().toCanon().doc("call `_.redraw()` to cause the window to be redrawn"); |
| 92 | |
| 93 | public FLineDrawing(Box root) { |
| 94 | this.root = root; |
| 95 | this.properties.putToList(Drawing.drawers, this); |
| 96 | this.properties.put(redraw, x -> { |
| 97 | Drawing.dirty(x); |
| 98 | return true; |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | static public Function<Box, FLine> boxOrigin(Function<Box, FLine> wrap, Vec2 origin) { |
| 103 | return new Cached<Box, Object, FLine>((box, previously) -> { |
| 104 | Rect frame = box.properties.get(Box.frame); |
| 105 | Vec2 o = new Vec2(frame.x + frame.w * origin.x, frame.y + frame.h * origin.y); |
nothing calls this directly
no test coverage detected