forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigVariableColor.I
More file actions
165 lines (151 loc) · 4.65 KB
/
configVariableColor.I
File metadata and controls
165 lines (151 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file configVariableColor.I
* @author rdb
* @date 2014-02-02
*/
/**
*
*/
INLINE ConfigVariableColor::
ConfigVariableColor(const std::string &name) :
ConfigVariable(name, VT_color),
_local_modified(initial_invalid_cache()),
_cache(0, 0, 0, 1)
{
_core->set_used();
}
/**
*
*/
INLINE ConfigVariableColor::
ConfigVariableColor(const std::string &name, const LColor &default_value,
const std::string &description, int flags) :
#ifdef PRC_SAVE_DESCRIPTIONS
ConfigVariable(name, ConfigVariableCore::VT_color, description, flags),
#else
ConfigVariable(name, ConfigVariableCore::VT_color, std::string(), flags),
#endif
_local_modified(initial_invalid_cache()),
_cache(0, 0, 0, 1)
{
set_default_value(default_value);
_core->set_used();
}
/**
*
*/
INLINE ConfigVariableColor::
ConfigVariableColor(const std::string &name, const std::string &default_value,
const std::string &description, int flags) :
#ifdef PRC_SAVE_DESCRIPTIONS
ConfigVariable(name, ConfigVariableCore::VT_color, description, flags),
#else
ConfigVariable(name, ConfigVariableCore::VT_color, std::string(), flags),
#endif
_local_modified(initial_invalid_cache()),
_cache(0, 0, 0, 1)
{
_core->set_default_value(default_value);
_core->set_used();
}
/**
* Reassigns the variable's local value.
*/
INLINE void ConfigVariableColor::
operator = (const LColor &value) {
set_value(value);
}
/**
* Returns the variable's value.
*/
INLINE ConfigVariableColor::
operator const LColor & () const {
return get_value();
}
/**
* Returns the value of the color's nth component (which is not necessarily
* the same thing as the variable's nth word).
*/
INLINE PN_stdfloat ConfigVariableColor::
operator [] (int n) const {
return get_value()[n];
}
/**
* Reassigns the variable's local value.
*/
INLINE void ConfigVariableColor::
set_value(const LColor &color) {
set_string_value("");
set_double_word(0, color[0]);
set_double_word(1, color[1]);
set_double_word(2, color[2]);
set_double_word(3, color[3]);
}
/**
* Returns the variable's value.
*/
INLINE const LColor &ConfigVariableColor::
get_value() const {
TAU_PROFILE("const LColor &ConfigVariableColor::get_value() const", " ", TAU_USER);
if (!is_cache_valid(_local_modified)) {
mark_cache_valid(_local_modified);
switch (get_num_words()) {
case 1:
_cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(0),
(PN_stdfloat)get_double_word(0), 1);
break;
case 2:
_cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(0),
(PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(1));
break;
case 3:
_cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(1),
(PN_stdfloat)get_double_word(2), 1);
break;
case 4:
_cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(1),
(PN_stdfloat)get_double_word(2), (PN_stdfloat)get_double_word(3));
break;
default:
prc_cat->warning()
<< "Invalid color value for ConfigVariable "
<< get_name() << ": " << get_string_value() << "\n";
}
}
return _cache;
}
/**
* Returns the variable's default value.
*/
INLINE LColor ConfigVariableColor::
get_default_value() const {
const ConfigDeclaration *decl = ConfigVariable::get_default_value();
if (decl != nullptr) {
switch (decl->get_num_words()) {
case 1:
return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(0),
(PN_stdfloat)decl->get_double_word(0), 1);
case 2:
return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(0),
(PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(1));
case 3:
return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(1),
(PN_stdfloat)decl->get_double_word(2), 1);
case 4:
return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(1),
(PN_stdfloat)decl->get_double_word(2), (PN_stdfloat)decl->get_double_word(3));
default:
prc_cat->warning()
<< "Invalid default color value for ConfigVariable "
<< get_name() << ": " << decl->get_string_value() << "\n";
}
}
return LColor(0, 0, 0, 1);
}