committed by
GitHub
55 changed files with 807 additions and 399 deletions
@ -1,7 +1,7 @@ |
|||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<ItemGroup> |
<ItemGroup> |
||||
<PackageReference Include="HarfBuzzSharp" Version="2.8.2" /> |
<PackageReference Include="HarfBuzzSharp" Version="2.8.2.1-preview.108" /> |
||||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2" /> |
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2.1-preview.108" /> |
||||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.WebAssembly" Version="2.8.2" /> |
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="HarfBuzzSharp.NativeAssets.WebAssembly" Version="2.8.2.1-preview.108" /> |
||||
</ItemGroup> |
</ItemGroup> |
||||
</Project> |
</Project> |
||||
|
|||||
@ -1,7 +1,7 @@ |
|||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<ItemGroup> |
<ItemGroup> |
||||
<PackageReference Include="SkiaSharp" Version="2.88.1-preview.1" /> |
<PackageReference Include="SkiaSharp" Version="2.88.1-preview.108" /> |
||||
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="SkiaSharp.NativeAssets.Linux" Version="2.88.1-preview.1" /> |
<PackageReference Condition="'$(IncludeLinuxSkia)' == 'true'" Include="SkiaSharp.NativeAssets.Linux" Version="2.88.1-preview.108" /> |
||||
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.1-preview.1" /> |
<PackageReference Condition="'$(IncludeWasmSkia)' == 'true'" Include="SkiaSharp.NativeAssets.WebAssembly" Version="2.88.1-preview.108" /> |
||||
</ItemGroup> |
</ItemGroup> |
||||
</Project> |
</Project> |
||||
|
|||||
@ -0,0 +1,97 @@ |
|||||
|
using System; |
||||
|
using Avalonia.Media; |
||||
|
using Avalonia.Utilities; |
||||
|
|
||||
|
namespace Avalonia.Controls.Shapes |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Represents a circular or elliptical sector (a pie-shaped closed region of a circle or ellipse).
|
||||
|
/// </summary>
|
||||
|
public class Sector : Shape |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Defines the <see cref="StartAngle"/> property.
|
||||
|
/// </summary>
|
||||
|
public static readonly StyledProperty<double> StartAngleProperty = |
||||
|
AvaloniaProperty.Register<Sector, double>(nameof(StartAngle), 0.0d); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Defines the <see cref="SweepAngle"/> property.
|
||||
|
/// </summary>
|
||||
|
public static readonly StyledProperty<double> SweepAngleProperty = |
||||
|
AvaloniaProperty.Register<Sector, double>(nameof(SweepAngle), 0.0d); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the angle at which the sector's arc starts, in degrees.
|
||||
|
/// </summary>
|
||||
|
public double StartAngle |
||||
|
{ |
||||
|
get => GetValue(StartAngleProperty); |
||||
|
set => SetValue(StartAngleProperty, value); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the angle, in degrees, added to the <see cref="StartAngle"/> defining where the sector's arc ends.
|
||||
|
/// A positive value is clockwise, negative is counter-clockwise.
|
||||
|
/// </summary>
|
||||
|
public double SweepAngle |
||||
|
{ |
||||
|
get => GetValue(SweepAngleProperty); |
||||
|
set => SetValue(SweepAngleProperty, value); |
||||
|
} |
||||
|
|
||||
|
static Sector() |
||||
|
{ |
||||
|
StrokeThicknessProperty.OverrideDefaultValue<Sector>(1.0d); |
||||
|
AffectsGeometry<Sector>( |
||||
|
BoundsProperty, |
||||
|
StrokeThicknessProperty, |
||||
|
StartAngleProperty, |
||||
|
SweepAngleProperty); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
protected override Geometry? CreateDefiningGeometry() |
||||
|
{ |
||||
|
Rect rect = new Rect(Bounds.Size); |
||||
|
Rect deflatedRect = rect.Deflate(StrokeThickness * 0.5d); |
||||
|
|
||||
|
if (SweepAngle >= 360.0d || SweepAngle <= -360.0d) |
||||
|
{ |
||||
|
return new EllipseGeometry(deflatedRect); |
||||
|
} |
||||
|
|
||||
|
if (SweepAngle == 0.0d) |
||||
|
{ |
||||
|
return new StreamGeometry(); |
||||
|
} |
||||
|
|
||||
|
(double startAngle, double endAngle) = MathUtilities.GetMinMaxFromDelta( |
||||
|
MathUtilities.Deg2Rad(StartAngle), |
||||
|
MathUtilities.Deg2Rad(SweepAngle)); |
||||
|
|
||||
|
Point centre = new Point(rect.Width * 0.5d, rect.Height * 0.5d); |
||||
|
double radiusX = deflatedRect.Width * 0.5d; |
||||
|
double radiusY = deflatedRect.Height * 0.5d; |
||||
|
Point startCurvePoint = MathUtilities.GetEllipsePoint(centre, radiusX, radiusY, startAngle); |
||||
|
Point endCurvePoint = MathUtilities.GetEllipsePoint(centre, radiusX, radiusY, endAngle); |
||||
|
Size size = new Size(radiusX, radiusY); |
||||
|
|
||||
|
var streamGeometry = new StreamGeometry(); |
||||
|
using (StreamGeometryContext context = streamGeometry.Open()) |
||||
|
{ |
||||
|
context.BeginFigure(startCurvePoint, false); |
||||
|
context.ArcTo( |
||||
|
endCurvePoint, |
||||
|
size, |
||||
|
rotationAngle: 0.0d, |
||||
|
isLargeArc: Math.Abs(SweepAngle) > 180.0d, |
||||
|
SweepDirection.Clockwise); |
||||
|
context.LineTo(centre); |
||||
|
context.EndFigure(true); |
||||
|
} |
||||
|
|
||||
|
return streamGeometry; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1 +1 @@ |
|||||
Subproject commit a4e6be2d1407abec4f35fcb208848830ce513ead |
Subproject commit c1c0594ec2c35b08988183b1a5b3e34dfa19179d |
||||
Loading…
Reference in new issue