Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ public partial class RingShape : Path
[GeneratedDependencyProperty(DefaultValue = 0.0d)]
public partial double RadiusHeight { get; set; }

[GeneratedDependencyProperty]
[GeneratedDependencyProperty(DefaultValue = false)]
public partial bool IsCircle { get; set; }

[GeneratedDependencyProperty]
public partial Point Center { get; set; }

[GeneratedDependencyProperty]
[GeneratedDependencyProperty(DefaultValue = 0.0d)]
public partial double ActualRadiusWidth { get; set; }

[GeneratedDependencyProperty]
[GeneratedDependencyProperty(DefaultValue = 0.0d)]
public partial double ActualRadiusHeight { get; set; }

partial void OnStartAngleChanged(double newValue)
Expand Down
110 changes: 54 additions & 56 deletions src/Files.App.Controls/Storage/RingShape/RingShape.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Shapes;
using System;
using Windows.Foundation;

namespace Files.App.Controls.Primitives
Expand All @@ -18,18 +16,18 @@ public partial class RingShape : Path

// Fields

private bool _isUpdating; // Is True when path is updating
private bool _isCircle; // When True, Width and Height are equalized
private Size _equalSize; // Calculated where Width and Height are equal
private double _equalRadius; // Calculated where RadiusWidth and RadiusHeight are equal
private Point _centerPoint; // Center Point within Width and Height bounds
private double _normalizedMinAngle; // Normalized MinAngle between -180 and 540
private double _normalizedMaxAngle; // Normalized MaxAngle between 0 and 360
private double _validStartAngle; // The validated StartAngle
private double _validEndAngle; // The validated EndAngle
private double _radiusWidth; // The radius Width
private double _radiusHeight; // The radius Height
private SweepDirection _sweepDirection; // The SweepDirection
private bool _isUpdating; // Is True when path is updating
private bool _isCircle; // When True, Width and Height are equalized
private Size _equalSize; // Calculated where Width and Height are equal
private double _equalRadius; // Calculated where RadiusWidth and RadiusHeight are equal
private Point _centerPoint; // Center Point within Width and Height bounds
private double _normalizedMinAngle; // Normalized MinAngle between -180 and 540
private double _normalizedMaxAngle; // Normalized MaxAngle between 0 and 360
private double _validStartAngle; // The validated StartAngle
private double _validEndAngle; // The validated EndAngle
private double _radiusWidth; // The radius Width
private double _radiusHeight; // The radius Height
private SweepDirection _sweepDirection; // The SweepDirection

// Constants

Expand Down Expand Up @@ -168,41 +166,41 @@ public void UpdateSizeAndStroke(DependencyObject d)
{
RingShape ringShape = (RingShape)d;

AdjustRadiusWidth( ringShape , ringShape.RadiusWidth , ringShape.StrokeThickness );
AdjustRadiusHeight( ringShape , ringShape.RadiusHeight , ringShape.StrokeThickness );
AdjustRadiusWidth(ringShape, ringShape.RadiusWidth, ringShape.StrokeThickness);
AdjustRadiusHeight(ringShape, ringShape.RadiusHeight, ringShape.StrokeThickness);

_equalSize = CalculateEqualSize( new Size( ringShape.Width , ringShape.Height ) , ringShape.StrokeThickness );
_equalRadius = CalculateEqualRadius( ringShape , ringShape.RadiusWidth , ringShape.RadiusHeight , ringShape.StrokeThickness );
_equalSize = CalculateEqualSize(new Size(ringShape.Width, ringShape.Height), ringShape.StrokeThickness);
_equalRadius = CalculateEqualRadius(ringShape, ringShape.RadiusWidth, ringShape.RadiusHeight, ringShape.StrokeThickness);

_centerPoint = new Point( ringShape.Width / 2 , ringShape.Height / 2 );
_centerPoint = new Point(ringShape.Width / 2, ringShape.Height / 2);
ringShape.Center = _centerPoint;

CalculateAndSetNormalizedAngles( ringShape , ringShape.MinAngle , ringShape.MaxAngle );
CalculateAndSetNormalizedAngles(ringShape, ringShape.MinAngle, ringShape.MaxAngle);

ValidateAngle( ringShape , ringShape.StartAngle , true );
ValidateAngle( ringShape , ringShape.EndAngle , false );
ValidateAngle(ringShape, ringShape.StartAngle, true);
ValidateAngle(ringShape, ringShape.EndAngle, false);
}

