-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
imgui_toggle_palette.cpp
85 lines (70 loc) · 2.64 KB
/
imgui_toggle_palette.cpp
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
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif // IMGUI_DEFINE_MATH_OPERATORS
#include "imgui_toggle_palette.h"
#include "imgui_toggle_math.h"
#include "imgui.h"
using namespace ImGuiToggleMath;
void ImGui::UnionPalette(ImGuiTogglePalette* target, const ImGuiTogglePalette* candidate, const ImVec4 colors[], bool v)
{
target->Knob = colors[ImGuiCol_Text];
target->KnobHover = colors[ImGuiCol_Text];
target->Frame = colors[!v ? ImGuiCol_FrameBg : ImGuiCol_Button];
target->FrameHover = colors[!v ? ImGuiCol_FrameBgHovered : ImGuiCol_ButtonHovered];
target->FrameBorder = colors[ImGuiCol_Border];
target->FrameShadow = colors[ImGuiCol_BorderShadow];
target->KnobBorder = colors[ImGuiCol_Border];
target->KnobShadow = colors[ImGuiCol_BorderShadow];
target->A11yGlyph = colors[!v ? ImGuiCol_FrameBg : ImGuiCol_Text];
// if the user didn't provide a candidate, just provide the theme colored palette.
if (candidate == nullptr)
{
return;
}
// if the user did provide a candidate, populate all non-zero colors
#define GET_PALETTE_POPULATE_NONZERO(member) \
do { \
if (IsNonZero(candidate->member)) \
{ \
target->member = candidate->member; \
} \
} while (0)
GET_PALETTE_POPULATE_NONZERO(Knob);
GET_PALETTE_POPULATE_NONZERO(KnobHover);
GET_PALETTE_POPULATE_NONZERO(Frame);
GET_PALETTE_POPULATE_NONZERO(FrameHover);
GET_PALETTE_POPULATE_NONZERO(FrameBorder);
GET_PALETTE_POPULATE_NONZERO(FrameShadow);
GET_PALETTE_POPULATE_NONZERO(KnobBorder);
GET_PALETTE_POPULATE_NONZERO(KnobShadow);
GET_PALETTE_POPULATE_NONZERO(A11yGlyph);
#undef GET_PALETTE_POPULATE_NONZERO
}
void ImGui::BlendPalettes(ImGuiTogglePalette* result, const ImGuiTogglePalette& a, const ImGuiTogglePalette& b, float blend_amount)
{
// a quick out for if we are at either end of the blend.
if (ImApproximately(blend_amount, 0.0f))
{
*result = a;
return;
}
else if (ImApproximately(blend_amount, 1.0f))
{
*result = b;
return;
}
#define BLEND_PALETTES_LERP(member) \
do { \
result->member = ImLerp(a.member, b.member, blend_amount); \
} while (0)
BLEND_PALETTES_LERP(Knob);
BLEND_PALETTES_LERP(KnobHover);
BLEND_PALETTES_LERP(Frame);
BLEND_PALETTES_LERP(FrameHover);
BLEND_PALETTES_LERP(FrameBorder);
BLEND_PALETTES_LERP(FrameShadow);
BLEND_PALETTES_LERP(KnobBorder);
BLEND_PALETTES_LERP(KnobShadow);
BLEND_PALETTES_LERP(A11yGlyph);
#undef BLEND_PALETTES_LERP
}