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