Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/themes/editor_theme.cpp
9896 views
1
/**************************************************************************/
2
/* editor_theme.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "editor_theme.h"
32
33
#include "editor/editor_string_names.h"
34
#include "scene/theme/theme_db.h"
35
36
Vector<StringName> EditorTheme::editor_theme_types;
37
38
// TODO: Refactor these and corresponding Theme methods to use the bool get_xxx(r_value) pattern internally.
39
40
// Keep in sync with Theme::get_color.
41
Color EditorTheme::get_color(const StringName &p_name, const StringName &p_theme_type) const {
42
if (color_map.has(p_theme_type) && color_map[p_theme_type].has(p_name)) {
43
return color_map[p_theme_type][p_name];
44
} else {
45
if (editor_theme_types.has(p_theme_type)) {
46
WARN_PRINT(vformat("Trying to access a non-existing editor theme color '%s' in '%s'.", p_name, p_theme_type));
47
}
48
return Color();
49
}
50
}
51
52
// Keep in sync with Theme::get_constant.
53
int EditorTheme::get_constant(const StringName &p_name, const StringName &p_theme_type) const {
54
if (constant_map.has(p_theme_type) && constant_map[p_theme_type].has(p_name)) {
55
return constant_map[p_theme_type][p_name];
56
} else {
57
if (editor_theme_types.has(p_theme_type)) {
58
WARN_PRINT(vformat("Trying to access a non-existing editor theme constant '%s' in '%s'.", p_name, p_theme_type));
59
}
60
return 0;
61
}
62
}
63
64
// Keep in sync with Theme::get_font.
65
Ref<Font> EditorTheme::get_font(const StringName &p_name, const StringName &p_theme_type) const {
66
if (font_map.has(p_theme_type) && font_map[p_theme_type].has(p_name) && font_map[p_theme_type][p_name].is_valid()) {
67
return font_map[p_theme_type][p_name];
68
} else if (has_default_font()) {
69
if (editor_theme_types.has(p_theme_type)) {
70
WARN_PRINT(vformat("Trying to access a non-existing editor theme font '%s' in '%s'.", p_name, p_theme_type));
71
}
72
return default_font;
73
} else {
74
if (editor_theme_types.has(p_theme_type)) {
75
WARN_PRINT(vformat("Trying to access a non-existing editor theme font '%s' in '%s'.", p_name, p_theme_type));
76
}
77
return ThemeDB::get_singleton()->get_fallback_font();
78
}
79
}
80
81
// Keep in sync with Theme::get_font_size.
82
int EditorTheme::get_font_size(const StringName &p_name, const StringName &p_theme_type) const {
83
if (font_size_map.has(p_theme_type) && font_size_map[p_theme_type].has(p_name) && (font_size_map[p_theme_type][p_name] > 0)) {
84
return font_size_map[p_theme_type][p_name];
85
} else if (has_default_font_size()) {
86
if (editor_theme_types.has(p_theme_type)) {
87
WARN_PRINT(vformat("Trying to access a non-existing editor theme font size '%s' in '%s'.", p_name, p_theme_type));
88
}
89
return default_font_size;
90
} else {
91
if (editor_theme_types.has(p_theme_type)) {
92
WARN_PRINT(vformat("Trying to access a non-existing editor theme font size '%s' in '%s'.", p_name, p_theme_type));
93
}
94
return ThemeDB::get_singleton()->get_fallback_font_size();
95
}
96
}
97
98
// Keep in sync with Theme::get_icon.
99
Ref<Texture2D> EditorTheme::get_icon(const StringName &p_name, const StringName &p_theme_type) const {
100
if (icon_map.has(p_theme_type) && icon_map[p_theme_type].has(p_name) && icon_map[p_theme_type][p_name].is_valid()) {
101
return icon_map[p_theme_type][p_name];
102
} else {
103
if (editor_theme_types.has(p_theme_type)) {
104
WARN_PRINT(vformat("Trying to access a non-existing editor theme icon '%s' in '%s'.", p_name, p_theme_type));
105
}
106
return ThemeDB::get_singleton()->get_fallback_icon();
107
}
108
}
109
110
// Keep in sync with Theme::get_stylebox.
111
Ref<StyleBox> EditorTheme::get_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
112
if (style_map.has(p_theme_type) && style_map[p_theme_type].has(p_name) && style_map[p_theme_type][p_name].is_valid()) {
113
return style_map[p_theme_type][p_name];
114
} else {
115
if (editor_theme_types.has(p_theme_type)) {
116
WARN_PRINT(vformat("Trying to access a non-existing editor theme stylebox '%s' in '%s'.", p_name, p_theme_type));
117
}
118
return ThemeDB::get_singleton()->get_fallback_stylebox();
119
}
120
}
121
122
void EditorTheme::initialize() {
123
editor_theme_types.append(EditorStringName(Editor));
124
editor_theme_types.append(EditorStringName(EditorFonts));
125
editor_theme_types.append(EditorStringName(EditorIcons));
126
editor_theme_types.append(EditorStringName(EditorStyles));
127
}
128
129
void EditorTheme::finalize() {
130
editor_theme_types.clear();
131
}
132
133