render2d/overlay.rs#
Source: lib/render2d/overlay.rs
overlay -- an immediate-mode layer over the scene, made anew every frame (G6d, decision 24; docs/RENDER2D.md
"Überlagerung"): rubber bands, window and crossing boxes, grips, snap markers. A child of scene.rs.
The app fills it between frames (Scene::overlay: clear, then lines, boxes, grips, markers in drawing units or in pixels);
prepare maps everything into the target's pixels on the CPU in f64 (a drawing unit through the camera: at 1e7 and 1e-6
units per pixel well within 1/1000 px), makes records (scene.rs records(): the same 64 bytes as every record), the
styles, the visible list, the fills' edges in pixels (what count writes for the scene), all into the frame's own upload
buffer, and Renderer::record copies them into the overlay's buffers under the barriers that cover the scene's uploads and
draws them with fs_fill (strokes, arcs, dashes and fills: anti-aliased as everything else) after the scene's layers in the
same render pass. An empty overlay costs a test per frame: nothing goes up, nothing is drawn. No culling: what lies
beside the target the vertex shader clips away.
enum Spacewhat overlay coordinates are: drawing units (through the camera at prepare) or pixels of the target (x right, y down from its top left corner)DrawingPx
enum Gripa grip's state: AutoCAD's cold (unselected), hover, hot (selected)ColdHoverHot
/// a grip's side (px, odd: whole pixels around the pixel it sits on) and colours (cold, hover, hot, its outline)
GRIP_PX: f64 = 9.0
GRIP_COLD: u32 = 0xFF1E_64FF
GRIP_HOVER: u32 = 0xFFFF_8C1A
GRIP_HOT: u32 = 0xFFE0_2020
GRIP_EDGE: u32 = 0xFF1A_1A1A
/// a snap marker's size (px), its lines' width (px) and colour
MARKER_PX: f64 = 12.0
MARKER_WIDTH: f32 = 2.0
MARKER_COLOR: u32 = 0xFFD8_9000
/// AutoCAD's window box (solid, blue tint) and crossing box (dashed, green tint): outline, fill
WINDOW_EDGE: u32 = 0xFF20_60FF
WINDOW_FILL: u32 = 0x3020_60FF
CROSSING_EDGE: u32 = 0xFF20_A040
CROSSING_FILL: u32 = 0x3020_C040
struct Overlaythe overlay of a scene: made anew every frame (Scene::overlay). What it holds at prepare is drawn over the scenestruct OverlayInfowhat the last prepare made of the overlay (Scene::overlay_info). It may growitems: u32records: u32-- its records and those drawn, its styles; the bytes it sentdrawn: u32styles: u32bytes: u64
impl Overlay
fn clear(&mut self)nothing in itfn is_empty(&self) -> boolfn len(&self) -> usizefn line(&mut self, a: [f64; 2], b: [f64; 2], space: Space, style: &Style)a line (a rubber band) in the style's look (widths and dashes in pixels or drawing units)fn polyline(&mut self, points: &[[f64; 2]], closed: bool, space: Space, style: &Style)a polylinefn arc(&mut self, center: [f64; 2], radius: f64, start: f64, sweep: f64, space: Space, style: &Style)an arc (angles counter-clockwise from the x axis, in the drawing's sense: y up in drawing units, y down in pixels turns them clockwise on the screen)fn circle(&mut self, center: [f64; 2], radius: f64, space: Space, style: &Style)fn rect(&mut self, a: [f64; 2], b: [f64; 2], space: Space, style: &Style)a rectangle's outline (axis-aligned in its space)fn fill(&mut self, points: &[[f64; 2]], space: Space, color: u32)a filled polygon (even-odd) of a colour (0xAARRGGBB)fn fill_rect(&mut self, a: [f64; 2], b: [f64; 2], space: Space, color: u32)fn selection_box(&mut self, first: [f64; 2], second: [f64; 2], space: Space)AutoCAD's selection box from the first corner to the second, axis-aligned on the screen: a window (the second corner right of the first on the screen: solid outline, blue tint) or a crossing (left: dashed, green tint)fn grip(&mut self, at: [f64; 2], space: Space, state: Grip)a grip: a square of GRIP_PX pixels on the pixel the point lies onfn marker(&mut self, kind: SnapKind, at: [f64; 2], space: Space)a snap marker: AutoCAD's symbol of the kind (square endpoint, triangle midpoint, circle centre, diamond quadrant, X intersection, the right angle of perpendicular, the circle and line of tangent, the hourglass of nearest, two squares of insertion), MARKER_PX pixels, on the pixel the point lies onfn box_is_window(first_px: [f64; 2], second_px: [f64; 2]) -> boola selection box is a window: its second corner (pixels) lies right of its first
impl Scene
fn overlay(&mut self) -> &mut Overlaythe overlay: what is drawn over the scene with the next frames (clear it and fill it again for each frame)fn overlay_info(&self) -> OverlayInfowhat the last prepare made of the overlay