1
1
// Copyright (c) Files Community
2
2
// Licensed under the MIT License.
3
3
4
- using Microsoft . UI . Xaml ;
5
4
using Microsoft . UI . Xaml . Media ;
6
5
using Microsoft . UI . Xaml . Shapes ;
7
- using System ;
8
6
using Windows . Foundation ;
9
7
10
8
namespace Files . App . Controls . Primitives
@@ -18,18 +16,18 @@ public partial class RingShape : Path
18
16
19
17
// Fields
20
18
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
33
31
34
32
// Constants
35
33
@@ -168,41 +166,41 @@ public void UpdateSizeAndStroke(DependencyObject d)
168
166
{
169
167
RingShape ringShape = ( RingShape ) d ;
170
168
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 ) ;
173
171
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 ) ;
176
174
177
- _centerPoint = new Point ( ringShape . Width / 2 , ringShape . Height / 2 ) ;
175
+ _centerPoint = new Point ( ringShape . Width / 2 , ringShape . Height / 2 ) ;
178
176
ringShape . Center = _centerPoint ;
179
177
180
- CalculateAndSetNormalizedAngles ( ringShape , ringShape . MinAngle , ringShape . MaxAngle ) ;
178
+ CalculateAndSetNormalizedAngles ( ringShape , ringShape . MinAngle , ringShape . MaxAngle ) ;
181
179
182
- ValidateAngle ( ringShape , ringShape . StartAngle , true ) ;
183
- ValidateAngle ( ringShape , ringShape . EndAngle , false ) ;
180
+ ValidateAngle ( ringShape , ringShape . StartAngle , true ) ;
181
+ ValidateAngle ( ringShape , ringShape . EndAngle , false ) ;
184
182
}
185
183
186
184
private static EllipseGeometry DrawEllipse ( bool IsCircle , Point Center , double EqualRadius , double RadiusWidth , double RadiusHeight )
187
185
{
188
186
EllipseGeometry eg ;
189
187
190
- if ( IsCircle == true )
188
+ if ( IsCircle == true )
191
189
{
192
190
eg = new EllipseGeometry
193
191
{
194
- Center = Center ,
195
- RadiusX = EqualRadius ,
196
- RadiusY = EqualRadius ,
192
+ Center = Center ,
193
+ RadiusX = EqualRadius ,
194
+ RadiusY = EqualRadius ,
197
195
} ;
198
196
}
199
197
else
200
198
{
201
199
eg = new EllipseGeometry
202
200
{
203
- Center = Center ,
204
- RadiusX = RadiusWidth ,
205
- RadiusY = RadiusHeight ,
201
+ Center = Center ,
202
+ RadiusX = RadiusWidth ,
203
+ RadiusY = RadiusHeight ,
206
204
} ;
207
205
}
208
206
@@ -220,19 +218,19 @@ private static PathGeometry DrawArc(RingShape RingShape, SweepDirection SweepDir
220
218
221
219
var arcSegment = new ArcSegment ( ) ;
222
220
223
- if ( IsCircle == true )
221
+ if ( IsCircle == true )
224
222
{
225
223
var radius = EqualRadius ;
226
224
227
225
RingShape . ActualRadiusWidth = radius ;
228
226
RingShape . ActualRadiusHeight = radius ;
229
227
230
228
// Start Point
231
- pathFigure . StartPoint = ArcStartPoint ( SweepDirection , newCenter , StartAngle , radius , radius ) ;
229
+ pathFigure . StartPoint = ArcStartPoint ( SweepDirection , newCenter , StartAngle , radius , radius ) ;
232
230
233
231
234
232
// Arc Segment and End Point
235
- arcSegment = CreateArcSegment ( SweepDirection , newCenter , StartAngle , EndAngle , radius , radius ) ;
233
+ arcSegment = CreateArcSegment ( SweepDirection , newCenter , StartAngle , EndAngle , radius , radius ) ;
236
234
}
237
235
else
238
236
{
@@ -243,63 +241,63 @@ private static PathGeometry DrawArc(RingShape RingShape, SweepDirection SweepDir
243
241
RingShape . ActualRadiusHeight = radiusHeight ;
244
242
245
243
// Start Point
246
- pathFigure . StartPoint = ArcStartPoint ( SweepDirection , newCenter , StartAngle , radiusWidth , radiusHeight ) ;
244
+ pathFigure . StartPoint = ArcStartPoint ( SweepDirection , newCenter , StartAngle , radiusWidth , radiusHeight ) ;
247
245
248
246
249
247
// Arc Segment and End Point
250
- arcSegment = CreateArcSegment ( SweepDirection , newCenter , StartAngle , EndAngle , radiusWidth , radiusHeight ) ;
248
+ arcSegment = CreateArcSegment ( SweepDirection , newCenter , StartAngle , EndAngle , radiusWidth , radiusHeight ) ;
251
249
}
252
250
253
- pathFigure . Segments . Add ( arcSegment ) ;
254
- pathGeometry . Figures . Add ( pathFigure ) ;
251
+ pathFigure . Segments . Add ( arcSegment ) ;
252
+ pathGeometry . Figures . Add ( pathFigure ) ;
255
253
256
254
return pathGeometry ;
257
255
}
258
256
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 )
260
258
{
261
259
var finalPoint = new Point ( ) ;
262
260
263
261
// Counterclockwise
264
- if ( SweepDirection == SweepDirection . Counterclockwise )
262
+ if ( SweepDirection == SweepDirection . Counterclockwise )
265
263
{
266
264
finalPoint =
267
265
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 ) ;
270
268
}
271
269
// Clockwise
272
270
else
273
271
{
274
272
finalPoint =
275
273
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 ) ;
278
276
}
279
277
280
278
return finalPoint ;
281
279
}
282
280
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
+ {
285
283
var finalArcSegment = new ArcSegment ( ) ;
286
284
287
285
// Counterclockwise
288
- if ( SweepDirection == SweepDirection . Counterclockwise )
286
+ if ( SweepDirection == SweepDirection . Counterclockwise )
289
287
{
290
288
finalArcSegment . Point =
291
289
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 ) ;
294
292
295
- if ( EndAngle < StartAngle )
293
+ if ( EndAngle < StartAngle )
296
294
{
297
- finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) <= - 180.0 ;
295
+ finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) <= - 180.0 ;
298
296
finalArcSegment . SweepDirection = SweepDirection . Clockwise ;
299
297
}
300
298
else
301
299
{
302
- finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) >= 180.0 ;
300
+ finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) >= 180.0 ;
303
301
finalArcSegment . SweepDirection = SweepDirection . Counterclockwise ;
304
302
}
305
303
}
@@ -308,21 +306,21 @@ private static ArcSegment CreateArcSegment(SweepDirection SweepDirection , Point
308
306
{
309
307
finalArcSegment . Point =
310
308
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 ) ;
313
311
//ArcSegment.IsLargeArc = ( EndAngle - StartAngle ) >= 180.0;
314
- if ( EndAngle < StartAngle )
312
+ if ( EndAngle < StartAngle )
315
313
{
316
- finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) <= - 180.0 ;
314
+ finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) <= - 180.0 ;
317
315
finalArcSegment . SweepDirection = SweepDirection . Counterclockwise ;
318
316
}
319
317
else
320
318
{
321
- finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) >= 180.0 ;
319
+ finalArcSegment . IsLargeArc = ( EndAngle - StartAngle ) >= 180.0 ;
322
320
finalArcSegment . SweepDirection = SweepDirection . Clockwise ;
323
321
}
324
322
}
325
- finalArcSegment . Size = new Size ( RadiusWidth , RadiusHeight ) ;
323
+ finalArcSegment . Size = new Size ( RadiusWidth , RadiusHeight ) ;
326
324
327
325
return finalArcSegment ;
328
326
}
0 commit comments