From 9be53e746f477e7612b7145eb397d415f773ffa5 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Wed, 21 Nov 2012 13:05:19 +0100 Subject: [PATCH] Allow canvas::Placements to have own properties --- simgear/canvas/Canvas.cxx | 16 ++++++++++++++++ simgear/canvas/Canvas.hxx | 4 ++-- simgear/canvas/CanvasPlacement.cxx | 22 +++++++++++++++++++++- simgear/canvas/CanvasPlacement.hxx | 12 +++++++++++- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/simgear/canvas/Canvas.cxx b/simgear/canvas/Canvas.cxx index 350fdf95..3112fcb3 100644 --- a/simgear/canvas/Canvas.cxx +++ b/simgear/canvas/Canvas.cxx @@ -18,6 +18,7 @@ #include "Canvas.hxx" #include +#include #include #include @@ -382,6 +383,21 @@ namespace canvas if( node->getParent()->getParent() == _node && node->getParent()->getNameString() == "placement" ) { + bool placement_dirty = false; + BOOST_FOREACH(Placements& placements, _placements) + { + BOOST_FOREACH(PlacementPtr& placement, placements) + { + // check if change can be directly handled by placement + if( placement->getProps() == node->getParent() + && !placement->childChanged(node) ) + placement_dirty = true; + } + } + + if( !placement_dirty ) + return; + // prevent double updates... for( size_t i = 0; i < _dirty_placements.size(); ++i ) { diff --git a/simgear/canvas/Canvas.hxx b/simgear/canvas/Canvas.hxx index 11c832c9..848908c3 100644 --- a/simgear/canvas/Canvas.hxx +++ b/simgear/canvas/Canvas.hxx @@ -159,12 +159,12 @@ namespace canvas bool _render_always; // _dirty_placements; - std::vector _placements; + std::vector _placements; std::set _dependent_canvases; // PlacementFactoryMap; + typedef std::map PlacementFactoryMap; static PlacementFactoryMap _placement_factories; virtual void setSelf(const PropertyBasedElementPtr& self); diff --git a/simgear/canvas/CanvasPlacement.cxx b/simgear/canvas/CanvasPlacement.cxx index 3024f302..1ff2a45f 100644 --- a/simgear/canvas/CanvasPlacement.cxx +++ b/simgear/canvas/CanvasPlacement.cxx @@ -17,6 +17,7 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA #include "CanvasPlacement.hxx" +#include namespace simgear { @@ -24,7 +25,8 @@ namespace canvas { //---------------------------------------------------------------------------- - Placement::Placement() + Placement::Placement(SGPropertyNode* node): + _node(node) { } @@ -35,5 +37,23 @@ namespace canvas } + //---------------------------------------------------------------------------- + SGConstPropertyNode_ptr Placement::getProps() const + { + return _node; + } + + //---------------------------------------------------------------------------- + SGPropertyNode_ptr Placement::getProps() + { + return _node; + } + + //---------------------------------------------------------------------------- + bool Placement::childChanged(SGPropertyNode* child) + { + return false; + } + } // namespace canvas } // namespace simgear diff --git a/simgear/canvas/CanvasPlacement.hxx b/simgear/canvas/CanvasPlacement.hxx index 05d85ba3..cda36795 100644 --- a/simgear/canvas/CanvasPlacement.hxx +++ b/simgear/canvas/CanvasPlacement.hxx @@ -19,6 +19,8 @@ #ifndef CANVAS_PLACEMENT_HXX_ #define CANVAS_PLACEMENT_HXX_ +#include + namespace simgear { namespace canvas @@ -27,9 +29,17 @@ namespace canvas class Placement { public: - Placement(); + Placement(SGPropertyNode* node); virtual ~Placement() = 0; + SGConstPropertyNode_ptr getProps() const; + SGPropertyNode_ptr getProps(); + + virtual bool childChanged(SGPropertyNode* child); + + protected: + SGPropertyNode_ptr _node; + private: Placement(const Placement&) /* = delete */; Placement& operator=(const Placement&) /* = delete */; -- 2.39.5