Browse Source

update headless platform stubs.

pull/2847/head
Dan Walmsley 6 years ago
parent
commit
80e02dd2f7
  1. 1
      samples/ControlCatalog.NetCore/Program.cs
  2. 2
      src/Avalonia.Headless.Vnc/HeadlessVncFramebufferSource.cs
  3. 89
      src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs
  4. 23
      src/Avalonia.Headless/HeadlessPlatformStubs.cs
  5. 57
      src/Avalonia.Headless/HeadlessWindowImpl.cs
  6. 10
      src/Avalonia.Headless/IHeadlessWindow.cs

1
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
{

2
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(() =>
{

89
src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs

@ -21,8 +21,9 @@ namespace Avalonia.Headless
public IEnumerable<string> InstalledFontNames { get; } = new[] { "Tahoma" };
public IFormattedTextImpl CreateFormattedText(string text, Typeface typeface, TextAlignment textAlignment,
TextWrapping wrapping, Size constraint, IReadOnlyList<FormattedTextStyleSpan> spans)
public bool SupportsIndividualRoundRects => throw new NotImplementedException();
public IFormattedTextImpl CreateFormattedText(string text, Typeface typeface, double fontSize, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList<FormattedTextStyleSpan> 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<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect,
BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default)
{
}
public void DrawImage(IRef<IBitmapImpl> 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<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default)
{
}
public void DrawBitmap(IRef<IBitmapImpl> 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

23
src/Avalonia.Headless/HeadlessPlatformStubs.cs

@ -13,6 +13,8 @@ namespace Avalonia.Headless
class HeadlessClipboardStub : IClipboard
{
private string _text;
private IDataObject _data;
public Task<string> 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<string[]> GetFormatsAsync()
{
throw new NotImplementedException();
}
public async Task<object> GetDataAsync(string format)
{
return await Task.Run(() => _data);
}
}
class HeadlessCursorFactoryStub : IStandardCursorFactory
@ -46,12 +63,12 @@ namespace Avalonia.Headless
class HeadlessSystemDialogsStub : ISystemDialogImpl
{
public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent)
public Task<string[]> ShowFileDialogAsync(FileDialog dialog, Window parent)
{
return Task.Run(() => (string[])null);
}
public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, Window parent)
{
return Task.Run(() => (string)null);
}
@ -89,7 +106,7 @@ namespace Avalonia.Headless
public IReadOnlyList<Screen> 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),
};
}

57
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<WindowTransparencyLevel> 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)
{
}
}
}

10
src/Avalonia.Headless/IHeadlessWindow.cs

@ -8,10 +8,10 @@ namespace Avalonia.Headless
public interface IHeadlessWindow
{
IRef<IWriteableBitmapImpl> 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);
}
}

Loading…
Cancel
Save