Include StrokeDashOffset property

This commit is contained in:
Javier Suárez Ruiz 2022-03-07 15:49:25 +01:00
Родитель cc1e48974d
Коммит 0efeda81e6
19 изменённых файлов: 68 добавлений и 32 удалений

Просмотреть файл

@ -306,14 +306,14 @@ namespace Microsoft.Maui.Graphics.Blazor
_context.Scale(fx, fy);
}
protected override void PlatformSetStrokeDashPattern(float[] pattern, float strokeSize)
protected override void PlatformSetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize)
{
float[] finalPattern = null;
if (pattern != null)
if (strokePattern != null)
{
finalPattern = new float[pattern.Length];
for (int i = 0; i < pattern.Length; i++)
finalPattern[i] = pattern[i] * strokeSize;
finalPattern = new float[strokePattern.Length];
for (int i = 0; i < strokePattern.Length; i++)
finalPattern[i] = strokePattern[i] * strokeSize;
}
CurrentState.BlazorDashPattern = finalPattern;

Просмотреть файл

@ -480,7 +480,7 @@ namespace Microsoft.Maui.Graphics.GDI
set => CurrentState.StrokeWidth = value;
}
protected override void PlatformSetStrokeDashPattern(float[] pattern, float strokeSize)
protected override void PlatformSetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize)
{
}

Просмотреть файл

@ -107,9 +107,9 @@ namespace Microsoft.Maui.Graphics.Platform.Gtk
set => CurrentState.BlendMode = value;
}
protected override void PlatformSetStrokeDashPattern(float[] pattern, float strokeSize)
protected override void PlatformSetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize)
{
CurrentState.StrokeDashPattern = pattern;
CurrentState.StrokeDashPattern = strokePattern;
}
private void Draw(bool preserve = false)

Просмотреть файл

@ -787,9 +787,9 @@ namespace Microsoft.Maui.Graphics.SharpDX
CurrentState.SetShadow(offset, blur, color);
}
protected override void PlatformSetStrokeDashPattern(float[] pattern, float strokeSize)
protected override void PlatformSetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize)
{
CurrentState.SetStrokeDashPattern(pattern, strokeSize);
CurrentState.SetStrokeDashPattern(strokePattern, strokeDashOffset, strokeSize);
}
protected override float PlatformStrokeSize

Просмотреть файл

@ -513,9 +513,9 @@ namespace Microsoft.Maui.Graphics.SharpDX
BlurRadius = 0;
}
public void SetStrokeDashPattern(float[] pattern, float strokeSize)
public void SetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize)
{
if (pattern == null || pattern.Length == 0)
if (strokePattern == null || strokePattern.Length == 0)
{
if (_needsStrokeStyle == false) return;
_strokeStyleProperties.DashStyle = DashStyle.Solid;
@ -524,7 +524,7 @@ namespace Microsoft.Maui.Graphics.SharpDX
else
{
_strokeStyleProperties.DashStyle = DashStyle.Custom;
_dashes = pattern;
_dashes = strokePattern;
}
InvalidateStrokeStyle();

Просмотреть файл

@ -215,10 +215,11 @@ namespace Microsoft.Maui.Graphics.Skia
}
protected override void PlatformSetStrokeDashPattern(
float[] pattern,
float[] strokePattern,
float strokeDashOffset,
float strokeSize)
{
CurrentState.SetStrokeDashPattern(pattern, strokeSize);
CurrentState.SetStrokeDashPattern(strokePattern, strokeDashOffset, strokeSize);
}
public override void SetFillPaint(Paint paint, RectF rectangle)

Просмотреть файл

@ -119,7 +119,7 @@ namespace Microsoft.Maui.Graphics.Skia
set => StrokePaint.StrokeMiter = value;
}
public void SetStrokeDashPattern(float[] pattern, float strokeSize)
public void SetStrokeDashPattern(float[] pattern, float strokeDashOffset, float strokeSize)
{
if (pattern == null || pattern.Length == 0 || strokeSize == 0)
{

Просмотреть файл

@ -84,9 +84,9 @@ After:
set => CurrentState.StrokeLineJoin = value;
}
protected override void PlatformSetStrokeDashPattern(float[] pattern, float strokeSize)
protected override void PlatformSetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize)
{
CurrentState.SetStrokeDashPattern(pattern, strokeSize);
CurrentState.SetStrokeDashPattern(strokePattern, strokeDashOffset, strokeSize);
}
public override Color FillColor

