]> git.mxchange.org Git - flightgear.git/blob - src/Canvas/property_helper.hxx
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / Canvas / property_helper.hxx
1 // Some helper functions for accessing the property tree
2 //
3 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19 #ifndef PROPERTY_HELPER_HXX_
20 #define PROPERTY_HELPER_HXX_
21
22 #include <simgear/props/props.hxx>
23 #include <osg/Vec4>
24
25 namespace canvas
26 {
27
28   /**
29    * Get property node with default value
30    */
31   template<typename T>
32   SGPropertyNode* getChildDefault( SGPropertyNode* parent,
33                                    const char* name,
34                                    T def_val )
35   {
36     SGPropertyNode* node = parent->getNode(name);
37     if( node )
38       // also set value for existing nodes to enforce type...
39       def_val = getValue<T>(node);
40     else
41       node = parent->getChild(name, 0, true);
42
43     setValue(node, def_val);
44     return node;
45   }
46
47   /**
48    * @param name    Name of color node
49    * @param parent  Parent for color channel nodes
50    * @param nodes   Vector to push color nodes into
51    * @param def     Default color
52    *
53    * <name>
54    *   <red type="float">def[0] or existing value</red>
55    *   <green type="float">def[1] or existing value</green>
56    *   <blue type="float">def[2] or existing value</blue>
57    *   <alpha type="float">def[3] or existing value</alpha>
58    * </name>
59    */
60   void linkColorNodes( const char* name,
61                        SGPropertyNode* parent,
62                        std::vector<SGPropertyNode_ptr>& nodes,
63                        const osg::Vec4& def = osg::Vec4(0,0,0,0) );
64
65 } // namespace canvas
66
67 #endif /* PROPERTY_HELPER_HXX_ */