Merge "Add transition headers in dali-toolkit.h" into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 29 Jul 2021 11:19:13 +0000 (11:19 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 29 Jul 2021 11:19:13 +0000 (11:19 +0000)
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-canvas-renderer.cpp
automated-tests/src/dali-toolkit/utc-Dali-CanvasView.cpp
dali-toolkit/devel-api/controls/canvas-view/canvas-view.cpp
dali-toolkit/devel-api/controls/canvas-view/canvas-view.h
dali-toolkit/internal/controls/canvas-view/canvas-view-impl.cpp
dali-toolkit/internal/controls/canvas-view/canvas-view-impl.h

index 8db2a84..f280f6f 100644 (file)
@@ -38,8 +38,10 @@ class CanvasRenderer: public Dali::BaseObject
 {
 public:
   CanvasRenderer( const Vector2& size )
-  : mPixelBuffer( Devel::PixelBuffer::New(size.width, size.height, Dali::Pixel::RGBA8888) ),
-    mSize(size)
+  : mDrawable(nullptr),
+    mPixelBuffer( Devel::PixelBuffer::New(size.width, size.height, Dali::Pixel::RGBA8888) ),
+    mSize(size),
+    mViewBox(size)
   {
   }
 
@@ -68,9 +70,33 @@ public:
     {
       return false;
     }
+    mDrawable = &drawable;
     return true;
   }
 
+  bool RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable)
+  {
+    if (!drawable)
+    {
+      return false;
+    }
+    if (mDrawable == &drawable)
+    {
+      mDrawable = nullptr;
+      return true;
+    }
+    return false;
+  }
+
+  bool RemoveAllDrawables()
+  {
+    if (mDrawable)
+    {
+      return true;
+    }
+    return false;
+  }
+
   Devel::PixelBuffer GetPixelBuffer()
   {
     return mPixelBuffer;
@@ -94,10 +120,27 @@ public:
     return mSize;
   }
 
+  bool SetViewBox(const Vector2& viewBox)
+  {
+    mViewBox = viewBox;
+    // For negative test
+    if ( viewBox.width == -999 && viewBox.height == -999 )
+    {
+      return false;
+    }
+    return true;
+  }
+
+  const Vector2& GetViewBox()
+  {
+    return mViewBox;
+  }
 
 public:
+   Dali::CanvasRenderer::Drawable* mDrawable;
    Devel::PixelBuffer mPixelBuffer;
    Vector2 mSize;
+   Vector2 mViewBox;
 };
 
 inline CanvasRenderer& GetImplementation( Dali::CanvasRenderer& renderer )
@@ -168,6 +211,16 @@ bool CanvasRenderer::AddDrawable(Dali::CanvasRenderer::Drawable& drawable)
   return Internal::Adaptor::GetImplementation(*this).AddDrawable(drawable);
 }
 
+bool CanvasRenderer::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable)
+{
+  return Internal::Adaptor::GetImplementation(*this).RemoveDrawable(drawable);
+}
+
+bool CanvasRenderer::RemoveAllDrawables()
+{
+  return Internal::Adaptor::GetImplementation(*this).RemoveAllDrawables();
+}
+
 bool CanvasRenderer::SetSize(const Vector2& size)
 {
   return Internal::Adaptor::GetImplementation(*this).SetSize(size);
@@ -178,5 +231,14 @@ const Vector2& CanvasRenderer::GetSize()
   return Internal::Adaptor::GetImplementation(*this).GetSize();
 }
 
+bool CanvasRenderer::SetViewBox(const Vector2& viewBox)
+{
+  return Internal::Adaptor::GetImplementation(*this).SetViewBox(viewBox);
+}
+
+const Vector2& CanvasRenderer::GetViewBox()
+{
+  return Internal::Adaptor::GetImplementation(*this).GetViewBox();
+}
 
 } // namespace Dali
index 3192617..36cf1df 100644 (file)
@@ -167,6 +167,63 @@ int UtcDaliCanvasViewAddN(void)
   END_TEST;
 }
 