Просмотреть файл

@ -242,7 +242,7 @@ namespace Microsoft.Maui.Graphics.Win2D
}
}
public void SetStrokeDashPattern(float[] pattern, float strokeSize)
public void SetStrokeDashPattern(float[] pattern, float strokeDashOffset, float strokeSize)
{
if (pattern == null || pattern.Length == 0)
{

Просмотреть файл

@ -273,6 +273,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -295,6 +296,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -320,6 +322,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -345,6 +348,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -412,6 +416,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -444,13 +449,14 @@ namespace Microsoft.Maui.Graphics.Xaml
{
System.Diagnostics.Debug.WriteLine(exc);
}
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
element.Opacity = CurrentState.Alpha;
}
protected override void PlatformSetStrokeDashPattern(float[] pattern, float strokeSize)
protected override void PlatformSetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize)
{
CurrentState.XamlDashArray = null;
}

Просмотреть файл

@ -270,6 +270,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -293,6 +294,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -319,6 +321,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -345,6 +348,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -415,6 +419,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -441,6 +446,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Stroke = CurrentState.XamlStrokeBrush;
element.StrokeThickness = CurrentState.StrokeSize;
element.StrokeDashArray = CurrentState.XamlDashArray;
element.StrokeDashOffset = CurrentState.StrokeDashOffset;
element.StrokeEndLineCap = CurrentState.XamlLineCap;
element.StrokeStartLineCap = CurrentState.XamlLineCap;
element.StrokeMiterLimit = CurrentState.MiterLimit;
@ -448,7 +454,7 @@ namespace Microsoft.Maui.Graphics.Xaml
element.Effect = CurrentState.XamlEffect;
}
protected override void NativeSetStrokeDashPattern(float[] pattern, float strokeSize)
protected override void NativeSetStrokeDashPattern(float[] strokePattern, float strokeSize)
{
CurrentState.XamlDashArray = null;
}

Просмотреть файл

@ -19,7 +19,8 @@ namespace Microsoft.Maui.Graphics
private bool _strokeDashPatternDirty;
protected abstract float PlatformStrokeSize { set; }
protected abstract void PlatformSetStrokeDashPattern(float[] pattern, float strokeSize);
protected abstract void PlatformSetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize);
protected abstract void PlatformDrawLine(float x1, float y1, float x2, float y2);
protected abstract void PlatformDrawArc(float x, float y, float width, float height, float startAngle, float endAngle, bool clockwise, bool closed);
protected abstract void PlatformDrawRectangle(float x, float y, float width, float height);
@ -113,12 +114,21 @@ namespace Microsoft.Maui.Graphics
}
}
}
public float StrokeDashOffset
{
set
{
var dashOffset = value;
_currentState.StrokeDashOffset = dashOffset;
}
}
private void EnsureStrokePatternSet()
{
if (_strokeDashPatternDirty)
{
PlatformSetStrokeDashPattern(_currentState.StrokeDashPattern, _currentState.StrokeSize);
PlatformSetStrokeDashPattern(_currentState.StrokeDashPattern, _currentState.StrokeDashOffset, _currentState.StrokeSize);
_strokeDashPatternDirty = false;
}
}

Просмотреть файл

@ -199,9 +199,9 @@ namespace Microsoft.Maui.Graphics.Platform
}
}
protected override void PlatformSetStrokeDashPattern(float[] patter, float linewidth)
protected override void PlatformSetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize)
{
CurrentState.SetStrokeDashPattern(patter, linewidth);
CurrentState.SetStrokeDashPattern(strokePattern, strokeDashOffset, strokeSize);
}
public override void SetFillPaint(Paint paint, RectF rectangle)

