{
const std::string COLOR_KEY( "color" );
const std::string OFFSET_KEY( "offset" );
-const std::string THICKNESS_KEY( "thickness" );
+const std::string BLUR_RADIUS_KEY( "blurRadius" );
+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 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& blurRadiusDefined,
+ float& blurRadius )
{
- 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< std::string >();
+ const KeyValuePair& valueGet = shadowPropertiesMap.GetKeyValue( index );
- switch( type )
+ if( COLOR_KEY == valueGet.first.stringKey )
{
- case EffectStyle::DEFAULT:
+ /// Color key.
+ colorDefined = true;
+
+ if( valueGet.second.GetType() == Dali::Property::STRING )
{
- // Stores the default underline's properties string to be recovered by the GetUnderlineProperties() function.
- controller->SetDefaultUnderlineProperties( properties );
- break;
+ const std::string colorStr = valueGet.second.Get<std::string>();
+ Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
}
- case EffectStyle::INPUT:
+ else
{
- // Stores the input underline's properties string to be recovered by the GetUnderlineProperties() function.
- controller->SetInputUnderlineProperties( properties );
- break;
+ color = valueGet.second.Get<Vector4>();
}
}
-
- // Parses and applies the style.
- Property::Map map;
- ParsePropertyString( properties, map );
-
- if( !map.Empty() )
+ else if( OFFSET_KEY == valueGet.first.stringKey )
{
- /// Color key
- Property::Value* colorValue = map.Find( COLOR_KEY );
+ /// Offset key.
+ offsetDefined = true;
- Vector4 color;
- const bool colorDefined = colorValue != NULL;
- if( colorDefined )
+ if( valueGet.second.GetType() == Dali::Property::STRING )
{
- const std::string colorStr = colorValue->Get<std::string>();
+ const std::string offsetStr = valueGet.second.Get<std::string>();
+ StringToVector2( offsetStr.c_str(), offsetStr.size(), offset );
+ }
+ else
+ {
+ offset = valueGet.second.Get<Vector2>();
+ }
+ }
+ else if( BLUR_RADIUS_KEY == valueGet.first.stringKey )
+ {
+ /// Blur radius key.
+ blurRadiusDefined = true;
- ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
+ if( valueGet.second.GetType() == Dali::Property::STRING )
+ {
+ const std::string blurRadiusStr = valueGet.second.Get<std::string>();
+ blurRadius = StringToFloat( blurRadiusStr.c_str() );
}
+ else
+ {
+ blurRadius = valueGet.second.Get<float>();
+ }
+ }
+ }
+
+ return 0u == numberOfItems;
+}
- /// Thickness key
- Property::Value* thicknessValue = map.Find( THICKNESS_KEY );
+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.
+ if( valueGet.second.GetType() == Dali::Property::STRING )
+ {
+ const std::string enableStr = valueGet.second.Get<std::string>();
+ enabled = Text::TokenComparison( TRUE_TOKEN, enableStr.c_str(), enableStr.size() );
+ }
+ else
+ {
+ enabled = valueGet.second.Get<bool>();
+ }
+ }
+ else if( COLOR_KEY == valueGet.first.stringKey )
+ {
+ /// Color key.
+ colorDefined = true;
- float thickness = 0.f;
- const bool thicknessDefined = thicknessValue != NULL;
- if( thicknessDefined )
+ if( valueGet.second.GetType() == Dali::Property::STRING )
+ {
+ const std::string colorStr = valueGet.second.Get<std::string>();
+ Text::ColorStringToVector4( colorStr.c_str(), colorStr.size(), color );
+ }
+ else
{
- const std::string thicknessStr = thicknessValue->Get<std::string>();
+ color = valueGet.second.Get<Vector4>();
+ }
+ }
+ else if( HEIGHT_KEY == valueGet.first.stringKey )
+ {
+ /// Height key.
+ heightDefined = true;
- thickness = StringToFloat( thicknessStr.c_str() );
+ if( valueGet.second.GetType() == Dali::Property::STRING )
+ {
+ const std::string heightStr = valueGet.second.Get<std::string>();
+ height = StringToFloat( heightStr.c_str() );
+ }
+ else
+ {
+ height = valueGet.second.Get<float>();
}
+ }
+ }
+
+ return 0u == numberOfItems;
+}
+
+bool ParseOutlineProperties( const Property::Map& underlinePropertiesMap,
+ bool& colorDefined,
+ Vector4& color,
+ bool& widthDefined,
+ unsigned int& width )
+{
+ 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( COLOR_KEY == valueGet.first.stringKey )
+ {
+ /// Color key.
+ colorDefined = true;
+ color = valueGet.second.Get<Vector4>();
+ }
+ else if( WIDTH_KEY == valueGet.first.stringKey )
+ {
+ /// Width key.
+ widthDefined = true;
+ width = static_cast<unsigned int>( valueGet.second.Get<float>() );
+ }
+ }
+
+ 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<Property::Map>();
+
+ 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<std::string>();
+
+ if ( !propertyString.empty() )
+ {
+ Property::Map parsedStringMap;
+ Text::ParsePropertyString( propertyString, parsedStringMap );
+
+ empty = ParseUnderlineProperties( parsedStringMap,
+ enabled,
+ colorDefined,
+ color,
+ heightDefined,
+ height );
+
+ controller->UnderlineSetByString( !empty );
+ }
+ }
+ else
{
- if( !controller->IsUnderlineEnabled() )
+ empty = ParseUnderlineProperties( propertiesMap,
+ enabled,
+ colorDefined,
+ color,
+ heightDefined,
+ height );
+
+ controller->UnderlineSetByString( false );
+ }
+
+ if( !empty )
+ {
+ if( enabled != controller->IsUnderlineEnabled() )
{
- controller->SetUnderlineEnabled( true );
+ controller->SetUnderlineEnabled( enabled );
update = true;
}
+
// Sets the default underline values.
if( colorDefined && ( controller->GetUnderlineColor() != color ) )
{
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;
}
}
- case EffectStyle::INPUT:
+ else
{
- // Sets the input underline values.
- // TODO: to be implemented.
- break;
+ // Disable underline.
+ if( controller->IsUnderlineEnabled() )
+ {
+ controller->SetUnderlineEnabled( false );
+ update = true;
+ }
}
+ break;
}
- }
- else
- {
- // Disable underline.
- if( controller->IsUnderlineEnabled() )
+ case EffectStyle::INPUT:
{
- controller->SetUnderlineEnabled( false );
- update = true;
+ const std::string& underlineProperties = value.Get<std::string>();
+
+ controller->SetInputUnderlineProperties( underlineProperties );
+ break;
}
- }
- }
+ } // switch
+ } // if( controller )
return update;
}
{
case EffectStyle::DEFAULT:
{
- value = controller->GetDefaultUnderlineProperties();
+ const bool enabled = controller->IsUnderlineEnabled();
+ const Vector4& color = controller->GetUnderlineColor();
+ const float height = controller->GetUnderlineHeight();
+
+ 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 + "\"}";
+
+ 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 );
+ map.Insert( HEIGHT_KEY, heightStr );
+
+ value = map;
+ }
+
break;
}
case EffectStyle::INPUT:
if( controller )
{
- 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;
- }
- }
+ const Property::Map& propertiesMap = value.Get<Property::Map>();
- // Parses and applies the style.
- Property::Map map;
- ParsePropertyString( properties, map );
+ bool colorDefined = false;
+ Vector4 color;
+ bool offsetDefined = false;
+ Vector2 offset;
+ bool blurRadiusDefined = false;
+ float blurRadius;
- 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<std::string>();
+ if ( propertiesMap.Empty() )
+ {
+ // Map empty so check if a string provided
+ const std::string propertyString = value.Get<std::string>();
- 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,
+ blurRadiusDefined,
+ blurRadius );
- Vector2 offset;
- const bool offsetDefined = offsetValue != NULL;
- if( offsetDefined )
- {
- const std::string offsetStr = offsetValue->Get<std::string>();
+ controller->ShadowSetByString( !empty );
- StringOffsetToVector2( offsetStr, offset );
- }
+ }
+ else
+ {
+ empty = ParseShadowProperties( propertiesMap,
+ colorDefined,
+ color,
+ offsetDefined,
+ offset,
+ blurRadiusDefined,
+ blurRadius );
+
+ controller->ShadowSetByString( false );
+ }
- switch( type )
- {
- case EffectStyle::DEFAULT:
+ if( !empty )
{
// Sets the default shadow values.
if( colorDefined && ( controller->GetShadowColor() != color ) )
controller->SetShadowOffset( offset );
update = true;
}
+
+ if( blurRadiusDefined && ( controller->GetShadowBlurRadius() != blurRadius ) )
+ {
+ controller->SetShadowBlurRadius( blurRadius );
+ update = true;
+ }
}
- case EffectStyle::INPUT:
+ else
{
- // Sets the input shadow values.
- // TODO: to be implemented.
- break;
+ // Disable shadow.
+ if( Vector2::ZERO != controller->GetShadowOffset() )
+ {
+ controller->SetShadowOffset( Vector2::ZERO );
+ }
}
+ break;
}
- }
- }
+ case EffectStyle::INPUT:
+ {
+ const std::string& shadowString = value.Get<std::string>();
+
+ controller->SetInputShadowProperties( shadowString );
+ break;
+ }
+ } // switch
+ } // if( controller )
return update;
}
{
case EffectStyle::DEFAULT:
{
- value = controller->GetDefaultShadowProperties();
+ const Vector4& color = controller->GetShadowColor();
+ const Vector2& offset = controller->GetShadowOffset();
+ const float& blurRadius = controller->GetShadowBlurRadius();
+
+ if ( controller->IsShadowSetByString() )
+ {
+ std::string shadowProperties = "{";
+
+ std::string colorStr;
+ Vector4ToColorString( color, colorStr );
+ shadowProperties += "\"color\":\"" + colorStr + "\",";
+
+ std::string offsetStr;
+ Vector2ToString( offset, offsetStr );
+ shadowProperties += "\"offset\":\"" + offsetStr + "\",";
+
+ std::string blurRadiusStr;
+ FloatToString( blurRadius, blurRadiusStr );
+ shadowProperties += "\"blurRadius\":\"" + blurRadiusStr + "\"}";
+
+ value = shadowProperties;
+ }
+ else
+ {
+ Property::Map map;
+
+ map.Insert( COLOR_KEY, color );
+ map.Insert( OFFSET_KEY, offset );
+ map.Insert( BLUR_RADIUS_KEY, blurRadius );
+
+ value = map;
+ }
break;
}
case EffectStyle::INPUT:
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<Property::Map>();
+
+ bool colorDefined = false;
+ Vector4 color;
+ bool widthDefined = false;
+ unsigned int width = 0u;
+
+ 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<std::string>();
+
+ // 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 && ( controller->GetOutlineWidth() != width ) )
+ {
+ controller->SetOutlineWidth( width );
+ update = true;
+ }
+ }
+ else
+ {
+ // Disable outline
+ if( 0u != controller->GetOutlineWidth() )
+ {
+ controller->SetOutlineWidth( 0u );
+ 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<std::string>();
+
+ controller->SetInputOutlineProperties( outlineProperties );
break;
}
- }
- }
+ } // switch
+ } // if( controller )
return update;
}
{
case EffectStyle::DEFAULT:
{
- value = controller->GetDefaultOutlineProperties();
- break;
+ if ( controller->IsOutlineSetByString() )
+ {
+ value = controller->GetDefaultOutlineProperties();
+ break;
+ }
+ else
+ {
+ const Vector4& color = controller->GetOutlineColor();
+ const unsigned int width = controller->GetOutlineWidth();
+
+ Property::Map map;
+ map.Insert( COLOR_KEY, color );
+ map.Insert( WIDTH_KEY, static_cast<int>( width ) );
+
+ value = map;
+
+ break;
+ }
}
case EffectStyle::INPUT:
{