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=ea1b3cfcd67083550ff0862ed5b8b4bc311839c3;hp=083cf47e5b25ba301ea5030bb8052ed0233c1449;hb=baef46c4babda42017ab2d5fbd362ae9e11be95b;hpb=63f9b5207c2794cdc460d587723be89585872a51 diff --git a/dali-toolkit/internal/text/text-effects-style.cpp b/dali-toolkit/internal/text/text-effects-style.cpp old mode 100644 new mode 100755 index 083cf47..ea1b3cf --- a/dali-toolkit/internal/text/text-effects-style.cpp +++ b/dali-toolkit/internal/text/text-effects-style.cpp @@ -35,102 +35,120 @@ namespace { const std::string COLOR_KEY( "color" ); const std::string OFFSET_KEY( "offset" ); +const std::string WIDTH_KEY( "width" ); 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 ParseProperties( const std::string& shadowProperties, - bool& colorDefined, - Vector4& color, - bool& offsetDefined, - Vector2& offset ) +bool ParseShadowProperties( const Property::Map& shadowPropertiesMap, + bool& colorDefined, + Vector4& color, + bool& offsetDefined, + Vector2& offset ) { - // Parses and applies the style. - Property::Map map; - Text::ParsePropertyString( shadowProperties, map ); - - const bool empty = map.Empty(); + const unsigned int numberOfItems = shadowPropertiesMap.Count(); - if( !empty ) + // Parses and applies the style. + for( unsigned int index = 0u; index < numberOfItems; ++index ) { - /// Color key. - Property::Value* colorValue = map.Find( COLOR_KEY ); + const KeyValuePair& valueGet = shadowPropertiesMap.GetKeyValue( index ); - colorDefined = colorValue != NULL; - if( colorDefined ) + if( COLOR_KEY == valueGet.first.stringKey ) { - const std::string colorStr = colorValue->Get(); + /// Color key. + colorDefined = true; + + const std::string colorStr = valueGet.second.Get(); Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); } - - /// Offset key. - Property::Value* offsetValue = map.Find( OFFSET_KEY ); - - offsetDefined = offsetValue != NULL; - if( offsetDefined ) + else if( OFFSET_KEY == valueGet.first.stringKey ) { - const std::string offsetStr = offsetValue->Get(); + /// Offset key. + offsetDefined = true; + + const std::string offsetStr = valueGet.second.Get(); StringToVector2( offsetStr.c_str(), offsetStr.size(), offset ); } } - return empty; + return 0u == numberOfItems; } -bool ParseProperties( const std::string& underlineProperties, - bool& enabled, - bool& colorDefined, - Vector4& color, - bool& heightDefined, - float& height ) +bool ParseUnderlineProperties( const Property::Map& underlinePropertiesMap, + bool& enabled, + bool& colorDefined, + Vector4& color, + bool& heightDefined, + float& height ) { - // Parses and applies the style. - Property::Map map; - Text::ParsePropertyString( underlineProperties, map ); + const unsigned int numberOfItems = underlinePropertiesMap.Count(); - const bool empty = map.Empty(); - - if( !empty ) + // Parses and applies the style. + for( unsigned int index = 0u; index < numberOfItems; ++index ) { - /// Enable key. - Property::Value* enableValue = map.Find( ENABLE_KEY ); + const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue( index ); - enabled = false; - const bool enabledDefined = enableValue != NULL; - if( enabledDefined ) + if( ENABLE_KEY == valueGet.first.stringKey ) { - const std::string enableStr = enableValue->Get(); + /// 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; - /// Color key. - Property::Value* colorValue = map.Find( COLOR_KEY ); + const std::string colorStr = valueGet.second.Get(); - colorDefined = colorValue != NULL; - if( colorDefined ) + Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + } + else if( HEIGHT_KEY == valueGet.first.stringKey ) { - const std::string colorStr = colorValue->Get(); + /// Height key. + heightDefined = true; - Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + const std::string heightStr = valueGet.second.Get(); + + height = StringToFloat( heightStr.c_str() ); } + } - /// Height key. - Property::Value* heightValue = map.Find( HEIGHT_KEY ); + return 0u == numberOfItems; +} - height = 0.f; - heightDefined = heightValue != NULL; - if( heightDefined ) - { - const std::string heightStr = heightValue->Get(); +bool ParseOutlineProperties( const Property::Map& underlinePropertiesMap, + bool& colorDefined, + Vector4& color, + bool& widthDefined, + float& width ) +{ + const unsigned int numberOfItems = underlinePropertiesMap.Count(); - height = StringToFloat( heightStr.c_str() ); + // Parses and applies the style. + for( unsigned int index = 0u; index < numberOfItems; ++index ) + { + const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue( index ); + + if( COLOR_KEY == valueGet.first.stringKey ) + { + /// Color key. + colorDefined = true; + color = valueGet.second.Get(); + } + else if( WIDTH_KEY == valueGet.first.stringKey ) + { + /// Width key. + widthDefined = true; + width = valueGet.second.Get(); } } - return empty; + return 0u == numberOfItems; } bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) @@ -139,26 +157,53 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va if( controller ) { - const std::string properties = value.Get(); - - bool enabled = false; - bool colorDefined = false; - Vector4 color; - bool heightDefined = false; - float height = 0.f; - - const bool empty = ParseProperties( properties, - enabled, - colorDefined, - color, - heightDefined, - height ); - - if( !empty ) + switch( type ) { - 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() ) { @@ -178,21 +223,8 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va 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() ) @@ -200,18 +232,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; } @@ -228,19 +260,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 heightStr; - FloatToString( height, heightStr ); - underlineProperties += "\"height\":\"" + heightStr + "\"}"; + std::string colorStr; + Vector4ToColorString( color, colorStr ); + map.Insert( COLOR_KEY, colorStr ); + + std::string heightStr; + FloatToString( height, heightStr ); + map.Insert( HEIGHT_KEY, heightStr ); + + value = map; + } - value = underlineProperties; break; } case EffectStyle::INPUT: @@ -258,24 +311,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(); - bool colorDefined = false; - Vector4 color; - bool offsetDefined = false; - Vector2 offset; + bool colorDefined = false; + Vector4 color; + bool offsetDefined = false; + Vector2 offset; - const bool empty = ParseProperties( properties, - colorDefined, - color, - offsetDefined, - offset ); + bool empty = true; - if( !empty ) - { - switch( type ) - { - case EffectStyle::DEFAULT: + if ( propertiesMap.Empty() ) + { + // Map empty so check if a string provided + const std::string propertyString = value.Get(); + + Property::Map parsedStringMap; + Text::ParsePropertyString( propertyString, parsedStringMap ); + + empty = ParseShadowProperties( parsedStringMap, + colorDefined, + color, + offsetDefined, + offset ); + + controller->ShadowSetByString( !empty ); + + } + else + { + empty = ParseShadowProperties( propertiesMap, + colorDefined, + color, + offsetDefined, + offset ); + + controller->ShadowSetByString( false ); + } + + if( !empty ) { // Sets the default shadow values. if( colorDefined && ( controller->GetShadowColor() != color ) ) @@ -289,39 +366,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; } @@ -337,17 +401,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; + value = shadowProperties; + } + else + { + Property::Map map; + + 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: @@ -413,24 +494,76 @@ bool SetOutlineProperties( ControllerPtr controller, const Property::Value& valu if( controller ) { - const std::string properties = value.Get< std::string >(); - switch( type ) { case EffectStyle::DEFAULT: { - // Stores the default outline's properties string to be recovered by the GetOutlineProperties() function. - controller->SetDefaultOutlineProperties( properties ); + const Property::Map& propertiesMap = value.Get(); + + bool colorDefined = false; + Vector4 color; + bool widthDefined = false; + float width = 0.f; + + bool empty = true; + + if ( propertiesMap.Empty() ) + { + // Map empty so check if a string provided + // This is purely to maintain backward compatibility, but we don't parse the string to be a property map. + const std::string propertyString = value.Get(); + + // Stores the default outline's properties string to be recovered by the GetOutlineProperties() function. + controller->SetDefaultOutlineProperties( propertyString ); + + controller->OutlineSetByString( true ); + } + else + { + empty = ParseOutlineProperties( propertiesMap, + colorDefined, + color, + widthDefined, + width ); + + controller->OutlineSetByString( false ); + } + + if( !empty ) + { + // Sets the default outline values. + if( colorDefined && ( controller->GetOutlineColor() != color ) ) + { + controller->SetOutlineColor( color ); + update = true; + } + + if( widthDefined && ( fabsf( controller->GetOutlineWidth() - width ) > Math::MACHINE_EPSILON_1000 ) ) + { + controller->SetOutlineWidth( width ); + update = true; + } + } + else + { + // Disable outline + if( fabsf( controller->GetOutlineWidth() ) > Math::MACHINE_EPSILON_1000 ) + { + controller->SetOutlineWidth( 0.0f ); + update = true; + } + } break; } case EffectStyle::INPUT: { - // Stores the input outline's properties string to be recovered by the GetOutlineProperties() function. - controller->SetInputOutlineProperties( properties ); + const std::string& outlineProperties = value.Get(); + + controller->SetInputOutlineProperties( outlineProperties ); break; } - } - } + } // switch + } // if( controller ) return update; } @@ -443,8 +576,30 @@ void GetOutlineProperties( ControllerPtr controller, Property::Value& value, Eff { case EffectStyle::DEFAULT: { - value = controller->GetDefaultOutlineProperties(); - break; + if ( controller->IsOutlineSetByString() ) + { + value = controller->GetDefaultOutlineProperties(); + break; + } + else + { + const Vector4& color = controller->GetOutlineColor(); + const float width = controller->GetOutlineWidth(); + + Property::Map map; + + std::string colorStr; + Vector4ToColorString( color, colorStr ); + map.Insert( COLOR_KEY, colorStr ); + + std::string widthStr; + FloatToString( width, widthStr ); + map.Insert( WIDTH_KEY, widthStr ); + + value = map; + + break; + } } case EffectStyle::INPUT: {