SurfaceRenderContext
Namespace: Hex1b.Surfaces
Assembly: Hex1b.dll
A render context that writes to a instead of emitting ANSI strings.
public class SurfaceRenderContext : Hex1bRenderContextInheritance
Object → Hex1bRenderContext → SurfaceRenderContext
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 .
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 .
public SurfaceRenderContext(Surface surface, int offsetX, int offsetY, Hex1bTheme? theme = null)Properties
CacheHits
Statistics about cache usage for the current frame.
Returns: Int32
public int CacheHits { get; }CacheMisses
Returns: Int32
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
public bool CachingEnabled { get; set; }Capabilities
Gets terminal capabilities. Returns capabilities inherited from parent context, falling back to if not set.
Returns: TerminalCapabilities
public override TerminalCapabilities Capabilities { get; }CellMetrics
Gets the cell metrics (pixel dimensions per cell).
Returns: CellMetrics
public CellMetrics CellMetrics { get; init; }Height
Gets the height of the surface.
Returns: Int32
public override int Height { get; }Surface
Gets the underlying surface being written to.
Returns: Surface
public Surface Surface { get; }Width
Gets the width of the surface.
Returns: Int32
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.
public override void BeginFrame()Clear()
Clears the entire surface.
public override void Clear()ClearRegion(Rect)
Clears a rectangular region by filling with spaces.
Parameters:
rect(Rect):
public override void ClearRegion(Rect rect)EndFrame()
Signals the end of a render frame. No-op for Surface rendering.
public override void EndFrame()EnterAlternateScreen()
Enter alternate screen - no-op for Surface rendering.
public override void EnterAlternateScreen()ExitAlternateScreen()
Exit alternate screen - no-op for Surface rendering.
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:
child(Hex1bNode): The child node to render.
public override void RenderChild(Hex1bNode child)ResetCacheStats()
Resets cache statistics. Call at the start of each frame.
public void ResetCacheStats()ResetStyle()
Resets the current style state to defaults.
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:
capabilities(TerminalCapabilities):
public void SetCapabilities(TerminalCapabilities capabilities)SetCursorPosition(int, int)
Sets the cursor position for subsequent writes.
Parameters:
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
public override bool ShouldRenderAt(int x, int y)Write(string)
Writes text at the current cursor position, parsing any embedded ANSI codes.
Parameters:
text(String):
public override void Write(string text)WriteClipped(int, int, string)
Writes text at the specified position, respecting the current layout provider's clipping.
Parameters:
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:
imageData(Byte[]):pixelWidth(Int32):pixelHeight(Int32):cellWidth(Int32):cellHeight(Int32):zOrder(KgpZOrder):clipX(Int32):clipY(Int32):clipW(Int32):clipH(Int32):
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.