OpenCPN Partial API docs
Loading...
Searching...
No Matches
user_colors.cpp
1#include <wx/colour.h>
2#include <wx/hashmap.h>
3
4#include "user_colors.h"
5#include "color_types.h"
6#include "color_handler.h"
7#include "s52plib.h"
8
9ColorScheme global_color_scheme = GLOBAL_COLOR_SCHEME_DAY;
10
11namespace user_colors {
12
13ColorScheme GetColorScheme() { return global_color_scheme; }
14
15static const char *const usercolors[] = {
16 //======================================================================
17 // Table:DAY - Bright daylight color scheme (full visibility mode)
18 //======================================================================
19 "Table:DAY",
20
21 // Standard palette colors - general purpose UI elements
22 "GREEN1;120;255;120;", "GREEN2; 45;150; 45;", "GREEN3;200;220;200;",
23 "GREEN4; 0;255; 0;", "GREEN5;170;254; 0;", "BLUE1; 170;170;255;",
24 "BLUE2; 45; 45;170;", "BLUE3; 0; 0;255;", "GREY1; 200;200;200;",
25 "GREY2; 230;230;230;", "RED1; 220;200;200;", "YELO1; 243;229; 47;",
26 "YELO2; 128; 80; 0;", "TEAL1; 0;128;128;",
27
28 // Basic UI colors
29 "UBLCK; 0; 0; 0;", // Universal black for text/lines
30 "UWHIT; 255;255;255;", // Universal white for backgrounds
31 "URED; 255; 0; 0;", // Own vessel color, AIS targets, predictor lines
32 "UGREN; 0;255; 0;", // Universal green for general purpose green
33 "COMPT; 245;247;244", // Compass rose background/details
34
35// Dialog system colors
36#ifdef __WXOSX__
37 "DILG0; 255;255;255;", // Dialog window background (macOS)
38#else
39 "DILG0; 238;239;242;", // Dialog window background (other platforms)
40#endif
41 "DILG1; 212;208;200;", // Background color for selected items
42 "DILG2; 255;255;255;", // Control backgrounds for text boxes and input
43 // fields
44 "DILG3; 0; 0; 0;", // Dialog text color in dialogs and controls
50 "DILG4; 0; 0; 0;",
51 "UITX1; 0; 0; 0;", // Menu text color
52
53 // Chart and information display colors
54 "CHGRF; 163; 180; 183;", // Chart gray foreground (grid lines, secondary
55 // text)
56 "CHYLW; 244; 218; 72;", // Chart yellow (AIS name invalid, warnings)
57 "CHWHT; 212; 234; 238;", // Chart white (AIS outlines, contrast elements)
58
59 // Information status colors
60 "UINFM; 197; 69; 195;", // Magenta - special indicators, chart magenta
61 // features
62 "UINFG; 104; 228; 86;", // Green - status indicators, tide/current
63 // graphics
64 "UINFR; 241; 84; 105;", // Red - alerts, errors, danger markers
65 "UINFF; 125; 137; 140;", // Default foreground - general UI elements
66 "SHIPS; 7; 7; 7;", // Other vessels/AIS target fills
67
68 // Route and navigation colors
69 "UDKRD; 124; 16; 0;", // Dark red variant - reduced visibility alternative
70 // to URED
71 "UARTE; 200; 0; 0;", // Active route color (bright red in day mode)
72
73 // Chart data and measurement colors
74 "NODTA; 163; 180; 183;", // No data available areas
75 "CHBLK; 7; 7; 7;", // Chart black - text, lines, piano keys
76 "SNDG1; 125; 137; 140;", // Sounding text (depth numbers) - primary
77 "SNDG2; 7; 7; 7;", // Sounding text (depth numbers) - secondary
78 "SCLBR; 235; 125; 54;", // Scale bar markings and text
79
80 // UI framework colors
81 "UIBDR; 125; 137; 140;", // UI borders, status bar background
82 "UIBCK; 212; 234; 238;", // Highlight backgrounds, info windows
83 "UINFB; 58; 120; 240;", // Information blue - active/selected states, tide
84 // markers
85 "UINFD; 7; 7; 7;", // Information dark - borders, inactive elements
86 "UINFO; 235; 125; 54;", // Information orange - warnings, highlights
87
88 // Route planning colors
89 "PLRTE; 220; 64; 37;", // Planned route color (not yet active)
90 "CHMGD; 197; 69; 195;", // Chart magenta - special chart features, AIS MMSI
91 // text
92
93 // Dashboard instrument colors
94 "DASHB; 255;255;255;", // Dashboard instrument background
95 "DASHL; 175;175;175;", // Dashboard instrument labels and graduations
96 "DASHF; 50; 50; 50;", // Dashboard foreground text and indicators
97 "DASHR; 200; 0; 0;", // Dashboard red indicators (alarms, danger zones)
98 "DASHG; 0;200; 0;", // Dashboard green indicators (normal status)
99 "DASHN; 200;120; 0;", // Dashboard needle/pointer color
100 "DASH1; 204;204;255;", // Dashboard graphic elements - primary
101 "DASH2; 122;131;172;", // Dashboard graphic elements - secondary
102 "COMP1; 211;211;211;", // Compass window background
103
104 // Window and canvas elements
105 "GREY3; 40; 40; 40;", // MUI toolbar background
106 "BLUE4; 100;100;200;", // Canvas focus indicator bar
107 "VIO01; 171; 33;141;", // Violet - vector chart special elements
108 "VIO02; 209;115;213;", // Violet variant - vector chart features
109 "BLUEBACK; 212;234;238;", // Deep water background color for basemap
110 "LANDBACK; 201;185;122;", // Land mass background color for basemap
111
112 //======================================================================
113 // Table:DUSK - Reduced brightness for twilight conditions
114 // Colors defined above are automatically dimmed for dusk visibility
115 //======================================================================
116 "Table:DUSK", "GREEN1; 60;128; 60;", "GREEN2; 22; 75; 22;",
117 "GREEN3; 80;100; 80;", "GREEN4; 0;128; 0;", "BLUE1; 80; 80;160;",
118 "BLUE2; 30; 30;120;", "BLUE3; 0; 0;128;", "GREY1; 100;100;100;",
119 "GREY2; 128;128;128;", "RED1; 150;100;100;", "UBLCK; 0; 0; 0;",
120 "UWHIT; 255;255;255;", "URED; 120; 54; 11;", "UGREN; 35;110; 20;",
121 "YELO1; 120;115; 24;", "YELO2; 64; 40; 0;", "TEAL1; 0; 64; 64;",
122 "GREEN5; 85;128; 0;", "COMPT; 124;126;121",
123
124 "CHGRF; 41; 46; 46;", "UINFM; 58; 20; 57;", "UINFG; 35; 76; 29;",
125 "UINFF; 41; 46; 46;", "UINFR; 80; 28; 35;", "SHIPS; 71; 78; 79;",
126 "CHYLW; 81; 73; 24;", "CHWHT; 71; 78; 79;",
127
128 "DILG0; 110;110;110;", // Dialog Background
129 "DILG1; 110;110;110;", // Dialog Background
130 "DILG2; 0; 0; 0;", // Control Background
131 "DILG3; 130;130;130;", // Text
132 "DILG4; 0; 0; 0;",
133 "UITX1; 41; 46; 46;", // Menu text color
134 "UDKRD; 80; 0; 0;", // Dark red variant - reduced visibility alternative
135 // to URED
136 "UARTE; 64; 64; 64;", // Active route color (grey for dusk/night modes)
137
138 "NODTA; 41; 46; 46;", "CHBLK; 54; 60; 61;", "SNDG1; 41; 46; 46;",
139 "SNDG2; 71; 78; 79;", "SCLBR; 75; 38; 19;", "UIBDR; 54; 60; 61;",
140 "UINFB; 19; 40; 80;", "UINFD; 71; 78; 79;", "UINFO; 75; 38; 19;",
141 "PLRTE; 73; 21; 12;", "CHMGD; 74; 58; 81;", "UIBCK; 7; 7; 7;",
142
143 "DASHB; 77; 77; 77;", // Dashboard Instr background
144 "DASHL; 54; 54; 54;", // Dashboard Instr Label
145 "DASHF; 0; 0; 0;", // Dashboard Foreground
146 "DASHR; 58; 21; 21;", // Dashboard Red
147 "DASHG; 21; 58; 21;", // Dashboard Green
148 "DASHN; 100; 50; 0;", // Dashboard Needle
149 "DASH1; 76; 76;113;", // Dashboard Illustrations
150 "DASH2; 48; 52; 72;", // Dashboard Illustrations
151 "COMP1; 107;107;107;", // Compass Window Background
152
153 "GREY3; 20; 20; 20;", // MUIBar/TB background
154 "BLUE4; 80; 80;160;", // Canvas Focus Bar
155 "VIO01; 128; 25;108;", "VIO02; 171; 33;141;", "BLUEBACK; 186;213;235;",
156 "LANDBACK; 201;185;122;",
157
158 //======================================================================
159 // Table:NIGHT - Dark adapted colors preserving night vision
160 // Colors are further dimmed and shifted toward red spectrum
161 //======================================================================
162 "Table:NIGHT", "GREEN1; 30; 80; 30;", "GREEN2; 15; 60; 15;",
163 "GREEN3; 12; 23; 9;", "GREEN4; 0; 64; 0;", "BLUE1; 60; 60;100;",
164 "BLUE2; 22; 22; 85;", "BLUE3; 0; 0; 40;", "GREY1; 48; 48; 48;",
165 "GREY2; 32; 32; 32;", "RED1; 100; 50; 50;", "UWHIT; 255;255;255;",
166 "UBLCK; 0; 0; 0;", "URED; 60; 27; 5;", "UGREN; 17; 55; 10;",
167 "YELO1; 60; 65; 12;", "YELO2; 32; 20; 0;", "TEAL1; 0; 32; 32;",
168 "GREEN5; 44; 64; 0;", "COMPT; 48; 49; 51",
169 "DILG0; 80; 80; 80;", // Dialog Background
170 "DILG1; 80; 80; 80;", // Dialog Background
171 "DILG2; 0; 0; 0;", // Control Background
172 "DILG3; 65; 65; 65;", // Text
173 "DILG4; 220;220;220;",
174 "UITX1; 31; 34; 35;", // Menu text color
175 "UDKRD; 50; 0; 0;", // Dark red variant - reduced visibility alternative
176 // to URED
177 "UARTE; 64; 64; 64;", // Active route color (grey for dusk/night modes)
178
179 "CHGRF; 16; 18; 18;", "UINFM; 52; 18; 52;", "UINFG; 22; 24; 7;",
180 "UINFF; 31; 34; 35;", "UINFR; 59; 17; 10;", "SHIPS; 37; 41; 41;",
181 "CHYLW; 31; 33; 10;", "CHWHT; 37; 41; 41;",
182
183 "NODTA; 7; 7; 7;", "CHBLK; 31; 34; 35;", "SNDG1; 31; 34; 35;",
184 "SNDG2; 43; 48; 48;", "SCLBR; 52; 28; 12;", "UIBDR; 31; 34; 35;",
185 "UINFB; 21; 29; 69;", "UINFD; 43; 48; 58;", "UINFO; 52; 28; 12;",
186 "PLRTE; 66; 19; 11;", "CHMGD; 52; 18; 52;", "UIBCK; 7; 7; 7;",
187
188 "DASHB; 0; 0; 0;", // Dashboard Instr background
189 "DASHL; 20; 20; 20;", // Dashboard Instr Label
190 "DASHF; 64; 64; 64;", // Dashboard Foreground
191 "DASHR; 70; 15; 15;", // Dashboard Red
192 "DASHG; 15; 70; 15;", // Dashboard Green
193 "DASHN; 17; 80; 56;", // Dashboard Needle
194 "DASH1; 48; 52; 72;", // Dashboard Illustrations
195 "DASH2; 36; 36; 53;", // Dashboard Illustrations
196 "COMP1; 24; 24; 24;", // Compass Window Background
197
198 "GREY3; 10; 10; 10;", // MUIBar/TB background
199 "BLUE4; 70; 70;140;", // Canvas Focus Bar
200 "VIO01; 85; 16; 72;", "VIO02; 128; 25;108;", "BLUEBACK; 186;213;235;",
201 "LANDBACK; 201;185;122;",
202
203 "*****"};
204
205static wxArrayPtrVoid *UserColorTableArray = 0;
206static wxArrayPtrVoid *UserColourHashTableArray;
207
208static int get_static_line(char *d, const char *const *p, int index, int n) {
209 if (!strcmp(p[index], "*****")) return 0;
210
211 strncpy(d, p[index], n);
212 return strlen(d);
213}
214
215void Initialize() {
216 const char *const *p = usercolors;
217 char buf[81];
218 int index = 0;
219 char TableName[20];
220 colTable *ctp;
221 colTable *ct;
222 int R, G, B;
223
224 UserColorTableArray = new wxArrayPtrVoid;
225 UserColourHashTableArray = new wxArrayPtrVoid;
226
227 // Create 3 color table entries
228 ct = new colTable;
229 ct->tableName = new wxString("DAY");
230 ct->color = new wxArrayPtrVoid;
231 UserColorTableArray->Add((void *)ct);
232
233 ct = new colTable;
234 ct->tableName = new wxString("DUSK");
235 ct->color = new wxArrayPtrVoid;
236 UserColorTableArray->Add((void *)ct);
237
238 ct = new colTable;
239 ct->tableName = new wxString("NIGHT");
240 ct->color = new wxArrayPtrVoid;
241 UserColorTableArray->Add((void *)ct);
242
243 while ((get_static_line(buf, p, index, sizeof(buf) - 1))) {
244 if (!strncmp(buf, "Table", 5)) {
245 sscanf(buf, "Table:%s", TableName);
246
247 for (unsigned int it = 0; it < UserColorTableArray->GetCount(); it++) {
248 ctp = (colTable *)(UserColorTableArray->Item(it));
249 if (!strcmp(TableName, ctp->tableName->mb_str())) {
250 ct = ctp;
251 break;
252 }
253 }
254
255 } else {
256 char name[21];
257 int j = 0;
258 while (buf[j] != ';' && j < 20) {
259 name[j] = buf[j];
260 j++;
261 }
262 name[j] = 0;
263
264 S52color *c = new S52color;
265 strcpy(c->colName, name);
266
267 sscanf(&buf[j], ";%i;%i;%i", &R, &G, &B);
268 c->R = (char)R;
269 c->G = (char)G;
270 c->B = (char)B;
271
272 ct->color->Add(c);
273 }
274
275 index++;
276 }
277
278 // Now create the Hash tables
279
280 for (unsigned int its = 0; its < UserColorTableArray->GetCount(); its++) {
281 wxColorHashMap *phash = new wxColorHashMap;
282 UserColourHashTableArray->Add((void *)phash);
283
284 colTable *ctp = (colTable *)(UserColorTableArray->Item(its));
285
286 for (unsigned int ic = 0; ic < ctp->color->GetCount(); ic++) {
287 S52color *c2 = (S52color *)(ctp->color->Item(ic));
288
289 wxColour c(c2->R, c2->G, c2->B);
290 wxString key(c2->colName, wxConvUTF8);
291 (*phash)[key] = c;
292 }
293 }
294
295 // Establish a default hash table pointer
296 // in case a color is needed before ColorScheme is set
298 (wxColorHashMap *)UserColourHashTableArray->Item(0);
299}
300void DeInitialize() {
301 if (!UserColorTableArray) return;
302 for (unsigned i = 0; i < UserColorTableArray->GetCount(); i++) {
303 colTable *ct = (colTable *)UserColorTableArray->Item(i);
304
305 for (unsigned int j = 0; j < ct->color->GetCount(); j++) {
306 S52color *c = (S52color *)ct->color->Item(j);
307 delete c; // color
308 }
309
310 delete ct->tableName; // wxString
311 delete ct->color; // wxArrayPtrVoid
312
313 delete ct; // colTable
314 }
315
316 delete UserColorTableArray;
317
318 for (unsigned i = 0; i < UserColourHashTableArray->GetCount(); i++) {
319 wxColorHashMap *phash = (wxColorHashMap *)UserColourHashTableArray->Item(i);
320 delete phash;
321 }
322
323 delete UserColourHashTableArray;
324}
325
326wxColorHashMap *GetMapByScheme(const std::string &scheme_name) {
327 unsigned Usercolortable_index = 0;
328 for (unsigned int i = 0; i < UserColorTableArray->GetCount(); i++) {
329 colTable *ct = (colTable *)UserColorTableArray->Item(i);
330 if (scheme_name == (*ct->tableName)) {
331 return (wxColorHashMap *)UserColourHashTableArray->Item(i);
332 }
333 }
334 return nullptr;
335}
336
337wxColor GetDimColor(wxColor c) {
338 if ((global_color_scheme == GLOBAL_COLOR_SCHEME_DAY) ||
339 (global_color_scheme == GLOBAL_COLOR_SCHEME_RGB))
340 return c;
341
342 float factor = 1.0;
343 if (global_color_scheme == GLOBAL_COLOR_SCHEME_DUSK) factor = 0.5;
344 if (global_color_scheme == GLOBAL_COLOR_SCHEME_NIGHT) factor = 0.25;
345
346 wxImage::RGBValue rgb(c.Red(), c.Green(), c.Blue());
347 wxImage::HSVValue hsv = wxImage::RGBtoHSV(rgb);
348 hsv.value = hsv.value * factor;
349 wxImage::RGBValue nrgb = wxImage::HSVtoRGB(hsv);
350
351 return wxColor(nrgb.red, nrgb.green, nrgb.blue);
352}
353
354} // namespace user_colors
wxColorHashMap * pcurrent_user_color_hash
Global instance.
Global color handling by name.