OpenCPN Partial API docs
Loading...
Searching...
No Matches
color_handler.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2018 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#include <wx/log.h>
25
26#include "color_handler.h"
27#include "model/gui_vars.h"
28#include "model/ocpn_types.h"
29#include "s52plib.h"
30
37extern s52plib* ps52plib; // In a library...
38extern wxColorHashMap* pcurrent_user_color_hash; // FIXME (leamas) find a home
39
40wxColour GetGlobalColor(wxString colorName) {
41 wxColour ret_color;
42
43 // Use the S52 Presentation library if present
44 if (ps52plib) ret_color = ps52plib->getwxColour(colorName);
45 if (!ret_color.Ok() && pcurrent_user_color_hash)
46 ret_color = (*pcurrent_user_color_hash)[colorName];
47
48 // Default
49 if (!ret_color.Ok()) {
50 ret_color.Set(128, 128, 128); // Simple Grey
51 wxLogMessage("Warning: Color not found " + colorName);
52 // Avoid duplicate warnings:
53 if (pcurrent_user_color_hash)
54 (*pcurrent_user_color_hash)[colorName] = ret_color;
55 }
56 return ret_color;
57}
58
59wxColour GetDialogColor(DialogColor color) {
60 wxColour col = *wxRED;
61
62 bool bUseSysColors = false;
63 bool bIsDarkMode = false;
64#ifdef __WXOSX__
65 if (wxPlatformInfo::Get().CheckOSVersion(10, 14)) bUseSysColors = true;
66#endif
67#ifdef __WXGTK__
68 bUseSysColors = true;
69#endif
70
71 if (bUseSysColors) {
72 wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
73 if (bg.Red() < 128) {
74 bIsDarkMode = true;
75 }
76 }
77
78 switch (color) {
79 case DLG_BACKGROUND:
80 if (bUseSysColors && bIsDarkMode) {
81 col = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
82 } else {
83 col = GetGlobalColor("DILG0");
84 }
85 break;
87 if (bUseSysColors && bIsDarkMode) {
88 col = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
89 } else {
90 col = GetGlobalColor("DILG1");
91 }
92 break;
94 if (bUseSysColors && bIsDarkMode) {
95 col = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
96 } else {
97 col = GetGlobalColor("DILG0");
98 }
99 break;
100 case DLG_ACCENT:
102 if (bUseSysColors && bIsDarkMode) {
103 col = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
104 } else {
105 col = GetGlobalColor("DILG3");
106 }
107 break;
109 if (bUseSysColors && bIsDarkMode) {
110 col = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
111 } else {
112 col = GetGlobalColor("DILG1");
113 }
114 break;
115 case DLG_TEXT:
116 if (bUseSysColors && bIsDarkMode) {
117 col = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
118 } else {
119 col = GetGlobalColor("DILG3");
120 }
121 break;
122 case DLG_HIGHLIGHT:
123 if (bUseSysColors && bIsDarkMode) {
124 col = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
125 } else {
126 col = GetGlobalColor("UIBCK");
127 }
128 break;
129 }
130 return col;
131}
wxColour GetDialogColor(DialogColor color)
Retrieves a dialog color based on its role in the application's dialogs.
Global color handling by name.
DialogColor
Enumeration of color types used in dialogs.
@ DLG_ACCENT
Accent color.
@ DLG_SELECTED_ACCENT
Accent color for selected items.
@ DLG_TEXT
Text color.
@ DLG_SELECTED_BACKGROUND
Background color for selected items.
@ DLG_UNSELECTED_ACCENT
Accent color for unselected items.
@ DLG_UNSELECTED_BACKGROUND
Background color for unselected items.
@ DLG_BACKGROUND
Background color of the dialog.
@ DLG_HIGHLIGHT
Highlight color.
Miscellaneous globals primarely used by gui layer.