]> git.mxchange.org Git - flightgear.git/blob - src/Canvas/canvas.hxx
Basic 2D canvas implementation.
[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     int _size_x,
77         _size_y,
78         _view_width,
79         _view_height;
80
81     int         _status;
82     std::string _status_msg;
83
84     FGODGauge       _texture;
85     SGPropertyNode *_node;
86
87     bool _sampling_dirty;
88
89     osg::ref_ptr<osg::NodeCallback> _camera_callback;
90     osg::ref_ptr<osg::NodeCallback> _cull_callback;
91     std::vector<SGPropertyNode*> _dirty_placements;
92     std::vector<Placements> _placements;
93
94     // TODO replace auto_ptr with unique_ptr as soon as C++11 is used!
95     std::vector<boost::shared_ptr<canvas::Group> > _groups;
96
97     void setStatusFlags(unsigned int flags, bool set = true);
98     void clearPlacements(int index);
99 };
100
101 #endif /* CANVAS_HXX_ */