]> git.mxchange.org Git - flightgear.git/blob - src/Canvas/elements/element.hxx
Canvas: Forward mouse events to elements.
[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 MouseEvent;
35   class Element:
36     public SGPropertyChangeListener
37   {
38     public:
39       virtual ~Element() = 0;
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       virtual bool handleMouseEvent(const canvas::MouseEvent& event);
49
50       osg::ref_ptr<osg::MatrixTransform> getMatrixTransform();
51
52       virtual void childAdded( SGPropertyNode * parent,
53                                SGPropertyNode * child );
54       virtual void childRemoved( SGPropertyNode * parent,
55                                  SGPropertyNode * child );
56       virtual void valueChanged(SGPropertyNode * child);
57
58     protected:
59
60       enum Attributes
61       {
62         COLOR           = 0x0001,
63         COLOR_FILL      = 0x0002,
64         BOUNDING_BOX    = 0x0004,
65         LAST_ATTRIBUTE  = BOUNDING_BOX
66       };
67
68       enum TransformType
69       {
70         TT_NONE,
71         TT_MATRIX,
72         TT_TRANSLATE,
73         TT_ROTATE,
74         TT_SCALE
75       };
76
77       uint32_t _attributes_used;
78       uint32_t _attributes_dirty;
79
80       bool _transform_dirty;
81       osg::ref_ptr<osg::MatrixTransform>    _transform;
82       std::vector<TransformType>            _transform_types;
83
84       SGPropertyNode_ptr                _node;
85       std::vector<SGPropertyNode_ptr>   _color,
86                                         _color_fill;
87       std::vector<SGPropertyNode_ptr>   _bounding_box;
88
89       Element(SGPropertyNode_ptr node, uint32_t attributes_used = 0);
90
91       virtual bool handleLocalMouseEvent(const canvas::MouseEvent& event);
92
93       virtual void childAdded(SGPropertyNode * child)  {}
94       virtual void childRemoved(SGPropertyNode * child){}
95       virtual void childChanged(SGPropertyNode * child){}
96
97       virtual void colorChanged(const osg::Vec4& color)  {}
98       virtual void colorFillChanged(const osg::Vec4& color){}
99
100       void setDrawable( osg::Drawable* drawable );
101
102     private:
103
104       osg::Drawable  *_drawable;
105
106       Element(const Element&);// = delete
107   };
108
109 }  // namespace canvas
110
111 #endif /* CANVAS_ELEMENT_HXX_ */