Skip to content

SurfaceRenderContext

Namespace: Hex1b.Surfaces

Assembly: Hex1b.dll

A render context that writes to a instead of emitting ANSI strings.

csharp
public class SurfaceRenderContext : Hex1bRenderContext

Inheritance

ObjectHex1bRenderContextSurfaceRenderContext

Constructors

SurfaceRenderContext(Surface, Hex1bTheme?)

Creates a new SurfaceRenderContext that writes to the specified surface.

Parameters:

  • surface (Surface): The surface to write to.
  • theme (Hex1bTheme): The theme to use for styling. Defaults to .
csharp
public SurfaceRenderContext(Surface surface, Hex1bTheme? theme = null)

SurfaceRenderContext(Surface, int, int, Hex1bTheme?)

Creates a new SurfaceRenderContext with coordinate offset for child rendering.

Parameters:

  • surface (Surface): The surface to write to.
  • offsetX (Int32): X offset to subtract from all coordinates.
  • offsetY (Int32): Y offset to subtract from all coordinates.
  • theme (Hex1bTheme): The theme to use for styling. Defaults to .
csharp
public SurfaceRenderContext(Surface surface, int offsetX, int offsetY, Hex1bTheme? theme = null)

Properties

CacheHits

Statistics about cache usage for the current frame.

Returns: Int32

csharp
public int CacheHits { get; }

CacheMisses

Returns: Int32

csharp
public int CacheMisses { get; }

CachingEnabled

Whether render caching is enabled. When true, RenderChild will use cached surfaces for nodes that are not dirty. Default is true.

Returns: Boolean

csharp
public bool CachingEnabled { get; set; }

Capabilities

Gets terminal capabilities. Returns capabilities inherited from parent context, falling back to if not set.

Returns: TerminalCapabilities

csharp
public override TerminalCapabilities Capabilities { get; }

CellMetrics

Gets the cell metrics (pixel dimensions per cell).

Returns: CellMetrics

csharp
public CellMetrics CellMetrics { get; init; }

Height

Gets the height of the surface.

Returns: Int32

csharp
public override int Height { get; }

Surface

Gets the underlying surface being written to.

Returns: Surface

csharp
public Surface Surface { get; }

Width

Gets the width of the surface.

Returns: Int32

csharp
public override int Width { get; }

Methods

BeginFrame()

Signals the beginning of a render frame. No-op for Surface rendering as the Surface itself handles frame boundaries.

csharp
public override void BeginFrame()

Clear()

Clears the entire surface.

csharp
public override void Clear()

ClearRegion(Rect)

Clears a rectangular region by filling with spaces.

Parameters:

csharp
public override void ClearRegion(Rect rect)

EndFrame()

Signals the end of a render frame. No-op for Surface rendering.

csharp
public override void EndFrame()

EnterAlternateScreen()

Enter alternate screen - no-op for Surface rendering.

csharp
public override void EnterAlternateScreen()

ExitAlternateScreen()

Exit alternate screen - no-op for Surface rendering.

csharp
public override void ExitAlternateScreen()

RenderChild(Hex1bNode)

Renders a child node. Container nodes should call this instead of child.Render(context) to enable the framework to apply optimizations like caching.

Parameters:

csharp
public override void RenderChild(Hex1bNode child)

ResetCacheStats()

Resets cache statistics. Call at the start of each frame.

csharp
public void ResetCacheStats()

ResetStyle()

Resets the current style state to defaults.

csharp
public void ResetStyle()

SetCapabilities(TerminalCapabilities)

Sets the terminal capabilities for this context and child contexts. Call this to propagate capabilities from a parent render context.

Parameters:

csharp
public void SetCapabilities(TerminalCapabilities capabilities)

SetCursorPosition(int, int)

Sets the cursor position for subsequent writes.

Parameters:

csharp
public override void SetCursorPosition(int left, int top)

ShouldRenderAt(int, int)

Checks if a position should be rendered based on the current layout provider.

Parameters:

Returns: Boolean

csharp
public override bool ShouldRenderAt(int x, int y)

Write(string)

Writes text at the current cursor position, parsing any embedded ANSI codes.

Parameters:

csharp
public override void Write(string text)

WriteClipped(int, int, string)

Writes text at the specified position, respecting the current layout provider's clipping.

Parameters:

csharp
public override void WriteClipped(int x, int y, string text)

WriteKgp(byte[], int, int, int, int, KgpZOrder, int, int, int, int)

Writes a KGP image at the current cursor position by populating surface cells with structured . The anchor cell (top-left) carries the KGP metadata; remaining cells in the region are filled with spaces. later reads the KGP data and emits transmit/placement tokens with proper z-ordering.

Parameters:

csharp
public override void WriteKgp(byte[] imageData, int pixelWidth, int pixelHeight, int cellWidth, int cellHeight, KgpZOrder zOrder, int clipX = 0, int clipY = 0, int clipW = 0, int clipH = 0)

Remarks

This context extends but captures rendered output to a Surface for later diffing and optimized output generation.

ANSI escape codes embedded in text are parsed and converted to SurfaceCell properties (foreground, background, attributes). This allows existing node rendering code to work unchanged while benefiting from Surface-based diffing.

Released under the MIT License.