X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-effects-style.cpp;h=083cf47e5b25ba301ea5030bb8052ed0233c1449;hb=63f9b5207c2794cdc460d587723be89585872a51;hp=7172f2329a131879d5bc11786115335fce92204e;hpb=479693b4fd773eb8888ae401d02b49188293e231;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/text-effects-style.cpp b/dali-toolkit/internal/text/text-effects-style.cpp index 7172f23..083cf47 100644 --- a/dali-toolkit/internal/text/text-effects-style.cpp +++ b/dali-toolkit/internal/text/text-effects-style.cpp @@ -35,72 +35,137 @@ namespace { const std::string COLOR_KEY( "color" ); const std::string OFFSET_KEY( "offset" ); -const std::string THICKNESS_KEY( "thickness" ); +const std::string HEIGHT_KEY( "height" ); +const std::string ENABLE_KEY( "enable" ); +const std::string TRUE_TOKEN( "true" ); } -bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) +bool ParseProperties( const std::string& shadowProperties, + bool& colorDefined, + Vector4& color, + bool& offsetDefined, + Vector2& offset ) { - bool update = false; + // Parses and applies the style. + Property::Map map; + Text::ParsePropertyString( shadowProperties, map ); - if( controller ) + const bool empty = map.Empty(); + + if( !empty ) { - const std::string properties = value.Get< std::string >(); + /// Color key. + Property::Value* colorValue = map.Find( COLOR_KEY ); - switch( type ) + colorDefined = colorValue != NULL; + if( colorDefined ) { - case EffectStyle::DEFAULT: - { - // Stores the default underline's properties string to be recovered by the GetUnderlineProperties() function. - controller->SetDefaultUnderlineProperties( properties ); - break; - } - case EffectStyle::INPUT: - { - // Stores the input underline's properties string to be recovered by the GetUnderlineProperties() function. - controller->SetInputUnderlineProperties( properties ); - break; - } + const std::string colorStr = colorValue->Get(); + + Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); } - // Parses and applies the style. - Property::Map map; - ParsePropertyString( properties, map ); + /// Offset key. + Property::Value* offsetValue = map.Find( OFFSET_KEY ); - if( !map.Empty() ) + offsetDefined = offsetValue != NULL; + if( offsetDefined ) { - /// Color key - Property::Value* colorValue = map.Find( COLOR_KEY ); + const std::string offsetStr = offsetValue->Get(); - Vector4 color; - const bool colorDefined = colorValue != NULL; - if( colorDefined ) - { - const std::string colorStr = colorValue->Get(); + StringToVector2( offsetStr.c_str(), offsetStr.size(), offset ); + } + } - ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); - } + return empty; +} + +bool ParseProperties( const std::string& underlineProperties, + bool& enabled, + bool& colorDefined, + Vector4& color, + bool& heightDefined, + float& height ) +{ + // Parses and applies the style. + Property::Map map; + Text::ParsePropertyString( underlineProperties, map ); - /// Thickness key - Property::Value* thicknessValue = map.Find( THICKNESS_KEY ); + const bool empty = map.Empty(); - float thickness = 0.f; - const bool thicknessDefined = thicknessValue != NULL; - if( thicknessDefined ) - { - const std::string thicknessStr = thicknessValue->Get(); + if( !empty ) + { + /// Enable key. + Property::Value* enableValue = map.Find( ENABLE_KEY ); - thickness = StringToFloat( thicknessStr.c_str() ); - } + enabled = false; + const bool enabledDefined = enableValue != NULL; + if( enabledDefined ) + { + const std::string enableStr = enableValue->Get(); + enabled = Text::TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() ); + } + + /// Color key. + Property::Value* colorValue = map.Find( COLOR_KEY ); + colorDefined = colorValue != NULL; + if( colorDefined ) + { + const std::string colorStr = colorValue->Get(); + + Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + } + + /// Height key. + Property::Value* heightValue = map.Find( HEIGHT_KEY ); + + height = 0.f; + heightDefined = heightValue != NULL; + if( heightDefined ) + { + const std::string heightStr = heightValue->Get(); + + height = StringToFloat( heightStr.c_str() ); + } + } + + return empty; +} + +bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) +{ + bool update = false; + + 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 ) { case EffectStyle::DEFAULT: { - if( !controller->IsUnderlineEnabled() ) + if( enabled != controller->IsUnderlineEnabled() ) { - controller->SetUnderlineEnabled( true ); + controller->SetUnderlineEnabled( enabled ); update = true; } + // Sets the default underline values. if( colorDefined && ( controller->GetUnderlineColor() != color ) ) { @@ -108,11 +173,12 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va update = true; } - if( thicknessDefined && fabsf( controller->GetUnderlineHeight() - thickness ) > Math::MACHINE_EPSILON_1000 ) + if( heightDefined && ( fabsf( controller->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 ) ) { - controller->SetUnderlineHeight( thickness ); + controller->SetUnderlineHeight( height ); update = true; } + break; } case EffectStyle::INPUT: { @@ -124,11 +190,25 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va } else { - // Disable underline. - if( controller->IsUnderlineEnabled() ) + switch( type ) { - controller->SetUnderlineEnabled( false ); - update = true; + case EffectStyle::DEFAULT: + { + // Disable underline. + if( controller->IsUnderlineEnabled() ) + { + controller->SetUnderlineEnabled( false ); + update = true; + } + break; + } + case EffectStyle::INPUT: + { + // Sets the input underline values. + // TODO: to be implemented. + controller->SetInputUnderlineProperties( properties ); + break; + } } } } @@ -144,7 +224,23 @@ void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, E { case EffectStyle::DEFAULT: { - value = controller->GetDefaultUnderlineProperties(); + const bool enabled = controller->IsUnderlineEnabled(); + const Vector4& color = controller->GetUnderlineColor(); + const float height = controller->GetUnderlineHeight(); + + 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 + "\"}"; + + value = underlineProperties; break; } case EffectStyle::INPUT: @@ -164,52 +260,19 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value { const std::string properties = value.Get< std::string >(); - switch( type ) - { - case EffectStyle::DEFAULT: - { - // Stores the default shadow's properties string to be recovered by the GetShadowProperties() function. - controller->SetDefaultShadowProperties( properties ); - break; - } - case EffectStyle::INPUT: - { - // Stores the input shadow's properties string to be recovered by the GetShadowProperties() function. - controller->SetInputShadowProperties( properties ); - break; - } - } + bool colorDefined = false; + Vector4 color; + bool offsetDefined = false; + Vector2 offset; - // Parses and applies the style. - Property::Map map; - ParsePropertyString( properties, map ); + const bool empty = ParseProperties( properties, + colorDefined, + color, + offsetDefined, + offset ); - if( !map.Empty() ) + if( !empty ) { - /// Color key - Property::Value* colorValue = map.Find( COLOR_KEY ); - - Vector4 color; - const bool colorDefined = colorValue != NULL; - if( colorDefined ) - { - const std::string colorStr = colorValue->Get(); - - ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); - } - - /// Offset key - Property::Value* offsetValue = map.Find( OFFSET_KEY ); - - Vector2 offset; - const bool offsetDefined = offsetValue != NULL; - if( offsetDefined ) - { - const std::string offsetStr = offsetValue->Get(); - - StringOffsetToVector2( offsetStr, offset ); - } - switch( type ) { case EffectStyle::DEFAULT: @@ -226,6 +289,7 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value controller->SetShadowOffset( offset ); update = true; } + break; } case EffectStyle::INPUT: { @@ -235,6 +299,28 @@ bool SetShadowProperties( ControllerPtr controller, const Property::Value& value } } } + else + { + switch( type ) + { + case EffectStyle::DEFAULT: + { + // 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; + } + } + } } return update; @@ -248,7 +334,20 @@ void GetShadowProperties( ControllerPtr controller, Property::Value& value, Effe { case EffectStyle::DEFAULT: { - value = controller->GetDefaultShadowProperties(); + const Vector4& color = controller->GetShadowColor(); + const Vector2& offset = controller->GetShadowOffset(); + + std::string shadowProperties = "{"; + + std::string colorStr; + Vector4ToColorString( color, colorStr ); + shadowProperties += "\"color\":\"" + colorStr + "\","; + + std::string offsetStr; + Vector2ToString( offset, offsetStr ); + shadowProperties += "\"offset\":\"" + offsetStr + "\"}"; + + value = shadowProperties; break; } case EffectStyle::INPUT: