X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-effects-style.cpp;h=75fabd77d3253a6e3716bb8058a272d64a7e9526;hp=1578329f16636ac330a320527bf5408b8621d516;hb=565f93cb19bc3e1058fc057bea74c973489deab3;hpb=44835162f4c0107591223e60557ee62b79cab35a diff --git a/dali-toolkit/internal/text/text-effects-style.cpp b/dali-toolkit/internal/text/text-effects-style.cpp index 1578329..75fabd7 100644 --- a/dali-toolkit/internal/text/text-effects-style.cpp +++ b/dali-toolkit/internal/text/text-effects-style.cpp @@ -38,66 +38,148 @@ const std::string OFFSET_KEY( "offset" ); const std::string HEIGHT_KEY( "height" ); const std::string ENABLE_KEY( "enable" ); const std::string TRUE_TOKEN( "true" ); +const std::string FALSE_TOKEN( "false" ); } -bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) +bool ParseShadowProperties( const Property::Map& shadowPropertiesMap, + bool& colorDefined, + Vector4& color, + bool& offsetDefined, + Vector2& offset ) { - bool update = false; + const unsigned int numberOfItems = shadowPropertiesMap.Count(); - if( controller ) + // Parses and applies the style. + for( unsigned int index = 0u; index < numberOfItems; ++index ) { - const std::string properties = value.Get(); + const KeyValuePair& valueGet = shadowPropertiesMap.GetKeyValue( index ); + + if( COLOR_KEY == valueGet.first.stringKey ) + { + /// Color key. + colorDefined = true; - // Parses and applies the style. - Property::Map map; - ParsePropertyString( properties, map ); + const std::string colorStr = valueGet.second.Get(); - if( !map.Empty() ) + Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + } + else if( OFFSET_KEY == valueGet.first.stringKey ) { - /// Enable key. - Property::Value* enableValue = map.Find( ENABLE_KEY ); + /// Offset key. + offsetDefined = true; - bool enabled = false; - const bool enabledDefined = enableValue != NULL; - if( enabledDefined ) - { - const std::string enableStr = enableValue->Get(); - enabled = TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() ); - } + const std::string offsetStr = valueGet.second.Get(); - /// Color key. - Property::Value* colorValue = map.Find( COLOR_KEY ); + StringToVector2( offsetStr.c_str(), offsetStr.size(), offset ); + } + } - Vector4 color; - const bool colorDefined = colorValue != NULL; - if( colorDefined ) - { - const std::string colorStr = colorValue->Get(); + return 0u == numberOfItems; +} - ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); - } +bool ParseUnderlineProperties( const Property::Map& underlinePropertiesMap, + bool& enabled, + bool& colorDefined, + Vector4& color, + bool& heightDefined, + float& height ) +{ + const unsigned int numberOfItems = underlinePropertiesMap.Count(); + + // Parses and applies the style. + for( unsigned int index = 0u; index < numberOfItems; ++index ) + { + const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue( index ); + if( ENABLE_KEY == valueGet.first.stringKey ) + { + /// Enable key. + const std::string enableStr = valueGet.second.Get(); + enabled = Text::TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() ); + } + else if( COLOR_KEY == valueGet.first.stringKey ) + { + /// Color key. + colorDefined = true; + + const std::string colorStr = valueGet.second.Get(); + + Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + } + else if( HEIGHT_KEY == valueGet.first.stringKey ) + { /// Height key. - Property::Value* heightValue = map.Find( HEIGHT_KEY ); + heightDefined = true; - float height = 0.f; - const bool heightDefined = heightValue != NULL; - if( heightDefined ) - { - const std::string heightStr = heightValue->Get(); + const std::string heightStr = valueGet.second.Get(); - height = StringToFloat( heightStr.c_str() ); - } + height = StringToFloat( heightStr.c_str() ); + } + } + + return 0u == numberOfItems; +} + +bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) +{ + bool update = false; - switch( type ) + if( controller ) + { + switch( type ) + { + case EffectStyle::DEFAULT: { - case EffectStyle::DEFAULT: + const Property::Map& propertiesMap = value.Get(); + + bool enabled = false; + bool colorDefined = false; + Vector4 color; + bool heightDefined = false; + float height = 0.f; + + bool empty = true; + + if ( propertiesMap.Empty() ) + { + // Map empty so check if a string provided + const std::string propertyString = value.Get(); + + if ( !propertyString.empty() ) + { + Property::Map parsedStringMap; + Text::ParsePropertyString( propertyString, parsedStringMap ); + + empty = ParseUnderlineProperties( parsedStringMap, + enabled, + colorDefined, + color, + heightDefined, + height ); + + controller->UnderlineSetByString( !empty); + } + } + else + { + empty = ParseUnderlineProperties( propertiesMap, + enabled, + colorDefined, + color, + heightDefined, + height ); + + controller->UnderlineSetByString( false ); + } + + if( !empty ) { if( enabled != controller->IsUnderlineEnabled() ) { controller->SetUnderlineEnabled( enabled ); update = true; } + // Sets the default underline values. if( colorDefined && ( controller->GetUnderlineColor() != color ) ) { @@ -105,26 +187,13 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va update = true; } - if( heightDefined && fabsf( controller->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 ) + if( heightDefined && ( fabsf( controller->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 ) ) { controller->SetUnderlineHeight( height ); update = true; } - break; } - case EffectStyle::INPUT: - { - // Sets the input underline values. - // TODO: to be implemented. - break; - } - } - } - else - { - switch( type ) - { - case EffectStyle::DEFAULT: + else { // Disable underline. if( controller->IsUnderlineEnabled() ) @@ -132,18 +201,18 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va controller->SetUnderlineEnabled( false ); update = true; } - break; - } - case EffectStyle::INPUT: - { - // Sets the input underline values. - // TODO: to be implemented. - controller->SetInputUnderlineProperties( properties ); - break; } + break; } - } - } + case EffectStyle::INPUT: + { + const std::string& underlineProperties = value.Get(); + + controller->SetInputUnderlineProperties( underlineProperties ); + break; + } + } // switch + } // if( controller ) return update; } @@ -160,19 +229,40 @@ void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, E const Vector4& color = controller->GetUnderlineColor(); const float height = controller->GetUnderlineHeight(); - std::string underlineProperties = "{\"enable\":"; - const std::string enabledStr = enabled ? "true" : "false"; - underlineProperties += "\"" + enabledStr + "\","; + if ( controller->IsUnderlineSetByString() ) + { + std::string underlineProperties = "{\"enable\":"; + const std::string enabledStr = enabled ? "true" : "false"; + underlineProperties += "\"" + enabledStr + "\","; + + std::string colorStr; + Vector4ToColorString( color, colorStr ); + underlineProperties += "\"color\":\"" + colorStr + "\","; + + std::string heightStr; + FloatToString( height, heightStr ); + underlineProperties += "\"height\":\"" + heightStr + "\"}"; - std::string colorStr; - Vector4ToColorString( color, colorStr ); - underlineProperties += "\"color\":\"" + colorStr + "\","; + value = underlineProperties; + } + else + { + Property::Map map; + + const std::string enabledStr = enabled ? TRUE_TOKEN : FALSE_TOKEN; + map.Insert( ENABLE_KEY, enabledStr ); + + std::string colorStr; + Vector4ToColorString( color, colorStr ); + map.Insert( COLOR_KEY, colorStr ); - std::string heightStr; - FloatToString( height, heightStr ); - underlineProperties += "\"height\":\"" + heightStr + "\"}"; + std::string heightStr; + FloatToString( height, heightStr ); + map.Insert( HEIGHT_KEY, heightStr ); + + value = map; + } - value = underlineProperties; break; } case EffectStyle::INPUT: @@ -190,41 +280,48 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value if( controller ) { - const std::string properties = value.Get< std::string >(); + switch( type ) + { + case EffectStyle::DEFAULT: + { + const Property::Map& propertiesMap = value.Get(); - // Parses and applies the style. - Property::Map map; - ParsePropertyString( properties, map ); + bool colorDefined = false; + Vector4 color; + bool offsetDefined = false; + Vector2 offset; - if( !map.Empty() ) - { - /// Color key - Property::Value* colorValue = map.Find( COLOR_KEY ); + bool empty = true; - Vector4 color; - const bool colorDefined = colorValue != NULL; - if( colorDefined ) - { - const std::string colorStr = colorValue->Get(); + if ( propertiesMap.Empty() ) + { + // Map empty so check if a string provided + const std::string propertyString = value.Get(); - ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); - } + Property::Map parsedStringMap; + Text::ParsePropertyString( propertyString, parsedStringMap ); - /// Offset key - Property::Value* offsetValue = map.Find( OFFSET_KEY ); + empty = ParseShadowProperties( parsedStringMap, + colorDefined, + color, + offsetDefined, + offset ); - Vector2 offset; - const bool offsetDefined = offsetValue != NULL; - if( offsetDefined ) - { - const std::string offsetStr = offsetValue->Get(); + controller->ShadowSetByString( !empty ); - StringToVector2( offsetStr.c_str(), offsetStr.size(), offset ); - } + } + else + { + empty = ParseShadowProperties( propertiesMap, + colorDefined, + color, + offsetDefined, + offset ); - switch( type ) - { - case EffectStyle::DEFAULT: + controller->ShadowSetByString( false ); + } + + if( !empty ) { // Sets the default shadow values. if( colorDefined && ( controller->GetShadowColor() != color ) ) @@ -238,39 +335,26 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value controller->SetShadowOffset( offset ); update = true; } - break; } - case EffectStyle::INPUT: - { - // Sets the input shadow values. - // TODO: to be implemented. - break; - } - } - } - else - { - switch( type ) - { - case EffectStyle::DEFAULT: + else { // Disable shadow. if( Vector2::ZERO != controller->GetShadowOffset() ) { controller->SetShadowOffset( Vector2::ZERO ); } - break; - } - case EffectStyle::INPUT: - { - // Sets the input shadow values. - // TODO: to be implemented. - controller->SetInputShadowProperties( properties ); - break; } + break; } - } - } + case EffectStyle::INPUT: + { + const std::string& shadowString = value.Get(); + + controller->SetInputShadowProperties( shadowString ); + break; + } + } // switch + } // if( controller ) return update; } @@ -286,17 +370,34 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe const Vector4& color = controller->GetShadowColor(); const Vector2& offset = controller->GetShadowOffset(); - std::string shadowProperties = "{"; + if ( controller->IsShadowSetByString() ) + { + std::string shadowProperties = "{"; + + std::string colorStr; + Vector4ToColorString( color, colorStr ); + shadowProperties += "\"color\":\"" + colorStr + "\","; - std::string colorStr; - Vector4ToColorString( color, colorStr ); - shadowProperties += "\"color\":\"" + colorStr + "\","; + std::string offsetStr; + Vector2ToString( offset, offsetStr ); + shadowProperties += "\"offset\":\"" + offsetStr + "\"}"; - std::string offsetStr; - Vector2ToString( offset, offsetStr ); - shadowProperties += "\"offset\":\"" + offsetStr + "\"}"; + value = shadowProperties; + } + else + { + Property::Map map; - value = shadowProperties; + std::string colorStr; + Vector4ToColorString( color, colorStr ); + map.Insert( COLOR_KEY, colorStr ); + + std::string offsetStr; + Vector2ToString( offset, offsetStr ); + map.Insert( OFFSET_KEY, offsetStr ); + + value = map; + } break; } case EffectStyle::INPUT: