Table of Contents

Class DesktopBackgroundService

Namespace
SharpConsoleUI.Core
Assembly
SharpConsoleUI.dll

Core service that owns a cached CharacterBuffer and renders the desktop background into it. The main render loop blits from this cache instead of flat-filling. Renders three composable layers: base fill (from theme) -> gradient overlay -> pattern overlay. For animated backgrounds, a PaintCallback takes full control and is driven by a timer.

public class DesktopBackgroundService : IDisposable
Inheritance
DesktopBackgroundService
Implements
Inherited Members
Extension Methods

Constructors

DesktopBackgroundService(Func<ITheme>, Action)

Creates a new DesktopBackgroundService.

public DesktopBackgroundService(Func<ITheme> getTheme, Action onDesktopDirty)

Parameters

getTheme Func<ITheme>

Accessor to get the current theme.

onDesktopDirty Action

Callback to signal that the desktop needs a redraw.

Fields

NeedsScreenUpdate

Set when the cached buffer has been re-rendered and exposed desktop regions need to be blitted to the screen. Cleared by the render coordinator after blitting. This is set on: config change, theme change, and animation tick.

public volatile bool NeedsScreenUpdate

Field Value

bool

Properties

Buffer

Gets the cached desktop background buffer.

public CharacterBuffer? Buffer { get; }

Property Value

CharacterBuffer

Config

Gets or sets the desktop background configuration. Setting this invalidates the cache and manages the animation timer.

public DesktopBackgroundConfig? Config { get; set; }

Property Value

DesktopBackgroundConfig

HasBuffer

Gets whether a cached buffer exists.

public bool HasBuffer { get; }

Property Value

bool

Methods

BlitRegion(CharacterBuffer, int, int, int, int)

Copies a rectangular region from the cached buffer to a target buffer. Used by the renderer to restore desktop areas when windows move or close.

public void BlitRegion(CharacterBuffer target, int srcX, int srcY, int width, int height)

Parameters

target CharacterBuffer

The target buffer to copy into.

srcX int

Source X position in the cached buffer.

srcY int

Source Y position in the cached buffer.

width int

Width of the region to copy.

height int

Height of the region to copy.

Dispose()

Disposes the service, stopping the animation timer.

public void Dispose()

Invalidate()

Re-renders the desktop if dimensions are known and signals dirty.

public void Invalidate()

OnThemeChanged()

Called when the theme changes. Invalidates and re-renders the desktop.

public void OnThemeChanged()

Render(int, int)

Renders the desktop background into the cached buffer. Creates or resizes the buffer if needed, then applies layers:

  1. Base fill (theme char + colors)
  2. PaintCallback (if set, takes full control and returns)
  3. Gradient overlay (if configured)
  4. Pattern overlay (if configured)
public void Render(int width, int height)

Parameters

width int

Screen width in columns.

height int

Screen height in rows.