Enum properties added for the text effects style.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-effects-style.cpp
index e56eac3..f65655b 100755 (executable)
@@ -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 <dali-toolkit/internal/text/text-effects-style.h>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/text-controls/text-style-properties-devel.h>
 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
 #include <dali-toolkit/internal/text/property-string-parser.h>
 
@@ -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<Vector4>();
       }
     }
-    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<Vector2>();
       }
     }
-    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,7 +123,7 @@ 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.
       if( valueGet.second.GetType() == Dali::Property::STRING )
@@ -135,7 +136,7 @@ bool ParseUnderlineProperties( const Property::Map& underlinePropertiesMap,
         enabled = valueGet.second.Get<bool>();
       }
     }
-    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;
@@ -150,7 +151,7 @@ bool ParseUnderlineProperties( const Property::Map& underlinePropertiesMap,
         color = valueGet.second.Get<Vector4>();
       }
     }
-    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;
@@ -183,13 +184,13 @@ 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<Vector4>();
     }
-    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;
@@ -200,6 +201,34 @@ bool ParseOutlineProperties( const Property::Map& underlinePropertiesMap,
   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<bool>();
+    }
+    else if( ( DevelText::Background::Property::COLOR == valueGet.first.indexKey ) || ( COLOR_KEY == valueGet.first.stringKey ) )
+    {
+      /// Color key.
+      colorDefined = true;
+      color = valueGet.second.Get<Vector4>();
+    }
+  }
+
+  return 0u == numberOfItems;
+}
+
 bool SetUnderlineProperties( ControllerPtr controller, const Property::Value& value, EffectStyle::Type type )
 {
   bool update = false;
@@ -649,14 +678,8 @@ void GetOutlineProperties( ControllerPtr controller, Property::Value& value, Eff
           const unsigned int width = controller->GetOutlineWidth();
 
           Property::Map map;
-
-          std::string colorStr;
-          Vector4ToColorString( color, colorStr );
-          map.Insert( COLOR_KEY, colorStr );
-
-          std::string widthStr;
-          UintToString( width, widthStr );
-          map.Insert( WIDTH_KEY, widthStr );
+          map.Insert( COLOR_KEY, color );
+          map.Insert( WIDTH_KEY, static_cast<int>( width ) );
 
           value = map;
 
@@ -672,6 +695,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<Property::Map>();
+
+        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