dash.c revision 32001f49
1#include "eglcommon.h"
2
3#include <VG/openvg.h>
4#include <X11/keysym.h>
5#include <stdio.h>
6
7const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0};
8const VGfloat color[4] = {0.4, 0.1, 1.0, 1.0};
9
10VGPath path;
11VGPaint fill;
12
13VGint cap_style = VG_CAP_BUTT;
14
15static void
16init(void)
17{
18   static const VGubyte cmds[] = {VG_MOVE_TO_ABS,
19                                  VG_LINE_TO_ABS,
20                                  VG_LINE_TO_ABS
21   };
22#if 1
23   static const VGfloat coords[]   = {100, 100, 150, 100,
24                                      150, 200
25   };
26#else
27   static const VGfloat coords[]   = {100, 20, 100, 220,
28   };
29#endif
30   VGfloat dash_pattern[2] = { 20.f, 20.f };
31   path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
32                       VG_PATH_CAPABILITY_APPEND_TO);
33   vgAppendPathData(path, 3, cmds, coords);
34
35   fill = vgCreatePaint();
36   vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color);
37   vgSetPaint(fill, VG_FILL_PATH);
38
39   vgSetfv(VG_CLEAR_COLOR, 4, white_color);
40   vgSetf(VG_STROKE_LINE_WIDTH, 20);
41   vgSeti(VG_STROKE_CAP_STYLE, cap_style);
42   vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
43   vgSetfv(VG_STROKE_DASH_PATTERN, 2, dash_pattern);
44   vgSetf(VG_STROKE_DASH_PHASE, 0.0f);
45}
46
47/* new window size or exposure */
48static void
49reshape(int w, int h)
50{
51   vgLoadIdentity();
52}
53
54static void
55draw(void)
56{
57   vgClear(0, 0, window_width(), window_height());
58   vgDrawPath(path, VG_STROKE_PATH);
59
60   vgFlush();
61}
62
63static int  key_press(unsigned key)
64{
65    switch(key) {
66    case XK_c:
67    case XK_C:
68        ++cap_style;
69        if (cap_style > VG_CAP_SQUARE)
70            cap_style = VG_CAP_BUTT;
71        switch(cap_style) {
72        case VG_CAP_BUTT:
73            fprintf(stderr, "Cap style 'butt'\n");
74            break;
75        case VG_CAP_ROUND:
76            fprintf(stderr, "Cap style 'round'\n");
77            break;
78        case VG_CAP_SQUARE:
79            fprintf(stderr, "Cap style 'square'\n");
80            break;
81        }
82        vgSeti(VG_STROKE_CAP_STYLE, cap_style);
83        break;
84    default:
85        break;
86    }
87
88    return VG_TRUE;
89}
90
91int main(int argc, char **argv)
92{
93   return run(argc, argv, init, reshape,
94              draw, key_press);
95}
96