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=d5f8ff13ba8cf1cb2a9718ec2748b0c86e34942e;hp=7c08ebe3e3007b6207dba547e07d4e0e28c989b2;hb=0e1683ef848d1d877e26633609fa95e0d2ab36b5;hpb=48d13d45cb7f363d3cf8da048ce6cef074c55060 diff --git a/dali-toolkit/internal/text/text-effects-style.cpp b/dali-toolkit/internal/text/text-effects-style.cpp index 7c08ebe..d5f8ff1 100755 --- a/dali-toolkit/internal/text/text-effects-style.cpp +++ b/dali-toolkit/internal/text/text-effects-style.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ #include // INTERNAL INCLUDES +#include #include #include @@ -58,7 +59,7 @@ bool ParseShadowProperties( const Property::Map& shadowPropertiesMap, { const KeyValuePair& valueGet = shadowPropertiesMap.GetKeyValue( index ); - if( COLOR_KEY == valueGet.first.stringKey ) + if( ( DevelText::Shadow::Property::COLOR == valueGet.first.indexKey ) || ( COLOR_KEY == valueGet.first.stringKey ) ) { /// Color key. colorDefined = true; @@ -73,7 +74,7 @@ bool ParseShadowProperties( const Property::Map& shadowPropertiesMap, color = valueGet.second.Get(); } } - else if( OFFSET_KEY == valueGet.first.stringKey ) + else if( ( DevelText::Shadow::Property::OFFSET == valueGet.first.indexKey ) || ( OFFSET_KEY == valueGet.first.stringKey ) ) { /// Offset key. offsetDefined = true; @@ -88,7 +89,7 @@ bool ParseShadowProperties( const Property::Map& shadowPropertiesMap, offset = valueGet.second.Get(); } } - else if( BLUR_RADIUS_KEY == valueGet.first.stringKey ) + else if( ( DevelText::Shadow::Property::BLUR_RADIUS == valueGet.first.indexKey ) || ( BLUR_RADIUS_KEY == valueGet.first.stringKey ) ) { /// Blur radius key. blurRadiusDefined = true; @@ -122,29 +123,48 @@ bool ParseUnderlineProperties( const Property::Map& underlinePropertiesMap, { const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue( index ); - if( ENABLE_KEY == valueGet.first.stringKey ) + if( ( DevelText::Underline::Property::ENABLE == valueGet.first.indexKey ) || ( ENABLE_KEY == valueGet.first.stringKey ) ) { /// Enable key. - const std::string enableStr = valueGet.second.Get(); - enabled = Text::TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() ); + if( valueGet.second.GetType() == Dali::Property::STRING ) + { + const std::string enableStr = valueGet.second.Get(); + enabled = Text::TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() ); + } + else + { + enabled = valueGet.second.Get(); + } } - else if( COLOR_KEY == valueGet.first.stringKey ) + else if( ( DevelText::Underline::Property::COLOR == valueGet.first.indexKey ) || ( COLOR_KEY == valueGet.first.stringKey ) ) { /// Color key. colorDefined = true; - const std::string colorStr = valueGet.second.Get(); - - Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + if( valueGet.second.GetType() == Dali::Property::STRING ) + { + const std::string colorStr = valueGet.second.Get(); + Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color ); + } + else + { + color = valueGet.second.Get(); + } } - else if( HEIGHT_KEY == valueGet.first.stringKey ) + else if( ( DevelText::Underline::Property::HEIGHT == valueGet.first.indexKey ) || ( HEIGHT_KEY == valueGet.first.stringKey ) ) { /// Height key. heightDefined = true; - const std::string heightStr = valueGet.second.Get(); - - height = StringToFloat( heightStr.c_str() ); + if( valueGet.second.GetType() == Dali::Property::STRING ) + { + const std::string heightStr = valueGet.second.Get(); + height = StringToFloat( heightStr.c_str() ); + } + else + { + height = valueGet.second.Get(); + } } } @@ -155,7 +175,7 @@ bool ParseOutlineProperties( const Property::Map& underlinePropertiesMap, bool& colorDefined, Vector4& color, bool& widthDefined, - float& width ) + uint16_t& width ) { const unsigned int numberOfItems = underlinePropertiesMap.Count(); @@ -164,17 +184,45 @@ bool ParseOutlineProperties( const Property::Map& underlinePropertiesMap, { const KeyValuePair& valueGet = underlinePropertiesMap.GetKeyValue( index ); - if( COLOR_KEY == valueGet.first.stringKey ) + if( ( DevelText::Outline::Property::COLOR == valueGet.first.indexKey ) || ( COLOR_KEY == valueGet.first.stringKey ) ) { /// Color key. colorDefined = true; color = valueGet.second.Get(); } - else if( WIDTH_KEY == valueGet.first.stringKey ) + else if( ( DevelText::Outline::Property::WIDTH == valueGet.first.indexKey ) || ( WIDTH_KEY == valueGet.first.stringKey ) ) { /// Width key. widthDefined = true; - width = valueGet.second.Get(); + width = static_cast( valueGet.second.Get() ); + } + } + + return 0u == numberOfItems; +} + +bool ParseBackgroundProperties( const Property::Map& backgroundProperties, + bool& enabled, + bool& colorDefined, + Vector4& color ) +{ + const unsigned int numberOfItems = backgroundProperties.Count(); + + // Parses and applies the style. + for( unsigned int index = 0u; index < numberOfItems; ++index ) + { + const KeyValuePair& valueGet = backgroundProperties.GetKeyValue( index ); + + if( ( DevelText::Background::Property::ENABLE == valueGet.first.indexKey ) || ( ENABLE_KEY == valueGet.first.stringKey ) ) + { + /// Enable key. + enabled = valueGet.second.Get(); + } + else if( ( DevelText::Background::Property::COLOR == valueGet.first.indexKey ) || ( COLOR_KEY == valueGet.first.stringKey ) ) + { + /// Color key. + colorDefined = true; + color = valueGet.second.Get(); } } @@ -218,7 +266,7 @@ bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& va heightDefined, height ); - controller->UnderlineSetByString( !empty); + controller->UnderlineSetByString( !empty ); } } else @@ -310,16 +358,9 @@ void GetUnderlineProperties( ControllerPtr controller, Property::Value& value, E { 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 ); - map.Insert( HEIGHT_KEY, heightStr ); + map.Insert( ENABLE_KEY, enabled ); + map.Insert( COLOR_KEY, color ); + map.Insert( HEIGHT_KEY, height ); value = map; } @@ -546,7 +587,7 @@ bool SetOutlineProperties( ControllerPtr controller, const Property::Value& valu bool colorDefined = false; Vector4 color; bool widthDefined = false; - float width = 0.f; + uint16_t width = 0u; bool empty = true; @@ -581,7 +622,7 @@ bool SetOutlineProperties( ControllerPtr controller, const Property::Value& valu update = true; } - if( widthDefined && ( fabsf( controller->GetOutlineWidth() - width ) > Math::MACHINE_EPSILON_1000 ) ) + if( widthDefined && ( controller->GetOutlineWidth() != width ) ) { controller->SetOutlineWidth( width ); update = true; @@ -590,9 +631,9 @@ bool SetOutlineProperties( ControllerPtr controller, const Property::Value& valu else { // Disable outline - if( fabsf( controller->GetOutlineWidth() ) > Math::MACHINE_EPSILON_1000 ) + if( 0u != controller->GetOutlineWidth() ) { - controller->SetOutlineWidth( 0.0f ); + controller->SetOutlineWidth( 0u ); update = true; } } @@ -627,17 +668,11 @@ void GetOutlineProperties( ControllerPtr controller, Property::Value& value, Eff else { const Vector4& color = controller->GetOutlineColor(); - const float width = controller->GetOutlineWidth(); + const uint16_t 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 ); + map.Insert( COLOR_KEY, color ); + map.Insert( WIDTH_KEY, static_cast( width ) ); value = map; @@ -653,6 +688,98 @@ void GetOutlineProperties( ControllerPtr controller, Property::Value& value, Eff } } +bool SetBackgroundProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type ) +{ + bool update = false; + + if( controller ) + { + switch( type ) + { + case EffectStyle::DEFAULT: + { + const Property::Map& propertiesMap = value.Get(); + + bool enabled = false; + bool colorDefined = false; + Vector4 color; + + bool empty = true; + + if ( !propertiesMap.Empty() ) + { + empty = ParseBackgroundProperties( propertiesMap, + enabled, + colorDefined, + color ); + } + + if( !empty ) + { + if( enabled != controller->IsBackgroundEnabled() ) + { + controller->SetBackgroundEnabled( enabled ); + update = true; + } + + if( colorDefined && ( controller->GetBackgroundColor() != color ) ) + { + controller->SetBackgroundColor( color ); + update = true; + } + } + else + { + // Disable background. + if( controller->IsBackgroundEnabled() ) + { + controller->SetBackgroundEnabled( false ); + update = true; + } + } + break; + } + case EffectStyle::INPUT: + { + // Text background is not supported while inputting yet + break; + } + } // switch + } // if( controller ) + + return update; +} + +void GetBackgroundProperties( ControllerPtr controller, Property::Value& value, EffectStyle::Type type ) +{ + if( controller ) + { + switch( type ) + { + case EffectStyle::DEFAULT: + { + const bool enabled = controller->IsBackgroundEnabled(); + const Vector4& color = controller->GetBackgroundColor(); + + Property::Map map; + map.Insert( ENABLE_KEY, enabled ); + map.Insert( COLOR_KEY, color ); + + value = map; + + break; + + } + case EffectStyle::INPUT: + { + // Text background is not supported while inputting yet + break; + } + } + } +} + + } // namespace Text } // namespace Toolkit