pub struct Scene { /* private fields */ }Expand description
entities, layers, styles and the camera of one scene: on a Renderer’s device, or without one (Scene::new_cpu; draw_cpu draws it through lib/gfx)
Implementations§
Source§impl Scene
impl Scene
Sourcepub fn set_highlight(&mut self, id: EntityId, bits: u8) -> Result<()>
pub fn set_highlight(&mut self, id: EntityId, bits: u8) -> Result<()>
an entity on a layer is highlighted (HL_SELECTED, HL_HOVER, both, or 0: not); an insert as a whole. Only the mask’s changed words go up with the next prepare
Sourcepub fn set_highlights(&mut self, ids: &[EntityId], bits: u8) -> Result<()>
pub fn set_highlights(&mut self, ids: &[EntityId], bits: u8) -> Result<()>
many at once (the same bits for each)
Sourcepub fn clear_highlights(&mut self, bits: u8)
pub fn clear_highlights(&mut self, bits: u8)
these bits off on every entity (HL_HOVER: no hover left; HL_SELECTED | HL_HOVER: nothing highlighted)
Sourcepub fn highlighted(&self) -> Vec<EntityId>
pub fn highlighted(&self) -> Vec<EntityId>
the entities highlighted now
Sourcepub fn highlight_info(&self) -> HighlightInfo
pub fn highlight_info(&self) -> HighlightInfo
what the last prepare sent of the highlights
Source§impl Scene
impl Scene
Sourcepub fn overlay(&mut self) -> &mut Overlay
pub fn overlay(&mut self) -> &mut Overlay
the overlay: what is drawn over the scene with the next frames (clear it and fill it again for each frame)
Sourcepub fn overlay_info(&self) -> OverlayInfo
pub fn overlay_info(&self) -> OverlayInfo
what the last prepare made of the overlay
Source§impl Scene
impl Scene
Sourcepub fn build_index(&mut self)
pub fn build_index(&mut self)
builds the spatial index now (else the first pick, select or snap does)
Sourcepub fn index_info(&self) -> IndexInfo
pub fn index_info(&self) -> IndexInfo
what the index holds
Sourcepub fn index_check(&mut self) -> Result<u32, &'static str>
pub fn index_check(&mut self) -> Result<u32, &'static str>
(tests) the trees’ invariants hold
Source§impl Scene
impl Scene
Sourcepub fn pick(&mut self, at: [f64; 2], tolerance: f64) -> Vec<Hit>
pub fn pick(&mut self, at: [f64; 2], tolerance: f64) -> Vec<Hit>
what is drawn within tolerance pixels of a point of the drawing (f64), topmost first (the painter’s order: an app
cycles through overlapping ones); inside an insert the hit names the insert and the way down to the entity
Source§impl Scene
impl Scene
Sourcepub fn select(&mut self, region: Region<'_>, mode: SelectMode) -> Vec<EntityId>
pub fn select(&mut self, region: Region<'_>, mode: SelectMode) -> Vec<EntityId>
the entities on layers a region selects (an insert as a whole): Window what lies wholly inside, Crossing what lies inside or touches it (AutoCAD’s); by the centre lines (widths do not count, as in AutoCAD), a fill by its rings (a crossing region inside a fill touches it), a text by its quad. In no particular order
Sourcepub fn select_filtered(
&mut self,
region: Region<'_>,
mode: SelectMode,
filter: &dyn Fn(LayerId) -> bool,
) -> Vec<EntityId>
pub fn select_filtered( &mut self, region: Region<'_>, mode: SelectMode, filter: &dyn Fn(LayerId) -> bool, ) -> Vec<EntityId>
select with a filter of layers (false: skipped)
Sourcepub fn select_brute(
&mut self,
region: Region<'_>,
mode: SelectMode,
) -> Vec<EntityId>
pub fn select_brute( &mut self, region: Region<'_>, mode: SelectMode, ) -> Vec<EntityId>
(tests) select without the index
Source§impl Scene
impl Scene
Sourcepub fn snap(&mut self, at: [f64; 2], opt: &SnapOptions) -> Option<Snap>
pub fn snap(&mut self, at: [f64; 2], opt: &SnapOptions) -> Option<Snap>
the object snap at a point of the drawing (f64): of the kinds asked for within the aperture, the one nearest the pointer (equally near: endpoint, intersection, midpoint, centre, quadrant, insertion, perpendicular, tangent), nearest only where nothing else is
Sourcepub fn snaps(&mut self, at: [f64; 2], opt: &SnapOptions) -> Vec<Snap>
pub fn snaps(&mut self, at: [f64; 2], opt: &SnapOptions) -> Vec<Snap>
every snap candidate in that order (an app cycles through them)
Sourcepub fn snaps_filtered(
&mut self,
at: [f64; 2],
opt: &SnapOptions,
filter: &dyn Fn(LayerId) -> bool,
) -> Vec<Snap>
pub fn snaps_filtered( &mut self, at: [f64; 2], opt: &SnapOptions, filter: &dyn Fn(LayerId) -> bool, ) -> Vec<Snap>
snaps with a filter of layers (false: skipped)
Sourcepub fn snaps_brute(&mut self, at: [f64; 2], opt: &SnapOptions) -> Vec<Snap>
pub fn snaps_brute(&mut self, at: [f64; 2], opt: &SnapOptions) -> Vec<Snap>
(tests) snaps without the index
Source§impl Scene
impl Scene
Sourcepub fn grip_points(&self, id: EntityId) -> Vec<[f64; 2]>
pub fn grip_points(&self, id: EntityId) -> Vec<[f64; 2]>
AutoCAD’s grips of an entity on a layer (drawing units): a line’s ends and middle, a polyline’s vertices and its segments’ middles, an arc’s centre, ends and middle, a circle’s centre and quadrants, an ellipse’s centre and its axes’ ends (an open one’s ends too), a Bézier chain’s and a spline’s control points, a fill’s corners, a text’s alignment point, an insert’s insertion point (each copy of an array). Empty for a dead id or a block’s entity
Source§impl Scene
impl Scene
Sourcepub fn draw_cpu(
&mut self,
dc: &mut Dc,
sf: &mut Surface,
r: [i32; 4],
) -> CpuInfo
pub fn draw_cpu( &mut self, dc: &mut Dc, sf: &mut Surface, r: [i32; 4], ) -> CpuInfo
the scene drawn on the CPU through lib/gfx (G6e1, decision 29): the camera’s view of a target of r’s size into the rectangle r (x, y, w, h, relative to dc’s origin) of sf, clipped to dc’s clip, blended over what is there (the app clears it first, as a frame’s load does); the painter’s order, the visible layers, the look, the highlights and the overlay of a frame on the GPU (docs/RENDER2D.md “Der CPU-Weg”). With and without a device. dc keeps its colour, clip and origin
Sourcepub fn set_cpu_single(&mut self, single: bool)
pub fn set_cpu_single(&mut self, single: bool)
draw_cpu on one thread (false: row bands on lib/gfx’s parallel loop where one is set, gfx::set_parallel: lib/ui sets its worker pool there; the same bytes either way)
Source§impl Scene
impl Scene
Sourcepub fn new(r: &Renderer) -> Result<Scene>
pub fn new(r: &Renderer) -> Result<Scene>
a scene on a renderer’s device (Scene::new_cpu, then attach)
Sourcepub fn new_cpu() -> Scene
pub fn new_cpu() -> Scene
a scene without a device (G6e1): everything but a frame on the GPU works on it (entities, layers, styles, blocks, text, picking, selection, snaps, highlights, the overlay), and draw_cpu draws it through lib/gfx. attach puts it on a renderer’s device (all of it goes up with the next prepare), detach takes it off again (a lost device: the drawing stays)
Sourcepub fn attach(&mut self, r: &Renderer) -> Result<()>
pub fn attach(&mut self, r: &Renderer) -> Result<()>
the scene on a renderer’s device (G6e1): its buffers made there, everything it holds goes up with the next prepare. Attached to another renderer before, it leaves that one first; to the same one, nothing happens. An error leaves it without a device
Sourcepub fn detach(&mut self)
pub fn detach(&mut self)
the scene off its device (G6e1; a lost device, another renderer next): what it made there goes, what it holds stays; draw_cpu draws it, attach puts it on a device again
Sourcepub fn attached(&self) -> bool
pub fn attached(&self) -> bool
the scene is on a renderer’s device (Scene::new, attach); else only draw_cpu draws it
Sourcepub fn add_style(&mut self, s: &Style) -> Result<StyleId>
pub fn add_style(&mut self, s: &Style) -> Result<StyleId>
a style for entities; the next frame shows it
Sourcepub fn set_style(&mut self, id: StyleId, s: &Style) -> Result<()>
pub fn set_style(&mut self, id: StyleId, s: &Style) -> Result<()>
a style changed: every entity of it shows the change with the next frame (nothing else goes up)
pub fn style(&self, id: StyleId) -> Option<Style>
Sourcepub fn add_layer(&mut self, l: &Layer) -> Result<LayerId>
pub fn add_layer(&mut self, l: &Layer) -> Result<LayerId>
a new layer, empty, on top of those of its order
Sourcepub fn set_layer(&mut self, id: LayerId, l: &Layer) -> Result<()>
pub fn set_layer(&mut self, id: LayerId, l: &Layer) -> Result<()>
shown or hidden, its place in the draw order, its transparency (nothing of its entities goes up: the layer table)
pub fn layer(&self, id: LayerId) -> Result<Layer>
Sourcepub fn remove_layer(&mut self, id: LayerId) -> Result<()>
pub fn remove_layer(&mut self, id: LayerId) -> Result<()>
the layer goes, with every entity on it
Sourcepub fn drawn_layers(&self) -> Vec<LayerId>
pub fn drawn_layers(&self) -> Vec<LayerId>
the visible layers in the order the last prepare drew them (the lists’ order: lists_buffer)
Sourcepub fn add_font(&mut self, data: &[u8], face: u32) -> Result<FontId>
pub fn add_font(&mut self, data: &[u8], face: u32) -> Result<FontId>
a font from TrueType or OpenType bytes (face: a collection’s font, else 0), lib/text’s parser
Sourcepub fn fonts(&mut self) -> &mut Fonts
pub fn fonts(&mut self) -> &mut Fonts
the scene’s fonts: their metrics and glyph outlines, and what lays text out with them (text::layout_text, layout_mtext: the CPU path of G6e draws the same layout)
Sourcepub fn add_text_style(&mut self, s: &TextStyle) -> Result<TextStyleId>
pub fn add_text_style(&mut self, s: &TextStyle) -> Result<TextStyleId>
a text style (DXF’s STYLE) for texts
Sourcepub fn set_text_style(&mut self, id: TextStyleId, s: &TextStyle) -> Result<()>
pub fn set_text_style(&mut self, id: TextStyleId, s: &TextStyle) -> Result<()>
a text style changes: every text of it is laid out again (its records go up, a block’s once for all its inserts)
pub fn text_style(&self, id: TextStyleId) -> Option<TextStyle>
Sourcepub fn text_layout(&self, id: EntityId) -> Option<&Layout>
pub fn text_layout(&self, id: EntityId) -> Option<&Layout>
a text’s layout (G6d picks with its extent: TextLayout::quad, bounds; G6e draws it): None for any other entity
Sourcepub fn atlas_hash(&self) -> u64
pub fn atlas_hash(&self) -> u64
(tests) FNV-1a of the atlas’s pages: the same bytes on every target for the same texts
Sourcepub fn insert(
&mut self,
layer: LayerId,
style: StyleId,
s: &Shape<'_>,
) -> Result<EntityId>
pub fn insert( &mut self, layer: LayerId, style: StyleId, s: &Shape<'_>, ) -> Result<EntityId>
a new entity at the end of its layer (drawn over everything there); an insert of a block (Shape::Insert) sits there with its block’s entities
Sourcepub fn update(&mut self, id: EntityId, s: &Shape<'_>) -> Result<()>
pub fn update(&mut self, id: EntityId, s: &Shape<'_>) -> Result<()>
new geometry; the entity keeps its place in the draw order (in its layer or its block). An insert on a layer that stays an insert of the same block with as many copies only moves: its instances’ transforms go up, nothing else
Sourcepub fn set_entity_style(&mut self, id: EntityId, style: StyleId) -> Result<()>
pub fn set_entity_style(&mut self, id: EntityId, style: StyleId) -> Result<()>
another style: its records go up again (a block’s entity: its block’s, once for all its inserts; an insert: what its block’s entities take by block)
Sourcepub fn remove(&mut self, id: EntityId) -> Result<()>
pub fn remove(&mut self, id: EntityId) -> Result<()>
the entity goes; its records become free places (and its id dead); a block’s entity leaves its block (its records go up once for all its inserts)
pub fn is_empty(&self) -> bool
Sourcepub fn locate(&self, id: EntityId) -> Option<(u32, u32)>
pub fn locate(&self, id: EntityId) -> Option<(u32, u32)>
(tests, tools) an entity’s records as the last prepare laid them out: its first record’s place in the pool and the records of its geometry (a polyline of n points: n - 1, closed n; a point: 1; an insert on a layer: its one record of zeros); None for a block’s entity (its records lie in its block’s variants)
Sourcepub fn add_block(&mut self, b: &Block) -> Result<BlockId>
pub fn add_block(&mut self, b: &Block) -> Result<BlockId>
a new block, empty: entities go into it with insert_in, Shape::Insert places it
pub fn block(&self, id: BlockId) -> Result<Block>
Sourcepub fn set_block(&mut self, id: BlockId, b: &Block) -> Result<()>
pub fn set_block(&mut self, id: BlockId, b: &Block) -> Result<()>
a block’s base point changed: every insert shows it (its records go up once)
Sourcepub fn remove_block(&mut self, id: BlockId) -> Result<()>
pub fn remove_block(&mut self, id: BlockId) -> Result<()>
the block goes with its entities; refused while an insert places it
Sourcepub fn insert_in(
&mut self,
block: BlockId,
style: StyleId,
s: &Shape<'_>,
) -> Result<EntityId>
pub fn insert_in( &mut self, block: BlockId, style: StyleId, s: &Shape<'_>, ) -> Result<EntityId>
a new entity at the end of a block (its units: the block’s base lands on an insert’s point); a Shape::Insert of another block nests it (no cycles, at most BLOCK_DEPTH levels). Every insert of the block shows it with the next frame, the block’s records going up once
Sourcepub fn instance_info(&self) -> InstanceInfo
pub fn instance_info(&self) -> InstanceInfo
what the blocks hold and what the last prepare sent of them
pub fn set_camera(&mut self, c: &Camera) -> Result<()>
pub fn camera(&self) -> &Camera
Sourcepub fn set_culling(&mut self, on: bool)
pub fn set_culling(&mut self, on: bool)
false: every live record of a visible layer is drawn (a test’s comparison, a debugging aid)
Sourcepub fn set_stats(&mut self, on: bool)
pub fn set_stats(&mut self, on: bool)
FrameStats of each frame: the records found visible (a small copy per frame), the GPU’s times
Sourcepub fn upload_info(&self) -> UploadInfo
pub fn upload_info(&self) -> UploadInfo
what the last prepare sent
Sourcepub fn lists_buffer(&self) -> &Buffer
pub fn lists_buffer(&self) -> &Buffer
(tests, tools) after a frame’s visibility: per visible layer in draw order (drawn_layers) its first place in the visible list and its count (16 bytes each); the visible list (record places in the pool); the indirect draws. These and pool_buffer panic on a scene without a device (Scene::attached)
pub fn visible_buffer(&self) -> &Buffer
pub fn draws_buffer(&self) -> &Buffer
Sourcepub fn pool_buffer(&self) -> &Buffer
pub fn pool_buffer(&self) -> &Buffer
(tests, tools) the pool of records (common.wgsl Record, 64 bytes each)
Sourcepub fn wait_slot(&mut self) -> Result<()>
pub fn wait_slot(&mut self) -> Result<()>
wait for the frame that last used this frame’s slot, so its data can be written; prepare does it too. The browser cannot wait, and needs not: its writes go in queue order
Sourcepub fn take_stats(&mut self) -> Vec<FrameStats>
pub fn take_stats(&mut self) -> Vec<FrameStats>
the finished frames’ stats since the last call
Sourcepub fn collect_stats(&mut self)
pub fn collect_stats(&mut self)
after Device::wait_idle: the stats of what was still in flight
Sourcepub fn reflattened(&self) -> u32
pub fn reflattened(&self) -> u32
curves and fills the last prepare flattened again (their zoom band changed, or the view left their window)