summaryrefslogtreecommitdiff
path: root/src/ui/color.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-16 16:15:30 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-16 16:15:30 +0300
commit027d8185b10632092508bfda62467d24c9f8655b (patch)
tree03b0bf1edb9f2f284afde1679e24ac390b2f201d /src/ui/color.c
parentb10087331ff28acbc368361ba14dba3a70b7dc90 (diff)
Palette has UI colors; defined Light theme colors
Diffstat (limited to 'src/ui/color.c')
-rw-r--r--src/ui/color.c140
1 files changed, 137 insertions, 3 deletions
diff --git a/src/ui/color.c b/src/ui/color.c
index a2ff6e27..b9470084 100644
--- a/src/ui/color.c
+++ b/src/ui/color.c
@@ -4,24 +4,134 @@
4 4
5static const iColor transparent_; 5static const iColor transparent_;
6 6
7static iColor palette_[max_ColorId] = { 7static const iColor darkPalette_[] = {
8 { 0, 0, 0, 255 }, 8 { 0, 0, 0, 255 },
9 { 40, 40, 40, 255 }, 9 { 40, 40, 40, 255 },
10 { 80, 80, 80, 255 }, 10 { 80, 80, 80, 255 },
11 { 160, 160, 160, 255 }, 11 { 160, 160, 160, 255 },
12 { 255, 255, 255, 255 }, 12 { 255, 255, 255, 255 },
13
13 { 106, 80, 0, 255 }, 14 { 106, 80, 0, 255 },
14 { 255, 192, 0, 255 }, 15 { 255, 192, 0, 255 },
15 { 0, 96, 128, 255 }, 16 { 0, 96, 128, 255 },
16 { 0, 192, 255, 255 }, 17 { 0, 192, 255, 255 },
18
17 { 255, 255, 32, 255 }, 19 { 255, 255, 32, 255 },
18 { 255, 64, 64, 255 }, 20 { 255, 64, 64, 255 },
19 { 255, 0, 255, 255 }, 21 { 255, 0, 255, 255 },
20 { 132, 132, 255, 255 }, 22 { 132, 132, 255, 255 },
21 { 0, 200, 0, 255 }, 23 { 0, 200, 0, 255 },
22 /* theme colors left black until theme is seeded */
23}; 24};
24 25
26static const iColor lightPalette_[] = {
27 { 0, 0, 0, 255 },
28 { 75, 75, 75, 255 },
29 { 150, 150, 150, 255 },
30 { 235, 235, 235, 255 },
31 { 255, 255, 255, 255 },
32
33 { 170, 128, 0, 255 },
34 { 255, 213, 86, 255 },
35 { 0, 96, 128, 255 },
36 { 86, 213, 255, 255 },
37
38 { 255, 255, 32, 255 },
39 { 255, 64, 64, 255 },
40 { 255, 0, 255, 255 },
41 { 132, 132, 255, 255 },
42 { 0, 150, 0, 255 },
43};
44
45static iColor palette_[max_ColorId];
46
47iLocalDef void copy_(enum iColorId dst, enum iColorId src) {
48 set_Color(dst, get_Color(src));
49}
50
51void setThemePalette_Color(enum iColorTheme theme) {
52 memcpy(palette_, theme == dark_ColorTheme ? darkPalette_ : lightPalette_, sizeof(darkPalette_));
53 switch (theme) {
54 default:
55 case dark_ColorTheme:
56 copy_(uiBackground_ColorId, gray25_ColorId);
57 copy_(uiBackgroundHover_ColorId, gray25_ColorId);
58 copy_(uiBackgroundPressed_ColorId, orange_ColorId);
59 copy_(uiBackgroundSelected_ColorId, teal_ColorId);
60 copy_(uiBackgroundFramelessHover_ColorId, teal_ColorId);
61 copy_(uiText_ColorId, gray75_ColorId);
62 copy_(uiTextPressed_ColorId, black_ColorId);
63 copy_(uiTextStrong_ColorId, white_ColorId);
64 copy_(uiTextSelected_ColorId, white_ColorId);
65 copy_(uiTextFramelessHover_ColorId, white_ColorId);
66 copy_(uiTextShortcut_ColorId, cyan_ColorId);
67 copy_(uiTextAction_ColorId, cyan_ColorId);
68 copy_(uiTextCaution_ColorId, orange_ColorId);
69 copy_(uiFrame_ColorId, gray25_ColorId);
70 copy_(uiEmboss1_ColorId, gray50_ColorId);
71 copy_(uiEmboss2_ColorId, black_ColorId);
72 copy_(uiEmbossHover1_ColorId, cyan_ColorId);
73 copy_(uiEmbossHover2_ColorId, teal_ColorId);
74 copy_(uiEmbossPressed1_ColorId, brown_ColorId);
75 copy_(uiEmbossPressed2_ColorId, white_ColorId);
76 copy_(uiEmbossSelected1_ColorId, cyan_ColorId);
77 copy_(uiEmbossSelected2_ColorId, black_ColorId);
78 copy_(uiEmbossSelectedHover1_ColorId, white_ColorId);
79 copy_(uiEmbossSelectedHover2_ColorId, cyan_ColorId);
80 copy_(uiInputBackground_ColorId, black_ColorId);
81 copy_(uiInputBackgroundFocused_ColorId, black_ColorId);
82 copy_(uiInputText_ColorId, gray75_ColorId);
83 copy_(uiInputTextFocused_ColorId, white_ColorId);
84 copy_(uiInputFrame_ColorId, gray50_ColorId);
85 copy_(uiInputFrameHover_ColorId, cyan_ColorId);
86 copy_(uiInputFrameFocused_ColorId, orange_ColorId);
87 copy_(uiInputCursor_ColorId, orange_ColorId);
88 copy_(uiInputCursorText_ColorId, black_ColorId);
89 copy_(uiHeading_ColorId, cyan_ColorId);
90 copy_(uiIcon_ColorId, cyan_ColorId);
91 copy_(uiSeparator_ColorId, black_ColorId);
92 break;
93 case light_ColorTheme:
94 copy_(uiBackground_ColorId, white_ColorId);
95 copy_(uiBackgroundHover_ColorId, gray75_ColorId);
96 copy_(uiBackgroundSelected_ColorId, orange_ColorId);
97 copy_(uiBackgroundPressed_ColorId, cyan_ColorId);
98 copy_(uiBackgroundFramelessHover_ColorId, orange_ColorId);
99 copy_(uiText_ColorId, gray25_ColorId);
100 copy_(uiTextStrong_ColorId, black_ColorId);
101 copy_(uiTextPressed_ColorId, black_ColorId);
102 copy_(uiTextStrong_ColorId, black_ColorId);
103 copy_(uiTextSelected_ColorId, black_ColorId);
104 copy_(uiTextFramelessHover_ColorId, black_ColorId);
105 copy_(uiTextShortcut_ColorId, brown_ColorId);
106 copy_(uiTextAction_ColorId, brown_ColorId);
107 copy_(uiTextCaution_ColorId, teal_ColorId);
108 copy_(uiFrame_ColorId, gray75_ColorId);
109 copy_(uiEmboss1_ColorId, white_ColorId);
110 copy_(uiEmboss2_ColorId, white_ColorId);
111 copy_(uiEmbossHover1_ColorId, gray25_ColorId);
112 copy_(uiEmbossHover2_ColorId, gray25_ColorId);
113 copy_(uiEmbossPressed1_ColorId, black_ColorId);
114 copy_(uiEmbossPressed2_ColorId, teal_ColorId);
115 copy_(uiEmbossSelected1_ColorId, white_ColorId);
116 copy_(uiEmbossSelected2_ColorId, brown_ColorId);
117 copy_(uiEmbossSelectedHover1_ColorId, gray50_ColorId);
118 copy_(uiEmbossSelectedHover2_ColorId, gray50_ColorId);
119 copy_(uiInputBackground_ColorId, white_ColorId);
120 copy_(uiInputBackgroundFocused_ColorId, white_ColorId);
121 copy_(uiInputText_ColorId, gray25_ColorId);
122 copy_(uiInputTextFocused_ColorId, black_ColorId);
123 copy_(uiInputFrame_ColorId, gray50_ColorId);
124 copy_(uiInputFrameHover_ColorId, brown_ColorId);
125 copy_(uiInputFrameFocused_ColorId, teal_ColorId);
126 copy_(uiInputCursor_ColorId, teal_ColorId);
127 copy_(uiInputCursorText_ColorId, white_ColorId);
128 copy_(uiHeading_ColorId, brown_ColorId);
129 copy_(uiIcon_ColorId, brown_ColorId);
130 copy_(uiSeparator_ColorId, gray50_ColorId);
131 break;
132 }
133}
134
25iColor get_Color(int color) { 135iColor get_Color(int color) {
26 const iColor *rgba = &transparent_; 136 const iColor *rgba = &transparent_;
27 if (color >= 0 && color < max_ColorId) { 137 if (color >= 0 && color < max_ColorId) {
@@ -31,11 +141,35 @@ iColor get_Color(int color) {
31} 141}
32 142
33void set_Color(int color, iColor rgba) { 143void set_Color(int color, iColor rgba) {
34 if (color >= tmFirst_ColorId && color < max_ColorId) { 144 if (color >= uiBackground_ColorId && color < max_ColorId) {
35 palette_[color] = rgba; 145 palette_[color] = rgba;
36 } 146 }
37} 147}
38 148
149iLocalDef iBool equal_Color_(const iColor *x, const iColor *y) {
150 return memcmp(x, y, sizeof(iColor)) == 0;
151}
152
153int darker_Color(int color) {
154 const iColor rgb = get_Color(color);
155 for (int i = 0; i < uiFirst_ColorId; i++) {
156 if (equal_Color_(&rgb, &palette_[i])) {
157 return i > 0 ? i - 1 : i;
158 }
159 }
160 return color;
161}
162
163int lighter_Color(int color) {
164 const iColor rgb = get_Color(color);
165 for (int i = 0; i < uiFirst_ColorId; i++) {
166 if (equal_Color_(&rgb, &palette_[i])) {
167 return i < uiFirst_ColorId - 1 ? i + 1 : i;
168 }
169 }
170 return color;
171}
172
39iLocalDef iFloat4 normalize_(iColor d) { 173iLocalDef iFloat4 normalize_(iColor d) {
40 return divf_F4(init_F4(d.r, d.g, d.b, d.a), 255.0f); 174 return divf_F4(init_F4(d.r, d.g, d.b, d.a), 255.0f);
41} 175}