Skip to content

Commit 30fbb02

Browse files
committed
Implement basic glow, change circle drawing
1 parent 8cb053e commit 30fbb02

File tree

3 files changed

+80
-77
lines changed

3 files changed

+80
-77
lines changed

DelvCD/Config/Styles/CircleStyleConfig.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Numerics;
1010
using System.Runtime.CompilerServices;
11+
using Dalamud.Interface.Utility;
1112

1213
namespace DelvCD.Config
1314
{
@@ -34,23 +35,26 @@ public class CircleStyleConfig : IConfigPage
3435
public int Thickness = 10;
3536
public int StartAngle = 0;
3637
public int EndAngle = 360;
37-
public CircleDirection Direction = CircleDirection.Clockwise;
38+
public CircleDirection Direction = CircleDirection.AntiClockwise;
3839
public ConfigColor FillColor = new ConfigColor(1, 0.5f, 0.5f, 1);
3940
public ConfigColor BackgroundColor = new ConfigColor(0, 0, 0, 0.5f);
4041

4142
public bool ShowBorder = true;
4243
public int BorderThickness = 1;
4344
public ConfigColor BorderColor = new ConfigColor(0, 0, 0, 1);
4445

46+
/*
4547
public bool Chunked = false;
4648
public bool ChunkedStacksFromTrigger = true;
4749
public int ChunkCount = 5;
4850
public int ChunkPadding = 2;
4951
public ConfigColor IncompleteChunkColor = new ConfigColor(0.6f, 0.6f, 0.6f, 1);
52+
*/
5053

5154
public bool Glow = false;
5255
public int GlowThickness = 2;
53-
public int GlowSegments = 8;
56+
public int GlowSegments = 20;
57+
public int GlowPadding = 5;
5458
public float GlowSpeed = 1f;
5559
public ConfigColor GlowColor = new ConfigColor(230f / 255f, 150f / 255f, 0f / 255f, 1f);
5660
public ConfigColor GlowColor2 = new ConfigColor(0f / 255f, 0f / 255f, 0f / 255f, 0f);
@@ -151,6 +155,7 @@ public void DrawConfig(IConfigurable parent, Vector2 size, float padX, float pad
151155
}
152156
}
153157

158+
/*
154159
// chunked
155160
ImGui.NewLine();
156161
ImGui.Checkbox("Draw in Chunks", ref Chunked);
@@ -189,6 +194,7 @@ public void DrawConfig(IConfigurable parent, Vector2 size, float padX, float pad
189194
IncompleteChunkColor.Vector = vector;
190195
}
191196
}
197+
*/
192198

