summaryrefslogtreecommitdiffstatsci
path: root/tests/dashes.c
blob: 1f2ade457afc6fd3a9ce77838509025b84f08191 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "test.h"

void test() {
    dash_offset += 0.2f;

    VkvgContext ctx = vkvg_create(surf);
    vkvg_clear(ctx);
    vkvg_set_source_rgb(ctx, 1, 1, 1);
    vkvg_paint(ctx);
    // const float dashes[] = {160.0f, 80};
    // float dashes[] = {7.0f, 3};
    float dashes[] = {100, 20, 20, 20};
    vkvg_set_line_cap(ctx, VKVG_LINE_CAP_ROUND);
    vkvg_set_line_join(ctx, VKVG_LINE_JOIN_ROUND);
    vkvg_set_dash(ctx, dashes, 4, dash_offset);
    vkvg_set_line_width(ctx, 4);
    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, 200);
    vkvg_rel_line_to(ctx, 200, 0);
    vkvg_rel_line_to(ctx, 0, 500);
    vkvg_rel_line_to(ctx, -700, 0);
    vkvg_close_path(ctx);
    vkvg_stroke(ctx);

    dashes[0] = 0;
    dashes[1] = 20;
    vkvg_set_dash(ctx, dashes, 2, dash_offset);

    vkvg_set_source_rgb(ctx, 0, 1, 0);

    vkvg_move_to(ctx, 100, 100);
    vkvg_rel_line_to(ctx, 400, 0);
    vkvg_rel_line_to(ctx, 0, 200);
    vkvg_rel_line_to(ctx, 200, 0);
    vkvg_rel_line_to(ctx, 0, 400);
    vkvg_rel_line_to(ctx, -600, 0);
    vkvg_close_path(ctx);
    vkvg_stroke(ctx);

    dashes[0] = 80;
    dashes[1] = 20;

    vkvg_set_line_width(ctx, 10);
    vkvg_set_source_rgb(ctx, 1, 0, 0);

    vkvg_set_dash(ctx, dashes, 2, dash_offset);

    vkvg_rectangle(ctx, 200, 300, 200, 200);
    /*vkvg_move_to(ctx, 200,300);
    vkvg_rel_line_to(ctx,200,0);*/
    vkvg_stroke(ctx);

    vkvg_destroy(ctx);
}

void _long_curve() {
    float w = (float)test_width;
    float h = (float)test_height;

    VkvgContext ctx = _initCtx();

    randomize_color(ctx);
    float x1 = w * rand() / RAND_MAX;
    float y1 = h * rand() / RAND_MAX;
    vkvg_move_to(ctx, x1, y1);

    for (uint32_t i = 0; i < test_size; i++)
        draw_random_curve(ctx);

    vkvg_stroke(ctx);
    vkvg_destroy(ctx);
}
void _long_path() {
    float w = (float)test_width - 10;
    float h = (float)test_height - 10;

    VkvgContext ctx = _initCtx();

    randomize_color(ctx);
    float x1 = w * rndf();
    float y1 = h * rndf();
    vkvg_move_to(ctx, x1, y1);
    for (uint32_t i = 0; i < test_size; i++) {
        x1 = w * rndf();
        y1 = h * rndf();
        vkvg_line_to(ctx, x1, y1);
    }
    vkvg_stroke(ctx);
    vkvg_destroy(ctx);
}

void path() { _long_path(); }
void curve() { _long_curve(); }

int main(int argc, char *argv[]) {
    dashes_count = 2;
    dashes[0]    = 0;
    dashes[1]    = 10;
    line_width   = 4;
    // test_size = 50;
    line_cap = VKVG_LINE_CAP_ROUND;
    PERFORM_TEST(test, argc, argv);
    PERFORM_TEST(path, argc, argv);
    PERFORM_TEST(curve, argc, argv);
    return 0;
}