Add borderline property for visual + Integrate some shaders in one
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.cpp
index 331eaf5..49b3120 100644 (file)
@@ -89,6 +89,14 @@ void Visual::Base::Initialize()
 
       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
     }
+    if(IsBorderlineRequired())
+    {
+      mImpl->mBorderlineWidthIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH,  BORDERLINE_WIDTH,  mImpl->mBorderlineWidth);
+      mImpl->mBorderlineColorIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR,  BORDERLINE_COLOR,  mImpl->mBorderlineColor);
+      mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+
+      mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
+    }
   }
 }
 
@@ -142,6 +150,18 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
       {
         matchKey = Property::Key(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE);
       }
+      else if(matchKey == BORDERLINE_WIDTH)
+      {
+        matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH);
+      }
+      else if(matchKey == BORDERLINE_COLOR)
+      {
+        matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_COLOR);
+      }
+      else if(matchKey == BORDERLINE_OFFSET)
+      {
+        matchKey = Property::Key(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET);
+      }
       else if(matchKey == CORNER_RADIUS)
       {
         matchKey = Property::Key(Toolkit::DevelVisual::Property::CORNER_RADIUS);
@@ -217,12 +237,55 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
           value, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT, mImpl->mFittingMode);
         break;
       }
+      case Toolkit::DevelVisual::Property::BORDERLINE_WIDTH:
+      {
+        float width;
+        if(value.Get(width))
+        {
+          mImpl->mBorderlineWidth = width;
+        }
+        break;
+      }
+      case Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
+      {
+        Vector4 color;
+        if(value.Get(color))
+        {
+          mImpl->mBorderlineColor = color;
+        }
+        break;
+      }
+      case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
+      {
+        float offset;
+        if(value.Get(offset))
+        {
+          mImpl->mBorderlineOffset = offset;
+        }
+        break;
+      }
       case Toolkit::DevelVisual::Property::CORNER_RADIUS:
       {
-        float radius;
-        if(value.Get(radius))
+        if(value.GetType() == Property::VECTOR4)
+        {
+          // If CORNER_RADIUS Property is Vector4,
+          // Each values mean the radius of
+          // (top-left, top-right, bottom-right, bottom-left)
+          Vector4 radius;
+          if(value.Get(radius))
+          {
+            mImpl->mCornerRadius = radius;
+          }
+        }
+        else
         {
-          mImpl->mCornerRadius = radius;
+          // If CORNER_RADIUS Property is float,
+          // Every corner radius have same value
+          float radius;
+          if(value.Get(radius))
+          {
+            mImpl->mCornerRadius = Vector4(radius, radius, radius, radius);
+          }
         }
         break;
       }
@@ -370,7 +433,19 @@ void Visual::Base::CreatePropertyMap(Property::Map& map) const
     }
     if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
     {
-      mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<float>(mImpl->mCornerRadiusIndex);
+      mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
+    }
+    if(mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
+    {
+      mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
+    }
+    if(mImpl->mBorderlineColorIndex != Property::INVALID_INDEX)
+    {
+      mImpl->mBorderlineColor = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mBorderlineColorIndex);
+    }
+    if(mImpl->mBorderlineOffsetIndex != Property::INVALID_INDEX)
+    {
+      mImpl->mBorderlineOffset = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineOffsetIndex);
     }
   }
 
@@ -397,6 +472,10 @@ void Visual::Base::CreatePropertyMap(Property::Map& map) const
     mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT);
   map.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, fittingModeString);
 
+  map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
+  map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor);
+  map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+
   map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->mCornerRadius);
   map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, static_cast<int>(mImpl->mCornerRadiusPolicy));
 }
@@ -449,9 +528,19 @@ bool Visual::Base::IsRoundedCornerRequired() const
   if(mImpl->mRenderer && mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
   {
     // Update values from Renderer
-    mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<float>(mImpl->mCornerRadiusIndex);
+    mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
+  }
+  return !(mImpl->mCornerRadius == Vector4::ZERO) || mImpl->mNeedCornerRadius;
+}
+
+bool Visual::Base::IsBorderlineRequired() const
+{
+  if(mImpl->mRenderer && mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
+  {
+    // Update values from Renderer
+    mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
   }
-  return !EqualsZero(mImpl->mCornerRadius) || mImpl->mNeedCornerRadius;
+  return !EqualsZero(mImpl->mBorderlineWidth) || mImpl->mNeedBorderline;
 }
 
 void Visual::Base::OnDoAction(const Property::Index actionId, const Property::Value& attributes)
@@ -808,7 +897,24 @@ Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
   Property::Index index = GetPropertyIndex(key);
   if(index == Property::INVALID_INDEX)
   {
-    if((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::CORNER_RADIUS) || (key.type == Property::Key::STRING && key.stringKey == CORNER_RADIUS))
+    if((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_WIDTH)  || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_WIDTH) ||
+       (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_COLOR)  || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_COLOR) ||
+       (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_OFFSET) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_OFFSET))
+    {
+      mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
+
+      // Register borderline properties
+      mImpl->mBorderlineWidthIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
+      mImpl->mBorderlineColorIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
+      mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+      mImpl->mNeedBorderline        = true;
+
+      index = mImpl->mRenderer.GetPropertyIndex(key);
+
+      // Change shader
+      UpdateShader();
+    }
+    else if((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::CORNER_RADIUS) || (key.type == Property::Key::STRING && key.stringKey == CORNER_RADIUS))
     {
       // Register CORNER_RADIUS property
       mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);