X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCanvas%2Fcanvas.hxx;h=2071452997cb88364f9c091a5523b4dd274df985;hb=4994973ef4d5a079acf76267b525313c15376478;hp=9094825d453ed1d7391762003eb39754826492c8;hpb=1575fad886a0b18825363d41d53a287e8d36b9c8;p=flightgear.git diff --git a/src/Canvas/canvas.hxx b/src/Canvas/canvas.hxx index 9094825d4..207145299 100644 --- a/src/Canvas/canvas.hxx +++ b/src/Canvas/canvas.hxx @@ -19,20 +19,21 @@ #ifndef CANVAS_HXX_ #define CANVAS_HXX_ -#include -#include +#include "placement.hxx" +#include "property_based_element.hxx" + +#include +#include + +#include #include +#include -#include +#include #include -namespace canvas -{ - class Group; -} - class Canvas: - public SGPropertyChangeListener + public PropertyBasedElement { public: @@ -44,26 +45,70 @@ class Canvas: CREATE_FAILED = 0x0004 }; - Canvas(); + /** + * Callback used to disable/enable rendering to the texture if it is not + * visible + */ + class CameraCullCallback: + public osg::NodeCallback + { + public: + CameraCullCallback(); + + /** + * Enable rendering for the next frame + */ + void enableRendering(); + + private: + bool _render; + unsigned int _render_frame; + + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); + }; + typedef osg::ref_ptr CameraCullCallbackPtr; + typedef osg::observer_ptr CameraCullCallbackWeakPtr; + + /** + * This callback is installed on every placement of the canvas in the + * scene to only render the canvas if at least one placement is visible + */ + class CullCallback: + public osg::NodeCallback + { + public: + CullCallback(CameraCullCallback* camera_cull); + + private: + CameraCullCallbackWeakPtr _camera_cull; + + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); + }; + typedef osg::ref_ptr CullCallbackPtr; + + /** + * Callback for resetting the render_dirty flag after rendering a frame. + */ + class DrawCallback; + + Canvas(SGPropertyNode* node); virtual ~Canvas(); - void reset(SGPropertyNode* node); void update(double delta_time_sec); - void setSizeX(int sx); - int getSizeX() const; + int getSizeX() const + { return _size_x; } + int getSizeY() const + { return _size_y; } + + void setSizeX(int sx); void setSizeY(int sy); - int getSizeY() const; void setViewWidth(int w); - int getViewWidth() const; - void setViewHeight(int h); - int getViewHeight() const; - int getStatus() const; - const char* getStatusMsg() const; + bool handleMouseEvent(const canvas::MouseEvent& event); virtual void childAdded( SGPropertyNode * parent, SGPropertyNode * child ); @@ -71,6 +116,15 @@ class Canvas: SGPropertyNode * child ); virtual void valueChanged (SGPropertyNode * node); + osg::Texture2D* getTexture() const; + GLuint getTexId() const; + + CameraCullCallbackPtr getCameraCullCallback() const; + CullCallbackPtr getCullCallback() const; + + static void addPlacementFactory( const std::string& type, + canvas::PlacementFactory factory ); + private: Canvas(const Canvas&); // = delete; @@ -81,30 +135,37 @@ class Canvas: _view_width, _view_height; - int _status; - std::string _status_msg; + simgear::PropertyObject _status; + simgear::PropertyObject _status_msg; + + simgear::PropertyObject _mouse_x, _mouse_y, + _mouse_dx, _mouse_dy, + _mouse_button, + _mouse_state, + _mouse_mod, + _mouse_scroll, + _mouse_event; bool _sampling_dirty, - _color_dirty; + _color_dirty, + _render_dirty; FGODGauge _texture; + std::auto_ptr _root_group; - SGPropertyNode_ptr _node; std::vector _color_background; - osg::ref_ptr _camera_callback; - osg::ref_ptr _cull_callback; + CameraCullCallbackPtr _camera_callback; + CullCallbackPtr _cull_callback; + bool _render_always; // _dirty_placements; - std::vector _placements; + std::vector _placements; - // TODO replace auto_ptr with unique_ptr as soon as C++11 is used! - std::vector > _groups; + typedef std::map PlacementFactoryMap; + static PlacementFactoryMap _placement_factories; void setStatusFlags(unsigned int flags, bool set = true); - void clearPlacements(int index); - void clearPlacements(); - - void unbind(); }; #endif /* CANVAS_HXX_ */