OpenCPN Partial API docs
Loading...
Searching...
No Matches
color_handler.cpp
1#include <wx/log.h>
2
3#include "color_handler.h"
4#include "s52plib.h"
5#include "ocpn_types.h"
6
7extern s52plib *ps52plib;
8extern wxColorHashMap* pcurrent_user_color_hash;
9
10
11wxColour GetGlobalColor(wxString colorName) {
12 wxColour ret_color;
13
14 // Use the S52 Presentation library if present
15 if (ps52plib) ret_color = ps52plib->getwxColour(colorName);
16 if (!ret_color.Ok() && pcurrent_user_color_hash)
17 ret_color = (*pcurrent_user_color_hash)[colorName];
18
19 // Default
20 if (!ret_color.Ok()) {
21 ret_color.Set(128, 128, 128); // Simple Grey
22 wxLogMessage(_T("Warning: Color not found ") + colorName);
23 // Avoid duplicate warnings:
24 if (pcurrent_user_color_hash)
25 (*pcurrent_user_color_hash)[colorName] = ret_color;
26 }
27 return ret_color;
28}
29
30wxColour GetDialogColor(DialogColor color) {
31 wxColour col = *wxRED;
32
33 bool bUseSysColors = false;
34 bool bIsDarkMode = false;
35#ifdef __WXOSX__
36 if (wxPlatformInfo::Get().CheckOSVersion(10, 14)) bUseSysColors = true;
37#endif
38#ifdef __WXGTK__
39 bUseSysColors = true;
40#endif
41
42 if (bUseSysColors) {
43 wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
44 if (bg.Red() < 128) {
45 bIsDarkMode = true;
46 }
47 }
48
49 switch (color) {
50 case DLG_BACKGROUND:
51 if (bUseSysColors && bIsDarkMode) {
52 col = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
53 } else {
54 col = GetGlobalColor("DILG0");
55 }
56 break;
57 case DLG_SELECTED_BACKGROUND:
58 if (bUseSysColors && bIsDarkMode) {
59 col = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
60 } else {
61 col = GetGlobalColor("DILG1");
62 }
63 break;
64 case DLG_UNSELECTED_BACKGROUND:
65 if (bUseSysColors && bIsDarkMode) {
66 col = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
67 } else {
68 col = GetGlobalColor("DILG0");
69 }
70 break;
71 case DLG_ACCENT:
72 case DLG_SELECTED_ACCENT:
73 if (bUseSysColors && bIsDarkMode) {
74 col = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
75 } else {
76 col = GetGlobalColor("DILG3");
77 }
78 break;
79 case DLG_UNSELECTED_ACCENT:
80 if (bUseSysColors && bIsDarkMode) {
81 col = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
82 } else {
83 col = GetGlobalColor("DILG1");
84 }
85 break;
86 case DLG_TEXT:
87 if (bUseSysColors && bIsDarkMode) {
88 col = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
89 } else {
90 col = GetGlobalColor("DILG3");
91 }
92 break;
93 case DLG_HIGHLIGHT:
94 if (bUseSysColors && bIsDarkMode) {
95 col = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
96 } else {
97 col = GetGlobalColor("UIBCK");
98 }
99 break;
100 }
101 return col;
102}
103
104
105