+int UtcDaliCanvasViewRemoveP(void)
+{
+  ToolkitTestApplication application;
+  CanvasView canvasView = CanvasView::New(Vector2(100,100));
+  DALI_TEST_CHECK( canvasView );
+
+  Dali::CanvasRenderer::Shape shape = Dali::CanvasRenderer::Shape::New();
+
+  canvasView.AddDrawable(shape);
+
+  DALI_TEST_CHECK( canvasView.RemoveDrawable(shape) );
+
+  END_TEST;
+}
+
+int UtcDaliCanvasViewRemoveN(void)
+{
+  ToolkitTestApplication application;
+
+  CanvasView canvasView = CanvasView::New(Vector2(100,100));
+  DALI_TEST_CHECK( canvasView );
+
+  Dali::CanvasRenderer::Shape shape = Dali::CanvasRenderer::Shape::New();
+
+  DALI_TEST_CHECK( !canvasView.RemoveDrawable(shape) );
+
+  END_TEST;
+}
+
+int UtcDaliCanvasViewRemoveAllP(void)
+{
+  ToolkitTestApplication application;
+  CanvasView canvasView = CanvasView::New(Vector2(100,100));
+  DALI_TEST_CHECK( canvasView );
+
+  Dali::CanvasRenderer::Shape shape = Dali::CanvasRenderer::Shape::New();
+
+  canvasView.AddDrawable(shape);
+
+  canvasView.RemoveAllDrawables();
+
+  END_TEST;
+}
+
+int UtcDaliCanvasViewRemoveAllN(void)
+{
+  ToolkitTestApplication application;
+
+  CanvasView canvasView = CanvasView::New(Vector2(100,100));
+  DALI_TEST_CHECK( canvasView );
+
+  canvasView.RemoveAllDrawables();
+
+  END_TEST;
+}
+
+
 int UtcDaliCanvasViewChangeSizeP(void)
 {
   ToolkitTestApplication application;
@@ -488,3 +545,42 @@ int UtcDaliCanvasViewSetSizeAndAddDrawable(void)
 
   END_TEST;
 }
+
+int UtcDaliCanvasViewViewBoxP(void)
+{
+  ToolkitTestApplication application;
+
+  CanvasView canvasView = CanvasView::New(Vector2(300, 300));
+  DALI_TEST_CHECK( canvasView );
+
+  application.GetScene().Add(canvasView);
+
+  canvasView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
+  canvasView.SetProperty(Toolkit::CanvasView::Property::VIEW_BOX, Vector2(100, 100));
+
+  application.SendNotification();
+  application.Render();
+
+  END_TEST;
+}
+
+int UtcDaliCanvasViewViewBoxN(void)
+{
+  ToolkitTestApplication application;
+
+  CanvasView canvasView = CanvasView::New(Vector2(300, 300));
+  DALI_TEST_CHECK( canvasView );
+
+  application.GetScene().Add(canvasView);
+
+  canvasView.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
+  canvasView.SetProperty(Toolkit::CanvasView::Property::VIEW_BOX, Vector2(-999, -999));
+
+  application.SendNotification();
+  application.Render();
+
+  Vector2 viewBox = canvasView.GetProperty(Toolkit::CanvasView::Property::VIEW_BOX).Get<Vector2>();
+  DALI_TEST_EQUALS( viewBox, Vector2(-999, -999), TEST_LOCATION );
+
+  END_TEST;
+}
index f2a4a2e..a00cd35 100644 (file)
@@ -73,6 +73,16 @@ void CanvasView::AddDrawable(Dali::CanvasRenderer::Drawable& drawable)
   Dali::Toolkit::GetImpl(*this).AddDrawable(drawable);
 }
 