Просмотреть файл

@ -111,7 +111,7 @@ namespace Microsoft.Maui.Graphics.Platform
set => StrokePaint.StrokeMiter = value;
}
public void SetStrokeDashPattern(float[] pattern, float strokeSize)
public void SetStrokeDashPattern(float[] pattern, float strokeDashOffset, float strokeSize)
{
if (pattern == null || pattern.Length == 0 || strokeSize == 0)
{

Просмотреть файл

@ -6,6 +6,7 @@ namespace Microsoft.Maui.Graphics
public class CanvasState : IDisposable
{
public float[] StrokeDashPattern { get; set; }
public float StrokeDashOffset { get; set; } = 1;
public float StrokeSize { get; set; } = 1;
private Matrix3x2 _transform = Matrix3x2.Identity;
@ -37,6 +38,7 @@ namespace Microsoft.Maui.Graphics
protected CanvasState(CanvasState prototype)
{
StrokeDashPattern = prototype.StrokeDashPattern;
StrokeDashOffset = prototype.StrokeDashOffset;
StrokeSize = prototype.StrokeSize;
this._transform = prototype._transform;

Просмотреть файл

@ -1,5 +1,4 @@
using System.Numerics;
using Microsoft.Maui.Graphics.Text;
namespace Microsoft.Maui.Graphics
@ -15,6 +14,7 @@ namespace Microsoft.Maui.Graphics
public LineCap StrokeLineCap { set; }
public LineJoin StrokeLineJoin { set; }
public float[] StrokeDashPattern { set; }
public float StrokeDashOffset { set; }
public Color FillColor { set; }
public Color FontColor { set; }
public IFont Font { set; }
@ -26,6 +26,7 @@ namespace Microsoft.Maui.Graphics
public void DrawPath(PathF path);
public void FillPath(PathF path, WindingMode windingMode);
public void SubtractFromClip(float x, float y, float width, float height);
public void ClipPath(PathF path, WindingMode windingMode = WindingMode.NonZero);

Просмотреть файл

@ -274,9 +274,9 @@ namespace Microsoft.Maui.Graphics.Platform
}
}
protected override void PlatformSetStrokeDashPattern(float[] pattern, float strokeSize)
protected override void PlatformSetStrokeDashPattern(float[] strokePattern, float strokeDashOffset, float strokeSize)
{
if (pattern == null)
if (strokePattern == null)
{
_context.SetLineDash(0, EmptyNFloatArray);
}
@ -293,10 +293,10 @@ namespace Microsoft.Maui.Graphics.Platform
actualStrokeSize = strokeLimit / scale;
}
var actualDashPattern = new nfloat[pattern.Length];
for (var i = 0; i < pattern.Length; i++)
var actualDashPattern = new nfloat[strokePattern.Length];
for (var i = 0; i < strokePattern.Length; i++)
{
actualDashPattern[i] = pattern[i] * actualStrokeSize;
actualDashPattern[i] = strokePattern[i] * actualStrokeSize;
}
_context.SetLineDash(0, actualDashPattern, actualDashPattern.Length);

Просмотреть файл

@ -71,6 +71,11 @@ namespace Microsoft.Maui.Graphics
set { _commands.Add(canvas => canvas.StrokeDashPattern = value); }
}
public float StrokeDashOffset
{
set { _commands.Add(canvas => canvas.StrokeDashOffset = value); }
}
public Color FillColor
{
set { _commands.Add(canvas => canvas.FillColor = value); }

Просмотреть файл

@ -72,6 +72,11 @@ namespace Microsoft.Maui.Graphics
set => _canvas.StrokeDashPattern = value;
}
public float StrokeDashOffset
{
set => _canvas.StrokeDashOffset = value;
}
public Color FillColor
{
set => _canvas.FillColor = value;