11// Copyright (c) Files Community
22// Licensed under the MIT License.
33
4- using Microsoft . UI . Xaml ;
54using Microsoft . UI . Xaml . Media ;
65using Microsoft . UI . Xaml . Shapes ;
7- using System ;
86using Windows . Foundation ;
97
108namespace Files . App . Controls . Primitives
@@ -18,18 +16,18 @@ public partial class RingShape : Path
1816
1917 // Fields
2018
21- private bool _isUpdating ; // Is True when path is updating
22- private bool _isCircle ; // When True, Width and Height are equalized
23- private Size _equalSize ; // Calculated where Width and Height are equal
24- private double _equalRadius ; // Calculated where RadiusWidth and RadiusHeight are equal
25- private Point _centerPoint ; // Center Point within Width and Height bounds
26- private double _normalizedMinAngle ; // Normalized MinAngle between -180 and 540
27- private double _normalizedMaxAngle ; // Normalized MaxAngle between 0 and 360
28- private double _validStartAngle ; // The validated StartAngle
29- private double _validEndAngle ; // The validated EndAngle
30- private double _radiusWidth ; // The radius Width
31- private double _radiusHeight ; // The radius Height
32- private SweepDirection _sweepDirection ; // The SweepDirection
19+ private bool _isUpdating ; // Is True when path is updating
20+ private bool _isCircle ; // When True, Width and Height are equalized
21+ private Size _equalSize ; // Calculated where Width and Height are equal
22+ private double _equalRadius ; // Calculated where RadiusWidth and RadiusHeight are equal
23+ private Point _centerPoint ; // Center Point within Width and Height bounds
24+ private double _normalizedMinAngle ; // Normalized MinAngle between -180 and 540
25+ private double _normalizedMaxAngle ; // Normalized MaxAngle between 0 and 360
26+ private double _validStartAngle ; // The validated StartAngle
27+ private double _validEndAngle ; // The validated EndAngle
28+ private double _radiusWidth ; // The radius Width
29+ private double _radiusHeight ; // The radius Height
30+ private SweepDirection _sweepDirection ; // The SweepDirection
3331
3432 // Constants
3533
@@ -168,41 +166,41 @@ public void UpdateSizeAndStroke(DependencyObject d)
168166 {
169167 RingShape ringShape = ( RingShape ) d ;
170168
171- AdjustRadiusWidth ( ringShape , ringShape . RadiusWidth , ringShape . StrokeThickness ) ;
172- AdjustRadiusHeight ( ringShape , ringShape . RadiusHeight , ringShape . StrokeThickness ) ;
169+ AdjustRadiusWidth ( ringShape , ringShape . RadiusWidth , ringShape . StrokeThickness ) ;
170+ AdjustRadiusHeight ( ringShape , ringShape . RadiusHeight , ringShape . StrokeThickness ) ;
173171
174- _equalSize = CalculateEqualSize ( new Size ( ringShape . Width , ringShape . Height ) , ringShape . StrokeThickness ) ;
175- _equalRadius = CalculateEqualRadius ( ringShape , ringShape . RadiusWidth , ringShape . RadiusHeight , ringShape . StrokeThickness ) ;
172+ _equalSize = CalculateEqualSize ( new Size ( ringShape . Width , ringShape . Height ) , ringShape . StrokeThickness ) ;
173+ _equalRadius = CalculateEqualRadius ( ringShape , ringShape . RadiusWidth , ringShape . RadiusHeight , ringShape . StrokeThickness ) ;
176174
177- _centerPoint = new Point ( ringShape . Width / 2 , ringShape . Height / 2 ) ;
175+ _centerPoint = new Point ( ringShape . Width / 2 , ringShape . Height / 2 ) ;
178176 ringShape . Center = _centerPoint ;
179177
180- CalculateAndSetNormalizedAngles ( ringShape , ringShape . MinAngle , ringShape . MaxAngle ) ;
178+ CalculateAndSetNormalizedAngles ( ringShape , ringShape . MinAngle , ringShape . MaxAngle ) ;
181179
182- ValidateAngle ( ringShape , ringShape . StartAngle , true ) ;
183- ValidateAngle ( ringShape , ringShape . EndAngle , false ) ;
180+ ValidateAngle ( ringShape , ringShape . StartAngle , true ) ;
181+ ValidateAngle ( ringShape , ringShape . EndAngle , false ) ;
184182 }
185183
186184 private static EllipseGeometry DrawEllipse ( bool IsCircle , Point Center , double EqualRadius , double RadiusWidth , double RadiusHeight )
187185 {
188186 EllipseGeometry eg ;
189187
190- if ( IsCircle == true )
188+ if ( IsCircle == true )
191189 {
192190 eg = new EllipseGeometry
193191 {
194- Center = Center ,
195- RadiusX = EqualRadius ,
196- RadiusY = EqualRadius ,
192+ Center = Center ,
193+ RadiusX = EqualRadius ,
194+ RadiusY = EqualRadius ,
197195 } ;
198196 }
199197 else
200198 {
201199 eg = new EllipseGeometry
202200 {
203- Center = Center ,
204- RadiusX = RadiusWidth ,
205- RadiusY = RadiusHeight ,
201+ Center = Center ,
202+ RadiusX = RadiusWidth ,
203+ RadiusY = RadiusHeight ,
206204 } ;
207205 }
208206
@@ -220,19 +218,19 @@ private static PathGeometry DrawArc(RingShape RingShape, SweepDirection SweepDir
220218
221219 var arcSegment = new ArcSegment ( ) ;
222220
223- if ( IsCircle == true )
221+ if ( IsCircle == true )
224222 {
225223 var radius = EqualRadius ;
226224
227225 RingShape . ActualRadiusWidth = radius ;
228226 RingShape . ActualRadiusHeight = radius ;
229227
230228 // Start Point
231- pathFigure . StartPoint = ArcStartPoint ( SweepDirection , newCenter , StartAngle , radius , radius ) ;
229+ pathFigure . StartPoint = ArcStartPoint ( SweepDirection , newCenter , StartAngle , radius , radius ) ;
232230
233231
234232 // Arc Segment and End Point
235- arcSegment = CreateArcSegment ( SweepDirection , newCenter , StartAngle , EndAngle , radius , radius ) ;
233+ arcSegment = CreateArcSegment ( SweepDirection , newCenter , StartAngle , EndAngle , radius , radius ) ;
236234 }
237235 else
238236 {
@@ -243,63 +241,63 @@ private static PathGeometry DrawArc(RingShape RingShape, SweepDirection SweepDir
243241 RingShape . ActualRadiusHeight = radiusHeight ;
244242
245243 // Start Point
246- pathFigure . StartPoint = ArcStartPoint ( SweepDirection , newCenter , StartAngle , radiusWidth , radiusHeight ) ;
244+ pathFigure . StartPoint = ArcStartPoint ( SweepDirection , newCenter , StartAngle , radiusWidth , radiusHeight ) ;
247245
248246
249247 // Arc Segment and End Point
250- arcSegment = CreateArcSegment ( SweepDirection , newCenter , StartAngle , EndAngle , radiusWidth , radiusHeight ) ;
248+ arcSegment = CreateArcSegment ( SweepDirection , newCenter , StartAngle , EndAngle , radiusWidth , radiusHeight ) ;
251249 }
252250
253- pathFigure . Segments . Add ( arcSegment ) ;
254- pathGeometry . Figures . Add ( pathFigure ) ;
251+ pathFigure . Segments . Add ( arcSegment ) ;
252+ pathGeometry . Figures . Add ( pathFigure ) ;
255253
256254 return pathGeometry ;
257255 }
258256
259- private static Point ArcStartPoint ( SweepDirection SweepDirection , Point Center , double StartAngle , double RadiusWidth , double RadiusHeight )
257+ private static Point ArcStartPoint ( SweepDirection SweepDirection , Point Center , double StartAngle , double RadiusWidth , double RadiusHeight )
260258 {
261259 var finalPoint = new Point ( ) ;
262260
263261 // Counterclockwise
264- if ( SweepDirection == SweepDirection . Counterclockwise )
262+ if ( SweepDirection == SweepDirection . Counterclockwise )
265263 {
266264 finalPoint =
267265 new Point (
268- Center . X - Math . Sin ( StartAngle * DegreesToRadians ) * RadiusWidth ,
269- Center . Y - Math . Cos ( StartAngle * DegreesToRadians ) * RadiusHeight ) ;
266+ Center . X - Math . Sin ( StartAngle * DegreesToRadians ) * RadiusWidth ,
267+ Center . Y - Math . Cos ( StartAngle * DegreesToRadians ) * RadiusHeight ) ;
270268 }
271269 // Clockwise
272270 else
273271 {
274272 finalPoint =
275273 new Point (
276- Center . X + Math . Sin ( StartAngle * DegreesToRadians ) * RadiusWidth ,
277- Center . Y - Math . Cos ( StartAngle * DegreesToRadians ) * RadiusHeight ) ;
274+ Center . X + Math . Sin ( StartAngle * DegreesToRadians ) * RadiusWidth ,
275+ Center . Y - Math . Cos ( StartAngle * DegreesToRadians ) * RadiusHeight ) ;
278276 }
279277
280278 return finalPoint ;
281279 }
282280
283- private static ArcSegment CreateArcSegment ( SweepDirection SweepDirection , Point Center , double StartAngle , double EndAngle , double RadiusWidth , double RadiusHeight )
284- {
281+ private static ArcSegment CreateArcSegment ( SweepDirection SweepDirection , Point Center , double StartAngle , double EndAngle , double RadiusWidth , double RadiusHeight )
282+ {
285283 var finalArcSegment = new ArcSegment ( ) ;
286284
287285 // Counterclockwise
288- if ( SweepDirection == SweepDirection . Counterclockwise )
286+ if ( SweepDirection == SweepDirection . Counterclockwise )
289287 {
290288 finalArcSegment . Point =
291289 new Point (
292- Center . X - Math . Sin ( EndAngle * DegreesToRadians ) * RadiusWidth ,
293- Center . Y - Math . Cos ( EndAngle * DegreesToRadians ) * RadiusHeight ) ;
290+ Center . X - Math . Sin ( EndAngle * DegreesToRadians ) * RadiusWidth ,
291+ Center . Y - Math . Cos ( EndAngle * DegreesToRadians ) * RadiusHeight ) ;
294292
295- if ( EndAngle < StartAngle )
293+ if ( EndAngle < StartAngle )
296294 {
297- finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) <= - 180.0 ;
295+ finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) <= - 180.0 ;
298296 finalArcSegment . SweepDirection = SweepDirection . Clockwise ;
299297 }
300298 else
301299 {
302- finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) >= 180.0 ;
300+ finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) >= 180.0 ;
303301 finalArcSegment . SweepDirection = SweepDirection . Counterclockwise ;
304302 }
305303 }
@@ -308,21 +306,21 @@ private static ArcSegment CreateArcSegment(SweepDirection SweepDirection , Point
308306 {
309307 finalArcSegment . Point =
310308 new Point (
311- Center . X + Math . Sin ( EndAngle * DegreesToRadians ) * RadiusWidth ,
312- Center . Y - Math . Cos ( EndAngle * DegreesToRadians ) * RadiusHeight ) ;
309+ Center . X + Math . Sin ( EndAngle * DegreesToRadians ) * RadiusWidth ,
310+ Center . Y - Math . Cos ( EndAngle * DegreesToRadians ) * RadiusHeight ) ;
313311 //ArcSegment.IsLargeArc = ( EndAngle - StartAngle ) >= 180.0;
314- if ( EndAngle < StartAngle )
312+ if ( EndAngle < StartAngle )
315313 {
316- finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) <= - 180.0 ;
314+ finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) <= - 180.0 ;
317315 finalArcSegment . SweepDirection = SweepDirection . Counterclockwise ;
318316 }
319317 else
320318 {
321- finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) >= 180.0 ;
319+ finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) >= 180.0 ;
322320 finalArcSegment . SweepDirection = SweepDirection . Clockwise ;
323321 }
324322 }
325- finalArcSegment . Size = new Size ( RadiusWidth , RadiusHeight ) ;
323+ finalArcSegment . Size = new Size ( RadiusWidth , RadiusHeight ) ;
326324
327325 return finalArcSegment ;
328326 }
0 commit comments