]> git.mxchange.org Git - flightgear.git/blob - src/Canvas/canvas.hxx
Canvas: Allow using canvases as PUI widgets.
[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 <memory>
27 #include <string>
28
29 namespace canvas
30 {
31   class Group;
32 }
33
34 class CameraCullCallback;
35 class Canvas:
36   public SGPropertyChangeListener
37 {
38   public:
39
40     enum StatusFlags
41     {
42       STATUS_OK,
43       MISSING_SIZE_X = 0x0001,
44       MISSING_SIZE_Y = 0x0002,
45       CREATE_FAILED  = 0x0004
46     };
47
48     Canvas();
49     virtual ~Canvas();
50
51     void reset(SGPropertyNode* node);
52     void update(double delta_time_sec);
53
54     void setSizeX(int sx);
55     int getSizeX() const;
56
57     void setSizeY(int sy);
58     int getSizeY() const;
59
60     void setViewWidth(int w);
61     int getViewWidth() const;
62
63     void setViewHeight(int h);
64     int getViewHeight() const;
65
66     int getStatus() const;
67     const char* getStatusMsg() const;
68
69     virtual void childAdded( SGPropertyNode * parent,
70                              SGPropertyNode * child );
71     virtual void childRemoved( SGPropertyNode * parent,
72                                SGPropertyNode * child );
73     virtual void valueChanged (SGPropertyNode * node);
74
75     GLuint getTexId() const;
76
77   private:
78
79     Canvas(const Canvas&); // = delete;
80     Canvas& operator=(const Canvas&); // = delete;
81
82     int _size_x,
83         _size_y,
84         _view_width,
85         _view_height;
86
87     int         _status;
88     std::string _status_msg;
89
90     bool _sampling_dirty,
91          _color_dirty;
92
93     FGODGauge _texture;
94     std::auto_ptr<canvas::Group> _root_group;
95
96     SGPropertyNode_ptr              _node;
97     std::vector<SGPropertyNode_ptr> _color_background;
98
99     osg::ref_ptr<CameraCullCallback> _camera_callback;
100     osg::ref_ptr<osg::NodeCallback> _cull_callback;
101
102     bool _render_always; //<! Used to disable automatic lazy rendering (culling)
103
104     std::vector<SGPropertyNode*> _dirty_placements;
105     std::vector<Placements> _placements;
106
107     void setStatusFlags(unsigned int flags, bool set = true);
108     void clearPlacements(int index);
109     void clearPlacements();
110
111     void unbind();
112 };
113
114 #endif /* CANVAS_HXX_ */