rigComponent 0.1.1
RigKit pack API - rigComponent
Loading...
Searching...
No Matches
sketch.h File Reference

Retained-style sketch helpers - fill once, then spawn ECS shapes. More...

#include <glm/glm.hpp>
#include <entt/entt.hpp>
#include <functional>
#include <vector>
Include dependency graph for sketch.h:

Typedefs

using rig::SketchEntityHook = std::function<void(entt::entity)>
 Called after each sketch primitive creates an entity (may be empty).

Functions

void rig::setSketchEntityHook (SketchEntityHook hook)
 Install an on-created hook (page placement, logging, ...).
void rig::resetSketch ()
 Reset fill/stroke, matrix stack, and path.
void rig::clearSketch ()
 Destroy entities spawned by sketch primitives and reset style.
int rig::sketchShapeCount ()
 How many sketch-spawned entities the currently bound ECS tracks.
void rig::rotate (float radians)
 Rotate the sketch matrix.
entt::entity rig::circle (float x, float y, float radius)
 Circle about (x, y).
entt::entity rig::rect (float x, float y, float w, float h)
 Rectangle from top-left (x, y).
entt::entity rig::ellipse (float x, float y, float w, float h)
 Ellipse about centre (x, y) with size w x h.
entt::entity rig::oval (float x, float y, float w, float h)
 Ellipse from top-left box (x, y, w, h).
entt::entity rig::line (float x1, float y1, float x2, float y2)
 Line segment.
void rig::curveTo (float c1x, float c1y, float c2x, float c2y, float x, float y)
 Cubic Bezier from the current point to (x, y).
entt::entity rig::drawPath ()
 Emit the recorded commands as a rig.geometry.path entity.

Detailed Description

Retained-style sketch helpers - fill once, then spawn ECS shapes.

Artist sugar over makeRect / makeCircle and friends: one fill and a matrix stack, then circle / rect write inspectable entities. circle(x, y, r) takes radius. This layer does not know pages; rigProject parents later sketch entities to currentPage(). rig::setSketchEntityHook replaces that.

Style setters are setFill / setStroke so they stay distinct from the CDrawStyle factories fill / stroke in create.h.

Angles are radians throughout (Processing-style); the bare creators in create.h keep their degree parameters.

Transforms live on the entity, exactly. Shapes are created in local coordinates and the sketch matrix at creation time is decomposed onto the entity's CTransform as translate * rotate * shear * scale - any 2D affine fits, so rotation, uneven scale and shear all survive with the shape still parametric (a sheared rect is a CRect with shear on its transform). Later matrix edits never move existing shapes.

State is process-global and single-threaded, and entity tracking is per bound ECS: rebinding via rig::setEcs drops tracking of earlier shapes (they live on in their own document; clearSketch never reaches across registries).

See also
create.h

Function Documentation

◆ circle()

entt::entity rig::circle ( float x,
float y,
float radius )

Circle about (x, y).

Parameters
radiusCentre to edge, not diameter.
Returns
New entity, or entt::null when there is no paint or no ECS.

◆ clearSketch()

void rig::clearSketch ( )

Destroy entities spawned by sketch primitives and reset style.

Does not touch pages or other document state. Only destroys shapes made in the currently bound ECS - shapes tracked before a setEcs rebind are left alone (handles must never cross registries).

◆ curveTo()

void rig::curveTo ( float c1x,
float c1y,
float c2x,
float c2y,
float x,
float y )

Cubic Bezier from the current point to (x, y).

Stored as a true CPath cubic - control points survive into the document; renderers flatten for display only. With an empty path it just starts the path at (x, y).

◆ line()

entt::entity rig::line ( float x1,
float y1,
float x2,
float y2 )

Line segment.

Uses the fill colour when no stroke is set.

◆ resetSketch()

void rig::resetSketch ( )

Reset fill/stroke, matrix stack, and path.

Does not destroy entities.

◆ rotate()

void rig::rotate ( float radians)

Rotate the sketch matrix.

Parameters
radiansCounter-clockwise about Z.

◆ setSketchEntityHook()

void rig::setSketchEntityHook ( SketchEntityHook hook)

Install an on-created hook (page placement, logging, ...).

Pass {} / nullptr to clear. rigProject's first page call installs placeOnPage; a later install replaces that.