private static EllipseGeometry DrawEllipse(bool IsCircle, Point Center, double EqualRadius, double RadiusWidth, double RadiusHeight)
{
EllipseGeometry eg;

if ( IsCircle == true )
if (IsCircle == true)
{
eg = new EllipseGeometry
{
Center = Center ,
RadiusX = EqualRadius ,
RadiusY = EqualRadius ,
Center = Center,
RadiusX = EqualRadius,
RadiusY = EqualRadius,
};
}
else
{
eg = new EllipseGeometry
{
Center = Center ,
RadiusX = RadiusWidth ,
RadiusY = RadiusHeight ,
Center = Center,
RadiusX = RadiusWidth,
RadiusY = RadiusHeight,
};
}

Expand All @@ -220,19 +218,19 @@ private static PathGeometry DrawArc(RingShape RingShape, SweepDirection SweepDir

var arcSegment = new ArcSegment();

if ( IsCircle == true )
if (IsCircle == true)
{
var radius = EqualRadius;

RingShape.ActualRadiusWidth = radius;
RingShape.ActualRadiusHeight = radius;

// Start Point
pathFigure.StartPoint = ArcStartPoint( SweepDirection , newCenter, StartAngle, radius, radius);
pathFigure.StartPoint = ArcStartPoint(SweepDirection, newCenter, StartAngle, radius, radius);


// Arc Segment and End Point
arcSegment = CreateArcSegment( SweepDirection , newCenter , StartAngle , EndAngle , radius , radius );
arcSegment = CreateArcSegment(SweepDirection, newCenter, StartAngle, EndAngle, radius, radius);
}
else
{
Expand All @@ -243,63 +241,63 @@ private static PathGeometry DrawArc(RingShape RingShape, SweepDirection SweepDir
RingShape.ActualRadiusHeight = radiusHeight;

// Start Point
pathFigure.StartPoint = ArcStartPoint( SweepDirection , newCenter , StartAngle , radiusWidth , radiusHeight );
pathFigure.StartPoint = ArcStartPoint(SweepDirection, newCenter, StartAngle, radiusWidth, radiusHeight);


// Arc Segment and End Point
arcSegment = CreateArcSegment( SweepDirection , newCenter , StartAngle , EndAngle , radiusWidth , radiusHeight );
arcSegment = CreateArcSegment(SweepDirection, newCenter, StartAngle, EndAngle, radiusWidth, radiusHeight);
}

pathFigure.Segments.Add( arcSegment );
pathGeometry.Figures.Add( pathFigure );
pathFigure.Segments.Add(arcSegment);
pathGeometry.Figures.Add(pathFigure);

return pathGeometry;
}

private static Point ArcStartPoint(SweepDirection SweepDirection , Point Center, double StartAngle , double RadiusWidth, double RadiusHeight)
private static Point ArcStartPoint(SweepDirection SweepDirection, Point Center, double StartAngle, double RadiusWidth, double RadiusHeight)
{
var finalPoint = new Point();

// Counterclockwise
if ( SweepDirection == SweepDirection.Counterclockwise )
if (SweepDirection == SweepDirection.Counterclockwise)
{
finalPoint =
new Point(
Center.X - Math.Sin( StartAngle * DegreesToRadians ) * RadiusWidth ,
Center.Y - Math.Cos( StartAngle * DegreesToRadians ) * RadiusHeight );
Center.X - Math.Sin(StartAngle * DegreesToRadians) * RadiusWidth,
Center.Y - Math.Cos(StartAngle * DegreesToRadians) * RadiusHeight);
}
// Clockwise
else
{
finalPoint =
new Point(
Center.X + Math.Sin( StartAngle * DegreesToRadians ) * RadiusWidth ,
Center.Y - Math.Cos( StartAngle * DegreesToRadians ) * RadiusHeight );
Center.X + Math.Sin(StartAngle * DegreesToRadians) * RadiusWidth,
Center.Y - Math.Cos(StartAngle * DegreesToRadians) * RadiusHeight);
}

return finalPoint;
}

