From 9c96298a995a4bc799934ffe32858818853a9edc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Wed, 5 Jan 2022 18:53:05 +0100 Subject: [PATCH] update tests --- tests/CMakeLists.txt | 36 +++----- tests/clip.c | 20 +++- tests/common/test.c | 7 ++ tests/compositing.c | 18 ++++ tests/curve.c | 2 - tests/fill_and_stroke.c | 2 +- tests/fill_non_zero.c | 1 + tests/gradient.c | 18 ++-- tests/img_surf.c | 56 +++++++++++ tests/inverse_colinear.c | 6 +- tests/paint_surf.c | 32 +++---- tests/path_extents.c | 185 +++++++++++++++++++++++++++++++++++++ tests/pattern_transforms.c | 93 +++++++++++++++++++ tests/save_restore.c | 6 +- tests/simple_paint.c | 20 ++-- tests/test1.c | 12 ++- tests/transform.c | 116 +++++++++++++++++++++++ 17 files changed, 551 insertions(+), 79 deletions(-) create mode 100644 tests/path_extents.c create mode 100644 tests/pattern_transforms.c create mode 100644 tests/transform.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 40da768..a0a0569 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,34 +11,28 @@ ENDIF () FUNCTION (buildtest TEST_FILE) GET_FILENAME_COMPONENT(TEST_NAME ${TEST_FILE} NAME_WE) ADD_EXECUTABLE(${TEST_NAME} ${TEST_FILE}) - TARGET_INCLUDE_DIRECTORIES(${TEST_NAME} PRIVATE - ${Vulkan_INCLUDE_DIRS} - ${GLFW3_INCLUDE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/../include - ${CMAKE_CURRENT_SOURCE_DIR}/../src - ${CMAKE_CURRENT_SOURCE_DIR}/common - ${CMAKE_CURRENT_SOURCE_DIR}/../vkh/include - ${CMAKE_CURRENT_SOURCE_DIR}/../vkh/src - ) TARGET_LINK_LIBRARIES(${TEST_NAME} tests_common ) ENDFUNCTION (buildtest) ADD_LIBRARY("tests_common" STATIC common/vkengine.c common/test.c common/rnd.c) -TARGET_INCLUDE_DIRECTORIES(tests_common PRIVATE - ${Vulkan_INCLUDE_DIRS} - ${GLFW3_INCLUDE_DIR} - "${CMAKE_CURRENT_SOURCE_DIR}/../include" - "${CMAKE_CURRENT_SOURCE_DIR}/../src" - "${CMAKE_CURRENT_SOURCE_DIR}/../common" - "${CMAKE_CURRENT_SOURCE_DIR}/../vkh/include" - "${CMAKE_CURRENT_SOURCE_DIR}/../vkh/src" - ) + +TARGET_INCLUDE_DIRECTORIES(tests_common + PUBLIC + ${Vulkan_INCLUDE_DIRS} + ${GLFW3_INCLUDE_DIR} + "${CMAKE_CURRENT_SOURCE_DIR}/../include" + "${CMAKE_CURRENT_SOURCE_DIR}/../src" + "${CMAKE_CURRENT_SOURCE_DIR}/common" + "${CMAKE_CURRENT_SOURCE_DIR}/../vkh/include" + "${CMAKE_CURRENT_SOURCE_DIR}/../vkh/src" +) TARGET_LINK_LIBRARIES(tests_common - ${Vulkan_LIBRARIES} - ${GLFW3_LIBRARY} - vkvg_static + PUBLIC + ${Vulkan_LIBRARIES} + ${GLFW3_LIBRARY} + vkvg ) file(GLOB_RECURSE DATAS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "data/*") diff --git a/tests/clip.c b/tests/clip.c index 0322295..e5c03a0 100644 --- a/tests/clip.c +++ b/tests/clip.c @@ -68,6 +68,22 @@ void clipped_transformed_ec () { vkvg_paint(ctx); vkvg_destroy(ctx); } +void clip_transformed_ec () { + VkvgContext ctx = vkvg_create(surf); + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); + vkvg_set_source_rgb(ctx,1,0,0); + vkvg_paint(ctx); + vkvg_rotate(ctx,0.1f); + vkvg_set_source_rgb(ctx,0,1,0); + vkvg_rectangle(ctx, 100,100,300,200); + vkvg_clip(ctx); + vkvg_paint(ctx); + vkvg_translate (ctx,200,100); + vkvg_set_source_rgb(ctx,0,0,1); + vkvg_paint(ctx); + + vkvg_destroy(ctx); +} void clipped_transformed_eo () { VkvgContext ctx = vkvg_create(surf); vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); @@ -122,11 +138,9 @@ void test_clip2(){ vkvg_clip(ctx); vkvg_save(ctx); - vkvg_set_source_rgb(ctx,1,1,0); vkvg_paint(ctx); - vkvg_rectangle(ctx, 200,200,200,200); vkvg_clip(ctx); @@ -135,7 +149,6 @@ void test_clip2(){ vkvg_restore(ctx); - vkvg_rectangle(ctx, 350,350,420,420); vkvg_set_source_rgb(ctx,0,0,1); vkvg_fill(ctx); @@ -160,6 +173,7 @@ void test_clip2(){ } int main(int argc, char *argv[]) { no_test_size = true; + PERFORM_TEST (clip_transformed_ec, argc, argv); PERFORM_TEST (clipped_paint_ec, argc, argv); PERFORM_TEST (clipped_paint_eo, argc, argv); PERFORM_TEST (clipped_transformed_ec, argc, argv); diff --git a/tests/common/test.c b/tests/common/test.c index 1572d16..20c6a38 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -190,6 +190,9 @@ void _print_usage_and_exit () { printf("\t\t\t - b: Butt (default)\n"); printf("\t\t\t - r: Rount\n"); printf("\t\t\t - s: Square\n"); + printf("\t-f fill_rule:\tset current fill rule:\n"); + printf("\t\t\t - 0: Even Odd\n"); + printf("\t\t\t - 1: Non Zero\n"); printf("\t-d:\t\tenable dashes.\n"); printf("\t-n index:\tRun only a single test, zero based index.\n"); printf("\t-q:\t\tQuiet, don't print measures table head row, usefull for batch tests.\n"); @@ -246,6 +249,10 @@ void _parse_args (int argc, char* argv[]) { line_width = atoi (argv[i]); }else if (strcmp (argv[i], "-d\0") == 0) { dashes_count = 2; + }else if (strcmp (argv[i], "-f\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + fill_rule = atoi (argv[i]); } else if (strcmp (argv[i], "-o\0") == 0) { offscreen = true; }else if (strcmp (argv[i], "-j\0") == 0) { diff --git a/tests/compositing.c b/tests/compositing.c index e144973..54711b4 100644 --- a/tests/compositing.c +++ b/tests/compositing.c @@ -14,9 +14,27 @@ void compositing(){ vkvg_destroy(ctx); } +void opacity(){ + VkvgContext ctx = vkvg_create(surf); + vkvg_clear(ctx); + + vkvg_set_source_rgba(ctx, 1,0,0,1.0f); + vkvg_rectangle(ctx,100,100,200,200); + vkvg_fill(ctx); + + vkvg_set_opacity(ctx,0.5f); + + vkvg_set_source_rgba(ctx, 0,0,1,1.0f); + vkvg_rectangle(ctx,200,200,200,200); + vkvg_fill(ctx); + + vkvg_destroy(ctx); +} + int main(int argc, char *argv[]) { no_test_size = true; PERFORM_TEST (compositing, argc, argv); + PERFORM_TEST (opacity, argc, argv); return 0; } diff --git a/tests/curve.c b/tests/curve.c index 6ad3d26..28e7b1e 100644 --- a/tests/curve.c +++ b/tests/curve.c @@ -3,7 +3,6 @@ void test(){ VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); vkvg_set_line_width(ctx, 20); vkvg_scale(ctx,2,2); @@ -134,7 +133,6 @@ void _long_curv () { float h = (float)test_height; VkvgContext ctx = _initCtx(); - vkvg_set_fill_rule(ctx, fill_rule); randomize_color(ctx); float x1 = rndf() * w; diff --git a/tests/fill_and_stroke.c b/tests/fill_and_stroke.c index 92352d5..6e3e21e 100644 --- a/tests/fill_and_stroke.c +++ b/tests/fill_and_stroke.c @@ -6,7 +6,7 @@ void test(){ vkvg_move_to (ctx, 100, 100); vkvg_rel_line_to (ctx, 50, -80); vkvg_rel_line_to (ctx, 50, 80); - //vkvg_close_path (ctx); + vkvg_close_path (ctx); vkvg_move_to (ctx, 300, 100); vkvg_rel_line_to (ctx, 50, -80); diff --git a/tests/fill_non_zero.c b/tests/fill_non_zero.c index b70c7ee..4f5f51b 100644 --- a/tests/fill_non_zero.c +++ b/tests/fill_non_zero.c @@ -25,6 +25,7 @@ void test(){ } int main(int argc, char *argv[]) { + //vkvg_log_level = VKVG_LOG_FULL; no_test_size = true; PERFORM_TEST (test, argc, argv); return 0; diff --git a/tests/gradient.c b/tests/gradient.c index 3fef7db..01f809f 100644 --- a/tests/gradient.c +++ b/tests/gradient.c @@ -21,25 +21,27 @@ void paint(){ float x = 100; pat = create_grad(ctx,x); //vkvg_pattern_set_extend(pat,VKVG_EXTEND_NONE); - vkvg_rectangle(ctx, x,200,20,20); + vkvg_rectangle(ctx, x,200,50,50); vkvg_set_source (ctx, pat); vkvg_pattern_destroy (pat); vkvg_fill(ctx); x+=100; - pat = create_grad(ctx,x); + pat = vkvg_pattern_create_linear(10,0,300,0); + vkvg_pattern_add_color_stop(pat, 0, 0, 0, 1, 0); + vkvg_pattern_add_color_stop(pat, 1, 1, 0, 0, 1); //vkvg_pattern_set_extend(pat,VKVG_EXTEND_NONE); - vkvg_rectangle(ctx, x,200,20,20); + vkvg_rectangle(ctx, 10,10,300,50); vkvg_set_source (ctx, pat); vkvg_pattern_destroy (pat); vkvg_fill(ctx); - x+=100; + x+=200; pat = create_grad(ctx,x); //vkvg_pattern_set_extend(pat,VKVG_EXTEND_NONE); - vkvg_rectangle(ctx, x,200,20,20); + vkvg_rectangle(ctx, x,200,50,50); vkvg_set_source (ctx, pat); vkvg_pattern_destroy (pat); vkvg_fill(ctx); @@ -48,7 +50,7 @@ void paint(){ pat = create_grad(ctx,x); //vkvg_pattern_set_extend(pat,VKVG_EXTEND_NONE); - vkvg_rectangle(ctx, x,200,20,20); + vkvg_rectangle(ctx, x,200,50,50); vkvg_set_source (ctx, pat); vkvg_pattern_destroy (pat); vkvg_fill(ctx); @@ -134,7 +136,7 @@ void gradient_transform() { int main(int argc, char *argv[]) { no_test_size = true; PERFORM_TEST(paint, argc, argv); - /*PERFORM_TEST(paint_repeat, argc, argv); - PERFORM_TEST(gradient_transform, argc, argv);*/ + PERFORM_TEST(paint_repeat, argc, argv); + PERFORM_TEST(gradient_transform, argc, argv); return 0; } diff --git a/tests/img_surf.c b/tests/img_surf.c index af6f9a6..bffc65c 100644 --- a/tests/img_surf.c +++ b/tests/img_surf.c @@ -32,6 +32,58 @@ void paint_with_scale(){ vkvg_surface_destroy(imgSurf); vkvg_destroy(ctx); } +void translate(){ + VkvgContext ctx = vkvg_create(surf); + vkvg_translate (ctx, 150,50); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath); + vkvg_set_source_surface(ctx, imgSurf, 0, 0); + + vkvg_paint(ctx); + + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} +void offset_and_scale(){ + VkvgContext ctx = vkvg_create(surf); + vkvg_scale (ctx, 0.2f,0.2f); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath); + vkvg_set_source_surface(ctx, imgSurf, 100, 100); + + vkvg_paint(ctx); + + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} + +static float angle = 0; +void paint_with_rot(){ + angle += 0.005; + VkvgContext ctx = vkvg_create(surf); + vkvg_clear(ctx); + + vkvg_rotate (ctx, angle); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath); + vkvg_set_source_surface(ctx, imgSurf, 0, 0); + + vkvg_paint(ctx); + + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} +void offset_and_rot(){ + angle += 0.005; + VkvgContext ctx = vkvg_create(surf); + vkvg_clear(ctx); + + vkvg_rotate (ctx, angle); + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath); + vkvg_set_source_surface(ctx, imgSurf, 100, 100); + + vkvg_paint(ctx); + + vkvg_surface_destroy(imgSurf); + vkvg_destroy(ctx); +} void paint_pattern () { VkvgContext ctx = vkvg_create(surf); @@ -108,6 +160,10 @@ int main(int argc, char *argv[]) { PERFORM_TEST (paint, argc, argv); PERFORM_TEST (paint_offset, argc, argv); PERFORM_TEST (paint_with_scale, argc, argv); + PERFORM_TEST (offset_and_scale, argc, argv); + PERFORM_TEST (translate, argc, argv); + PERFORM_TEST (paint_with_rot, argc, argv); + PERFORM_TEST (offset_and_rot, argc, argv); PERFORM_TEST (paint_pattern, argc, argv); PERFORM_TEST (paint_patt_repeat, argc, argv); PERFORM_TEST (paint_patt_repeat_scalled, argc, argv); diff --git a/tests/inverse_colinear.c b/tests/inverse_colinear.c index 2df57e3..47146fb 100644 --- a/tests/inverse_colinear.c +++ b/tests/inverse_colinear.c @@ -44,13 +44,13 @@ void draw (){ vkvg_set_line_cap (ctx, lineCap); if (startWithArc) - vkvg_arc(ctx,pts[0].x,pts[0].y,200, 0.3f, M_PIF); + vkvg_arc_negative(ctx,pts[0].x,pts[0].y,200, M_PIF*1.5f, M_PIF); else vkvg_move_to(ctx,pts[0].x,pts[0].y); for (int i=1; i=0) { + if (isClosed) + vkvg_fill_preserve(ctx); + vkvg_set_source_rgba(ctx,1,0.2,0.2,0.5); + vkvg_stroke_preserve(ctx); + vkvg_set_dash(ctx, NULL, 0, 0); + vkvg_set_line_width(ctx,1); + vkvg_set_source_rgba(ctx,0,0,0,1); + vkvg_stroke(ctx); + vkvg_set_source_rgba(ctx,0.5f,0.5f,1.0f,0.7f); + vkvg_arc (ctx, pts[hoverPt].x, pts[hoverPt].y, pointSize, 0, M_PIF*2); + vkvg_fill_preserve(ctx); + vkvg_stroke(ctx); + } else { + if (isClosed) + vkvg_fill_preserve(ctx); + vkvg_set_source_rgba(ctx,1,0.2,0.2,0.5); + vkvg_stroke(ctx); + } + + vkvg_rectangle(ctx, x1, y1, x2 - x1, y2 - y1); + vkvg_set_dash(ctx, _dashes, _ndashes, 0); + vkvg_set_line_width(ctx,1); + vkvg_set_source_rgba(ctx,0,1,0,1); + vkvg_stroke(ctx); + + vkvg_destroy(ctx); +} +static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { + if (action != GLFW_PRESS) + return; + switch (key) { + case GLFW_KEY_ESCAPE : + glfwSetWindowShouldClose(window, GLFW_TRUE); + break; + case GLFW_KEY_W : + isClosed ^= true; + break; + case GLFW_KEY_DELETE : + ptsCount = 0; + break; + case GLFW_KEY_J : + lineJoin++; + if (lineJoin > 2) + lineJoin = 0; + break; + case GLFW_KEY_C : + lineCap++; + if (lineCap > 2) + lineCap = 0; + break; + case GLFW_KEY_KP_SUBTRACT : + if (ptsCount > 1) + ptsCount--; + break; + } + refresh = true; +} +static vec2 mousePos; +static void mouse_move_callback(GLFWwindow* window, double x, double y){ + mousePos = (vec2) {x, y}; + if (mouseDown) { + if (hoverPt < 0) + return; + pts[hoverPt] = mousePos; + refresh = true; + } else { + for (int i=0; i pts[i].x - pointSize && + x < pts[i].x + pointSize && + y > pts[i].y - pointSize && + y < pts[i].y + pointSize) { + hoverPt = i; + refresh = true; + return; + } + } + refresh = true; + hoverPt = -1; + } +} +static void scroll_callback(GLFWwindow* window, double x, double y){ + if (y<0.f) + zoom *= 0.5f; + else + zoom *= 2.0f; +} +static void mouse_button_callback(GLFWwindow* window, int but, int state, int modif){ + if (but != GLFW_MOUSE_BUTTON_1) + return; + if (state == GLFW_TRUE) + mouseDown = true; + else + mouseDown = false; + if (state == GLFW_TRUE && hoverPt < 0) + pts[ptsCount++] = mousePos; + refresh = true; +} + + + +int main(int argc, char* argv[]) { + + _parse_args (argc, argv); + VkEngine e; + e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_FIFO_KHR, test_width, test_height); + + VkhPresenter r = e->renderer; + vkengine_set_key_callback (e, key_callback); + vkengine_set_mouse_but_callback(e, mouse_button_callback); + vkengine_set_cursor_pos_callback(e, mouse_move_callback); + vkengine_set_scroll_callback(e, scroll_callback); + + bool deferredResolve = false; + + device = vkvg_device_create_from_vk_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); + surf = vkvg_surface_create(device, test_width, test_height); + + vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), test_width, test_height); + + while (!vkengine_should_close (e)) { + glfwPollEvents(); + + if (refresh) + draw (); + + if (!vkh_presenter_draw (r)){ + vkh_presenter_get_size (r, &test_width, &test_height); + vkvg_surface_destroy (surf); + surf = vkvg_surface_create(device, test_width, test_height); + vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), test_width, test_height); + vkDeviceWaitIdle(r->dev->dev); + continue; + } + } + vkDeviceWaitIdle(e->dev->dev); + + vkvg_surface_destroy (surf); + + vkvg_device_destroy (device); + + vkengine_destroy (e); + + return 0; +} diff --git a/tests/pattern_transforms.c b/tests/pattern_transforms.c new file mode 100644 index 0000000..18e528a --- /dev/null +++ b/tests/pattern_transforms.c @@ -0,0 +1,93 @@ +#include "test.h" + +float lineWidth = 10.f; +const char* imgPath = "data/miroir.jpg"; + +VkvgPattern create_grad (VkvgContext ctx) { + VkvgPattern pat = vkvg_pattern_create_linear(0,0,200,0); + vkvg_pattern_add_color_stop(pat, 0, 1, 0, 0, 1); + vkvg_pattern_add_color_stop(pat, 0.5, 0, 1, 0, 1); + vkvg_pattern_add_color_stop(pat, 1.0, 0, 0, 1, 1); + return pat; +} + +VkvgSurface createSurf (uint32_t width, uint32_t height) { + VkvgSurface s = vkvg_surface_create(device, width, height); + VkvgContext ctx = _initCtx(surf); + vkvg_set_line_width(ctx,lineWidth); + float hlw = lineWidth/2.f; + /* + vkvg_set_source_rgba(ctx,0,1,0,0.5); + vkvg_fill_preserve(ctx);*/ + vkvg_set_source_rgba(ctx,1,0,0,0.5); + vkvg_paint(ctx); + vkvg_set_source_rgba(ctx,0,0,1,0.5); + vkvg_rectangle(ctx,hlw,hlw,(float)width-lineWidth,(float)height-lineWidth); + vkvg_stroke(ctx); + vkvg_destroy(ctx); + return s; +} + +void img_scale() { + VkvgSurface imgSurf = vkvg_surface_create_from_image(device, imgPath); + VkvgPattern pat = vkvg_pattern_create_for_surface(imgSurf); + VkvgContext ctx = _initCtx(surf); + + vkvg_translate(ctx, 100,100); + + vkvg_matrix_t mat; + vkvg_matrix_init_scale(&mat, 2.0, 2.0); + vkvg_pattern_set_matrix (pat, &mat); + + vkvg_set_source (ctx, pat); + vkvg_rectangle(ctx, 0 , 0, 200, 140); + vkvg_fill(ctx); + vkvg_destroy(ctx); + vkvg_pattern_destroy(pat); + vkvg_surface_destroy(imgSurf); +} + +void pat_scale(){ + + VkvgContext ctx = _initCtx(surf); + VkvgPattern pat = create_grad(ctx); + + vkvg_translate(ctx, 100,100); + + vkvg_matrix_t mat; + vkvg_matrix_init_scale(&mat, 0.5, 0.5); + vkvg_pattern_set_matrix (pat, &mat); + + vkvg_set_source (ctx, pat); + vkvg_rectangle(ctx, 0 , 0, 200, 140); + vkvg_fill(ctx); + vkvg_destroy(ctx); + vkvg_pattern_destroy(pat); +} +static float angle = 0; +void pat_rotate(){ + angle += 0.001f; + + VkvgContext ctx = _initCtx(surf); + VkvgPattern pat = create_grad(ctx); + + //vkvg_translate(ctx, 100,100); + + vkvg_matrix_t mat; + vkvg_matrix_init_translate(&mat, 100, 70); + vkvg_matrix_rotate(&mat, angle); + vkvg_pattern_set_matrix (pat, &mat); + + vkvg_set_source (ctx, pat); + vkvg_rectangle(ctx, 0 , 0, 200, 140); + vkvg_fill(ctx); + vkvg_destroy(ctx); + vkvg_pattern_destroy(pat); +} +int main(int argc, char *argv[]) { + no_test_size = true; + PERFORM_TEST (pat_scale, argc, argv); + PERFORM_TEST (pat_rotate, argc, argv); + PERFORM_TEST (img_scale, argc, argv); + return 0; +} diff --git a/tests/save_restore.c b/tests/save_restore.c index dc7f2a6..b50861b 100644 --- a/tests/save_restore.c +++ b/tests/save_restore.c @@ -6,10 +6,10 @@ void recurse_draw(VkvgContext ctx, int depth) { vkvg_translate (ctx, 5,5); vkvg_rectangle(ctx, (float)depth,(float)depth,200,200); - vkvg_clip_preserve(ctx); + /*vkvg_clip_preserve(ctx); vkvg_set_source_rgb(ctx, 1.f/depth, 1.f / depth, 1.f / depth); - vkvg_fill_preserve(ctx); - vkvg_set_source_rgb(ctx, 0,0,0); + vkvg_fill_preserve(ctx);*/ + vkvg_set_source_rgb(ctx, 0,1,0); vkvg_stroke(ctx); if (depth < 20) diff --git a/tests/simple_paint.c b/tests/simple_paint.c index f451c6b..7dc47d1 100644 --- a/tests/simple_paint.c +++ b/tests/simple_paint.c @@ -1,33 +1,27 @@ #include "test.h" -vkvg_fill_rule_t fillrule = VKVG_FILL_RULE_NON_ZERO; - void paint(){ - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx,fillrule); + VkvgContext ctx = _initCtx(surf); vkvg_set_source_rgba(ctx,1,0,0,1); vkvg_paint(ctx); vkvg_destroy(ctx); } void paint_with_rotation(){ - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx,fillrule); + VkvgContext ctx = _initCtx(surf); vkvg_rotate(ctx, 45); vkvg_set_source_rgba(ctx,1,0,0,1); vkvg_paint(ctx); vkvg_destroy(ctx); } void paint_with_scale(){ - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx,fillrule); + VkvgContext ctx = _initCtx(surf); vkvg_scale (ctx, 0.2f,0.2f); vkvg_set_source_rgba(ctx,1,0,0,1); vkvg_paint(ctx); vkvg_destroy(ctx); } void paint_rect(){ - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx,fillrule); + VkvgContext ctx = _initCtx(surf); vkvg_set_source_rgba(ctx,1,0,0,1); vkvg_rectangle(ctx,100,100,300,200); vkvg_paint(ctx); @@ -35,8 +29,7 @@ void paint_rect(){ } //TODO:test failed: full screen paint instead of rotated rect void paint_rect_with_rotation(){ - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx,fillrule); + VkvgContext ctx = _initCtx(surf); vkvg_rotate(ctx, 45); vkvg_set_source_rgba(ctx,1,0,0,1); vkvg_rectangle(ctx,100,100,300,200); @@ -44,8 +37,7 @@ void paint_rect_with_rotation(){ vkvg_destroy(ctx); } void paint_rect_with_scale(){ - VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx,fillrule); + VkvgContext ctx = _initCtx(surf); vkvg_scale (ctx, 0.2f,0.2f); vkvg_set_source_rgba(ctx,1,0,0,1); vkvg_rectangle(ctx,100,100,300,200); diff --git a/tests/test1.c b/tests/test1.c index df454fc..302f8a7 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -345,10 +345,11 @@ void cairo_tests () { rotation+=0.002f; vkvg_matrix_t mat; - vkvg_matrix_init_translate (&mat, 512,400); - vkvg_matrix_rotate(&mat,rotation); + vkvg_matrix_init_translate (&mat, panX,panY); vkvg_matrix_scale(&mat,zoom,zoom); - vkvg_matrix_translate(&mat,-512.f + panX,-400.f +panY); + vkvg_matrix_translate (&mat, 400,400); + vkvg_matrix_rotate(&mat,rotation); + vkvg_matrix_translate(&mat,-400.f,-400.f); VkvgContext ctx = vkvg_create(surf); @@ -357,6 +358,11 @@ void cairo_tests () { vkvg_paint(ctx); //vkvg_set_matrix(ctx,&mat); + vkvg_translate (ctx, panX,panY); + vkvg_scale(ctx,zoom,zoom); + vkvg_translate (ctx, 400,400); + vkvg_rotate(ctx,rotation); + vkvg_translate(ctx,-400.f,-400.f); cairo_print_arc(ctx); diff --git a/tests/transform.c b/tests/transform.c new file mode 100644 index 0000000..b89db50 --- /dev/null +++ b/tests/transform.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2018-2022 Jean-Philippe Bruyère + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "test.h" + + +void _test_rounded_rect (VkvgContext cr) { + /* a custom shape that could be wrapped in a function */ + float x0 = -100, /* parameters like vkvg_rectangle */ + y0 = -100, + rect_width = 200, + rect_height = 200, + radius = 102.4f; /* 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