]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/CanvasEvent.cxx
Canvas: base Elements/Canvas on SGWeakReferenced.
[simgear.git] / simgear / canvas / CanvasEvent.cxx
index 36b73ecf313919b00af9f99f1b69dbe43bb72f38..414d19938eb775485f3510fa6ec97e829084b2b5 100644 (file)
@@ -1,4 +1,4 @@
-// Canvas Event for event model similar to DOM Level 2 Event Model
+// Canvas Event for event model similar to DOM Level 3 Event Model
 //
 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
 //
@@ -25,7 +25,14 @@ namespace canvas
 
   //----------------------------------------------------------------------------
   Event::Event():
-    type(UNKNOWN)
+    type(UNKNOWN),
+    propagation_stopped(false)
+  {
+
+  }
+
+  //----------------------------------------------------------------------------
+  Event::~Event()
   {
 
   }
@@ -55,5 +62,43 @@ namespace canvas
     return target;
   }
 
+  //----------------------------------------------------------------------------
+  ElementWeakPtr Event::getCurrentTarget() const
+  {
+    return current_target;
+  }
+
+  //----------------------------------------------------------------------------
+  double Event::getTime() const
+  {
+    return time;
+  }
+
+  //----------------------------------------------------------------------------
+  void Event::stopPropagation()
+  {
+    propagation_stopped = true;
+  }
+
+  //----------------------------------------------------------------------------
+  Event::Type Event::strToType(const std::string& str)
+  {
+    typedef std::map<std::string, Type> TypeMap;
+    static TypeMap type_map;
+
+    if( type_map.empty() )
+    {
+#     define ENUM_MAPPING(type, str) type_map[ str ] = type;
+#       include "CanvasEventTypes.hxx"
+#     undef ENUM_MAPPING
+    }
+
+    TypeMap::const_iterator it = type_map.find(str);
+    if( it == type_map.end() )
+      return UNKNOWN;
+
+    return it->second;
+  }
+
 } // namespace canvas
 } // namespace simgear