]> O.S.I.I.S - jp/vkvg.git/commitdiff
tests with dashed lines
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 30 Jan 2020 06:01:35 +0000 (07:01 +0100)
committerj-p <jp_bruyere@hotmail.com>
Tue, 5 May 2020 20:14:27 +0000 (22:14 +0200)
appveyor.yml
src/vkvg_context.c
tests/dashes.c [new file with mode: 0644]
vkh

index 6916627c2f4df57d76f4b774027cec300fc3d3a5..cb43170b86b50c101829af97dd84a5c9c465d41c 100644 (file)
@@ -33,7 +33,8 @@ for:
     build_script:
         - msbuild vkvg.sln /p:Configuration=Debug /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
     after_build:
-        - 7z a vkvg.zip %APPVEYOR_BUILD_FOLDER%/build/*.dll %APPVEYOR_BUILD_FOLDER%/build/*.exe %APPVEYOR_BUILD_FOLDER%/build/*.lib
+        - cd ..
+        - 7z a vkvg.zip build/*.dll build/*.exe build/*.lib
 
   -
     matrix:
@@ -52,7 +53,8 @@ for:
     build_script:
         - make
     after_build:
-        - 7z a vkvg.zip %APPVEYOR_BUILD_FOLDER%/build/*.so* %APPVEYOR_BUILD_FOLDER%/build/test_*
+        - cd ..
+        - 7z a build/vkvg.zip *.so* build/test_*
     
 
 
index a2022aa1e9eaefee676f8054bd328dc1e9b5b904..b03b33e99d6b31230ba0f0eaacdf4518b40387d7 100644 (file)
@@ -577,13 +577,12 @@ void vkvg_fill_preserve (VkvgContext ctx){
     }
 }
 
-void _draw_stoke_cap (VkvgContext ctx, float hw, vec2 p0, vec2 p1, bool isStart) {
+void _draw_stoke_cap (VkvgContext ctx, float hw, vec2 p0, vec2 n, bool isStart) {
     Vertex v = {0};
     v.uv.z = -1;
     VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
 
     if (isStart){
-        vec2 n = vec2_line_norm(p0, p1);
         vec2 vhw = vec2_mult(n,hw);
 
         if (ctx->lineCap == VKVG_LINE_CAP_SQUARE)
@@ -616,7 +615,7 @@ void _draw_stoke_cap (VkvgContext ctx, float hw, vec2 p0, vec2 p1, bool isStart)
 
         _add_tri_indices_for_rect(ctx, firstIdx);
     }else{
-        vec2 n = vec2_line_norm(p1, p0);
+        vec2_inv (&n);
         vec2 vhw = vec2_mult(n, hw);
 
         if (ctx->lineCap == VKVG_LINE_CAP_SQUARE)
@@ -650,6 +649,35 @@ void _draw_stoke_cap (VkvgContext ctx, float hw, vec2 p0, vec2 p1, bool isStart)
         }
     }
 }
+
+static bool     dashOn          = true;
+static uint32_t curDash         = 0;    //current dash index
+static float    curDashOffset   = 0.f;  //cur dash offset between defined path point and last dash segment(on/off) start
+static vec2     normal          = {0};
+
+void _draw_dashed_segment (VkvgContext ctx, vec2 pL, vec2 p, vec2 pR, float hw) {
+    Vertex v = {0};
+    v.uv.z = -1;
+
+    if (!dashOn)//we test in fact the next dash start, if dashOn = true => next segment is a void.
+        _build_vb_step (ctx, v, hw, pL, p, pR, false);
+
+    vec2 d = vec2_sub (pR, p);
+    normal = vec2_norm (d);
+    float segmentLength = vec2_length(d);
+
+    while (curDashOffset < segmentLength){
+        vec2 p0 = vec2_add (p, vec2_mult(normal, curDashOffset));
+
+        _draw_stoke_cap (ctx, hw, p0, normal, dashOn);
+        dashOn ^= true;
+
+        curDashOffset += ctx->dashes[curDash++];
+        if (curDash == ctx->dashCount)
+            curDash = 0;
+    }
+    curDashOffset -= segmentLength;
+}
 void vkvg_stroke_preserve (VkvgContext ctx)
 {
     if (ctx->pathPtr == 0)//nothing to stroke
@@ -666,6 +694,13 @@ void vkvg_stroke_preserve (VkvgContext ctx)
 
     while (ptrPath < ctx->pathPtr){
         uint32_t ptrCurve = 0;
+
+        //used for dashed lines
+        dashOn = true;
+        curDash = 0;          //current dash index
+        curDashOffset = 0.f;  //cur dash offset between defined path point and last dash segment(on/off) start
+        //---
+
         VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
         curPathPointIdx = ctx->pathes[ptrPath]&PATH_ELT_MASK;
 
@@ -674,7 +709,7 @@ void vkvg_stroke_preserve (VkvgContext ctx)
         lastPathPointIdx = ctx->pathes[ptrPath+1]&PATH_ELT_MASK;
         LOG(LOG_INFO_PATH, "end = %d\n", lastPathPointIdx);
 
-        if (_path_is_closed(ctx,ptrPath)){
+/*        if (_path_is_closed(ctx,ptrPath)){
             //prevent closing on the same position, this could be generalize
             //to prevent processing of two consecutive point at the same position
             if (vec2_equ(ctx->points[curPathPointIdx], ctx->points[lastPathPointIdx]))
@@ -682,11 +717,10 @@ void vkvg_stroke_preserve (VkvgContext ctx)
             iL = lastPathPointIdx;
         }else{
             _draw_stoke_cap (ctx, hw, ctx->points[curPathPointIdx], ctx->points[curPathPointIdx+1], true);
-
             iL = curPathPointIdx++;
-        }
+        }*/
 