+bool CanvasView::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable)
+{
+  return Dali::Toolkit::GetImpl(*this).RemoveDrawable(drawable);
+}
+
+void CanvasView::RemoveAllDrawables()
+{
+  Dali::Toolkit::GetImpl(*this).RemoveAllDrawables();
+}
+
 CanvasView::CanvasView(Internal::CanvasView& implementation)
 : Control(implementation)
 {
index c0e0709..64e1397 100644 (file)
@@ -51,12 +51,42 @@ class CanvasView;
  *    myCanvasView.AddDrawable( shape );
  * @endcode
  *
+ * @section CanvasViewProperties Properties
+ * |%Property enum                    |String name          |Type            |Writable|Animatable|
+ * |----------------------------------|---------------------|----------------|--------|----------|
+ * | Property::VIEW_BOX               | viewBox             |  Vector2       | O      | X        |
  *
  */
 class DALI_TOOLKIT_API CanvasView : public Control
 {
 public:
   /**
+   * @brief The start and end property ranges for this control.
+   */
+  enum PropertyRange
+  {
+    PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
+  };
+
+  /**
+   * @brief An enumeration of properties belonging to the CanvasView class.
+   */
+  struct Property
+  {
+    /**
+     * @brief An enumeration of properties belonging to the CanvasView class.
+     */
+    enum
+    {
+      /**
+       * @brief the viewbox of the CanvasView.
+       * @details Name "viewBox", type Property::VECTOR2.
+       */
+      VIEW_BOX = PROPERTY_START_INDEX,
+    };
+  };
+public:
+  /**
    * @brief Creates an uninitialized CanvasView.
    */
   CanvasView();
@@ -127,9 +157,23 @@ public:
   /**
    * @brief Add drawable object to the CanvasView.
    * This method is similar to registration. The added shape is drawn on the inner canvas.
+   * @param[in] drawable the drawable object.
    */
   void AddDrawable(Dali::CanvasRenderer::Drawable& drawable);
 
+  /**
+   * @brief Remove drawable object to the CanvasView.
+   * This method is similar to deregistration.
+   * @param[in] drawable the drawable object.
+   * @return Returns True when it's successful. False otherwise.
+   */
+  bool RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable);
+
+  /**
+   * @brief Remove all drawable objects added to the CanvasView.
+   */
+  void RemoveAllDrawables();
+
 public: // Not intended for application developers
   /// @cond internal
   /**
index 0132e3c..c04a730 100644 (file)
@@ -45,6 +45,7 @@ BaseHandle Create()
 }
 // Setup properties, signals and actions using the type-registry.
 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::CanvasView, Toolkit::Control, Create);
+DALI_PROPERTY_REGISTRATION(Toolkit, CanvasView, "viewBox", VECTOR2, VIEW_BOX)
 DALI_TYPE_REGISTRATION_END()
 } // anonymous namespace
 
@@ -126,6 +127,50 @@ void CanvasView::OnSizeSet(const Vector3& targetSize)
   mSize.height = targetSize.height;
 }
 
+void CanvasView::SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value)
+{
+  Toolkit::CanvasView canvasView = Toolkit::CanvasView::DownCast(Dali::BaseHandle(object));
+  if(canvasView)
+  {
+    CanvasView& canvasViewImpl(GetImpl(canvasView));
+
+    switch(propertyIndex)
+    {
+      case Toolkit::CanvasView::Property::VIEW_BOX:
+      {
+        Vector2 valueVector2;
+        if(value.Get(valueVector2))
+        {
+          canvasViewImpl.SetViewBox(valueVector2);
+        }
+        break;
+      }
+    }
+  }
+}
+
+Property::Value CanvasView::GetProperty(BaseObject* object, Property::Index propertyIndex)
+{
+  Property::Value value;
+
+  Toolkit::CanvasView canvasView = Toolkit::CanvasView::DownCast(Dali::BaseHandle(object));
+
+  if(canvasView)
+  {
+    CanvasView& canvasViewImpl(GetImpl(canvasView));
+
+    switch(propertyIndex)
+    {
+      case Toolkit::CanvasView::Property::VIEW_BOX:
+      {
+        value = canvasViewImpl.GetViewBox();
+        break;
+      }
+    }
+  }
+  return value;
+}
+
 void CanvasView::Process(bool postProcessor)
 {
   if(mCanvasRenderer && mCanvasRenderer.IsCanvasChanged() && mSize.width > 0 && mSize.height > 0)
@@ -205,6 +250,42 @@ bool CanvasView::AddDrawable(Dali::CanvasRenderer::Drawable& drawable)
   }
   return false;
 }
+
+bool CanvasView::RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable)
+{
+  if(mCanvasRenderer && mCanvasRenderer.RemoveDrawable(drawable))
+  {
+    return true;
+  }
+  return false;
+}
+
+bool CanvasView::RemoveAllDrawables()
+{
+  if(mCanvasRenderer && mCanvasRenderer.RemoveAllDrawables())
+  {
+    return true;
+  }
+  return false;
+}
+
+bool CanvasView::SetViewBox(const Vector2& viewBox)
+{
+  if(mCanvasRenderer && mCanvasRenderer.SetViewBox(viewBox))
+  {
+    return true;
+  }
+  return false;
+}
+
+const Vector2& CanvasView::GetViewBox()
+{
+  if(mCanvasRenderer)
+  {
+    return mCanvasRenderer.GetViewBox();
+  }
+  return Vector2::ZERO;
+}
 } // namespace Internal
 } // namespace Toolkit
 } // namespace Dali
index 1a468b0..6b6cf93 100644 (file)
@@ -63,6 +63,32 @@ public:
    */
   bool AddDrawable(Dali::CanvasRenderer::Drawable& drawable);
 
+  /**
+   * Called when a property of an object of this type is set.
+   * @param[in] object The object whose property is set.
+   * @param[in] propertyIndex The property index.
+   * @param[in] value The new property value.
+   */
+  static void SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value);
+
+  /**
+   * Called to retrieve a property of an object of this type.
+   * @param[in] object The object whose property is to be retrieved.
+   * @param[in] propertyIndex The property index.
+   * @return The current value of the property.
+   */
+  static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
+
+  /**
+   * @copydoc Toolkit::Control::CanvasView::RemoveDrawable
+   */
+  bool RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable);
+
+  /**
+   * @copydoc Toolkit::Control::CanvasView::RemoveAllDrawables
+   */
+  bool RemoveAllDrawables();
+
 private: // From Control
   /**
    * @copydoc Control::OnRelayout
@@ -80,6 +106,19 @@ private: // From Control
   void OnInitialize() override;
 
   /**
+   * @brief This is the viewbox of the Canvas.
+   * @param[in] viewBox The size of viewbox.
+   * @return Returns True when it's successful. False otherwise.
+   */
+  bool SetViewBox(const Vector2& viewBox);
+
+  /**
+   * @brief This is the viewbox of the Canvas.
+   * @return Returns The size of viewbox.
+   */
+  const Vector2& GetViewBox();
+
+  /**
    * @bried Rasterize the canvas, and add it to the view.
    *
    * @param[in] size The target size of the canvas view rasterization.