Browse Source

Add TryGetSegment

pull/5683/head
Jumar Macato 5 years ago
parent
commit
4ef47bfdb0
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 6
      src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs
  2. 13
      src/Avalonia.Visuals/Platform/IGeometryImpl.cs
  3. 22
      src/Skia/Avalonia.Skia/GeometryImpl.cs
  4. 9
      src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs
  5. 6
      tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs
  6. 5
      tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs

6
src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs

@ -142,6 +142,12 @@ namespace Avalonia.Headless
tangent = new Point();
return false;
}
public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry)
{
segmentGeometry = null;
return false;
}
}
class HeadlessTransformedGeometryStub : HeadlessGeometryStub, ITransformedGeometryImpl

13
src/Avalonia.Visuals/Platform/IGeometryImpl.cs

@ -73,5 +73,18 @@ namespace Avalonia.Platform
/// <param name="tangent">The tangent in the specified distance.</param>
/// <returns>If there's valid point and tangent at the specified distance.</returns>
bool TryGetPointAndTangentAtDistance(double distance, out Point point, out Point tangent);
/// <summary>
/// Attempts to get the corresponding path segment
/// given by the two distances specified.
/// Imagine it like snipping a part of the current
/// geometry.
/// </summary>
/// <param name="startDistance">The contour distance to start snipping from.</param>
/// <param name="stopDistance">The contour distance to stop snipping to.</param>
/// <param name="startOnBeginFigure">If ture, the resulting snipped path will start with a BeginFigure call.</param>
/// <param name="segmentGeometry">The resulting snipped path.</param>
/// <returns>If the snipping operation is successful.</returns>
bool TryGetSegment (float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry);
}
}

22
src/Skia/Avalonia.Skia/GeometryImpl.cs

@ -138,6 +138,28 @@ namespace Avalonia.Skia
return res;
}
public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry)
{
if (_pathCache.CachePathMeasure is null)
{
segmentGeometry = null;
return false;
}
segmentGeometry = null;
SKPath _skPathSegment = null;
var res = _pathCache.CachePathMeasure.GetSegment(startDistance, stopDistance, _skPathSegment, startOnBeginFigure);
if (res)
{
segmentGeometry = new StreamGeometryImpl(_skPathSegment);
}
return res;
}
/// <summary>
/// Invalidate all caches. Call after chaining path contents.
/// </summary>

9
src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs

@ -82,6 +82,15 @@ namespace Avalonia.Direct2D1.Media
return false;
}
public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry)
{
// Direct2D doesnt have this too sadly.
Logger.TryGet(LogEventLevel.Warning, LogArea.Visual)?.Log(this, "TryGetSegment is not available in Direct2D.");
segmentGeometry = null;
return false;
}
protected virtual Geometry GetSourceGeometry() => Geometry;
}
}

6
tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs

@ -84,6 +84,12 @@ namespace Avalonia.UnitTests
return false;
}
public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry)
{
segmentGeometry = null;
return false;
}
class MockStreamGeometryContext : IStreamGeometryContextImpl
{
private List<Point> points = new List<Point>();

5
tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs

@ -163,6 +163,11 @@ namespace Avalonia.Visuals.UnitTests.VisualTree
throw new NotImplementedException();
}
public bool TryGetSegment(float startDistance, float stopDistance, bool startOnBeginFigure, out IGeometryImpl segmentGeometry)
{
throw new NotImplementedException();
}
class MockStreamGeometryContext : IStreamGeometryContextImpl
{
private List<Point> points = new List<Point>();

Loading…
Cancel
Save