Skip to content

Commit 4e6f018

Browse files
committed
Update documentation
- Update README with new examples and features - Expand COMPOSITOR_EFFECTS.md with PreBufferPaint usage - Update RENDERING_PIPELINE.md with buffer paint events - Add EXAMPLES.md documenting all example applications
1 parent 0ca884a commit 4e6f018

4 files changed

Lines changed: 533 additions & 37 deletions

File tree

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,20 +574,35 @@ windowSystem.Theme = new MyDarkTheme();
574574

575575
### Compositor Effects
576576

577-
SharpConsoleUI v2.0+ exposes the rendering buffer for post-processing effects, enabling compositor-style visual enhancements:
577+
SharpConsoleUI v2.0+ exposes the rendering buffer for custom backgrounds and post-processing effects via `PreBufferPaint` and `PostBufferPaint` events:
578578

579579
```csharp
580-
// Apply fade-in transition effect
580+
// Custom animated background (renders BEFORE controls)
581+
public class FractalWindow : Window
582+
{
583+
public FractalWindow(ConsoleWindowSystem windowSystem) : base(windowSystem)
584+
{
585+
// PreBufferPaint: fires after clear, before controls paint
586+
Renderer.PreBufferPaint += (buffer, dirtyRegion, clipRect) =>
587+
{
588+
// Render fractal/gradient/pattern - controls appear on top
589+
for (int y = 0; y < buffer.Height; y++)
590+
for (int x = 0; x < buffer.Width; x++)
591+
buffer.SetCell(x, y, '█', ComputeFractalColor(x, y), Color.Black);
592+
};
593+
}
594+
}
595+
596+
// Post-processing effect (renders AFTER controls)
581597
public class FadeInWindow : Window
582598
{
583599
private float _fadeProgress = 0f;
584600

585601
public FadeInWindow(ConsoleWindowSystem windowSystem) : base(windowSystem)
586602
{
587-
// Subscribe to post-paint event
603+
// PostBufferPaint: fires after controls paint, before display
588604
Renderer.PostBufferPaint += (buffer, dirtyRegion, clipRect) =>
589605
{
590-
// Manipulate buffer after painting, before display
591606
for (int y = 0; y < buffer.Height; y++)
592607
{
593608
for (int x = 0; x < buffer.Width; x++)
@@ -604,8 +619,9 @@ public class FadeInWindow : Window
604619
```
605620

606621
**Use Cases:**
607-
- **Transitions**: Fade-in/fade-out, slide, dissolve effects
608-
- **Filters**: Blur, sharpen, color grading, sepia tone
622+
- **Custom Backgrounds**: Animated fractals, gradients, patterns (PreBufferPaint)
623+
- **Transitions**: Fade-in/fade-out, slide, dissolve effects (PostBufferPaint)
624+
- **Filters**: Blur, sharpen, color grading, sepia tone (PostBufferPaint)
609625
- **Overlays**: Glow effects, borders, highlights on focused controls
610626
- **Screenshots**: Capture immutable buffer snapshots with `buffer.CreateSnapshot()`
611627
- **Recording**: Frame-by-frame capture for replay or analysis

docs/COMPOSITOR_EFFECTS.md

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ The compositor effects system allows you to manipulate the rendered buffer **aft
2020

2121
### Key Features
2222

23-
- **Post-Paint Hook**: `PostBufferPaint` event fires after painting, before ANSI conversion
23+
- **Pre-Paint Hook**: `PreBufferPaint` event fires after buffer clear, before controls paint (for backgrounds)
24+
- **Post-Paint Hook**: `PostBufferPaint` event fires after painting, before ANSI conversion (for effects)
2425
- **Direct Buffer Access**: Full `CharacterBuffer` API for cell-level manipulation
2526
- **Immutable Snapshots**: `BufferSnapshot` for safe buffer capture (screenshots, recording)
2627
- **Zero Overhead**: Event system has no cost when not used
@@ -40,12 +41,21 @@ Window Rendering Pipeline:
4041
└──────────┬──────────┘
4142
4243
┌──────────▼──────────┐
44+
│ Buffer.Clear() │ Clear buffer with background color
45+
└──────────┬──────────┘
46+
47+
┌──────────▼──────────────────────┐
48+
│ PreBufferPaint Event Fires │ ◄── BACKGROUNDS GO HERE
49+
│ (Paint backgrounds, fractals) │ (before controls)
50+
└──────────┬──────────────────────┘
51+
52+
┌──────────▼──────────┐
4353
│ PaintDOM() │ Paint controls to CharacterBuffer
4454
└──────────┬──────────┘
4555
4656
┌──────────▼──────────────────────┐
47-
│ PostBufferPaint Event Fires │ ◄── YOUR EFFECTS GO HERE
48-
│ (Buffer manipulation allowed)
57+
│ PostBufferPaint Event Fires │ ◄── EFFECTS GO HERE
58+
│ (Fade, blur, overlays) │ (after controls)
4959
└──────────┬──────────────────────┘
5060
5161
┌──────────▼──────────┐
@@ -73,25 +83,53 @@ public CharacterBuffer? Buffer { get; }
7383

7484
**CAUTION**: Direct buffer manipulation should only be done via the `PostBufferPaint` event to avoid race conditions. Reading is safe at any time.
7585

76-
### 3. WindowRenderer.PostBufferPaint Event
86+
### 3. WindowRenderer.PreBufferPaint Event
87+
88+
Event that fires after the buffer is cleared but before controls are painted. Ideal for custom backgrounds.
89+
90+
```csharp
91+
public delegate void BufferPaintDelegate(
92+
CharacterBuffer buffer,
93+
LayoutRect dirtyRegion,
94+
LayoutRect clipRect);
95+
96+
public event BufferPaintDelegate? PreBufferPaint;
97+
```
98+
99+
**Parameters**:
100+
- `buffer`: The character buffer (cleared with background color)
101+
- `dirtyRegion`: The region being painted (or full bounds if entire buffer)
102+
- `clipRect`: The clipping rectangle used during paint
103+
104+
**Use cases**:
105+
- Animated backgrounds (fractals, patterns)
106+
- Custom window backgrounds
107+
- Full-buffer graphics that controls render ON TOP of
108+
109+
### 4. WindowRenderer.PostBufferPaint Event
77110

78111
Event that fires after painting controls but before converting to ANSI strings.
79112

80113
```csharp
81-
public delegate void PostBufferPaintDelegate(
114+
public delegate void BufferPaintDelegate(
82115
CharacterBuffer buffer,
83116
LayoutRect dirtyRegion,
84117
LayoutRect clipRect);
85118

86-
public event PostBufferPaintDelegate? PostBufferPaint;
119+
public event BufferPaintDelegate? PostBufferPaint;
87120
```
88121

89122
**Parameters**:
90123
- `buffer`: The character buffer that was just painted
91124
- `dirtyRegion`: The region that was painted (or full bounds if entire buffer)
92125
- `clipRect`: The clipping rectangle used during paint
93126

94-
### 4. BufferSnapshot
127+
**Use cases**:
128+
- Transitions (fade in/out)
129+
- Filters (blur, color grading)
130+
- Overlays (glow, highlights)
131+
132+
### 5. BufferSnapshot
95133

96134
Immutable snapshot of a CharacterBuffer at a point in time.
97135

0 commit comments

Comments
 (0)