Panda3D
 All Classes Functions Variables Enumerations
configVariableColor.I
1 // Filename: configVariableColor.I
2 // Created by: rdb (02Feb14)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: ConfigVariableColor::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ConfigVariableColor::
22 ConfigVariableColor(const string &name) :
23  ConfigVariable(name, VT_color),
24  _local_modified(initial_invalid_cache()),
25  _cache(0, 0, 0, 1)
26 {
27  _core->set_used();
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: ConfigVariableColor::Constructor
32 // Access: Published
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 INLINE ConfigVariableColor::
36 ConfigVariableColor(const string &name, const LColor &default_value,
37  const string &description, int flags) :
38 #ifdef PRC_SAVE_DESCRIPTIONS
39  ConfigVariable(name, ConfigVariableCore::VT_color, description, flags),
40 #else
41  ConfigVariable(name, ConfigVariableCore::VT_color, string(), flags),
42 #endif
43  _local_modified(initial_invalid_cache()),
44  _cache(0, 0, 0, 1)
45 {
46  set_default_value(default_value);
47  _core->set_used();
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: ConfigVariableColor::Constructor
52 // Access: Published
53 // Description:
54 ////////////////////////////////////////////////////////////////////
55 INLINE ConfigVariableColor::
56 ConfigVariableColor(const string &name, const string &default_value,
57  const string &description, int flags) :
58 #ifdef PRC_SAVE_DESCRIPTIONS
59  ConfigVariable(name, ConfigVariableCore::VT_color, description, flags),
60 #else
61  ConfigVariable(name, ConfigVariableCore::VT_color, string(), flags),
62 #endif
63  _local_modified(initial_invalid_cache()),
64  _cache(0, 0, 0, 1)
65 {
66  _core->set_default_value(default_value);
67  _core->set_used();
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: ConfigVariableColor::operator =
72 // Access: Published
73 // Description: Reassigns the variable's local value.
74 ////////////////////////////////////////////////////////////////////
75 INLINE void ConfigVariableColor::
76 operator = (const LColor &value) {
77  set_value(value);
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: ConfigVariableColor::typecast operator
82 // Access: Published
83 // Description: Returns the variable's value.
84 ////////////////////////////////////////////////////////////////////
85 INLINE ConfigVariableColor::
86 operator const LColor & () const {
87  return get_value();
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function: ConfigVariableColor::operator []
92 // Access: Published
93 // Description: Returns the value of the color's nth component
94 // (which is not necessarily the same thing as the
95 // variable's nth word).
96 ////////////////////////////////////////////////////////////////////
97 INLINE PN_stdfloat ConfigVariableColor::
98 operator [] (int n) const {
99  return get_value()[n];
100 }
101 
102 ////////////////////////////////////////////////////////////////////
103 // Function: ConfigVariableColor::set_value
104 // Access: Published
105 // Description: Reassigns the variable's local value.
106 ////////////////////////////////////////////////////////////////////
107 INLINE void ConfigVariableColor::
109  set_string_value("");
110  set_double_word(0, color[0]);
111  set_double_word(1, color[1]);
112  set_double_word(2, color[2]);
113  set_double_word(3, color[3]);
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: ConfigVariableColor::get_value
118 // Access: Published
119 // Description: Returns the variable's value.
120 ////////////////////////////////////////////////////////////////////
121 INLINE const LColor &ConfigVariableColor::
122 get_value() const {
123  TAU_PROFILE("const LColor &ConfigVariableColor::get_value() const", " ", TAU_USER);
124  if (!is_cache_valid(_local_modified)) {
125  mark_cache_valid(_local_modified);
126 
127  switch (get_num_words()) {
128  case 1:
129  _cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(0),
130  (PN_stdfloat)get_double_word(0), 1);
131  break;
132 
133  case 2:
134  _cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(0),
135  (PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(1));
136  break;
137 
138  case 3:
139  _cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(1),
140  (PN_stdfloat)get_double_word(2), 1);
141  break;
142 
143  case 4:
144  _cache.set((PN_stdfloat)get_double_word(0), (PN_stdfloat)get_double_word(1),
145  (PN_stdfloat)get_double_word(2), (PN_stdfloat)get_double_word(3));
146  break;
147 
148  default:
149  prc_cat->warning()
150  << "Invalid color value for ConfigVariable "
151  << get_name() << ": " << get_string_value() << "\n";
152  }
153  }
154  return _cache;
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: ConfigVariableColor::get_default_value
159 // Access: Published
160 // Description: Returns the variable's default value.
161 ////////////////////////////////////////////////////////////////////
165  if (decl != (ConfigDeclaration *)NULL) {
166  switch (decl->get_num_words()) {
167  case 1:
168  return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(0),
169  (PN_stdfloat)decl->get_double_word(0), 1);
170  case 2:
171  return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(0),
172  (PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(1));
173  case 3:
174  return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(1),
175  (PN_stdfloat)decl->get_double_word(2), 1);
176  case 4:
177  return LColor((PN_stdfloat)decl->get_double_word(0), (PN_stdfloat)decl->get_double_word(1),
178  (PN_stdfloat)decl->get_double_word(2), (PN_stdfloat)decl->get_double_word(3));
179  default:
180  prc_cat->warning()
181  << "Invalid default color value for ConfigVariable "
182  << get_name() << ": " << decl->get_string_value() << "\n";
183  }
184  }
185  return LColor(0, 0, 0, 1);
186 }
The internal definition of a ConfigVariable.
void set_value(const LColor &value)
Reassigns the variable&#39;s local value.
int get_num_words() const
Returns the number of words in the variable&#39;s value.
void operator=(const LColor &value)
Reassigns the variable&#39;s local value.
const string & get_string_value() const
Returns the value assigned to this variable.
LColor get_default_value() const
Returns the variable&#39;s default value.
void set_double_word(int n, double value)
Changes the nth word to the indicated value without affecting the other words.
const string & get_string_value() const
Returns the toplevel value of the variable, formatted as a string.
int get_num_words() const
Returns the number of words in the declaration&#39;s value.
double get_double_word(int n) const
Returns the integer value of the nth word of the declaration&#39;s value, or 0 if there is no nth value...
const ConfigDeclaration * get_default_value() const
Returns the default variable specified for this variable.
double get_double_word(int n) const
Returns the integer value of the nth word of the variable&#39;s value, or 0 if there is no nth value...
This is a generic, untyped ConfigVariable.
const LColor & get_value() const
Returns the variable&#39;s value.
const string & get_name() const
Returns the name of the variable.
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
void set_string_value(const string &value)
Changes the value assigned to this variable.
A single declaration of a config variable, typically defined as one line in a .prc file...
PN_stdfloat operator[](int n) const
Returns the value of the color&#39;s nth component (which is not necessarily the same thing as the variab...