@@ -185,38 +185,28 @@ public override void Draw(Vector2 pos, Vector2? parentSize = null, bool parentVi
185
185
style . Position = localPos - pos ;
186
186
}
187
187
}
188
-
189
- // controls how smooth the arc looks
188
+
190
189
const int segments = 100 ;
191
190
float startAngle = ( float ) ( - Math . PI / 2f + style . StartAngle * ( Math . PI / 180f ) ) ;
192
191
float endAngle = ( float ) ( - Math . PI / 2f + style . EndAngle * ( Math . PI / 180f ) ) ;
193
192
194
- List < CircleData > circles ;
195
- circles = new List < CircleData > ( ) { CalculateCircle ( startAngle , endAngle , progressValue , progressMaxValue , style . Direction ) } ;
193
+ CircleData circle = CalculateCircle ( startAngle , endAngle , progressValue , progressMaxValue , style . Direction ) ;
196
194
197
- foreach ( CircleData circle in circles )
198
- {
199
- // fill
200
- ConfigColor fillColor = circle . FillColor ?? style . FillColor ;
195
+ ConfigColor fillColor = circle . FillColor ?? style . FillColor ;
201
196
202
- // Draw background arc first
203
- if ( circle . EndAngle != startAngle )
204
- {
205
- drawList . PathArcTo ( localPos , style . Radius , circle . StartAngle , endAngle , segments ) ;
206
- drawList . PathStroke ( ImGui . ColorConvertFloat4ToU32 ( style . BackgroundColor . Vector ) , ImDrawFlags . None , style . Thickness ) ;
207
- }
197
+ // Draw the background arc
198
+ drawList . PathArcTo ( localPos , style . Radius , startAngle , endAngle , segments ) ;
199
+ drawList . PathStroke ( ImGui . ColorConvertFloat4ToU32 ( style . BackgroundColor . Vector ) , ImDrawFlags . None , style . Thickness ) ;
208
200
209
- // Draw fill arc on top
210
- drawList . PathArcTo ( localPos , style . Radius , circle . StartAngle , circle . EndAngle , segments ) ;
211
- drawList . PathStroke ( ImGui . ColorConvertFloat4ToU32 ( fillColor . Vector ) , ImDrawFlags . None , style . Thickness ) ;
212
-
213
-
214
- if ( style . Glow )
215
- {
216
- DrawHelpers . DrawGlowCircle ( localPos , style . Radius , style . Thickness , style . GlowPadding , style . GlowSegments , style . GlowSpeed , style . GlowColor , style . GlowColor2 , drawList ) ;
217
- }
218
-
201
+ // Draw the filled arc
202
+ drawList . PathArcTo ( localPos , style . Radius , circle . StartAngle , circle . EndAngle , segments ) ;
203
+ drawList . PathStroke ( ImGui . ColorConvertFloat4ToU32 ( fillColor . Vector ) , ImDrawFlags . None , style . Thickness ) ;
204
+
205
+ if ( style . Glow )
206
+ {
207
+ DrawHelpers . DrawGlowCircle ( localPos , style . Radius , style . Thickness , style . GlowPadding , style . GlowSegments , style . GlowSpeed , style . GlowColor , style . GlowColor2 , drawList ) ;
219
208
}
209
+
220
210
if ( style . ShowBorder )
221
211
{
222
212
drawList . PathArcTo ( localPos , style . Radius - style . Thickness / 2f , startAngle , endAngle , segments ) ;
@@ -245,6 +235,7 @@ public override void Draw(Vector2 pos, Vector2? parentSize = null, bool parentVi
245
235
}
246
236
}
247
237
}
238
+
248
239
249
240
private CircleData CalculateCircle ( float startAngle , float endAngle , float progress , float max , CircleDirection direction )
250
241
{
@@ -253,28 +244,19 @@ private CircleData CalculateCircle(float startAngle, float endAngle, float progr
253
244
float fillPercent = max == 0 ? 1f : Math . Clamp ( progress / max , 0f , 1f ) ;
254
245
float angleRange = endAngle - startAngle ;
255
246
256
- if ( direction == CircleDirection . AntiClockwise )
257
- {
258
- // If anticlockwise, the angle range needs to be reversed
259
- angleRange = startAngle - endAngle ;
260
- }
261
-
262
247
float fillAngle = angleRange * fillPercent ;
263
248
264
- // Adjusting for direction
265
- float relativeAngle ;
266
249
if ( direction == CircleDirection . Clockwise )
267
250
{
268
- relativeAngle = startAngle + fillAngle ;
251
+ circle . StartAngle = startAngle ;
252
+ circle . EndAngle = startAngle + fillAngle ;
269
253
}
270
- else // Anticlockwise
254
+ else
271
255
{
272
- relativeAngle = startAngle - fillAngle ;
256
+ circle . StartAngle = - ( startAngle + ( float ) Math . PI ) ;
257
+ circle . EndAngle = - ( startAngle + ( float ) Math . PI ) ;
273
258
}
274
259
275
- circle . StartAngle = startAngle ;
276
- circle . EndAngle = relativeAngle ;
277
-
278
260
return circle ;
279
261
}
280
262
@@ -323,7 +305,6 @@ internal struct CircleData
323
305
{
324
306
public float StartAngle ;
325
307
public float EndAngle ;
326
- public Vector2 FillSize ;
327
308
328
309
public ConfigColor ? FillColor ;
329
310
}
0 commit comments