]> git.mxchange.org Git - flightgear.git/blob - src/Canvas/canvas.hxx
9094825d453ed1d7391762003eb39754826492c8
[flightgear.git] / src / Canvas / canvas.hxx
1 // The canvas for rendering with the 2d api
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_HXX_
20 #define CANVAS_HXX_
21
22 #include <Instrumentation/od_gauge.hxx>
23 #include <simgear/props/props.hxx>
24 #include <osg/NodeCallback>
25
26 #include <boost/shared_ptr.hpp>
27 #include <string>
28
29 namespace canvas
30 {
31   class Group;
32 }
33
34 class Canvas:
35   public SGPropertyChangeListener
36 {
37   public:
38
39     enum StatusFlags
40     {
41       STATUS_OK,
42       MISSING_SIZE_X = 0x0001,
43       MISSING_SIZE_Y = 0x0002,
44       CREATE_FAILED  = 0x0004
45     };
46
47     Canvas();
48     virtual ~Canvas();
49
50     void reset(SGPropertyNode* node);
51     void update(double delta_time_sec);
52
53     void setSizeX(int sx);
54     int getSizeX() const;
55
56     void setSizeY(int sy);
57     int getSizeY() const;
58
59     void setViewWidth(int w);
60     int getViewWidth() const;
61
62     void setViewHeight(int h);
63     int getViewHeight() const;
64
65     int getStatus() const;
66     const char* getStatusMsg() const;
67
68     virtual void childAdded( SGPropertyNode * parent,
69                              SGPropertyNode * child );
70     virtual void childRemoved( SGPropertyNode * parent,
71                                SGPropertyNode * child );
72     virtual void valueChanged (SGPropertyNode * node);
73
74   private:
75
76     Canvas(const Canvas&); // = delete;
77     Canvas& operator=(const Canvas&); // = delete;
78
79     int _size_x,
80         _size_y,
81         _view_width,
82         _view_height;
83
84     int         _status;
85     std::string _status_msg;
86
87     bool _sampling_dirty,
88          _color_dirty;
89
90     FGODGauge _texture;
91
92     SGPropertyNode_ptr              _node;
93     std::vector<SGPropertyNode_ptr> _color_background;
94
95     osg::ref_ptr<osg::NodeCallback> _camera_callback;
96     osg::ref_ptr<osg::NodeCallback> _cull_callback;
97     std::vector<SGPropertyNode*> _dirty_placements;
98     std::vector<Placements> _placements;
99
100     // TODO replace auto_ptr with unique_ptr as soon as C++11 is used!
101     std::vector<boost::shared_ptr<canvas::Group> > _groups;
102
103     void setStatusFlags(unsigned int flags, bool set = true);
104     void clearPlacements(int index);
105     void clearPlacements();
106
107     void unbind();
108 };
109
110 #endif /* CANVAS_HXX_ */