1 // The canvas for rendering with the 2d API
3 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "canvas_fwd.hxx"
23 #include "ODGauge.hxx"
25 #include <simgear/canvas/elements/CanvasGroup.hxx>
26 #include <simgear/props/PropertyBasedElement.hxx>
27 #include <simgear/props/propertyObject.hxx>
28 #include <osg/NodeCallback>
29 #include <osg/observer_ptr>
42 public PropertyBasedElement
49 MISSING_SIZE_X = 0x0001,
50 MISSING_SIZE_Y = 0x0002,
51 CREATE_FAILED = 0x0004
55 * This callback is installed on every placement of the canvas in the
56 * scene to only render the canvas if at least one placement is visible
59 public osg::NodeCallback
62 CullCallback(const CanvasWeakPtr& canvas);
65 CanvasWeakPtr _canvas;
67 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
69 typedef osg::ref_ptr<CullCallback> CullCallbackPtr;
71 Canvas(SGPropertyNode* node);
74 void setSystemAdapter(const SystemAdapterPtr& system_adapter);
75 SystemAdapterPtr getSystemAdapter() const;
77 void setCanvasMgr(CanvasMgr* canvas_mgr);
78 CanvasMgr* getCanvasMgr() const;
81 * Add a canvas which should be mared as dirty upon any change to this
84 * This mechanism is used to eg. redraw a canvas if it's displaying
85 * another canvas (recursive canvases)
87 void addDependentCanvas(const CanvasWeakPtr& canvas);
90 * Stop notifying the given canvas upon changes
92 void removeDependentCanvas(const CanvasWeakPtr& canvas);
94 GroupPtr createGroup(const std::string& name = "");
97 * Enable rendering for the next frame
99 * @param force Force redraw even if nothing has changed (if dirty flag
102 void enableRendering(bool force = false);
104 void update(double delta_time_sec);
106 void setSizeX(int sx);
107 void setSizeY(int sy);
109 int getSizeX() const;
110 int getSizeY() const;
112 void setViewWidth(int w);
113 void setViewHeight(int h);
115 bool handleMouseEvent(const MouseEvent& event);
117 virtual void childAdded( SGPropertyNode * parent,
118 SGPropertyNode * child );
119 virtual void childRemoved( SGPropertyNode * parent,
120 SGPropertyNode * child );
121 virtual void valueChanged (SGPropertyNode * node);
123 osg::Texture2D* getTexture() const;
125 CullCallbackPtr getCullCallback() const;
127 static void addPlacementFactory( const std::string& type,
128 PlacementFactory factory );
132 SystemAdapterPtr _system_adapter;
133 CanvasMgr *_canvas_mgr;
140 PropertyObject<int> _status;
141 PropertyObject<std::string> _status_msg;
143 PropertyObject<int> _mouse_x, _mouse_y,
144 _mouse_dx, _mouse_dy,
151 bool _sampling_dirty,
156 std::auto_ptr<Group> _root_group;
158 CullCallbackPtr _cull_callback;
159 bool _render_always; //<! Used to disable automatic lazy rendering (culling)
161 std::vector<SGPropertyNode*> _dirty_placements;
162 std::vector<Placements> _placements;
163 std::set<CanvasWeakPtr> _dependent_canvases; //<! Canvases which use this
164 // canvas and should be
165 // notified about changes
167 typedef std::map<std::string, PlacementFactory> PlacementFactoryMap;
168 static PlacementFactoryMap _placement_factories;
170 virtual void setSelf(const PropertyBasedElementPtr& self);
171 void setStatusFlags(unsigned int flags, bool set = true);
175 Canvas(const Canvas&); // = delete;
176 Canvas& operator=(const Canvas&); // = delete;
179 } // namespace canvas
180 } // namespace simgear
182 #endif /* CANVAS_HXX_ */