X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fcanvas%2FCanvasEvent.cxx;h=6c2684bc47ef724fc545b2557059d426bd6a9503;hb=d3a14bfd612efa7c7e2dda444bfc85fdbf2ebbcf;hp=36b73ecf313919b00af9f99f1b69dbe43bb72f38;hpb=77946585b1c9b54c4848b604eb1549e2ec55df12;p=simgear.git diff --git a/simgear/canvas/CanvasEvent.cxx b/simgear/canvas/CanvasEvent.cxx index 36b73ecf..6c2684bc 100644 --- a/simgear/canvas/CanvasEvent.cxx +++ b/simgear/canvas/CanvasEvent.cxx @@ -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 // @@ -25,13 +25,27 @@ namespace canvas //---------------------------------------------------------------------------- Event::Event(): - type(UNKNOWN) + type(UNKNOWN), + time(-1), + propagation_stopped(false) { } //---------------------------------------------------------------------------- - Event::Type Event::getType() const + Event::~Event() + { + + } + + //---------------------------------------------------------------------------- + bool Event::canBubble() const + { + return true; + } + + //---------------------------------------------------------------------------- + int Event::getType() const { return type; } @@ -39,14 +53,7 @@ namespace canvas //---------------------------------------------------------------------------- std::string Event::getTypeString() const { - switch( type ) - { -# define ENUM_MAPPING(name, str) case name: return str; -# include "CanvasEventTypes.hxx" -# undef ENUM_MAPPING - default: - return "unknown"; - } + return typeToStr(type); } //---------------------------------------------------------------------------- @@ -55,5 +62,77 @@ namespace canvas return target; } + //---------------------------------------------------------------------------- + ElementWeakPtr Event::getCurrentTarget() const + { + return current_target; + } + + //---------------------------------------------------------------------------- + double Event::getTime() const + { + return time; + } + + //---------------------------------------------------------------------------- + void Event::stopPropagation() + { + propagation_stopped = true; + } + + //---------------------------------------------------------------------------- + int Event::getOrRegisterType(const std::string& type_str) + { + int type = strToType(type_str); + + if( type == UNKNOWN ) + { + // Register new type + TypeMap& type_map = getTypeMap(); + type = type_map.size() + 1; // ids start with 1 (after UNKNOWN) + type_map.insert(TypeMap::value_type(type_str, type)); + } + + return type; + } + + //---------------------------------------------------------------------------- + int Event::strToType(const std::string& str) + { + TypeMap const& type_map = getTypeMap(); + + TypeMap::map_by::const_iterator it = type_map.by().find(str); + if( it == type_map.by().end() ) + return UNKNOWN; + return it->second; + } + + //---------------------------------------------------------------------------- + std::string Event::typeToStr(int type) + { + TypeMap const& type_map = getTypeMap(); + + TypeMap::map_by::const_iterator it = type_map.by().find(type); + if( it == type_map.by().end() ) + return "unknown"; + return it->second; + } + + //---------------------------------------------------------------------------- + Event::TypeMap& Event::getTypeMap() + { + static TypeMap type_map; + + if( type_map.empty() ) + { +# define ENUM_MAPPING(type, str)\ + type_map.insert(TypeMap::value_type(str, type)); +# include "CanvasEventTypes.hxx" +# undef ENUM_MAPPING + } + + return type_map; + } + } // namespace canvas } // namespace simgear