Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isStroked overload for IGeometryContext #12617

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Avalonia.Base/Media/StreamGeometryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Avalonia.Media
/// of <see cref="StreamGeometryContext"/> is obtained by calling
/// <see cref="StreamGeometry.Open"/>.
/// </remarks>
public class StreamGeometryContext : IGeometryContext
public class StreamGeometryContext : IGeometryContext, IGeometryContextEx
{
private readonly IStreamGeometryContextImpl _impl;

Expand Down Expand Up @@ -128,5 +128,20 @@ public void Dispose()
{
_impl.Dispose();
}

/// <summary>
/// Draws a line to the specified point.
/// </summary>
/// <param name="point">The destination point.</param>
/// <param name="isStroked">Whether the segment is stroked</param>
public void LineTo(Point point, bool isStroked)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"hasStroke", "drawStroke" or "includeStroke" might be better names for the parameter. I do prefer "Is" when naming bool; however, "stroked" isn't a standard word. "isStroked" has good symmetry with "isFilled" though... so just ideas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name was taken from wpf's, but if there's better wording for it, I could change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, if naming is coming over from WPF its fine and I don't have concerns other than noted below (line should always have a stroke I think).

{
if (_impl is IGeometryContextEx contextEx)
contextEx.LineTo(point, isStroked);
else
_impl.LineTo(point);

_currentPoint = point;
}
}
}
1 change: 1 addition & 0 deletions src/Avalonia.Base/Platform/IGeometryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ public interface IGeometryContext : IDisposable
/// <param name="fillRule">The fill rule.</param>
void SetFillRule(FillRule fillRule);
}

}
13 changes: 13 additions & 0 deletions src/Avalonia.Base/Platform/IGeometryContextEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Avalonia.Platform
{
public interface IGeometryContextEx : IGeometryContext
{
/// <summary>
/// Draws a line to the specified point.
/// </summary>
/// <param name="point">The destination point.</param>
/// <param name="isStroked">Whether the segment is stroked</param>
void LineTo(Point point, bool isStroked);
}

}
35 changes: 27 additions & 8 deletions src/Skia/Avalonia.Skia/StreamGeometryImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static SKPath CreateEmptyPath()
/// <summary>
/// A Skia implementation of a <see cref="IStreamGeometryContextImpl"/>.
/// </summary>
private class StreamContext : IStreamGeometryContextImpl
private class StreamContext : IStreamGeometryContextImpl, IGeometryContextEx
{
private readonly StreamGeometryImpl _geometryImpl;
private SKPath Stroke => _geometryImpl._strokePath;
Expand All @@ -93,7 +93,7 @@ public StreamContext(StreamGeometryImpl geometryImpl)
{
_geometryImpl = geometryImpl;
}

/// <inheritdoc />
/// <remarks>Will update bounds of passed geometry.</remarks>
public void Dispose()
Expand All @@ -117,7 +117,7 @@ public void ArcTo(Point point, Size size, double rotationAngle, bool isLargeArc,
sweep,
(float)point.X,
(float)point.Y);
if(Duplicate)
if (Duplicate)
Fill.ArcTo(
(float)size.Width,
(float)size.Height,
Expand All @@ -136,34 +136,34 @@ public void BeginFigure(Point startPoint, bool isFilled)
if (Stroke == Fill)
_geometryImpl._fillPath = Stroke.Clone();
}

_isFilled = isFilled;
Stroke.MoveTo((float)startPoint.X, (float)startPoint.Y);
if(Duplicate)
if (Duplicate)
Fill.MoveTo((float)startPoint.X, (float)startPoint.Y);
}

/// <inheritdoc />
public void CubicBezierTo(Point point1, Point point2, Point point3)
{
Stroke.CubicTo((float)point1.X, (float)point1.Y, (float)point2.X, (float)point2.Y, (float)point3.X, (float)point3.Y);
if(Duplicate)
if (Duplicate)
Fill.CubicTo((float)point1.X, (float)point1.Y, (float)point2.X, (float)point2.Y, (float)point3.X, (float)point3.Y);
}

/// <inheritdoc />
public void QuadraticBezierTo(Point point1, Point point2)
{
Stroke.QuadTo((float)point1.X, (float)point1.Y, (float)point2.X, (float)point2.Y);
if(Duplicate)
if (Duplicate)
Fill.QuadTo((float)point1.X, (float)point1.Y, (float)point2.X, (float)point2.Y);
}

/// <inheritdoc />
public void LineTo(Point point)
{
Stroke.LineTo((float)point.X, (float)point.Y);
if(Duplicate)
if (Duplicate)
Fill.LineTo((float)point.X, (float)point.Y);
}

Expand All @@ -183,6 +183,25 @@ public void SetFillRule(FillRule fillRule)
{
Fill.FillType = fillRule == FillRule.EvenOdd ? SKPathFillType.EvenOdd : SKPathFillType.Winding;
}

/// <inheritdoc />
public void LineTo(Point point, bool isStroked)
{
if (isStroked)
{

Stroke.LineTo((float)point.X, (float)point.Y);
}
else
{
if (Stroke == Fill)
_geometryImpl._fillPath = Stroke.Clone();

Stroke.MoveTo((float)point.X, (float)point.Y);
}
if (Duplicate)
Fill.LineTo((float)point.X, (float)point.Y);
}
}
}
}