if (ctx->pointCount - ctx->pathes [ctx->pathPtr-1] > 2){
//set end idx of path to the same as start idx
ctx->pathes[ctx->pathPtr] = ctx->pathes [ctx->pathPtr-1];
+ //if last point of path is same pos as first point, remove it
+ if (vec2_equ(ctx->points[ctx->pointCount-1], ctx->points[ctx->pathes[ctx->pathPtr]]))
+ ctx->pointCount--;
//start new path
_check_pathes_array(ctx);
ctx->pathPtr++;
vkvg_move_to(ctx, x,y);
}
-//this function expect that current path is empty (ctx->pathPtr % 2 == 0)
-void _start_sub_path (VkvgContext ctx){
- //set start to current idx in point array
- ctx->pathes[ctx->pathPtr] = ctx->pointCount;
- _check_pathes_array(ctx);
- ctx->pathPtr++;
-}
void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, float a2){
while (a2 < a1)
a2 += 2*M_PI;
ctx->curPosExists = true;
}
void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) {
- _bezier (ctx, ctx->curPos.x, ctx->curPos.y, x1, y1, x2, y2, x3, y3);
+ vec2 p = ctx->curPos;
+ vec2 p1 = {x1,y1};
+
+ if (_current_path_is_empty(ctx)){
+ _start_sub_path(ctx);
+ if (!ctx->curPosExists)
+ p = p1;
+ if (!vec2_equ (p,p1))
+ _add_point (ctx, p.x, p.y);
+ }
+
+ _recursive_bezier (ctx, p.x, p.y, x1, y1, x2, y2, x3, y3, 0);
+ _add_point_cp_update (ctx, x3, y3);
}
void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) {
vkvg_curve_to (ctx, ctx->curPos.x + x1, ctx->curPos.y + y1, ctx->curPos.x + x2, ctx->curPos.y + y2, ctx->curPos.x + x3, ctx->curPos.y + y3);
vkCmdSetStencilReference(ctx->cmd,VK_STENCIL_FRONT_AND_BACK, ctx->stencilRef);
}
void vkvg_reset_clip (VkvgContext ctx){
- /*
- VkClearValue clearValue = {0};
- VkClearAttachment clrAtt = {VK_IMAGE_ASPECT_STENCIL_BIT, 2 ,clearValue};
- VkClearRect clr = {{{0,0},{ctx->pSurf->width,ctx->pSurf->height}},0,1};
- ctx->stencilRef=0;
- vkCmdSetStencilReference(ctx->cmd,VK_STENCIL_FRONT_AND_BACK, ctx->stencilRef);
- vkCmdClearAttachments (ctx->cmd ,1,&clrAtt,1,&clr);
- */
_flush_cmd_buff(ctx);
_clear_stencil(ctx->pSurf);
ctx->stencilRef=0;
_record_draw_cmd (ctx);
}
+inline void vkvg_set_source_rgb (VkvgContext ctx, float r, float g, float b) {
+ vkvg_set_source_rgba (ctx, r, g, b, 1);
+}
void vkvg_set_source_rgba (VkvgContext ctx, float r, float g, float b, float a)
{
uint32_t lastPat = ctx->pushConsts.patternType;
vkvg_fill(ctx);
}
-void vkvg_test_curves (VkvgContext ctx) {
+void vkvg_test_curves2 (VkvgContext ctx) {
vkvg_set_source_rgba (ctx, 0.5,0.0,1.0,0.5);
vkvg_set_line_width(ctx, 10);
vkvg_stroke (ctx);
}
+void vkvg_test_curves (VkvgContext ctx){
+ vkvg_set_line_width(ctx, 10);
+ vkvg_set_source_rgb (ctx, 0,0,0);
+
+ vkvg_arc(ctx, 150, 100, 10, 0, M_PI*2);
+ vkvg_fill(ctx);
+ vkvg_arc(ctx, 200, 200, 10, 0, M_PI*2);
+ vkvg_fill(ctx);
+
+ vkvg_set_source_rgba (ctx, 0.5,0.0,1.0,0.5);
+ vkvg_move_to(ctx,100,100);
+ vkvg_line_to(ctx,200,100);
+ vkvg_curve_to(ctx,250,100,300,150,300,200);
+ vkvg_line_to(ctx,300,300);
+ vkvg_curve_to(ctx,300,350,250,400,200,400);
+ vkvg_line_to(ctx,100,400);
+ vkvg_curve_to(ctx,50,400,10,350,10,300);
+ vkvg_line_to(ctx,10,200);
+ vkvg_curve_to(ctx,10,150,50,100,100,100);
+ vkvg_close_path(ctx);
+ //vkvg_curve_to(ctx, 150,100,200,150,200,200);
+ vkvg_fill_preserve(ctx);
+ vkvg_set_source_rgba (ctx, 1,1,1.0,0.5);
+ vkvg_stroke(ctx);
+}
void vkvg_test_stroke(VkvgContext ctx){
vkvg_set_line_width(ctx, 2);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_line_to(ctx,400,600);
vkvg_stroke(ctx);
}
-
void test_text (VkvgContext ctx) {
int size = 19;
int penY = 50;
//vkvg_show_text (ctx,"ABCDABCD");
//vkvg_show_text (ctx,"j");
}
-
void vkvg_test_stroke2(VkvgContext ctx){
vkvg_set_line_width(ctx,20);
vkvg_set_source_rgba(ctx,1,0,0,1);
vkvg_close_path(ctx);
vkvg_fill(ctx);
}
-
void test_img_surface (VkvgContext ctx) {
VkvgSurface imgSurf;// = vkvg_surface_create_from_image(device, "/mnt/data/images/blason.png");
//VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "/mnt/data/images/2000px-Tux.svg.png");
vkvg_flush(ctx);
vkvg_surface_destroy(imgSurf);
}
-
void test_line_caps (VkvgContext ctx) {
float x = 20, y = 20, dx = 30, dy = 60;
vkvg_rel_line_to(ctx,0,dy);
vkvg_stroke(ctx);
}
-
void test_line_join (VkvgContext ctx){
float x = 50, y = 150, dx = 150, dy = 140;
vkvg_stroke(ctx);
vkvg_set_line_join(ctx,VKVG_LINE_JOIN_MITER);
}
+void test_colinear () {
+ VkvgContext ctx = vkvg_create(surf);
+ vkvg_set_source_rgba(ctx,0.7,0.7,0.7,1);
+ vkvg_paint(ctx);
+
+ vkvg_set_source_rgba(ctx,0,0,0,1);
+ vkvg_set_line_width(ctx,10);
+
+ vkvg_move_to(ctx,100,100);
+ vkvg_line_to(ctx,100,200);
+ vkvg_line_to(ctx,100,100);
+ vkvg_stroke(ctx);
+
+ vkvg_destroy(ctx);
+}
void multi_test1 () {
VkvgSurface surf2 = vkvg_surface_create (device,1024,800);;
// vkvg_set_line_join(ctx,VKVG_LINE_JOIN_ROUND);
- //test_line_join(ctx);
+ test_line_join(ctx);
//vkvg_test_clip(ctx);
test_text(ctx);
vkvg_test_fill2(ctx);
- //vkvg_test_fill(ctx);
+ vkvg_test_fill(ctx);
// vkvg_translate(ctx, 10,10);
// vkvg_rotate(ctx, 0.2);
//vkvg_scale(ctx, 2,2);
- //vkvg_test_stroke(ctx);
-// vkvg_test_gradient (ctx);
+ vkvg_test_stroke(ctx);
+ vkvg_test_gradient (ctx);
vkvg_test_curves(ctx);
//test_img_surface(ctx);
vkvg_surface_destroy(surf2);
}
+void cairo_test_clip (VkvgContext cr){
+ vkvg_arc (cr, 128.0, 128.0, 76.8, 0, 2 * M_PI);
+ vkvg_clip (cr);
+
+ //vkvg_new_path (cr); /* current path is not
+ // consumed by vkvg_clip() */
+ vkvg_set_source_rgba(cr, 0, 0, 0, 1);
+ vkvg_rectangle (cr, 0, 0, 256, 256);
+ vkvg_fill (cr);
+ vkvg_set_source_rgba (cr, 0, 1, 0, 1);
+ vkvg_move_to (cr, 0, 0);
+ vkvg_line_to (cr, 256, 256);
+ vkvg_move_to (cr, 256, 0);
+ vkvg_line_to (cr, 0, 256);
+ vkvg_set_line_width (cr, 10.0);
+ vkvg_stroke (cr);
+}
+
+void cairo_test_rounded_rect (VkvgContext cr) {
+ /* a custom shape that could be wrapped in a function */
+ float x0 = 25.6, /* parameters like vkvg_rectangle */
+ y0 = 25.6,
+ rect_width = 204.8,
+ rect_height = 204.8,
+ radius = 102.4; /* and an approximate curvature radius */
+
+ float x1,y1;
+
+ x1=x0+rect_width;
+ y1=y0+rect_height;
+ if (!rect_width || !rect_height)
+ return;
+ if (rect_width/2<radius) {
+ if (rect_height/2<radius) {
+ vkvg_move_to (cr, x0, (y0 + y1)/2);
+ vkvg_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+ vkvg_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
+ vkvg_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
+ vkvg_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
+ } else {
+ vkvg_move_to (cr, x0, y0 + radius);
+ vkvg_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+ vkvg_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+ vkvg_line_to (cr, x1 , y1 - radius);
+ vkvg_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
+ vkvg_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
+ }
+ } else {
+ if (rect_height/2<radius) {
+ vkvg_move_to (cr, x0, (y0 + y1)/2);
+ vkvg_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
+ vkvg_line_to (cr, x1 - radius, y0);
+ vkvg_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
+ vkvg_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+ vkvg_line_to (cr, x0 + radius, y1);
+ vkvg_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
+ } else {
+ vkvg_move_to (cr, x0, y0 + radius);
+ vkvg_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
+ vkvg_line_to (cr, x1 - radius, y0);
+ vkvg_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+ vkvg_line_to (cr, x1 , y1 - radius);
+ vkvg_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+ vkvg_line_to (cr, x0 + radius, y1);
+ vkvg_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
+ }
+ }
+ vkvg_close_path (cr);
+
+ vkvg_set_source_rgb (cr, 0.5, 0.5, 1);
+ vkvg_fill_preserve (cr);
+ vkvg_set_source_rgba (cr, 0.5, 0, 0, 0.5);
+ vkvg_set_line_width (cr, 10.0);
+ vkvg_stroke (cr);
+}
void cairo_print_arc_neg (VkvgContext cr){
float xc = 128.0;
float yc = 128.0;
VkvgContext ctx = vkvg_create(surf);
vkvg_set_source_rgba(ctx,0.7,0.7,0.7,1);
vkvg_paint(ctx);
- cairo_print_arc(ctx);
- vkvg_translate(ctx,200,0);
- cairo_print_arc_neg(ctx);
+ //cairo_print_arc(ctx);
+ //cairo_print_arc_neg(ctx);
+ //cairo_test_clip(ctx);
+ cairo_test_rounded_rect(ctx);
+ //vkvg_test_curves(ctx);
vkvg_destroy(ctx);
}
//multi_test1();
//test_grad_transforms();
+
cairo_tests();
+ //test_colinear();
+
setupSimpleBlit(&e.renderer);
while (!glfwWindowShouldClose(e.renderer.window)) {