X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fcanvas%2FCanvasEvent.cxx;h=6c2684bc47ef724fc545b2557059d426bd6a9503;hb=d3a14bfd612efa7c7e2dda444bfc85fdbf2ebbcf;hp=1e9815e8bb0d1c2207c9bf22d1810679ae7f306f;hpb=46442ef50c5a2b7c8e41e5c025f86c1cd35e6e15;p=simgear.git diff --git a/simgear/canvas/CanvasEvent.cxx b/simgear/canvas/CanvasEvent.cxx index 1e9815e8..6c2684bc 100644 --- a/simgear/canvas/CanvasEvent.cxx +++ b/simgear/canvas/CanvasEvent.cxx @@ -26,6 +26,7 @@ namespace canvas //---------------------------------------------------------------------------- Event::Event(): type(UNKNOWN), + time(-1), propagation_stopped(false) { @@ -38,7 +39,13 @@ namespace canvas } //---------------------------------------------------------------------------- - Event::Type Event::getType() const + bool Event::canBubble() const + { + return true; + } + + //---------------------------------------------------------------------------- + int Event::getType() const { return type; } @@ -46,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); } //---------------------------------------------------------------------------- @@ -62,6 +62,18 @@ namespace canvas return target; } + //---------------------------------------------------------------------------- + ElementWeakPtr Event::getCurrentTarget() const + { + return current_target; + } + + //---------------------------------------------------------------------------- + double Event::getTime() const + { + return time; + } + //---------------------------------------------------------------------------- void Event::stopPropagation() { @@ -69,24 +81,58 @@ namespace canvas } //---------------------------------------------------------------------------- - Event::Type Event::strToType(const std::string& str) + int Event::getOrRegisterType(const std::string& type_str) { - typedef std::map TypeMap; - static TypeMap type_map; + int type = strToType(type_str); - if( type_map.empty() ) + if( type == UNKNOWN ) { -# define ENUM_MAPPING(type, str) type_map[ str ] = type; -# include "CanvasEventTypes.hxx" -# undef ENUM_MAPPING + // 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)); } - TypeMap::const_iterator it = type_map.find(str); - if( it == type_map.end() ) + 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