-        if (_path_has_curves (ctx,ptrPath)) {
+        /*if (_path_has_curves (ctx,ptrPath)) {
             while (curPathPointIdx < lastPathPointIdx){
                 if (ptrPath + ptrCurve + 2 < ctx->pathPtr && (ctx->pathes [ptrPath + 2 + ptrCurve]&PATH_ELT_MASK) == curPathPointIdx){
                     uint32_t lastCurvePointIdx = ctx->pathes[ptrPath + 3 + ptrCurve]&PATH_ELT_MASK;
@@ -702,18 +736,30 @@ void vkvg_stroke_preserve (VkvgContext ctx)
                     iL = curPathPointIdx++;
                 }
             }
-        }else{
-            while (curPathPointIdx < lastPathPointIdx){
-                iR = curPathPointIdx+1;
-                _build_vb_step (ctx, v, hw, ctx->points[iL], ctx->points[curPathPointIdx], ctx->points[iR], false);
-                iL = curPathPointIdx++;
+        }else{*/
+        iL = lastPathPointIdx;
+            if (ctx->dashCount > 0) {
+                while (curPathPointIdx < lastPathPointIdx){
+                    iR = curPathPointIdx+1;
+                    _draw_dashed_segment(ctx, ctx->points[iL], ctx->points[curPathPointIdx], ctx->points[iR], hw);
+                    iL = curPathPointIdx++;
+                }
+                if (_path_is_closed(ctx,ptrPath)){
+                    iR = ctx->pathes[ptrPath] & PATH_ELT_MASK;
+                    _draw_dashed_segment(ctx, ctx->points[iL++], ctx->points[curPathPointIdx++], ctx->points[iR], hw);
+                }
+                if (!dashOn)
+                    _draw_stoke_cap (ctx, hw, ctx->points[curPathPointIdx], normal, false);
+            } else {
+                while (curPathPointIdx < lastPathPointIdx){
+                    iR = curPathPointIdx+1;
+                    _build_vb_step (ctx, v, hw, ctx->points[iL], ctx->points[curPathPointIdx], ctx->points[iR], false);
+                    iL = curPathPointIdx++;
+                }
             }
-        }
+        //}
 
-        if (!_path_is_closed(ctx,ptrPath)){
-            _draw_stoke_cap (ctx, hw, ctx->points[curPathPointIdx], ctx->points[curPathPointIdx-1], false);
-            //curPathPointIdx++;
-        }else{
+        /*if (_path_is_closed(ctx,ptrPath)){
             iR = ctx->pathes[ptrPath] & PATH_ELT_MASK;
             float cross = _build_vb_step (ctx, v, hw, ctx->points[iL], ctx->points[curPathPointIdx], ctx->points[iR], false);
 
@@ -729,7 +775,8 @@ void vkvg_stroke_preserve (VkvgContext ctx)
                 inds[5] = ii+1;
             }
             curPathPointIdx++;
-        }
+        }else
+            _draw_stoke_cap (ctx, hw, ctx->points[curPathPointIdx], ctx->points[curPathPointIdx-1], false);*/
 
         ptrPath+=2+ptrCurve;
     }
diff --git a/tests/dashes.c b/tests/dashes.c
new file mode 100644 (file)
index 0000000..a72bb3d
--- /dev/null
@@ -0,0 +1,29 @@
+#include "test.h"
+
+void test(){
+    vkvg_surface_clear(surf);
+
+    VkvgContext ctx = vkvg_create(surf);
+    const float dashes[] = {60.0f, 40};
+    vkvg_set_line_cap(ctx, VKVG_LINE_CAP_ROUND);
+    vkvg_set_dash(ctx, dashes, 2, 0.f);
+    vkvg_set_line_width(ctx, 20);
+    vkvg_set_source_rgb(ctx, 0, 0, 1);
+
+    vkvg_move_to (ctx, 50, 50);
+    vkvg_rel_line_to (ctx, 500, 0);
+    vkvg_rel_line_to (ctx, 0, 500);
+    vkvg_rel_line_to (ctx, 200, 0);
+    vkvg_rel_line_to (ctx, 0, 200);
+    vkvg_rel_line_to (ctx, -700, 0);
+    vkvg_stroke (ctx);
+
+    vkvg_destroy(ctx);
+}
+
+int main(int argc, char *argv[]) {
+
+    perform_test (test, 1024, 768);
+
+    return 0;
+}
diff --git a/vkh b/vkh
index fe84bd171b3ef9ea34ee961859c148c4892e548d..d13ee198a63102ae2ec6feb3397a65a503dcc25e 160000 (submodule)
--- a/vkh
+++ b/vkh
@@ -1 +1 @@
-Subproject commit fe84bd171b3ef9ea34ee961859c148c4892e548d
+Subproject commit d13ee198a63102ae2ec6feb3397a65a503dcc25e