private static ArcSegment CreateArcSegment(SweepDirection SweepDirection , Point Center , double StartAngle, double EndAngle , double RadiusWidth , double RadiusHeight)
{
private static ArcSegment CreateArcSegment(SweepDirection SweepDirection, Point Center, double StartAngle, double EndAngle, double RadiusWidth, double RadiusHeight)
{
var finalArcSegment = new ArcSegment();

// Counterclockwise
if ( SweepDirection == SweepDirection.Counterclockwise )
if (SweepDirection == SweepDirection.Counterclockwise)
{
finalArcSegment.Point =
new Point(
Center.X - Math.Sin( EndAngle * DegreesToRadians ) * RadiusWidth ,
Center.Y - Math.Cos( EndAngle * DegreesToRadians ) * RadiusHeight );
Center.X - Math.Sin(EndAngle * DegreesToRadians) * RadiusWidth,
Center.Y - Math.Cos(EndAngle * DegreesToRadians) * RadiusHeight);

if ( EndAngle < StartAngle )
if (EndAngle < StartAngle)
{
finalArcSegment.IsLargeArc = ( EndAngle - StartAngle ) <= -180.0;
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) <= -180.0;
finalArcSegment.SweepDirection = SweepDirection.Clockwise;
}
else
{
finalArcSegment.IsLargeArc = ( EndAngle - StartAngle ) >= 180.0;
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
finalArcSegment.SweepDirection = SweepDirection.Counterclockwise;
}
}
Expand All @@ -308,21 +306,21 @@ private static ArcSegment CreateArcSegment(SweepDirection SweepDirection , Point
{
finalArcSegment.Point =
new Point(
Center.X + Math.Sin( EndAngle * DegreesToRadians ) * RadiusWidth ,
Center.Y - Math.Cos( EndAngle * DegreesToRadians ) * RadiusHeight );
Center.X + Math.Sin(EndAngle * DegreesToRadians) * RadiusWidth,
Center.Y - Math.Cos(EndAngle * DegreesToRadians) * RadiusHeight);
//ArcSegment.IsLargeArc = ( EndAngle - StartAngle ) >= 180.0;
if ( EndAngle < StartAngle )
if (EndAngle < StartAngle)
{
finalArcSegment.IsLargeArc = ( EndAngle - StartAngle ) <= -180.0;
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) <= -180.0;
finalArcSegment.SweepDirection = SweepDirection.Counterclockwise;
}
else
{
finalArcSegment.IsLargeArc = ( EndAngle - StartAngle ) >= 180.0;
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
finalArcSegment.SweepDirection = SweepDirection.Clockwise;
}
}
finalArcSegment.Size = new Size( RadiusWidth , RadiusHeight );
finalArcSegment.Size = new Size(RadiusWidth, RadiusHeight);

return finalArcSegment;
}
Expand Down
40 changes: 0 additions & 40 deletions src/Files.App.Controls/Storage/StorageBar/StorageBar.Constants.cs

This file was deleted.

28 changes: 13 additions & 15 deletions src/Files.App.Controls/Storage/StorageBar/StorageBar.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
// Licensed under the MIT License.

using CommunityToolkit.WinUI;
using Microsoft.UI.Xaml;

namespace Files.App.Controls
{
public partial class StorageBar
{
[GeneratedDependencyProperty(DefaultValue = 4.0d)]
[GeneratedDependencyProperty(DefaultValue = 6.0d)]
public partial double ValueBarHeight { get; set; }

[GeneratedDependencyProperty(DefaultValue = 2.0d)]
[GeneratedDependencyProperty(DefaultValue = 3.0d)]
public partial double TrackBarHeight { get; set; }

[GeneratedDependencyProperty(DefaultValue = BarShapes.Round)]
Expand All @@ -28,57 +27,56 @@ public partial class StorageBar

partial void OnValueBarHeightChanged(double newValue)
{
UpdateControl(this);
UpdateControl();
}

partial void OnTrackBarHeightChanged(double newValue)
{
UpdateControl(this);
UpdateControl();
}

partial void OnBarShapeChanged(BarShapes newValue)
{
UpdateControl(this);
UpdateControl();
}

partial void OnPercentChanged(double newValue)
{
return; //Read-only

DoubleToPercentage(Value, Minimum, Maximum);
UpdateControl(this);
}

partial void OnPercentCautionChanged(double newValue)
{
UpdateControl(this);
UpdateControl();
}

partial void OnPercentCriticalChanged(double newValue)
{
UpdateControl(this);
UpdateControl();
}

/// <inheritdoc/>
protected override void OnValueChanged(double oldValue, double newValue)
{
_oldValue = oldValue;
base.OnValueChanged(oldValue, newValue);
UpdateValue(this, Value, _oldValue, false, -1.0);

UpdateValue(Value, _oldValue, false, -1.0);
}

/// <inheritdoc/>
protected override void OnMaximumChanged(double oldValue, double newValue)
{
base.OnMaximumChanged(oldValue, newValue);
UpdateValue(this, oldValue, newValue, false, -1.0);

UpdateValue(oldValue, newValue, false, -1.0);
}

/// <inheritdoc/>
protected override void OnMinimumChanged(double oldValue, double newValue)
{
base.OnMinimumChanged(oldValue, newValue);
UpdateValue(this, oldValue, newValue, false, -1.0);

UpdateValue(oldValue, newValue, false, -1.0);
}
}
}
Loading
Loading