Browse Source
- Move the logic into `SKPathHelper.CreateStrokedPath`; called from `PathHelper` and `GetWidenedGeometry` - Use a pen hash code to check if we're up-to-date in `PathHelper` and include the dash style in thatpull/12724/head
3 changed files with 89 additions and 45 deletions
@ -0,0 +1,38 @@ |
|||||
|
using System; |
||||
|
using Avalonia.Media; |
||||
|
|
||||
|
namespace Avalonia.Skia.Helpers; |
||||
|
|
||||
|
internal static class PenHelper |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets a hash code for a pen, optionally including the brush.
|
||||
|
/// </summary>
|
||||
|
/// <param name="pen">The pen.</param>
|
||||
|
/// <param name="includeBrush">Whether to include the brush in the hash code.</param>
|
||||
|
/// <returns>The hash code.</returns>
|
||||
|
public static int GetHashCode(IPen? pen, bool includeBrush) |
||||
|
{ |
||||
|
if (pen is null) |
||||
|
return 0; |
||||
|
|
||||
|
var hash = new HashCode(); |
||||
|
hash.Add(pen.LineCap); |
||||
|
hash.Add(pen.LineJoin); |
||||
|
hash.Add(pen.MiterLimit); |
||||
|
hash.Add(pen.Thickness); |
||||
|
|
||||
|
if (pen.DashStyle is { } dashStyle) |
||||
|
{ |
||||
|
hash.Add(dashStyle.Offset); |
||||
|
|
||||
|
for (var i = 0; i < dashStyle.Dashes?.Count; i++) |
||||
|
hash.Add(dashStyle.Dashes[i]); |
||||
|
} |
||||
|
|
||||
|
if (includeBrush) |
||||
|
hash.Add(pen.Brush); |
||||
|
|
||||
|
return hash.ToHashCode(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue