]> O.S.I.I.S - jp/vkvg.git/commitdiff
removed pattern status, commands return status instead; vkvg_pattern_get_color_stop_c...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 29 Dec 2021 17:18:55 +0000 (18:18 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 29 Dec 2021 17:18:55 +0000 (18:18 +0100)
include/vkvg.h
src/vkvg_pattern.c
src/vkvg_pattern.h

index da8bc6a44bc95de99dd61b5920bb9353819e28d8..53b9433ad2a7e0b8768072e413630aac8cf48283 100644 (file)
@@ -108,6 +108,7 @@ typedef enum {
        VKVG_STATUS_NO_CURRENT_POINT,           /*!< path command expecting a current point to be defined failed*/
        VKVG_STATUS_INVALID_MATRIX,                     /*!< invalid matrix (not invertible)*/
        VKVG_STATUS_INVALID_STATUS,                     /*!< */
+       VKVG_STATUS_INVALID_INDEX,                      /*!< */
        VKVG_STATUS_NULL_POINTER,                       /*!< NULL pointer*/
        VKVG_STATUS_INVALID_STRING,                     /*!< */
        VKVG_STATUS_INVALID_PATH_DATA,          /*!< */
@@ -1045,42 +1046,56 @@ void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float
 vkvg_public
 void vkvg_rectangle(VkvgContext ctx, float x, float y, float w, float h);
 /**
- * @brief
+ * @brief Stroke command
+ *
+ * Perform a stroke of the current path and reset it.
  *
  * @param ctx a valid vkvg @ref context
  */
 vkvg_public
 void vkvg_stroke (VkvgContext ctx);
 /**
- * @brief
+ * @brief Stroke command that preserve current path.
+ *
+ * Perform a stroke of the current path and preserve it after the operation.
  *
  * @param ctx a valid vkvg @ref context
  */
 vkvg_public
 void vkvg_stroke_preserve (VkvgContext ctx);
 /**
- * @brief
+ * @brief Fill command
+ *
+ * Perform the filling of the current path. If no path is defined, this command has no effect.
+ * The current path is reseted after this operation.
  *
  * @param ctx a valid vkvg @ref context
  */
 vkvg_public
 void vkvg_fill (VkvgContext ctx);
 /**
- * @brief
+ * @brief Fill command that preserve current path.
+ *
+ * Same as @ref vkvg_fill, but don't reset the current path after the operation.
  *
  * @param ctx a valid vkvg @ref context
  */
 vkvg_public
 void vkvg_fill_preserve (VkvgContext ctx);
 /**
- * @brief
+ * @brief Paint command.
+ *
+ * perform a fill operation on the current path or on the full surface if no path is defined with
+ * the currently active pattern.
  *
  * @param ctx a valid vkvg @ref context
  */
 vkvg_public
 void vkvg_paint (VkvgContext ctx);
 /**
- * @brief
+ * @brief clear surface
+ *
+ * Color and clipping are reset to 0.
  *
  * @param ctx a valid vkvg @ref context
  */
@@ -1498,16 +1513,16 @@ VkvgPattern vkvg_pattern_create_linear (float x0, float y0, float x1, float y1);
 /**
  * @brief edit an existing linear gradient.
  *
- * edit control points of an existing linear gradient. If supplied pattern is not a linear gradient,
- * @ref VKVG_STATUS_PATTERN_TYPE_MISMATCH is set for pattern.
+ * edit control points of an existing linear gradient.
  *
  * @param x0 x coordinate of the start point
  * @param y0 y coordinate of the start point
  * @param x1 x coordinate of the end point
  * @param y1 y coordinate of the end point
+ * @return VKVG_STATUS_SUCCESS, or VKVG_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a linear gradient.
  */
 vkvg_public
-void vkvg_pattern_edit_linear (VkvgPattern pat, float x0, float y0, float x1, float y1);
+vkvg_status_t vkvg_pattern_edit_linear(VkvgPattern pat, float x0, float y0, float x1, float y1);
 /**
  * @brief get the gradient end points for a linear gradient
  *
@@ -1517,9 +1532,10 @@ void vkvg_pattern_edit_linear (VkvgPattern pat, float x0, float y0, float x1, fl
  * @param y0 y coordinate of the start point
  * @param x1 x coordinate of the end point
  * @param y1 y coordinate of the end point
+ * @return VKVG_STATUS_SUCCESS, or VKVG_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a linear gradient.
  */
 vkvg_public
-void vkvg_pattern_get_linear_points (VkvgPattern pat, float* x0, float* y0, float* x1, float* y1);
+vkvg_status_t vkvg_pattern_get_linear_points(VkvgPattern pat, float* x0, float* y0, float* x1, float* y1);
 /**
  * @brief create a new radial gradient.
  * 
@@ -1549,11 +1565,42 @@ VkvgPattern vkvg_pattern_create_radial (float cx0, float cy0, float radius0,
  * @param cx1 x coordinate for the center of the end circle, the outer circle.
  * @param cy1 y coordinate for the center of the end circle, the outer circle.
  * @param radius1 radius for the center of the end circle, the outer circle.
+ * @return VKVG_STATUS_SUCCESS, or VKVG_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a radial gradient.
  */
 vkvg_public
-void vkvg_pattern_edit_radial (VkvgPattern pat,
+vkvg_status_t vkvg_pattern_edit_radial(VkvgPattern pat,
                                                                float cx0, float cy0, float radius0,
                                                                float cx1, float cy1, float radius1);
+/**
+ * @brief get color stop count.
+ *
+ * Retrieve the color stop count of a gradient pattern.
+ *
+ * @param pat a valid pattern pointer.
+ * @param count a valid integer pointer to old the current stop count returned.
+ * @return VKVG_STATUS_SUCCESS, or VKVG_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a gradient.
+ */
+vkvg_public
+vkvg_status_t vkvg_pattern_get_color_stop_count (VkvgPattern pat, uint32_t* count);
+/**
+ * @brief get color stop.
+ *
+ * Gets the color and offset information at the given index for a gradient pattern. Values of index range from 0 to n-1 where n is the number
+ * returned by @ref vkvg_pattern_get_color_stop_count().
+ *
+ * @param pat a valid pattern pointer.
+ * @param index index of the stop to return data for.
+ * @param offset a valid float pointer to old the stop offset.
+ * @param r a valid float pointer to old the red component.
+ * @param g a valid float pointer to old the green component.
+ * @param b a valid float pointer to old the blue component.
+ * @param a a valid float pointer to old the alpha component.
+ * @return VKVG_STATUS_SUCCESS, VKVG_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a gradient, VKVG_STATUS_INVALID_INDEX if index is out of bounds.
+ */
+vkvg_public
+vkvg_status_t vkvg_pattern_get_color_stop_rgba (VkvgPattern pat, uint32_t index,
+                                                                                               float* offset, float* r, float* g, float* b, float* a);
+
 /**
  * @brief dispose pattern.
  * 
@@ -1577,7 +1624,7 @@ void vkvg_pattern_destroy (VkvgPattern pat);
  * @param a the alpha chanel of the color stop
  */
 vkvg_public
-void vkvg_pattern_add_color_stop (VkvgPattern pat, float offset, float r, float g, float b, float a);
+vkvg_status_t vkvg_pattern_add_color_stop(VkvgPattern pat, float offset, float r, float g, float b, float a);
 /**
  * @brief control the extend of the pattern
  * 
@@ -1585,6 +1632,7 @@ void vkvg_pattern_add_color_stop (VkvgPattern pat, float offset, float r, float
  *
  * @param pat the pattern to set extend for.
  * @param extend one value of the @ref vkvg_extend_t enumeration.
+ * @return VKVG_STATUS_SUCCESS, or VKVG_STATUS_PATTERN_TYPE_MISMATCH if the pattern is not a gradient.
  */
 vkvg_public
 void vkvg_pattern_set_extend (VkvgPattern pat, vkvg_extend_t extend);
index 3460b00e91a31b2bb67b03087ff388d7f3f05e2a..80601223ca588bad0880a978f3e668147033c05f 100644 (file)
@@ -36,33 +36,26 @@ VkvgPattern vkvg_pattern_create_for_surface (VkvgSurface surf){
 
        return pat;
 }
-void vkvg_pattern_get_linear_points (VkvgPattern pat, float* x0, float* y0, float* x1, float* y1) {
-       if (pat->status)
-               return;
+vkvg_status_t vkvg_pattern_get_linear_points (VkvgPattern pat, float* x0, float* y0, float* x1, float* y1) {
+       if (pat->type != VKVG_PATTERN_TYPE_LINEAR)
+               return VKVG_STATUS_PATTERN_TYPE_MISMATCH;
 
-       if (pat->type != VKVG_PATTERN_TYPE_LINEAR) {
-               pat->status = VKVG_STATUS_PATTERN_TYPE_MISMATCH;
-               return;
-       }
        vkvg_gradient_t* grad = (vkvg_gradient_t*)pat->data;
 
        *x0 = grad->cp[0].x;
        *y0 = grad->cp[0].y;
        *x1 = grad->cp[0].z;
        *y1 = grad->cp[0].w;
+       return VKVG_STATUS_SUCCESS;
 }
-void vkvg_pattern_edit_linear (VkvgPattern pat, float x0, float y0, float x1, float y1){
-       if (pat->status)
-               return;
-
-       if (pat->type != VKVG_PATTERN_TYPE_LINEAR) {
-               pat->status = VKVG_STATUS_PATTERN_TYPE_MISMATCH;
-               return;
-       }
+vkvg_status_t vkvg_pattern_edit_linear (VkvgPattern pat, float x0, float y0, float x1, float y1){
+       if (pat->type != VKVG_PATTERN_TYPE_LINEAR)
+               return VKVG_STATUS_PATTERN_TYPE_MISMATCH;
 
        vkvg_gradient_t* grad = (vkvg_gradient_t*)pat->data;
 
        grad->cp[0] = (vec4){{x0}, {y0}, {x1}, {y1}};
+       return VKVG_STATUS_SUCCESS;
 }
 VkvgPattern vkvg_pattern_create_linear (float x0, float y0, float x1, float y1){
        VkvgPattern pat = (vkvg_pattern_t*)calloc(1, sizeof(vkvg_pattern_t));
@@ -73,8 +66,8 @@ VkvgPattern vkvg_pattern_create_linear (float x0, float y0, float x1, float y1){
 
        pat->data = (void*)calloc(1,sizeof(vkvg_gradient_t));
        if (!pat->data) {
-               pat->status = VKVG_STATUS_NO_MEMORY;
-               return pat;
+               free (pat);
+               return NULL;
        }
 
        vkvg_pattern_edit_linear(pat, x0, y0, x1, y1);
@@ -83,16 +76,11 @@ VkvgPattern vkvg_pattern_create_linear (float x0, float y0, float x1, float y1){
 
        return pat;
 }
-void vkvg_pattern_edit_radial (VkvgPattern pat,
+vkvg_status_t vkvg_pattern_edit_radial (VkvgPattern pat,
                                                                                float cx0, float cy0, float radius0,
                                                                                float cx1, float cy1, float radius1) {
-       if (pat->status)
-               return;
-
-       if (pat->type != VKVG_PATTERN_TYPE_RADIAL) {
-               pat->status = VKVG_STATUS_PATTERN_TYPE_MISMATCH;
-               return;
-       }
+       if (pat->type != VKVG_PATTERN_TYPE_RADIAL)
+               return VKVG_STATUS_PATTERN_TYPE_MISMATCH;
 
        vkvg_gradient_t* grad = (vkvg_gradient_t*)pat->data;
 
@@ -110,6 +98,7 @@ void vkvg_pattern_edit_radial (VkvgPattern pat,
 
        grad->cp[0] = (vec4){{c0.x}, {c0.y},{radius0},{0}};
        grad->cp[1] = (vec4){{c1.x}, {c1.y},{radius1},{0}};
+       return VKVG_STATUS_SUCCESS;
 }
 VkvgPattern vkvg_pattern_create_radial (float cx0, float cy0, float radius0,
                                                                                float cx1, float cy1, float radius1){
@@ -121,8 +110,8 @@ VkvgPattern vkvg_pattern_create_radial (float cx0, float cy0, float radius0,
 
        pat->data = (void*)calloc(1,sizeof(vkvg_gradient_t));
        if (!pat->data) {
-               pat->status = VKVG_STATUS_NO_MEMORY;
-               return pat;
+               free (pat);
+               return NULL;
        }
 
        vkvg_pattern_edit_radial (pat, cx0, cy0, radius0, cx1, cy1, radius1);
@@ -131,9 +120,6 @@ VkvgPattern vkvg_pattern_create_radial (float cx0, float cy0, float radius0,
 
        return pat;
 }
-vkvg_status_t vkvg_pattern_status (VkvgPattern pat) {
-       return pat->status;
-}
 VkvgPattern vkvg_pattern_reference (VkvgPattern pat) {
        pat->references++;
        return pat;
@@ -141,9 +127,9 @@ VkvgPattern vkvg_pattern_reference (VkvgPattern pat) {
 uint32_t vkvg_pattern_get_reference_count (VkvgPattern pat) {
        return pat->references;
 }
-void vkvg_pattern_add_color_stop (VkvgPattern pat, float offset, float r, float g, float b, float a) {
+vkvg_status_t vkvg_pattern_add_color_stop (VkvgPattern pat, float offset, float r, float g, float b, float a) {
        if (pat->type == VKVG_PATTERN_TYPE_SURFACE || pat->type == VKVG_PATTERN_TYPE_SOLID)
-               return;
+               return VKVG_STATUS_PATTERN_TYPE_MISMATCH;
 
        vkvg_gradient_t* grad = (vkvg_gradient_t*)pat->data;
        vkvg_color_t c = {r,g,b,a};
@@ -167,6 +153,26 @@ vkvg_filter_t vkvg_pattern_get_filter (VkvgPattern pat){
 vkvg_pattern_type_t vkvg_pattern_get_type (VkvgPattern pat){
        return pat->type;
 }
+vkvg_status_t vkvg_pattern_get_color_stop_count (VkvgPattern pat, uint32_t* count) {
+       if (pat->type == VKVG_PATTERN_TYPE_SURFACE || pat->type == VKVG_PATTERN_TYPE_SOLID)
+               return VKVG_STATUS_PATTERN_TYPE_MISMATCH;
+       vkvg_gradient_t* grad = (vkvg_gradient_t*)pat->data;
+       *count = grad->count;
+       return VKVG_STATUS_SUCCESS;
+}
+vkvg_status_t vkvg_pattern_get_color_stop_rgba (VkvgPattern pat, uint32_t index,
+                                                                                               float* offset, float* r, float* g, float* b, float* a) {
+       if (pat->type == VKVG_PATTERN_TYPE_SURFACE || pat->type == VKVG_PATTERN_TYPE_SOLID)
+               return VKVG_STATUS_PATTERN_TYPE_MISMATCH;
+       vkvg_gradient_t* grad = (vkvg_gradient_t*)pat->data;
+       *offset = grad->stops[index];
+       vkvg_color_t c = grad->colors[index];
+       *r = c.r;
+       *g = c.g;
+       *b = c.b;
+       *a = c.a;
+       return VKVG_STATUS_SUCCESS;
+}
 
 void vkvg_pattern_destroy(VkvgPattern pat)
 {
index 3188d9e28ae4d92bc5e87e1183ba63584c1912c0..e43703062f96cd26b2143cb0511c1d77b6f545f6 100644 (file)
@@ -32,7 +32,6 @@ typedef struct _vkvg_pattern_t {
        vkvg_filter_t           filter;
        void*                           data;
        uint32_t                        references;
-       vkvg_status_t           status;
 }vkvg_pattern_t;
 
 typedef struct _vkvg_gradient_t {