[C API] Added extra SkPath methods
authorMatthew Leibowitz <mattleibow@live.com>
Fri, 29 Jul 2016 18:06:05 +0000 (20:06 +0200)
committerMatthew Leibowitz <mattleibow@live.com>
Fri, 29 Jul 2016 18:06:05 +0000 (20:06 +0200)
include/c/sk_path.h
include/c/sk_types.h
src/c/sk_enums.cpp
src/c/sk_path.cpp

index 9922f68..b5de9a0 100644 (file)
@@ -53,6 +53,17 @@ SK_API void sk_path_cubic_to(sk_path_t*,
                              float x1, float y1,
                              float x2, float y2);
 /**
+ *  Append an elliptical arc from the current point in the format used by SVG.
+ *  The center of the ellipse is computed to satisfy the constraints below.
+ */
+SK_API void sk_path_arc_to(sk_path_t*, float rx, float ry, float xAxisRotate, sk_path_arc_size_t largeArc, sk_path_direction_t sweep, float x, float y);
+/**
+ *  Same as arcTo format used by SVG, but the destination coordinate is relative to the
+ *  last point on this contour. If there is no previous point, then a
+ *  moveTo(0,0) is inserted automatically.
+ */
+SK_API void sk_path_rarc_to(sk_path_t*, float rx, float ry, float xAxisRotate, sk_path_arc_size_t largeArc, sk_path_direction_t sweep, float x, float y);
+/**
    Close the current contour. If the current point is not equal to the
    first point of the contour, a line segment is automatically added.
 */
@@ -63,9 +74,18 @@ SK_API void sk_path_close(sk_path_t*);
 */
 SK_API void sk_path_add_rect(sk_path_t*, const sk_rect_t*, sk_path_direction_t);
 /**
+ *  Add a closed rounded rectangle contour to the path.
+ */
+SK_API void sk_path_add_rounded_rect(sk_path_t*, const sk_rect_t*, float, float, sk_path_direction_t);
+/**
     Add a closed oval contour to the path
 */
 SK_API void sk_path_add_oval(sk_path_t*, const sk_rect_t*, sk_path_direction_t);
+/**
+ *  Add a closed circle contour to the path. The circle contour begins at
+ *  the right-most point (as though 1 were passed to addOval's 'start' param).
+ */
+SK_API void sk_path_add_circle(sk_path_t*, float x, float y, float radius, sk_path_direction_t dir);
 
 /**
  *  If the path is empty, return false and set the rect parameter to [0, 0, 0, 0].
index 5f70b0d..c735248 100644 (file)
@@ -497,6 +497,11 @@ typedef enum {
     CCW_SK_PATH_DIRECTION,
 } sk_path_direction_t;
 
+typedef enum {
+    SMALL_SK_PATH_ARC_SIZE,
+    LARGE_SK_PATH_ARC_SIZE,
+} sk_path_arc_size_t;
+
 SK_C_PLUS_PLUS_END_GUARD
 
 #endif
index 6106bda..8987ff4 100644 (file)
@@ -49,6 +49,10 @@ static_assert ((int)SkPath::AddPathMode::kExtend_AddPathMode   == (int)EXTEND_SK
 static_assert ((int)SkPath::Direction::kCCW_Direction   == (int)CCW_SK_PATH_DIRECTION,   ASSERT_MSG(SkPath::Direction, sk_path_direction_t));
 static_assert ((int)SkPath::Direction::kCW_Direction    == (int)CW_SK_PATH_DIRECTION,    ASSERT_MSG(SkPath::Direction, sk_path_direction_t));
 
+// sk_path_arc_size_t
+static_assert ((int)SkPath::ArcSize::kLarge_ArcSize   == (int)LARGE_SK_PATH_ARC_SIZE,   ASSERT_MSG(SkPath::ArcSize, sk_path_arc_size_t));
+static_assert ((int)SkPath::ArcSize::kSmall_ArcSize   == (int)SMALL_SK_PATH_ARC_SIZE,   ASSERT_MSG(SkPath::ArcSize, sk_path_arc_size_t));
+
 // sk_path_filltype_t
 static_assert ((int)SkPath::FillType::kWinding_FillType          == (int)WINDING_SK_PATH_FILLTYPE,           ASSERT_MSG(SkPath::FillType, sk_path_filltype_t));
 static_assert ((int)SkPath::FillType::kEvenOdd_FillType          == (int)EVENODD_SK_PATH_FILLTYPE,           ASSERT_MSG(SkPath::FillType, sk_path_filltype_t));
index 6d42dcb..f343600 100644 (file)
@@ -180,6 +180,14 @@ void sk_path_cubic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1,
     AsPath(cpath)->cubicTo(x0, y0, x1, y1, x2, y2);
 }
 
+void sk_path_arc_to(sk_path_t* cpath, float rx, float ry, float xAxisRotate, sk_path_arc_size_t largeArc, sk_path_direction_t sweep, float x, float y) {
+    AsPath(cpath)->arcTo(rx, ry, xAxisRotate, (SkPath::ArcSize)largeArc, (SkPath::Direction)sweep, x, y);
+}
+
+void sk_path_rarc_to(sk_path_t* cpath, float rx, float ry, float xAxisRotate, sk_path_arc_size_t largeArc, sk_path_direction_t sweep, float x, float y) {
+    AsPath(cpath)->rArcTo(rx, ry, xAxisRotate, (SkPath::ArcSize)largeArc, (SkPath::Direction)sweep, x, y);
+}
+
 void sk_path_close(sk_path_t* cpath) {
     AsPath(cpath)->close();
 }
@@ -188,10 +196,18 @@ void sk_path_add_rect(sk_path_t* cpath, const sk_rect_t* crect, sk_path_directio
     AsPath(cpath)->addRect(AsRect(*crect), (SkPath::Direction)cdir);
 }
 
+void sk_path_add_rounded_rect(sk_path_t* cpath, const sk_rect_t* crect, float rx, float ry, sk_path_direction_t cdir) {
+    AsPath(cpath)->addRoundRect(AsRect(*crect), rx, ry, (SkPath::Direction)cdir);
+}
+
 void sk_path_add_oval(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir) {
     AsPath(cpath)->addOval(AsRect(*crect), (SkPath::Direction)cdir);
 }
 
+void sk_path_add_circle(sk_path_t* cpath, float x, float y, float radius, sk_path_direction_t dir) {
+    AsPath(cpath)->addCircle(x, y, radius, (SkPath::Direction)dir);
+}
+
 bool sk_path_get_bounds(const sk_path_t* cpath, sk_rect_t* crect) {
     const SkPath& path = AsPath(*cpath);