-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometry.cpp
More file actions
41 lines (35 loc) · 1.12 KB
/
Copy pathgeometry.cpp
File metadata and controls
41 lines (35 loc) · 1.12 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
#include <metahook.h>
#include "geometry.h"
std::vector<ItemAngle> g_CachedItemAngles;
static std::string g_CachedMenuName;
static int g_CachedPage = -1;
// Distributes N items evenly around the circle (2*PI / N per sector).
// Sector 0 starts at 12 o'clock (-PI/2).
std::vector<ItemAngle> GetItemAngles(const std::vector<RadialMenuEntry>& active_items)
{
int M = (int)active_items.size();
std::vector<ItemAngle> angles(M);
if (M <= 0) return angles;
float sector_width = 2.0f * IM_PI / M;
for (int i = 0; i < M; i++)
{
float slot_angle = -IM_PI / 2.0f + i * sector_width;
angles[i].start = slot_angle - sector_width / 2.0f;
angles[i].end = slot_angle + sector_width / 2.0f;
}
return angles;
}
void UpdateItemAnglesCache(const std::vector<RadialMenuEntry>& active_items)
{
if (g_CachedMenuName == g_ActiveMenuName && g_CachedPage == g_CurrentMenuPage && !g_CachedItemAngles.empty())
return;
g_CachedItemAngles = GetItemAngles(active_items);
g_CachedMenuName = g_ActiveMenuName;
g_CachedPage = g_CurrentMenuPage;
}
void ClearItemAnglesCache()
{
g_CachedItemAngles.clear();
g_CachedMenuName.clear();
g_CachedPage = -1;
}