X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fcanvas%2FCanvasEvent.cxx;h=a438472b0380cf0c55a362cd645f08bea873d9bc;hb=b409f93240dfde9891435869c64a6f879790d3bd;hp=414d19938eb775485f3510fa6ec97e829084b2b5;hpb=943efbb3ed37afda79a761a643030647e85278c0;p=simgear.git diff --git a/simgear/canvas/CanvasEvent.cxx b/simgear/canvas/CanvasEvent.cxx index 414d1993..a438472b 100644 --- a/simgear/canvas/CanvasEvent.cxx +++ b/simgear/canvas/CanvasEvent.cxx @@ -26,7 +26,9 @@ namespace canvas //---------------------------------------------------------------------------- Event::Event(): type(UNKNOWN), - propagation_stopped(false) + time(-1), + propagation_stopped(false), + default_prevented(false) { } @@ -38,7 +40,13 @@ namespace canvas } //---------------------------------------------------------------------------- - Event::Type Event::getType() const + bool Event::canBubble() const + { + return true; + } + + //---------------------------------------------------------------------------- + int Event::getType() const { return type; } @@ -46,14 +54,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); } //---------------------------------------------------------------------------- @@ -81,24 +82,70 @@ namespace canvas } //---------------------------------------------------------------------------- - Event::Type Event::strToType(const std::string& str) + void Event::preventDefault() { - typedef std::map TypeMap; - static TypeMap type_map; + default_prevented = true; + } - if( type_map.empty() ) + //---------------------------------------------------------------------------- + bool Event::defaultPrevented() const + { + return default_prevented; + } + + //---------------------------------------------------------------------------- + int Event::getOrRegisterType(const std::string& type_str) + { + int type = strToType(type_str); + + 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, class_name)\ + type_map.insert(TypeMap::value_type(str, type)); +# include "CanvasEventTypes.hxx" +# undef ENUM_MAPPING + } + + return type_map; + } + } // namespace canvas } // namespace simgear