-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrendering.cpp
More file actions
441 lines (369 loc) · 15.5 KB
/
Copy pathrendering.cpp
File metadata and controls
441 lines (369 loc) · 15.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#include <metahook.h>
#include "rendering.h"
#include "config.h"
#include "geometry.h"
#include "plugins.h"
void DrawRadialMenu(long long elapsedMs)
{
ImGuiIO& io = ImGui::GetIO();
ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(io.DisplaySize);
ImGui::Begin("##RadialMenuWindow", nullptr,
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_NoBackground);
ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImVec2 center = ImVec2(glwidth / 2.0f, glheight / 2.0f);
if (!g_JsonErrorMsg.empty())
{
// Draw full-screen dark overlay
draw_list->AddRectFilled(ImVec2(0, 0), io.DisplaySize, IM_COL32(0, 0, 0, 180));
// Draw error center sphere
ImU32 errorColor = IM_COL32(200, 30, 30, 245);
draw_list->AddCircleFilled(center, 70.0f, errorColor, 32);
draw_list->AddCircle(center, 70.0f, IM_COL32_WHITE, 32, 2.5f);
ImVec2 err_text_size = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize() * 1.3f, FLT_MAX, 0.0f, "ERROR");
draw_list->AddText(ImGui::GetFont(), ImGui::GetFontSize() * 1.3f, center - err_text_size * 0.5f, IM_COL32_WHITE, "ERROR");
// Draw error message below
ImVec2 desc_pos = center + ImVec2(0, 100.0f);
std::string msg = "Failed to load radialmenu.json:\n" + g_JsonErrorMsg;
float wrap_width = 600.0f;
ImVec2 desc_size = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize() * 1.1f, wrap_width, 0.0f, msg.c_str());
draw_list->AddText(ImGui::GetFont(), ImGui::GetFontSize() * 1.1f, desc_pos - ImVec2(desc_size.x * 0.5f, 0), IM_COL32(255, 100, 100, 255), msg.c_str(), nullptr, wrap_width);
ImGui::End();
return;
}
auto mIt = g_Menus.find(g_ActiveMenuName);
if (mIt == g_Menus.end())
{
ImGui::End();
return;
}
const auto& menu = mIt->second;
if (menu.items.empty())
{
ImGui::End();
return;
}
int num_pages = 1;
int current_page = 0;
std::vector<RadialMenuEntry> active_items = GetActivePageItems(menu, num_pages, current_page);
UpdateItemAnglesCache(active_items);
// Fullscreen dark overlay
draw_list->AddRectFilled(ImVec2(0, 0), io.DisplaySize, IM_COL32(0, 0, 0, 120));
// Calculate expansion animation progress
float progress = 1.0f;
if (g_Style.animation_duration_ms > 0)
{
if (elapsedMs < g_Style.animation_duration_ms)
{
progress = (float)elapsedMs / (float)g_Style.animation_duration_ms;
}
}
float rad_min = g_Style.radius_min * progress;
float rad_inner = (g_Style.radius_min + 5.0f) * progress;
bool isCenterAutoBack = !g_MenuHistory.empty() && IsCenterEmpty(menu.center);
// Pagination arrows: two small circular buttons outside the ring, drawn
// independently of the center (which is now free to always show
// center_split or plain BACK, whichever the menu configures).
if (num_pages > 1 && progress > 0.1f)
{
bool leftDisabled = (current_page == 0);
bool rightDisabled = (current_page == num_pages - 1);
bool leftHovered = (g_iSelectedSector == -5);
bool rightHovered = (g_iSelectedSector == -6);
float btn_radius = g_Style.pagination_arrow_radius * progress;
ImVec2 leftPos = center - ImVec2(g_Style.radius_max + g_Style.pagination_arrow_offset, 0.0f);
ImVec2 rightPos = center + ImVec2(g_Style.radius_max + g_Style.pagination_arrow_offset, 0.0f);
auto drawArrowButton = [&](const ImVec2& pos, bool hovered, bool disabled, const char* glyph)
{
ImU32 fillColor = hovered ? g_Style.service_hover_color : g_Style.service_color;
ImU32 textColor = IM_COL32_WHITE;
if (disabled)
{
ImVec4 col_vec = ImGui::ColorConvertU32ToFloat4(fillColor);
col_vec.w *= 0.3f;
fillColor = ImGui::ColorConvertFloat4ToU32(col_vec);
textColor = IM_COL32(110, 110, 110, 140);
}
draw_list->AddCircleFilled(pos, btn_radius, fillColor, 20);
draw_list->AddCircle(pos, btn_radius, IM_COL32(200, 200, 200, 120), 20, 1.5f);
float font_size = ImGui::GetFontSize() * 1.0f * progress;
ImVec2 text_size = ImGui::GetFont()->CalcTextSizeA(font_size, FLT_MAX, 0.0f, glyph);
draw_list->AddText(ImGui::GetFont(), font_size, pos - text_size * 0.5f, textColor, glyph);
};
drawArrowButton(leftPos, leftHovered, leftDisabled, "◀");
drawArrowButton(rightPos, rightHovered, rightDisabled, "▶");
}
if (menu.center_split)
{
bool leftHovered = (g_iSelectedSector == -3);
ImU32 leftColor;
if (menu.center_left.hover_color_override != 0 && leftHovered)
leftColor = menu.center_left.hover_color_override;
else if (menu.center_left.color_override != 0 && !leftHovered)
leftColor = menu.center_left.color_override;
else
leftColor = leftHovered ? g_Style.hover_color : IM_COL32(30, 30, 30, 240);
if (menu.center_left.disabled)
{
ImVec4 col_vec = ImGui::ColorConvertU32ToFloat4(leftColor);
col_vec.w *= 0.35f;
col_vec.x *= 0.6f;
col_vec.y *= 0.6f;
col_vec.z *= 0.6f;
leftColor = ImGui::ColorConvertFloat4ToU32(col_vec);
}
bool rightHovered = (g_iSelectedSector == -4);
ImU32 rightColor;
if (menu.center_right.hover_color_override != 0 && rightHovered)
rightColor = menu.center_right.hover_color_override;
else if (menu.center_right.color_override != 0 && !rightHovered)
rightColor = menu.center_right.color_override;
else
rightColor = rightHovered ? g_Style.hover_color : IM_COL32(30, 30, 30, 240);
if (menu.center_right.disabled)
{
ImVec4 col_vec = ImGui::ColorConvertU32ToFloat4(rightColor);
col_vec.w *= 0.35f;
col_vec.x *= 0.6f;
col_vec.y *= 0.6f;
col_vec.z *= 0.6f;
rightColor = ImGui::ColorConvertFloat4ToU32(col_vec);
}
// Draw Left Half
draw_list->PathClear();
draw_list->PathArcTo(center, rad_min, IM_PI * 0.5f, IM_PI * 1.5f, 16);
draw_list->PathLineTo(center);
draw_list->PathFillConvex(leftColor);
draw_list->PathClear();
draw_list->PathArcTo(center, rad_min, IM_PI * 0.5f, IM_PI * 1.5f, 16);
draw_list->PathLineTo(center);
draw_list->PathStroke(IM_COL32(200, 200, 200, 100), ImDrawFlags_Closed, 1.5f);
// Draw Right Half
draw_list->PathClear();
draw_list->PathArcTo(center, rad_min, -IM_PI * 0.5f, IM_PI * 0.5f, 16);
draw_list->PathLineTo(center);
draw_list->PathFillConvex(rightColor);
draw_list->PathClear();
draw_list->PathArcTo(center, rad_min, -IM_PI * 0.5f, IM_PI * 0.5f, 16);
draw_list->PathLineTo(center);
draw_list->PathStroke(IM_COL32(200, 200, 200, 100), ImDrawFlags_Closed, 1.5f);
// Divider
draw_list->AddLine(center - ImVec2(0, rad_min), center + ImVec2(0, rad_min), IM_COL32(200, 200, 200, 100), 1.5f);
// Left Text
if (!menu.center_left.label.empty() && progress > 0.1f)
{
float left_font_size = ImGui::GetFontSize() * 0.8f * progress;
ImVec2 text_size = ImGui::GetFont()->CalcTextSizeA(left_font_size, FLT_MAX, 0.0f, menu.center_left.label.c_str());
ImVec2 text_pos = center - ImVec2(rad_min * 0.45f, 0.0f) - text_size * 0.5f;
ImU32 textColor = menu.center_left.disabled ? IM_COL32(110, 110, 110, 120) : IM_COL32_WHITE;
draw_list->AddText(ImGui::GetFont(), left_font_size, text_pos, textColor, menu.center_left.label.c_str());
}
// Right Text
if (!menu.center_right.label.empty() && progress > 0.1f)
{
float right_font_size = ImGui::GetFontSize() * 0.8f * progress;
ImVec2 text_size = ImGui::GetFont()->CalcTextSizeA(right_font_size, FLT_MAX, 0.0f, menu.center_right.label.c_str());
ImVec2 text_pos = center + ImVec2(rad_min * 0.45f, 0.0f) - text_size * 0.5f;
ImU32 textColor = menu.center_right.disabled ? IM_COL32(110, 110, 110, 120) : IM_COL32_WHITE;
draw_list->AddText(ImGui::GetFont(), right_font_size, text_pos, textColor, menu.center_right.label.c_str());
}
}
else
{
bool centerHovered = (g_iSelectedSector == -2);
ImU32 centerColor;
if (menu.center.hover_color_override != 0 && centerHovered)
centerColor = menu.center.hover_color_override;
else if (menu.center.color_override != 0 && !centerHovered)
centerColor = menu.center.color_override;
else if (isCenterAutoBack)
centerColor = centerHovered ? g_Style.service_hover_color : g_Style.service_color;
else
centerColor = centerHovered ? g_Style.hover_color : IM_COL32(30, 30, 30, 240);
if (menu.center.disabled)
{
ImVec4 col_vec = ImGui::ColorConvertU32ToFloat4(centerColor);
col_vec.w *= 0.35f;
col_vec.x *= 0.6f;
col_vec.y *= 0.6f;
col_vec.z *= 0.6f;
centerColor = ImGui::ColorConvertFloat4ToU32(col_vec);
}
draw_list->AddCircleFilled(center, rad_min, centerColor, 32);
draw_list->AddCircle(center, rad_min, IM_COL32(200, 200, 200, 100), 32, 2.0f);
std::string displayLabel = menu.center.label;
if (isCenterAutoBack)
{
displayLabel = "BACK";
}
if (!displayLabel.empty() && progress > 0.1f)
{
ImVec2 center_text_size = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize() * progress, FLT_MAX, 0.0f, displayLabel.c_str());
ImU32 textColor = (menu.center.disabled || (isCenterAutoBack && menu.center.disabled)) ? IM_COL32(110, 110, 110, 120) : IM_COL32_WHITE;
draw_list->AddText(ImGui::GetFont(), ImGui::GetFontSize() * progress, center - center_text_size * 0.5f, textColor, displayLabel.c_str());
}
}
int M = (int)active_items.size();
std::vector<ItemAngle> item_angles = g_CachedItemAngles;
for (int i = 0; i < M; i++)
{
RadialMenuEntry entry = active_items[i];
float angle_start = item_angles[i].start;
float angle_end = item_angles[i].end;
float slot_angle = (angle_start + angle_end) / 2.0f;
bool hovered = (g_iSelectedSector == i);
bool isService = !entry.submenu.empty();
ImU32 color;
if (hovered)
{
if (entry.hover_color_override != 0)
color = entry.hover_color_override;
else if (isService)
color = g_Style.service_hover_color;
else
color = g_Style.hover_color;
}
else
{
if (entry.color_override != 0)
color = entry.color_override;
else if (isService)
color = g_Style.service_color;
else
color = g_Style.sector_color;
}
if (entry.disabled)
{
ImVec4 col_vec = ImGui::ColorConvertU32ToFloat4(color);
col_vec.w *= 0.35f;
col_vec.x *= 0.6f;
col_vec.y *= 0.6f;
col_vec.z *= 0.6f;
color = ImGui::ColorConvertFloat4ToU32(col_vec);
}
float current_radius_max = (hovered ? g_Style.radius_max + 15.0f : g_Style.radius_max) * progress;
float arc_span = angle_end - angle_start;
bool isFullCircle = arc_span >= (2.0f * IM_PI - 0.001f);
// Segment count scales with arc span so a full-circle single-item
// sector (span = 2*PI) stays as smooth as a normal ~45-degree wedge
// instead of showing 16 flat facets across the whole ring.
int segments = (int)(arc_span / (IM_PI / 4.0f) * 16.0f);
if (segments < 8) segments = 8;
if (segments > 128) segments = 128;
int num_vertices = (segments + 1) * 2;
int num_indices = segments * 6;
draw_list->PrimReserve(num_indices, num_vertices);
ImVec2 uv = ImGui::GetIO().Fonts->TexUvWhitePixel;
int vtx_base_idx = draw_list->_VtxCurrentIdx;
for (int j = 0; j <= segments; j++)
{
float step_angle = angle_start + (angle_end - angle_start) * (j / (float)segments);
ImVec2 dir(cosf(step_angle), sinf(step_angle));
draw_list->_VtxWritePtr[0].pos = center + dir * rad_inner;
draw_list->_VtxWritePtr[0].uv = uv;
draw_list->_VtxWritePtr[0].col = color;
draw_list->_VtxWritePtr[1].pos = center + dir * current_radius_max;
draw_list->_VtxWritePtr[1].uv = uv;
draw_list->_VtxWritePtr[1].col = color;
draw_list->_VtxWritePtr += 2;
}
for (int j = 0; j < segments; j++)
{
int i0 = vtx_base_idx + j * 2;
int i1 = i0 + 1;
int i2 = i0 + 2;
int i3 = i0 + 3;
draw_list->_IdxWritePtr[0] = (ImDrawIdx)i0;
draw_list->_IdxWritePtr[1] = (ImDrawIdx)i1;
draw_list->_IdxWritePtr[2] = (ImDrawIdx)i2;
draw_list->_IdxWritePtr[3] = (ImDrawIdx)i1;
draw_list->_IdxWritePtr[4] = (ImDrawIdx)i3;
draw_list->_IdxWritePtr[5] = (ImDrawIdx)i2;
draw_list->_IdxWritePtr += 6;
}
draw_list->_VtxCurrentIdx += num_vertices;
if (hovered)
{
if (isFullCircle)
{
// No seam to draw when the sector wraps all the way around -
// angle_start and angle_end are the same physical point, so
// a radial line between them is a visual artifact, not an edge.
draw_list->AddCircle(center, current_radius_max, IM_COL32(255, 255, 255, 200), segments, 2.5f);
}
else
{
draw_list->PathClear();
draw_list->PathArcTo(center, current_radius_max, angle_start, angle_end, segments);
draw_list->PathLineTo(center + ImVec2(cosf(angle_end), sinf(angle_end)) * rad_inner);
draw_list->PathArcTo(center, rad_inner, angle_end, angle_start, segments);
draw_list->PathStroke(IM_COL32(255, 255, 255, 200), ImDrawFlags_Closed, 2.5f);
}
}
bool hasIcon = !entry.symbolic_icon.empty();
bool hasLabel = !entry.label.empty();
bool hasDesc = !entry.description.empty();
if (progress > 0.15f)
{
float icon_font_size = ImGui::GetFontSize() * entry.icon_scale * (hovered ? 1.8f : 1.4f) * progress;
float label_font_size = ImGui::GetFontSize() * (hovered ? 1.1f : 0.9f) * progress;
float desc_font_size = ImGui::GetFontSize() * (hovered ? 0.8f : 0.7f) * progress;
ImVec2 icon_size = hasIcon ? ImGui::GetFont()->CalcTextSizeA(icon_font_size, FLT_MAX, 0.0f, entry.symbolic_icon.c_str()) : ImVec2(0, 0);
ImVec2 label_size = hasLabel ? ImGui::GetFont()->CalcTextSizeA(label_font_size, FLT_MAX, 0.0f, entry.label.c_str()) : ImVec2(0, 0);
ImVec2 desc_size = hasDesc ? ImGui::GetFont()->CalcTextSizeA(desc_font_size, FLT_MAX, 0.0f, entry.description.c_str()) : ImVec2(0, 0);
float total_height = 0.0f;
int element_count = 0;
if (hasIcon) { total_height += icon_size.y; element_count++; }
if (hasLabel) { total_height += label_size.y; element_count++; }
if (hasDesc) { total_height += desc_size.y; element_count++; }
float gap = 2.0f * progress;
if (element_count > 1)
total_height += gap * (element_count - 1);
ImVec2 content_center = ImVec2(
center.x + cosf(slot_angle) * (rad_min + current_radius_max) * 0.55f,
center.y + sinf(slot_angle) * (rad_min + current_radius_max) * 0.55f
);
float current_y = content_center.y - total_height * 0.5f;
if (hasIcon)
{
ImVec2 pos = ImVec2(content_center.x - icon_size.x * 0.5f, current_y);
ImU32 iconColor = entry.disabled ? IM_COL32(110, 110, 110, 120) : (entry.has_icon_color ? entry.icon_color : IM_COL32_WHITE);
draw_list->AddText(ImGui::GetFont(), icon_font_size, pos, iconColor, entry.symbolic_icon.c_str());
current_y += icon_size.y + gap;
}
if (hasLabel)
{
ImVec2 pos = ImVec2(content_center.x - label_size.x * 0.5f, current_y);
ImU32 labelColor = entry.disabled ? IM_COL32(110, 110, 110, 120) : IM_COL32_WHITE;
draw_list->AddText(ImGui::GetFont(), label_font_size, pos, labelColor, entry.label.c_str());
current_y += label_size.y + gap;
}
if (hasDesc)
{
ImVec2 pos = ImVec2(content_center.x - desc_size.x * 0.5f, current_y);
ImU32 descColor = entry.disabled ? IM_COL32(110, 110, 110, 120) : (entry.has_description_color ? entry.description_color : IM_COL32(200, 200, 200, 255));
draw_list->AddText(ImGui::GetFont(), desc_font_size, pos, descColor, entry.description.c_str());
}
}
}
if (num_pages > 1)
{
float dot_radius = 4.0f * progress;
float dot_spacing = 14.0f * progress;
float row_width = (num_pages - 1) * dot_spacing;
ImVec2 start_pos = center + ImVec2(-row_width * 0.5f, g_Style.radius_max * progress + 25.0f * progress);
for (int p = 0; p < num_pages; p++)
{
ImVec2 pos = start_pos + ImVec2(p * dot_spacing, 0.0f);
ImU32 dot_color = (p == current_page) ? g_Style.hover_color : IM_COL32(120, 120, 120, 150);
draw_list->AddCircleFilled(pos, dot_radius, dot_color, 12);
}
}
ImGui::End();
}