]> git.mxchange.org Git - flightgear.git/blobdiff - src/Canvas/elements/map.cxx
Canvas: Support z-index inside Groups/Maps
[flightgear.git] / src / Canvas / elements / map.cxx
index 59a7d9bacfb55f8a1775cf2b6d0129a49ec1604d..503e815439304170e802dcdac74cc5f156cb8f15 100644 (file)
@@ -24,6 +24,8 @@
 #include <Main/fg_props.hxx>
 #include <cmath>
 
+#include <boost/algorithm/string/predicate.hpp>
+
 #define LOG_GEO_RET(msg) \
   {\
     SG_LOG\
 namespace canvas
 {
 
-  // TODO make projection configurable
-  SansonFlamsteedProjection projection;
   const std::string GEO = "-geo";
 
   //----------------------------------------------------------------------------
-  Map::Map(SGPropertyNode_ptr node):
-    Group(node),
+  Map::Map(SGPropertyNode_ptr node, const Style& parent_style):
+    Group(node, parent_style),
+    // TODO make projection configurable
+    _projection(new SansonFlamsteedProjection),
     _projection_dirty(true)
   {
 
@@ -78,7 +80,7 @@ namespace canvas
         continue;
 
       Projection::ScreenPosition pos =
-        projection.worldToScreen(lat.value, lon.value);
+        _projection->worldToScreen(lat.value, lon.value);
 
       geo_node->setScreenPos(pos.x, pos.y);
 
@@ -93,7 +95,7 @@ namespace canvas
   //----------------------------------------------------------------------------
   void Map::childAdded(SGPropertyNode* parent, SGPropertyNode* child)
   {
-    if( !hasSuffix(child->getNameString(), GEO) )
+    if( !boost::ends_with(child->getNameString(), GEO) )
       return Element::childAdded(parent, child);
 
     _geo_nodes[child].reset(new GeoNodePair());
@@ -102,7 +104,7 @@ namespace canvas
   //----------------------------------------------------------------------------
   void Map::childRemoved(SGPropertyNode* parent, SGPropertyNode* child)
   {
-    if( !hasSuffix(child->getNameString(), GEO) )
+    if( !boost::ends_with(child->getNameString(), GEO) )
       return Element::childRemoved(parent, child);
 
     // TODO remove from other node
@@ -114,7 +116,7 @@ namespace canvas
   {
     const std::string& name = child->getNameString();
 
-    if( !hasSuffix(name, GEO) )
+    if( !boost::ends_with(name, GEO) )
       return Group::valueChanged(child);
 
     GeoNodes::iterator it_geo_node = _geo_nodes.find(child);
@@ -175,16 +177,19 @@ namespace canvas
   //----------------------------------------------------------------------------
   void Map::childChanged(SGPropertyNode * child)
   {
+    if( child->getParent() != _node )
+      return Group::childChanged(child);
+
     if(    child->getNameString() == "ref-lat"
         || child->getNameString() == "ref-lon" )
-      projection.setWorldPosition( _node->getDoubleValue("ref-lat"),
-                                   _node->getDoubleValue("ref-lon") );
+      _projection->setWorldPosition( _node->getDoubleValue("ref-lat"),
+                                     _node->getDoubleValue("ref-lon") );
     else if( child->getNameString() == "hdg" )
-      projection.setOrientation(child->getFloatValue());
+      _projection->setOrientation(child->getFloatValue());
     else if( child->getNameString() == "range" )
-      projection.setRange(child->getDoubleValue());
+      _projection->setRange(child->getDoubleValue());
     else
-      return;
+      return Group::childChanged(child);
 
     _projection_dirty = true;
   }
@@ -218,15 +223,4 @@ namespace canvas
     return coord;
   }
 
-  //----------------------------------------------------------------------------
-  bool Map::hasSuffix(const std::string& str, const std::string& suffix) const
-  {
-    if( suffix.length() > str.length() )
-      return false;
-
-    return ( str.compare( str.length() - suffix.length(),
-                          suffix.length(),
-                          suffix ) == 0 );
-  }
-
 } // namespace canvas