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
getThemeFunc<ITheme>Accessor to get the current theme.
onDesktopDirtyActionCallback 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
Properties
Buffer
Gets the cached desktop background buffer.
public CharacterBuffer? Buffer { get; }
Property Value
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
HasBuffer
Gets whether a cached buffer exists.
public bool HasBuffer { get; }
Property Value
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
targetCharacterBufferThe target buffer to copy into.
srcXintSource X position in the cached buffer.
srcYintSource Y position in the cached buffer.
widthintWidth of the region to copy.
heightintHeight 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:
- Base fill (theme char + colors)
- PaintCallback (if set, takes full control and returns)
- Gradient overlay (if configured)
- Pattern overlay (if configured)
public void Render(int width, int height)