ShapeDrawer

Abstract generic base class for all shape drawers in the ShapesDrawer system. Defines the queue-and-draw pattern: subclasses enqueue shape structs via an Add(...) method, and the system calls Draw() once per camera per frame to render the entire queue using the Shapes library. Also defines the IShapeDrawer interface used for type-erased access.

Definition

Namespace: Paragon.Core.ShapesDrawer Assembly: Paragon.dll

public interface IShapeDrawer
{
    Type Type { get; }
    void Draw();
    void Reset();
}
public abstract class ShapeDrawer<TShape> : IShapeDrawer
    where TShape : struct

Implements: IShapeDrawer

Remarks

ShapeDrawer<TShape> provides the shared infrastructure for all shape types:

  • A List<TShape> draw queue that collects shapes throughout the frame.

  • Default Shapes library style settings (LineGeometry.Volumetric3D, ThicknessSpace.Pixels).

  • A Reset() method called each frame at PRE_UPDATE to clear the queue.

  • An abstract Draw() method that subclasses override to iterate the queue and issue Shapes library draw calls.

The IShapeDrawer interface provides non-generic access for the ShapesDrawer singleton, which stores all drawers in a Dictionary<Type, IShapeDrawer>.

Quick Lookup

Goal
How

Create a new shape drawer

Subclass ShapeDrawer<TShape>, define a nested struct, override Draw()

Enqueue a shape

Add to drawQueue (typically via an Add(...) method)

Render all shapes

Override Draw() — called automatically by ShapesDrawer

Clear the queue

Reset() — called automatically each frame

Properties

Type

The concrete runtime type of this drawer. Used as the dictionary key in ShapesDrawer.

Fields

drawQueue

The queue of shapes to render this frame. Subclasses add to this in their Add(...) method.

lineGeometry

Default line geometry mode for line-based shapes.

thicknessSpace

Default thickness space for shape rendering.

Methods

Draw

Renders all shapes in the drawQueue. Subclasses must override this to iterate the queue and issue Shapes library draw calls within a PushStyle() / PopStyle() block.

Reset

Clears the draw queue. Called automatically at PRE_UPDATE by ShapesDrawer. Can be overridden for additional cleanup.

Extension Points

Required Overrides

Method
Purpose

Draw()

Iterate drawQueue and issue Shapes library draw calls

Optional Overrides

Method
Purpose

Reset()

Additional cleanup beyond clearing the queue. Call base.Reset().

Implementation Requirements

When subclassing ShapeDrawer<TShape>, you MUST:

  1. Define a nested readonly struct for TShape with all draw parameters as readonly fields

  2. Override Draw() to render all items in drawQueue using the Shapes library

  3. Wrap draw calls in Shapes.Draw.PushStyle() / Shapes.Draw.PopStyle() to avoid style leaking

  4. Provide a public Add(...) method that creates the struct and enqueues it

You SHOULD:

  • Apply lineGeometry and thicknessSpace at the start of Draw() for line-based shapes

  • Keep the struct lightweight (value types only, no allocations)

Type Parameters

Parameter
Constraint
Description

TShape

struct

The readonly struct defining the shape's draw parameters (e.g., LineDrawer.Line)

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Custom Shape Drawer

See Also

Last updated