From 80e02dd2f7b5f1f0546619fd45b5ac3e353fcb23 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 22 Jun 2020 14:05:30 -0300 Subject: [PATCH] update headless platform stubs. --- samples/ControlCatalog.NetCore/Program.cs | 1 + .../HeadlessVncFramebufferSource.cs | 2 +- .../HeadlessPlatformRenderInterface.cs | 89 ++++++++++++------- .../HeadlessPlatformStubs.cs | 23 ++++- src/Avalonia.Headless/HeadlessWindowImpl.cs | 57 ++++++++++-- src/Avalonia.Headless/IHeadlessWindow.cs | 10 +-- 6 files changed, 133 insertions(+), 49 deletions(-) diff --git a/samples/ControlCatalog.NetCore/Program.cs b/samples/ControlCatalog.NetCore/Program.cs index 26ac30cb95..142736a0bb 100644 --- a/samples/ControlCatalog.NetCore/Program.cs +++ b/samples/ControlCatalog.NetCore/Program.cs @@ -12,6 +12,7 @@ using Avalonia.LogicalTree; using Avalonia.Skia; using Avalonia.ReactiveUI; using Avalonia.Threading; +using Avalonia.Dialogs; namespace ControlCatalog.NetCore { diff --git a/src/Avalonia.Headless.Vnc/HeadlessVncFramebufferSource.cs b/src/Avalonia.Headless.Vnc/HeadlessVncFramebufferSource.cs index df68807195..32f9f99709 100644 --- a/src/Avalonia.Headless.Vnc/HeadlessVncFramebufferSource.cs +++ b/src/Avalonia.Headless.Vnc/HeadlessVncFramebufferSource.cs @@ -27,7 +27,7 @@ namespace Avalonia.Headless.Vnc int TranslateButton(VncButton vncButton) => vncButton == VncButton.Left ? 0 : vncButton == VncButton.Right ? 1 : 2; - var modifiers = (InputModifiers)(((int)buttons & 7) << 4); + var modifiers = (RawInputModifiers)(((int)buttons & 7) << 4); Dispatcher.UIThread.Post(() => { diff --git a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index abeb41cc08..5eb91e3c6b 100644 --- a/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -21,8 +21,9 @@ namespace Avalonia.Headless public IEnumerable InstalledFontNames { get; } = new[] { "Tahoma" }; - public IFormattedTextImpl CreateFormattedText(string text, Typeface typeface, TextAlignment textAlignment, - TextWrapping wrapping, Size constraint, IReadOnlyList spans) + public bool SupportsIndividualRoundRects => throw new NotImplementedException(); + + public IFormattedTextImpl CreateFormattedText(string text, Typeface typeface, double fontSize, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList spans) { return new HeadlessFormattedTextStub(text, constraint); } @@ -68,6 +69,27 @@ namespace Avalonia.Headless public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride) { return new HeadlessBitmapStub(new Size(1, 1), new Vector(96, 96)); + } + + public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) + { + return new HeadlessBitmapStub(new Size(width, width), new Vector(96, 96)); + } + + public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) + { + return new HeadlessBitmapStub(new Size(height, height), new Vector(96, 96)); + } + + public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) + { + return new HeadlessBitmapStub(destinationSize, new Vector(96, 96)); + } + + public IGlyphRunImpl CreateGlyphRun(GlyphRun glyphRun, out double width) + { + width = 100; + return new HeadlessGlyphRunStub(); } class HeadlessGeometryStub : IGeometryImpl @@ -126,6 +148,13 @@ namespace Avalonia.Headless public Matrix Transform { get; } } + class HeadlessGlyphRunStub : IGlyphRunImpl + { + public void Dispose() + { + } + } + class HeadlessStreamingGeometryStub : HeadlessGeometryStub, IStreamGeometryImpl { public HeadlessStreamingGeometryStub() : base(Rect.Empty) @@ -264,42 +293,11 @@ namespace Avalonia.Headless } - public void DrawImage(IRef source, double opacity, Rect sourceRect, Rect destRect, - BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default) - { - - } - - public void DrawImage(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect) - { - - } - - public void DrawLine(Pen pen, Point p1, Point p2) - { - - } - - public void DrawGeometry(IBrush brush, Pen pen, IGeometryImpl geometry) - { - - } - - public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0) - { - - } - public void DrawText(IBrush foreground, Point origin, IFormattedTextImpl text) { } - public void FillRectangle(IBrush brush, Rect rect, float cornerRadius = 0) - { - - } - public IRenderTargetBitmapImpl CreateLayer(Size size) { return new HeadlessBitmapStub(size, new Vector(96, 96)); @@ -362,6 +360,31 @@ namespace Avalonia.Headless public void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0) { } + + public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default) + { + + } + + public void DrawBitmap(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect) + { + + } + + public void DrawRectangle(IBrush brush, IPen pen, RoundedRect rect, BoxShadows boxShadow = default) + { + + } + + public void DrawGlyphRun(IBrush foreground, GlyphRun glyphRun, Point baselineOrigin) + { + + } + + public void PushClip(RoundedRect clip) + { + + } } class HeadlessRenderTarget : IRenderTarget diff --git a/src/Avalonia.Headless/HeadlessPlatformStubs.cs b/src/Avalonia.Headless/HeadlessPlatformStubs.cs index debe77c1b6..f8f5f2a046 100644 --- a/src/Avalonia.Headless/HeadlessPlatformStubs.cs +++ b/src/Avalonia.Headless/HeadlessPlatformStubs.cs @@ -13,6 +13,8 @@ namespace Avalonia.Headless class HeadlessClipboardStub : IClipboard { private string _text; + private IDataObject _data; + public Task GetTextAsync() { return Task.Run(() => _text); @@ -27,6 +29,21 @@ namespace Avalonia.Headless { return Task.Run(() => _text = null); } + + public Task SetDataObjectAsync(IDataObject data) + { + return Task.Run(() => _data = data); + } + + public Task GetFormatsAsync() + { + throw new NotImplementedException(); + } + + public async Task GetDataAsync(string format) + { + return await Task.Run(() => _data); + } } class HeadlessCursorFactoryStub : IStandardCursorFactory @@ -46,12 +63,12 @@ namespace Avalonia.Headless class HeadlessSystemDialogsStub : ISystemDialogImpl { - public Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) + public Task ShowFileDialogAsync(FileDialog dialog, Window parent) { return Task.Run(() => (string[])null); } - public Task ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) + public Task ShowFolderDialogAsync(OpenFolderDialog dialog, Window parent) { return Task.Run(() => (string)null); } @@ -89,7 +106,7 @@ namespace Avalonia.Headless public IReadOnlyList AllScreens { get; } = new[] { - new Screen(new PixelRect(0, 0, 1920, 1280), + new Screen(1, new PixelRect(0, 0, 1920, 1280), new PixelRect(0, 0, 1920, 1280), true), }; } diff --git a/src/Avalonia.Headless/HeadlessWindowImpl.cs b/src/Avalonia.Headless/HeadlessWindowImpl.cs index 2ff9d3e949..679edcaa59 100644 --- a/src/Avalonia.Headless/HeadlessWindowImpl.cs +++ b/src/Avalonia.Headless/HeadlessWindowImpl.cs @@ -224,17 +224,25 @@ namespace Avalonia.Headless // TODO: Hook recent Popup changes. IPopupPositioner IPopupImpl.PopupPositioner => null; - void IHeadlessWindow.KeyPress(Key key, InputModifiers modifiers) + public Size MaxAutoSizeHint => new Size(1920, 1080); + + public Action TransparencyLevelChanged { get; set; } + + public WindowTransparencyLevel TransparencyLevel => WindowTransparencyLevel.None; + + public Action GotInputWhenDisabled { get; set; } + + void IHeadlessWindow.KeyPress(Key key, RawInputModifiers modifiers) { - Input?.Invoke(new RawKeyEventArgs(_keyboard, Timestamp, RawKeyEventType.KeyDown, key, modifiers)); + Input?.Invoke(new RawKeyEventArgs(_keyboard, Timestamp, InputRoot, RawKeyEventType.KeyDown, key, modifiers)); } - void IHeadlessWindow.KeyRelease(Key key, InputModifiers modifiers) + void IHeadlessWindow.KeyRelease(Key key, RawInputModifiers modifiers) { - Input?.Invoke(new RawKeyEventArgs(_keyboard, Timestamp, RawKeyEventType.KeyUp, key, modifiers)); + Input?.Invoke(new RawKeyEventArgs(_keyboard, Timestamp, InputRoot, RawKeyEventType.KeyUp, key, modifiers)); } - void IHeadlessWindow.MouseDown(Point point, int button, InputModifiers modifiers) + void IHeadlessWindow.MouseDown(Point point, int button, RawInputModifiers modifiers) { Input?.Invoke(new RawPointerEventArgs(MouseDevice, Timestamp, InputRoot, button == 0 ? RawPointerEventType.LeftButtonDown : @@ -242,13 +250,13 @@ namespace Avalonia.Headless point, modifiers)); } - void IHeadlessWindow.MouseMove(Point point, InputModifiers modifiers) + void IHeadlessWindow.MouseMove(Point point, RawInputModifiers modifiers) { Input?.Invoke(new RawPointerEventArgs(MouseDevice, Timestamp, InputRoot, RawPointerEventType.Move, point, modifiers)); } - void IHeadlessWindow.MouseUp(Point point, int button, InputModifiers modifiers) + void IHeadlessWindow.MouseUp(Point point, int button, RawInputModifiers modifiers) { Input?.Invoke(new RawPointerEventArgs(MouseDevice, Timestamp, InputRoot, button == 0 ? RawPointerEventType.LeftButtonUp : @@ -266,5 +274,40 @@ namespace Avalonia.Headless // TODO: Hook recent Popup changes. return null; } + + public void SetWindowManagerAddShadowHint(bool enabled) + { + + } + + public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel) + { + + } + + public void SetParent(IWindowImpl parent) + { + + } + + public void SetEnabled(bool enable) + { + + } + + public void SetSystemDecorations(SystemDecorations enabled) + { + + } + + public void BeginMoveDrag(PointerPressedEventArgs e) + { + + } + + public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e) + { + + } } } diff --git a/src/Avalonia.Headless/IHeadlessWindow.cs b/src/Avalonia.Headless/IHeadlessWindow.cs index aafad2e500..282662f98b 100644 --- a/src/Avalonia.Headless/IHeadlessWindow.cs +++ b/src/Avalonia.Headless/IHeadlessWindow.cs @@ -8,10 +8,10 @@ namespace Avalonia.Headless public interface IHeadlessWindow { IRef GetLastRenderedFrame(); - void KeyPress(Key key, InputModifiers modifiers); - void KeyRelease(Key key, InputModifiers modifiers); - void MouseDown(Point point, int button, InputModifiers modifiers = InputModifiers.None); - void MouseMove(Point point, InputModifiers modifiers = InputModifiers.None); - void MouseUp(Point point, int button, InputModifiers modifiers = InputModifiers.None); + void KeyPress(Key key, RawInputModifiers modifiers); + void KeyRelease(Key key, RawInputModifiers modifiers); + void MouseDown(Point point, int button, RawInputModifiers modifiers = RawInputModifiers.None); + void MouseMove(Point point, RawInputModifiers modifiers = RawInputModifiers.None); + void MouseUp(Point point, int button, RawInputModifiers modifiers = RawInputModifiers.None); } }