CanvasRenderer::Shape: Add AddPath() Api 73/262073/6
authorJunsuChoi <jsuya.choi@samsung.com>
Mon, 2 Aug 2021 08:51:16 +0000 (17:51 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Fri, 13 Aug 2021 00:51:51 +0000 (09:51 +0900)
Adds an API that adds a large path information.
The PathCommands structure has a PathCommandType array, a Point array
and the number of each array.

ex)
//Prepare Path Commands
Dali::CanvasRenderer::Shape::PathCommandType commands[11];
commands[0] = Dali::CanvasRenderer::Shape::PathCommandType::MOVE_TO;
commands[1] = Dali::CanvasRenderer::Shape::PathCommandType::LINE_TO;
commands[2] = Dali::CanvasRenderer::Shape::PathCommandType::LINE_TO;
commands[3] = Dali::CanvasRenderer::Shape::PathCommandType::LINE_TO;
commands[4] = Dali::CanvasRenderer::Shape::PathCommandType::LINE_TO;
commands[5] = Dali::CanvasRenderer::Shape::PathCommandType::LINE_TO;
commands[6] = Dali::CanvasRenderer::Shape::PathCommandType::LINE_TO;
commands[7] = Dali::CanvasRenderer::Shape::PathCommandType::LINE_TO;
commands[8] = Dali::CanvasRenderer::Shape::PathCommandType::LINE_TO;
commands[9] = Dali::CanvasRenderer::Shape::PathCommandType::LINE_TO;
commands[10] = Dali::CanvasRenderer::Shape::PathCommandType::CLOSE;

//Prepare Path Points
float points[20] = {-1.0f, -165.0f,
                    53.0f, -56.0f,
                    174.0f, -39.0f,
                    87.0f, 45.0f,
                    107.0f, 166.0f,
                    -1.0f, 110.0f,
                    -103.0f, 166.0f,
                    -88.0f, 46.0f,
                    -174.0f, -38.0f,
                    -54.0f, -56.0f};

Dali::CanvasRenderer::Shape::PathCommands starPath = { commands, 11, points, 20 };

Dali::CanvasRenderer::Shape star = Dali::CanvasRenderer::Shape::New();
star.AddPath(starPath);
mCanvasView.AddDrawable(star);

Change-Id: I36cea22b1e80bfe2182cdb7fb2a8e262523c2a4f

dali/devel-api/adaptor-framework/canvas-renderer-shape.cpp
dali/devel-api/adaptor-framework/canvas-renderer-shape.h
dali/internal/canvas-renderer/common/shape-impl.cpp
dali/internal/canvas-renderer/common/shape-impl.h
dali/internal/canvas-renderer/generic/shape-impl-generic.cpp
dali/internal/canvas-renderer/generic/shape-impl-generic.h
dali/internal/canvas-renderer/tizen/shape-impl-tizen.cpp
dali/internal/canvas-renderer/tizen/shape-impl-tizen.h
dali/internal/canvas-renderer/ubuntu/shape-impl-ubuntu.cpp
dali/internal/canvas-renderer/ubuntu/shape-impl-ubuntu.h

index 20ab50a..f9dd12a 100644 (file)
@@ -73,6 +73,11 @@ bool CanvasRenderer::Shape::AddCubicTo(Vector2 controlPoint1, Vector2 controlPoi
   return GetImplementation(*this).AddCubicTo(controlPoint1, controlPoint2, endPoint);
 }
 
+bool CanvasRenderer::Shape::AddPath(PathCommands& pathCommand)
+{
+  return GetImplementation(*this).AddPath(pathCommand);
+}
+
 bool CanvasRenderer::Shape::Close()
 {
   return GetImplementation(*this).Close();
index 892abb5..281d772 100644 (file)
@@ -105,6 +105,30 @@ public:
     EVEN_ODD     ///< Draw a horizontal line from the point to a location outside the shape, and count the number of intersections. If the number of intersections is an odd number, the point is inside the shape.
   };
 
+  /**
+   * @brief Enumeration specifying the values of the path commands.
+   * Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others).
+   */
+  enum class PathCommandType
+  {
+    CLOSE = 0, ///< Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.
+    MOVE_TO,   ///< Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.
+    LINE_TO,   ///< Draws a line from the current point to the given point and sets a new value of the current point. This command expects 1 point: the end-position of the line.
+    CUBIC_TO   ///< Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point. This command expects 3 points: the 1st control-point, the 2nd control-point, the end-point of the curve.
+  };
+
+  /**
+   * @brief Structure that contains information about a list of path commands.
+   * For each command from the mCommands array, an appropriate number of points in mPoints array should be specified.
+   */
+  struct PathCommands
+  {
+    PathCommandType* mCommands;     ///< Set of each PathComand.
+    uint32_t         mCommandCount; ///< The number of command array.
+    float*           mPoints;       ///< Set of each Point
+    uint32_t         mPointCount;   ///< The number of point array.
+  };
+
 public:
   /**
    * @brief Append the given rectangle with rounded corner to the path.
@@ -171,6 +195,16 @@ public:
   bool AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint);
 
   /**
+   * @brief Appends a given sub-path to the path.
+   * The current point value is set to the last point from the sub-path.
+   * @param[in] pathCommand The command object that contain sub-path information. (This command information is copied internally.)
+   * @return Returns True when it's successful. False otherwise.
+   * @note The interface is designed for optimal path setting if the caller has a completed path commands already.
+   *
+   */
+  bool AddPath(PathCommands& pathCommand);
+
+  /**
    * @brief Closes the current subpath by drawing a line to the beginning of the
    * subpath, automatically starting a new path. The current point of the
    * new path is (0, 0).
index dd3bcae..67ebd42 100644 (file)
@@ -58,6 +58,11 @@ bool Shape::AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 end
   return false;
 }
 
+bool Shape::AddPath(Dali::CanvasRenderer::Shape::PathCommands& pathCommand)
+{
+  return false;
+}
+
 bool Shape::Close()
 {
   return false;
index 4c22519..1aecdf7 100644 (file)
@@ -79,6 +79,11 @@ public:
   virtual bool AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint);
 
   /**
+   * @copydoc Dali::CanvasRenderer::Shape::AddPath()
+   */
+  virtual bool AddPath(Dali::CanvasRenderer::Shape::PathCommands& pathCommand);
+
+  /**
    * @copydoc Dali::CanvasRenderer::Shape::Close()
    */
   virtual bool Close();
