]> git.mxchange.org Git - flightgear.git/blob - src/Canvas/elements/element.hxx
Fix Win32 build, hopefully.
[flightgear.git] / src / Canvas / elements / element.hxx
1 // Interface for 2D canvas element
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 CANVAS_ELEMENT_HXX_
20 #define CANVAS_ELEMENT_HXX_
21
22 #include <simgear/props/props.hxx>
23 #include <osg/MatrixTransform>
24 #include <simgear/misc/stdint.hxx> // for uint32_t
25
26 namespace osg
27 {
28   class Drawable;
29 }
30
31 namespace canvas
32 {
33
34   class Element:
35     private SGPropertyChangeListener
36   {
37     public:
38       virtual ~Element() = 0;
39       SGPropertyNode* getPropertyNode();
40
41       /**
42        * Called every frame to update internal state
43        *
44        * @param dt  Frame time in seconds
45        */
46       virtual void update(double dt);
47
48       osg::ref_ptr<osg::MatrixTransform> getMatrixTransform();
49
50     protected:
51
52       enum Attributes
53       {
54         COLOR           = 0x0001,
55         COLOR_FILL      = 0x0002,
56         BOUNDING_BOX    = 0x0004
57       };
58
59       enum TransformType
60       {
61         TT_NONE,
62         TT_MATRIX,
63         TT_TRANSLATE,
64         TT_ROTATE,
65         TT_SCALE
66       };
67
68       SGPropertyNode *_node;
69       osg::Drawable  *_drawable;
70
71       uint32_t _attributes_used;
72       uint32_t _attributes_dirty;
73
74       bool _transform_dirty;
75       osg::ref_ptr<osg::MatrixTransform>    _transform;
76       std::vector<TransformType>            _transform_types;
77
78       SGPropertyNode    *_bounding_box[4]; ///<! x-min, y-min, x-max, y-max
79       SGPropertyNode    *_color[3];
80       SGPropertyNode    *_color_fill[3];
81
82       Element(SGPropertyNode* node, uint32_t attributes_used = 0);
83
84       virtual void childAdded(SGPropertyNode * child)  {}
85       virtual void childRemoved(SGPropertyNode * child){}
86       virtual void childChanged(SGPropertyNode * child){}
87
88       virtual void colorChanged(const osg::Vec4& color)  {}
89       virtual void colorFillChanged(const osg::Vec4& color){}
90
91       void linkColorNodes( const char* name,
92                            SGPropertyNode** nodes,
93                            const osg::Vec4& def = osg::Vec4(1,1,0,1) );
94
95     private:
96       Element(const Element&);// = delete
97
98       virtual void childAdded( SGPropertyNode * parent,
99                                SGPropertyNode * child );
100       virtual void childRemoved( SGPropertyNode * parent,
101                                  SGPropertyNode * child );
102       virtual void valueChanged(SGPropertyNode * child);
103   };
104
105 }  // namespace canvas
106
107 #endif /* CANVAS_ELEMENT_HXX_ */