193199
// glow
194200
ImGui.NewLine();
@@ -199,7 +205,10 @@ public void DrawConfig(IConfigurable parent, Vector2 size, float padX, float pad
199205
ImGui.DragInt("Thickness##Glow", ref GlowThickness, 1, 1, 16);
200206

201207
DrawHelpers.DrawNestIndicator(1);
202-
ImGui.DragInt("Glow Segments##Glow", ref GlowSegments, 1, 2, 16);
208+
ImGui.DragInt("Glow Segments##Glow", ref GlowSegments, 1, 2, 40);
209+
210+
DrawHelpers.DrawNestIndicator(1);
211+
ImGui.DragInt("Glow Padding##Glow", ref GlowPadding, 1, 2, 200);
203212

204213
DrawHelpers.DrawNestIndicator(1);
205214
ImGui.DragFloat("Animation Speed##Glow", ref GlowSpeed, 0.05f, 0, 2f);

DelvCD/Helpers/DrawHelpers.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,41 @@ public static void DrawGlow(Vector2 pos, Vector2 size, int thickness, int segmen
299299
DrawSegmentedLineHorizontal(drawList, c3.AddY(-thickness), -size.X, thickness, prog, segments, col1, col2);
300300
DrawSegmentedLineVertical(drawList, c4, thickness, -size.Y, prog, segments, col1, col2);
301301
}
302+
303+
public static void DrawGlowCircle(Vector2 center, float radius, float thickness, float padding, int segments, float speed, ConfigColor col1, ConfigColor col2, ImDrawListPtr drawList)
304+
{
305+
speed = Math.Abs(speed);
306+
int mod = speed == 0 ? 1 : (int)(250 / speed);
307+
float prog = (float)(DateTimeOffset.Now.ToUnixTimeMilliseconds() % mod) / mod;
308+
309+
float angleStep = (float)(Math.PI * 2 / segments);
310+
float startAngle = -MathF.PI / 2f;
311+
312+
for (int i = 0; i < segments; i++)
313+
{
314+
float currentAngle = startAngle + i * angleStep;
315+
float nextAngle = currentAngle + angleStep;
316+
317+
// Calculate the color gradient
318+
float t = ((float)i / segments + prog) % 1;
319+
Vector4 color = new Vector4(
320+
col1.Vector.X * (1 - t) + col2.Vector.X * t,
321+
col1.Vector.Y * (1 - t) + col2.Vector.Y * t,
322+
col1.Vector.Z * (1 - t) + col2.Vector.Z * t,
323+
col1.Vector.W * (1 - t) + col2.Vector.W * t
324+
);
325+
326+
uint colorUint = ImGui.ColorConvertFloat4ToU32(color);
327+
328+
// Draw the glowing segment around the outer edge with padding
329+
drawList.PathArcTo(center, radius + thickness / 2 + padding, currentAngle, nextAngle, 2);
330+
drawList.PathStroke(colorUint, ImDrawFlags.None, thickness / 2);
331+
332+
// Draw the glowing segment around the inner edge with padding
333+
drawList.PathArcTo(center, radius - thickness / 2 - padding, currentAngle, nextAngle, 2);
334+
drawList.PathStroke(colorUint, ImDrawFlags.None, thickness / 2);
335+
}
336+
}
302337

303338
public static void DrawGlowNGon(Vector2 center, float radius, int thickness, int sides, int segments, float speed, ConfigColor col1, ConfigColor col2, ImDrawListPtr drawList)
304339
{

DelvCD/UIElements/Circle.cs

Lines changed: 33 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Text.Json.Serialization;
1010
using System.Threading;
1111
using Dalamud.Logging;
12+
using Dalamud.Plugin.Services;
1213

1314
namespace DelvCD.UIElements
1415
{
@@ -189,46 +190,32 @@ public override void Draw(Vector2 pos, Vector2? parentSize = null, bool parentVi
189190
const int segments = 100;
190191
float startAngle = (float)(-Math.PI / 2f + style.StartAngle * (Math.PI / 180f));
191192
float endAngle = (float)(-Math.PI / 2f + style.EndAngle * (Math.PI / 180f));
192-
193-
if (style.Direction == CircleDirection.AntiClockwise)
194-
{
195-
startAngle *= -1;
196-
endAngle *= -1;
197-
}
198-
199193

200194
List<CircleData> circles;
201-
if (!style.Chunked)
202-
{
203-
circles = new List<CircleData>() { CalculateCircle(startAngle, endAngle, progressValue, progressMaxValue, style.Direction) };
204-
}
205-
else
206-
{
207-
int chunkCount = style.ChunkedStacksFromTrigger ? (int)progressMaxValue : style.ChunkCount;
208-
circles = CalculateChunkedCircles(startAngle, endAngle, progressValue, progressMaxValue, chunkCount, style.ChunkPadding, style.Direction, style.IncompleteChunkColor);
209-
}
195+
circles = new List<CircleData>() { CalculateCircle(startAngle, endAngle, progressValue, progressMaxValue, style.Direction) };
210196

211197
foreach (CircleData circle in circles)
212198
{
213-
214-
//PluginLog.Information($"{startAngle}|{endAngle}|{circle.StartAngle}|{circle.EndAngle}");
215-
216199
// fill
217200
ConfigColor fillColor = circle.FillColor ?? style.FillColor;
218-
201+
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+
}
208+
209+
// Draw fill arc on top
219210
drawList.PathArcTo(localPos, style.Radius, circle.StartAngle, circle.EndAngle, segments);
220211
drawList.PathStroke(ImGui.ColorConvertFloat4ToU32(fillColor.Vector), ImDrawFlags.None, style.Thickness);
221212

222-
// anything that remains is background
223-
drawList.PathArcTo(localPos, style.Radius, circle.EndAngle, endAngle, segments);
224-
drawList.PathStroke(ImGui.ColorConvertFloat4ToU32(style.BackgroundColor.Vector), ImDrawFlags.None, style.Thickness);
225213

226-
/*
227214
if (style.Glow)
228215
{
229-
DrawHelpers.DrawGlow(localPos, size, style.GlowThickness, style.GlowSegments, style.GlowSpeed, style.GlowColor, style.GlowColor2, drawList);
216+
DrawHelpers.DrawGlowCircle(localPos, style.Radius, style.Thickness, style.GlowPadding, style.GlowSegments, style.GlowSpeed, style.GlowColor, style.GlowColor2, drawList);
230217
}
231-
*/
218+
232219
}
233220
if (style.ShowBorder)
234221
{
@@ -258,65 +245,37 @@ public override void Draw(Vector2 pos, Vector2? parentSize = null, bool parentVi
258245
}
259246
}
260247
}
261-
248+
262249
private CircleData CalculateCircle(float startAngle, float endAngle, float progress, float max, CircleDirection direction)
263250
{
264251
CircleData circle = new();
265-
/*
252+
266253
float fillPercent = max == 0 ? 1f : Math.Clamp(progress / max, 0f, 1f);
267-
float fillAngle = max == 0 ? endAngle : Math.Clamp(progress / max, startAngle, endAngle);
268-
*/
269-
float current = progress / max;
270254
float angleRange = endAngle - startAngle;
271-
float relativeAngle = startAngle + (angleRange * current);
272-
273-
circle.StartAngle = startAngle;
274-
circle.EndAngle = relativeAngle;
275-
276-
return circle;
277-
}
278-
279-
private List<CircleData> CalculateChunkedCircles(float startAngle, float endAngle, float progress, float max, int count, int padding, CircleDirection direction, ConfigColor incompleteColor)
280-
{
281-
282-
return new List<CircleData>() { CalculateCircle(startAngle, endAngle, progress, 1, direction) };
283-
284-
/*
285255

286-
int paddingCount = count - 1;
287-
int chunkLength = horizontal ?
288-
(int)((size.X - (paddingCount * padding)) / count) :
289-
(int)((size.Y - (paddingCount * padding)) / count);
290-
291-
Vector2 chunkSize = horizontal ?
292-
new(chunkLength, size.Y) :
293-
new(size.X, chunkLength);
294-
295-
float chunkProgressSize = max / count;
296-
297-
Vector2 pos = Vector2.Zero;
298-
List<CircleData> bars = new(count);
299-
300-
for (int i = 0; i < count; i++)
256+
if (direction == CircleDirection.AntiClockwise)
301257
{
302-
int index = reversed ? count - i - 1 : i;
303-
float chunkProgress = Math.Min(progress - (chunkProgressSize * index), chunkProgressSize);
304-
CircleData bar = CalculateCircle(pos, chunkSize, chunkProgress, chunkProgressSize, direction);
305-
306-
pos = horizontal ?
307-
new Vector2(pos.X + padding + chunkLength, pos.Y) :
308-
new Vector2(pos.X, pos.Y + padding + chunkLength);
258+
// If anticlockwise, the angle range needs to be reversed
259+
angleRange = startAngle - endAngle;
260+
}
309261

310-
if (chunkProgress < chunkProgressSize)
311-
{
312-
circle.FillColor = incompleteColor;
313-
}
262+
float fillAngle = angleRange * fillPercent;
314263

315-
circles.Add(circle);
264+
// Adjusting for direction
265+
float relativeAngle;
266+
if (direction == CircleDirection.Clockwise)
267+
{
268+
relativeAngle = startAngle + fillAngle;
269+
}
270+
else // Anticlockwise
271+
{
272+
relativeAngle = startAngle - fillAngle;
316273
}
317274

318-
return circles;
319-
*/
275+
circle.StartAngle = startAngle;
276+
circle.EndAngle = relativeAngle;
277+
278+
return circle;
320279
}
321280

322281
public void Resize(Vector2 size, bool conditions)

0 commit comments

Comments
 (0)