瀏覽代碼

Fix missing interface calls.

Jumar Macato 6 年之前
父節點
當前提交
86e9ac5ea9
共有 2 個文件被更改,包括 88 次插入52 次删除
  1. 56 35
      src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs
  2. 32 17
      src/Avalonia.Headless/HeadlessWindowImpl.cs

+ 56 - 35
src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs

@@ -19,7 +19,7 @@ namespace Avalonia.Headless
                 .Bind<IPlatformRenderInterface>().ToConstant(new HeadlessPlatformRenderInterface());
         }
 
-        public IEnumerable<string> InstalledFontNames { get; } = new[] {"Tahoma"};
+        public IEnumerable<string> InstalledFontNames { get; } = new[] { "Tahoma" };
 
         public IFormattedTextImpl CreateFormattedText(string text, Typeface typeface, TextAlignment textAlignment,
             TextWrapping wrapping, Size constraint, IReadOnlyList<FormattedTextStyleSpan> spans)
@@ -76,14 +76,22 @@ namespace Avalonia.Headless
             {
                 Bounds = bounds;
             }
+
             public Rect Bounds { get; set; }
-            public virtual Rect GetRenderBounds(Pen pen) => Bounds.Inflate(pen.Thickness / 2);
             public virtual bool FillContains(Point point) => Bounds.Contains(point);
 
-            public IGeometryImpl Intersect(IGeometryImpl geometry) 
-                => new HeadlessGeometryStub(geometry.Bounds.Intersect(Bounds));
+            public Rect GetRenderBounds(IPen pen)
+            {
+                return Bounds.Inflate(pen.Thickness / 2);
+            }
+
+            public bool StrokeContains(IPen pen, Point point)
+            {
+                return false;
+            }
 
-            public bool StrokeContains(Pen pen, Point point) => false;
+            public IGeometryImpl Intersect(IGeometryImpl geometry)
+                => new HeadlessGeometryStub(geometry.Bounds.Intersect(Bounds));
 
             public ITransformedGeometryImpl WithTransform(Matrix transform) =>
                 new HeadlessTransformedGeometryStub(this, transform);
@@ -93,7 +101,7 @@ namespace Avalonia.Headless
         {
             public HeadlessTransformedGeometryStub(IGeometryImpl b, Matrix transform) : this(Fix(b, transform))
             {
-                
+
             }
 
             static (IGeometryImpl, Matrix, Rect) Fix(IGeometryImpl b, Matrix transform)
@@ -160,7 +168,7 @@ namespace Avalonia.Headless
                     _parent.Bounds = new Rect(_x1, _y1, _x2 - _x1, _y2 - _y1);
                 }
 
-                public void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection) 
+                public void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection)
                     => Track(point);
 
                 public void BeginFigure(Point startPoint, bool isFilled = true) => Track(startPoint);
@@ -187,7 +195,7 @@ namespace Avalonia.Headless
 
                 public void SetFillRule(FillRule fillRule)
                 {
-                    
+
                 }
             }
         }
@@ -203,17 +211,17 @@ namespace Avalonia.Headless
                 var pixel = Size * (Dpi / 96);
                 PixelSize = new PixelSize(Math.Max(1, (int)pixel.Width), Math.Max(1, (int)pixel.Height));
             }
-            
+
             public HeadlessBitmapStub(PixelSize size, Vector dpi)
             {
                 PixelSize = size;
                 Dpi = dpi;
                 Size = PixelSize.ToSizeWithDpi(dpi);
             }
-            
+
             public void Dispose()
             {
-                
+
             }
 
             public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
@@ -226,12 +234,12 @@ namespace Avalonia.Headless
             public int Version { get; set; }
             public void Save(string fileName)
             {
-                
+
             }
 
             public void Save(Stream stream)
             {
-                
+
             }
 
             public ILockedFramebuffer Lock()
@@ -247,49 +255,49 @@ namespace Avalonia.Headless
         {
             public void Dispose()
             {
-                
+
             }
 
             public Matrix Transform { get; set; }
             public void Clear(Color color)
             {
-                
+
             }
 
             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)
@@ -299,47 +307,60 @@ namespace Avalonia.Headless
 
             public void PushClip(Rect clip)
             {
-                
+
             }
 
             public void PopClip()
             {
-                
+
             }
 
             public void PushOpacity(double opacity)
             {
-                
+
             }
 
             public void PopOpacity()
             {
-                
+
             }
 
             public void PushOpacityMask(IBrush mask, Rect bounds)
             {
-                
+
             }
 
             public void PopOpacityMask()
             {
-                
+
             }
 
             public void PushGeometryClip(IGeometryImpl clip)
             {
-                
+
             }
 
             public void PopGeometryClip()
             {
-                
+
             }
 
             public void Custom(ICustomDrawOperation custom)
             {
-                
+
+            }
+
+            public void DrawLine(IPen pen, Point p1, Point p2)
+            {
+                throw new NotImplementedException();
+            }
+
+            public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry)
+            {
+            }
+
+            public void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0)
+            {
             }
         }
 
@@ -347,7 +368,7 @@ namespace Avalonia.Headless
         {
             public void Dispose()
             {
-                
+
             }
 
             public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer)
