XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
namespace XFESystem.Desktop;

/// <summary>Framebuffer adapter. Coordinates are layout units; the adapter clips and maps them to native scanout pixels.</summary>
public interface IDesktopCanvas
{
    int Width { get; }
    int Height { get; }
    int NativeWidth => Width;
    int NativeHeight => Height;
    int ScalePercent => 100;
    int TextWidth(string text) => text.Length * 8;
    void Fill(uint rgb, int x, int y, int width, int height);
    void Line(uint rgb, int x1, int y1, int x2, int y2);
    void Text(string text, uint rgb, int x, int y);
    void Present();
    bool SupportsSceneCache => false;
    void BeginScene(DesktopBounds damage) { }
    void SaveScene() { }
    void SaveScene(DesktopBounds damage) => SaveScene();
    void RestoreSceneRegion(DesktopBounds bounds) { }
    void Present(DesktopBounds damage) => Present();
}

public interface IBrandedDesktopCanvas : IDesktopCanvas
{
    void BrandIcon(int x, int y, int size);
}

/// <summary>Theme assets are supplied by the platform; shared UI never opens host files.</summary>
public interface IDesktopIconCanvas : IDesktopCanvas
{
    void DrawIcon(DesktopIcon icon, int x, int y, int size);
}

/// <summary>
/// Optional native-resolution coverage compositing. The mask contains straight
/// alpha coverage bytes, row-major with stride equal to width and exactly
/// width*height entries. Native coordinates may extend beyond the framebuffer;
/// the implementation clips and blends against its actual current pixel buffer.
/// There is no assumed white background or premultiplied RGB input.
/// </summary>
public interface IDesktopCoverageCanvas : IDesktopCanvas
{
    void BlendCoverage(uint rgb, int nativeX, int nativeY, int width, int height, ReadOnlySpan<byte> coverage);
}

/// <summary>Reuses an unchanged opaque document body from the last pointer-free scene during a pure window translation.</summary>
public interface IDesktopSceneMotionCanvas : IDesktopCanvas
{
    void PreserveTranslatedSceneRegion(DesktopBounds source, int destinationX, int destinationY);
    void PreserveTranslatedSceneRegion(DesktopBounds source, int destinationX, int destinationY, bool unchangedInScanout)
        => PreserveTranslatedSceneRegion(source, destinationX, destinationY);
    void EndScenePreservation();
    // Cancellation must also discard any pending scanout-copy exclusions.
    // Normal EndScenePreservation may keep those until the completed Present.
    void AbortScenePreservation() => EndScenePreservation();
}

public enum DesktopIcon { Files, Editor, Browser, Terminal, Folder, TextFile, CodeFile, MarkdownFile, ApplicationFile, Settings }

public readonly record struct DesktopBounds(int X, int Y, int Width, int Height)
{
    public bool Contains(int x, int y) => x >= X && y >= Y && x < X + Width && y < Y + Height;
}

public enum DesktopKey
{
    Character, Enter, Backspace, Delete, Left, Right, Up, Down, Home, End, Tab, Escape, Save, Run, FocusAddress,
    StartMenu, ShowDesktop, OpenFiles, SwitchWindow, SwitchWindowBack, EndWindowSwitch,
    SnapLeft, SnapRight, Maximize, Restore, Minimize, CloseWindow, Insert, Cancel, DisplaySettings
}
public enum DesktopApplication { Files, Editor, Browser, Terminal, Settings }