index 793c6b6..01bb06e 100644 (file)
@@ -82,6 +82,11 @@ bool ShapeGeneric::AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vect
   return false;
 }
 
+bool ShapeGeneric::AddPath(Dali::CanvasRenderer::Shape::PathCommands& pathCommand)
+{
+  return false;
+}
+
 bool ShapeGeneric::Close()
 {
   return false;
index 52a6eba..630a9e6 100644 (file)
@@ -74,6 +74,11 @@ public:
   bool AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint) override;
 
   /**
+   * @copydoc Dali::CanvasRenderer::Shape::AddPath()
+   */
+  bool AddPath(Dali::CanvasRenderer::Shape::PathCommands& pathCommand) override;
+
+  /**
    * @copydoc Dali::CanvasRenderer::Shape::Close()
    */
   bool Close() override;
index 9e5946e..1665f96 100644 (file)
@@ -199,6 +199,27 @@ bool ShapeTizen::AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector
 #endif
 }
 
+bool ShapeTizen::AddPath(Dali::CanvasRenderer::Shape::PathCommands& pathCommand)
+{
+#ifdef THORVG_SUPPORT
+  if(!Drawable::GetObject() || !mTvgShape)
+  {
+    DALI_LOG_ERROR("Shape is null\n");
+    return false;
+  }
+
+  if(static_cast<tvg::Shape*>(mTvgShape)->appendPath(reinterpret_cast<const tvg::PathCommand*>(pathCommand.mCommands), pathCommand.mCommandCount, static_cast<const tvg::Point*>((void*)pathCommand.mPoints), pathCommand.mPointCount) != tvg::Result::Success)
+  {
+    DALI_LOG_ERROR("AddPath() fail.\n");
+    return false;
+  }
+  Drawable::SetChanged(true);
+  return true;
+#else
+  return false;
+#endif
+}
+
 bool ShapeTizen::Close()
 {
 #ifdef THORVG_SUPPORT
index a5c8dc4..3c43c48 100644 (file)
@@ -77,6 +77,11 @@ public:
   bool AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint) override;
 
   /**
+   * @copydoc Dali::CanvasRenderer::Shape::AddPath()
+   */
+  bool AddPath(Dali::CanvasRenderer::Shape::PathCommands& pathCommand) override;
+
+  /**
    * @copydoc Dali::CanvasRenderer::Shape::Close()
    */
   bool Close() override;
index 2c5bb2f..758dc97 100644 (file)
@@ -199,6 +199,27 @@ bool ShapeUbuntu::AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vecto
 #endif
 }
 
+bool ShapeUbuntu::AddPath(Dali::CanvasRenderer::Shape::PathCommands& pathCommand)
+{
+#ifdef THORVG_SUPPORT
+  if(!Drawable::GetObject() || !mTvgShape)
+  {
+    DALI_LOG_ERROR("Shape is null\n");
+    return false;
+  }
+
+  if(static_cast<tvg::Shape*>(mTvgShape)->appendPath(reinterpret_cast<const tvg::PathCommand*>(pathCommand.mCommands), pathCommand.mCommandCount, static_cast<const tvg::Point*>((void*)pathCommand.mPoints), pathCommand.mPointCount) != tvg::Result::Success)
+  {
+    DALI_LOG_ERROR("AddPath() fail.\n");
+    return false;
+  }
+  Drawable::SetChanged(true);
+  return true;
+#else
+  return false;
+#endif
+}
+
 bool ShapeUbuntu::Close()
 {
 #ifdef THORVG_SUPPORT
index 6efe304..a459a35 100644 (file)
@@ -77,6 +77,11 @@ public:
   bool AddCubicTo(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint) override;
 
   /**
+   * @copydoc Dali::CanvasRenderer::Shape::AddPath()
+   */
+  bool AddPath(Dali::CanvasRenderer::Shape::PathCommands& pathCommand) override;
+
+  /**
    * @copydoc Dali::CanvasRenderer::Shape::Close()
    */
   bool Close() override;