@@ -364,15 +385,15 @@ namespace Avalonia.Headless
                 Constraint = constraint;
                 Bounds = new Rect(Constraint.Constrain(new Size(50, 50)));
             }
-            
+
             public Size Constraint { get; }
             public Rect Bounds { get; }
             public string Text { get; }
 
-            
+
             public IEnumerable<FormattedTextLine> GetLines()
             {
-                return new[] {new FormattedTextLine(Text.Length, 10)};
+                return new[] { new FormattedTextLine(Text.Length, 10) };
             }
 
             public TextHitTestResult HitTestPoint(Point point) => new TextHitTestResult();

+ 32 - 17
src/Avalonia.Headless/HeadlessWindowImpl.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using Avalonia.Controls;
 using Avalonia.Controls.Platform.Surfaces;
+using Avalonia.Controls.Primitives.PopupPositioning;
 using Avalonia.Input;
 using Avalonia.Input.Raw;
 using Avalonia.Media.Imaging;
@@ -25,7 +26,7 @@ namespace Avalonia.Headless
         public HeadlessWindowImpl(bool isPopup)
         {
             IsPopup = isPopup;
-            Surfaces = new object[] {this};
+            Surfaces = new object[] { this };
             _keyboard = AvaloniaLocator.Current.GetService<IKeyboardDevice>();
             _mousePointer = new Pointer(Pointer.GetNextFreeId(), PointerType.Mouse, true);
             MouseDevice = new MouseDevice(_mousePointer);
@@ -46,8 +47,8 @@ namespace Avalonia.Headless
         public Action<Rect> Paint { get; set; }
         public Action<Size> Resized { get; set; }
         public Action<double> ScalingChanged { get; set; }
-        
-        public IRenderer CreateRenderer(IRenderRoot root) 
+
+        public IRenderer CreateRenderer(IRenderRoot root)
             => new DeferredRenderer(root, AvaloniaLocator.Current.GetService<IRenderLoop>());
 
         public void Invalidate(Rect rect)
@@ -67,7 +68,7 @@ namespace Avalonia.Headless
 
         public void SetCursor(IPlatformHandle cursor)
         {
-            
+
         }
 
         public Action Closed { get; set; }
@@ -85,12 +86,12 @@ namespace Avalonia.Headless
 
         public void BeginMoveDrag()
         {
-            
+
         }
 
         public void BeginResizeDrag(WindowEdge edge)
         {
-            
+
         }
 
         public PixelPoint Position { get; set; }
@@ -128,12 +129,12 @@ namespace Avalonia.Headless
 
         public void SetMinMaxSize(Size minSize, Size maxSize)
         {
-            
+
         }
 
         public void SetTopmost(bool value)
         {
-            
+
         }
 
         public IScreenImpl Screen { get; } = new HeadlessScreensStub();
@@ -141,7 +142,7 @@ namespace Avalonia.Headless
         public Action<WindowState> WindowStateChanged { get; set; }
         public void SetTitle(string title)
         {
-            
+
         }
 
         public void ShowDialog(IWindowImpl parent)
@@ -151,22 +152,22 @@ namespace Avalonia.Headless
 
         public void SetSystemDecorations(bool enabled)
         {
-            
+
         }
 
         public void SetIcon(IWindowIconImpl icon)
         {
-            
+
         }
 
         public void ShowTaskbarIcon(bool value)
         {
-            
+
         }
 
         public void CanResize(bool value)
         {
-            
+
         }
 
         public Func<bool> Closing { get; set; }
@@ -184,7 +185,7 @@ namespace Avalonia.Headless
             }
             public void Dispose()
             {
-                if(_disposed)
+                if (_disposed)
                     return;
                 _disposed = true;
                 _fb.Dispose();
@@ -197,7 +198,7 @@ namespace Avalonia.Headless
             public Vector Dpi => _fb.Dpi;
             public PixelFormat Format => _fb.Format;
         }
-        
+
         public ILockedFramebuffer Lock()
         {
             var bmp = new WriteableBitmap(PixelSize.FromSize(ClientSize, Scaling), new Vector(96, 96) * Scaling);
@@ -217,9 +218,12 @@ namespace Avalonia.Headless
             lock (_sync)
                 return _lastRenderedFrame?.PlatformImpl?.CloneAs<IWriteableBitmapImpl>();
         }
-        
+
         private ulong Timestamp => (ulong)_st.ElapsedMilliseconds;
-        
+
+        // TODO: Hook recent Popup changes. 
+        IPopupPositioner IPopupImpl.PopupPositioner => null;
+
         void IHeadlessWindow.KeyPress(Key key, InputModifiers modifiers)
         {
             Input?.Invoke(new RawKeyEventArgs(_keyboard, Timestamp, RawKeyEventType.KeyDown, key, modifiers));
@@ -251,5 +255,16 @@ namespace Avalonia.Headless
                 button == 1 ? RawPointerEventType.MiddleButtonUp : RawPointerEventType.RightButtonUp,
                 point, modifiers));
         }
+
+        void IWindowImpl.Move(PixelPoint point)
+        {
+
+        }
+
+        public IPopupImpl CreatePopup()
+        {
+            // TODO: Hook recent Popup changes. 
+            return null;
+        }
     }
 }