Fundamental drawing support for Field. For each layer on the screen this box manages the primary OpenGL drawing resources (the MeshBuilder for meshes, lines and points) and their shaders. All drawing ultimately goes through these MeshBuilders. Drawing for the FieldBoxWindow is done lazily --
| 33 | * This class is the low level drawing plumbing FieldBox (Boxes) to talk to the Field graphics system (MeshBuilder). For drawing that you can use from Boxes, see FLineDrawing |
| 34 | */ |
| 35 | public class Drawing extends Box implements DrawingInterface { |
| 36 | |
| 37 | static public final Dict.Prop<Collection<Drawer>> drawers = new Dict.Prop<>("drawers").type() |
| 38 | .toCanon() |
| 39 | .doc("a collection of things that will draw inside the OpenGL paint context. Currently FrameDrawer & FLineInteraction plug into the window at this low level"); |
| 40 | static public final Dict.Prop<Collection<Drawer>> lateDrawers = new Dict.Prop<>("lateDrawers").type() |
| 41 | .toCanon() |
| 42 | .doc("a collection of things that will draw inside the OpenGL paint context, after everything else has drawn. Viewport plugs in at this level."); |
| 43 | static public final Dict.Prop<Drawing> drawing = new Dict.Prop<>("drawing").type() |
| 44 | .toCanon() |
| 45 | .doc("the Drawing plugin") |
| 46 | .set(Dict.readOnly, true); |
| 47 | |
| 48 | static public final Dict.Prop<Boolean> needRepaint = new Dict.Prop<>("_needRepaint").type() |
| 49 | .toCanon(); |
| 50 | static public final Dict.Prop<Vec2> windowSpace = new Dict.Prop<>("windowSpace").type() |
| 51 | .toCanon() |
| 52 | .doc("set to make this box stick to the viewport when it pans around. The value is a <code>Vec2(x,y)</code>. <code>x=0, y=0</code> pins the top left of this box to the top left of " + |
| 53 | "the window; similarly <code>x=1, y=1</code> pins the top left of this box to the bottom right. "); |
| 54 | |
| 55 | static public final Dict.Prop<Vec2> windowScale = new Dict.Prop<>("windowScale").type() |
| 56 | .toCanon() |
| 57 | .doc("like `windowSpace` but changes the width and height of the box to maintain a position in space for the lower right corner of a box. Combine with `_.windowSpace`."); |
| 58 | |
| 59 | static { |
| 60 | IO.persist(windowSpace); |
| 61 | IO.persist(windowScale); |
| 62 | } |
| 63 | |
| 64 | public float displayZ; |
| 65 | |
| 66 | Map<String, PerLayer> layerLocal = new LinkedHashMap<>(); |
| 67 | List<Bracketable> bracketableList = new ArrayList<>(); |
| 68 | boolean insideDrawing = false; |
| 69 | Vec2 lastDimensions = null; |
| 70 | Vec2 nextDimensions = null; |
| 71 | private Vec2 translation = new Vec2(0, 0); |
| 72 | private Vec2 translationNext = null; |
| 73 | private Vec2 scale = new Vec2(1.f, 1.f); |
| 74 | private Vec2 scaleNext = null; |
| 75 | private Vec2 boxScale = new Vec2(1, 1); |
| 76 | private float opacity = 1f; |
| 77 | |
| 78 | static int autoDirty = 0; |
| 79 | |
| 80 | public Drawing() { |
| 81 | this.properties.putToMap(IO.onPreparingToSave, "__checkWindowSpace__", () -> { |
| 82 | System.out.println(" handling window space boxes "); |
| 83 | |
| 84 | Map<Box, Rect> oldFrames = new LinkedHashMap<>(); |
| 85 | |
| 86 | this.breadthFirstAll(this.allDownwardsFrom()).forEach(x -> { |
| 87 | if (x.properties.has(frame)) |
| 88 | oldFrames.put(x, x.properties.get(frame).duplicate()); |
| 89 | }); |
| 90 | |
| 91 | updateWindowSpaceBoxes(translation, new Vec2(0, 0), lastDimensions, lastDimensions, scale, new Vec2(1, 1)); |
| 92 |