Skip to content

CompositeSurface

Namespace: Hex1b.Surfaces

Assembly: Hex1b.dll

A surface composed of multiple layered surface sources with deferred resolution.

csharp
public sealed class CompositeSurface : ISurfaceSource

Inheritance

ObjectCompositeSurface

Implements

Constructors

CompositeSurface(int, int, CellMetrics)

Creates a new composite surface with the specified dimensions and cell metrics.

Parameters:

  • width (Int32): The width in columns. Must be positive.
  • height (Int32): The height in rows. Must be positive.
  • cellMetrics (CellMetrics): The pixel dimensions of terminal cells.
csharp
public CompositeSurface(int width, int height, CellMetrics cellMetrics)

CompositeSurface(int, int)

Creates a new composite surface with the specified dimensions and default cell metrics.

Parameters:

  • width (Int32): The width in columns. Must be positive.
  • height (Int32): The height in rows. Must be positive.
csharp
public CompositeSurface(int width, int height)

Properties

CellMetrics

Gets the cell metrics for this composite surface.

Returns: CellMetrics

csharp
public CellMetrics CellMetrics { get; }

HasKgp

Gets whether any layer in this composite contains KGP images.

Returns: Boolean

csharp
public bool HasKgp { get; }

HasSixels

Gets whether any layer in this composite contains sixel graphics.

Returns: Boolean

csharp
public bool HasSixels { get; }

Height

Gets the height of the composite surface in rows.

Returns: Int32

csharp
public int Height { get; }

LayerCount

Gets the number of layers in this composite.

Returns: Int32

csharp
public int LayerCount { get; }

Width

Gets the width of the composite surface in columns.

Returns: Int32

csharp
public int Width { get; }

Methods

AddComputedLayer(int, int, CellCompute, int, int)

Adds a computed layer to the composite surface.

Parameters:

  • width (Int32): The width of the computed layer.
  • height (Int32): The height of the computed layer.
  • compute (CellCompute): The delegate that computes cell values.
  • offsetX (Int32): The X offset where the layer's (0,0) will be placed.
  • offsetY (Int32): The Y offset where the layer's (0,0) will be placed.
csharp
public void AddComputedLayer(int width, int height, CellCompute compute, int offsetX = 0, int offsetY = 0)

AddLayer(ISurfaceSource, int, int)

Adds a layer to the composite surface.

Parameters:

  • source (ISurfaceSource): The surface source to add as a layer.
  • offsetX (Int32): The X offset where the source's (0,0) will be placed.
  • offsetY (Int32): The Y offset where the source's (0,0) will be placed.
csharp
public void AddLayer(ISurfaceSource source, int offsetX = 0, int offsetY = 0)

Clear()

Removes all layers from the composite surface.

csharp
public void Clear()

Flatten()

Flattens all layers into a single .

Returns: Surface

A new Surface containing the flattened result.

csharp
public Surface Flatten()

FlattenInto(Surface)

Flattens all layers into the provided instance.

Parameters:

  • result (Surface): The surface to write into. Must match width/height/cell metrics.
csharp
public void FlattenInto(Surface result)

GetCell(int, int)

Gets the cell at the specified position.

Parameters:

  • x (Int32): The column (0-based).
  • y (Int32): The row (0-based).

Returns: SurfaceCell

The cell at the specified position.

csharp
public SurfaceCell GetCell(int x, int y)

GetSixelFragments()

Computes sixel fragments for all sixels in this composite, accounting for occlusion.

Returns: IReadOnlyList<SixelFragment>

List of sixel fragments to render.

csharp
public IReadOnlyList<SixelFragment> GetSixelFragments()

IsInBounds(int, int)

Checks if the specified position is within bounds.

Parameters:

  • x (Int32): The column (0-based).
  • y (Int32): The row (0-based).

Returns: Boolean

True if the position is within bounds, false otherwise.

csharp
public bool IsInBounds(int x, int y)

TryGetCell(int, int, out SurfaceCell)

Tries to get the cell at the specified position.

Parameters:

  • x (Int32): The column (0-based).
  • y (Int32): The row (0-based).
  • cell (SurfaceCell): The cell at the position, or default if out of bounds.

Returns: Boolean

True if the position is valid, false otherwise.

csharp
public bool TryGetCell(int x, int y, out SurfaceCell cell)

Remarks

Unlike which immediately copies cells during compositing, records layers and resolves them lazily when cells are accessed or when is called.

This deferred approach enables: Computed cells that can query cells from layers belowEfficient nested composition without intermediate copiesLayer manipulation before final resolution

Layers are z-ordered by add order: first added is at the bottom, last added is on top. When resolving a cell, layers are composited bottom-up with transparency support.

Released under the MIT License.