1#include "eglcommon.h"
2
3#include <VG/openvg.h>
4#include <VG/vgu.h>
5#include <stdio.h>
6#include <math.h>
7#include <stdlib.h>
8
9#include <X11/keysym.h>
10
11//VGint x_pos = -10, y_pos = -10;
12VGint x_pos = 0, y_pos = 4;
13VGint img_width = 120, img_height = 120;
14
15static void RectToPath(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height)
16{
17    static const VGubyte segments[5] = {VG_MOVE_TO_ABS,
18                                        VG_HLINE_TO_ABS,
19                                        VG_VLINE_TO_ABS,
20                                        VG_HLINE_TO_ABS,
21                                        VG_CLOSE_PATH};
22    VGfloat data[5];
23
24    data[0] = x;
25    data[1] = y;
26    data[2] = x + width;
27    data[3] = y + height;
28    data[4] = x;
29
30    vgAppendPathData(path, 5, segments, data);
31}
32
33static void
34init(void)
35{
36}
37
38/* new window size or exposure */
39static void
40reshape(int w, int h)
41{
42}
43
44int  key_press(unsigned key)
45{
46    switch(key) {
47    case XK_Right:
48        x_pos +=1;
49        break;
50    case XK_Left:
51        x_pos -=1;
52        break;
53    case XK_Up:
54        y_pos +=1;
55        break;
56    case XK_Down:
57        y_pos -=1;
58        break;
59    case 'a':
60        img_width  -= 5;
61        img_height -= 5;
62        break;
63    case 's':
64        img_width  += 5;
65        img_height += 5;
66        break;
67    default:
68        break;
69    }
70    fprintf(stderr, "Posi = %dx%d\n", x_pos, y_pos);
71    fprintf(stderr, "Size = %dx%d\n", img_width, img_height);
72    return VG_FALSE;
73}
74
75static void
76draw(void)
77{
78    VGint WINDSIZEX = window_width();
79    VGint WINDSIZEY = window_height();
80
81    VGPaint fill;
82    VGPath box;
83    VGfloat color[4]		= {1.f, 0.f, 0.f, 1.f};
84    VGfloat bgCol[4]		= {0.7f, 0.7f, 0.7f, 1.0f};
85    VGfloat transCol[4]         = {0.f, 0.f, 0.f, 0.f};
86    VGImage image = vgCreateImage(VG_sRGBA_8888, img_width, img_height,
87                                  VG_IMAGE_QUALITY_NONANTIALIASED);
88
89    /* Background clear */
90    fill = vgCreatePaint();
91    vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color);
92    vgSetPaint(fill, VG_FILL_PATH);
93
94    box = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
95                       1, 0, 0, 0, VG_PATH_CAPABILITY_ALL);
96    /* Rectangle to cover completely 16x16 pixel area. */
97    RectToPath(box, 0, 0, 64, 64);
98
99    vgSetfv(VG_CLEAR_COLOR, 4, transCol);
100    vgClearImage(image, 0, 0, img_width, img_height);
101    vgSetfv(VG_CLEAR_COLOR, 4, color);
102    vgClearImage(image, 10, 10, 12, 12);
103    //vgImageSubData(image, pukki_64x64_data, pukki_64x64_stride,
104    //               VG_sRGBA_8888, 0, 0, 32, 32);
105    vgSeti(VG_MASKING, VG_TRUE);
106    vgLoadIdentity();
107
108    vgSetfv(VG_CLEAR_COLOR, 4, bgCol);
109    vgClear(0, 0, WINDSIZEX, WINDSIZEY);
110
111
112    vgMask(image, VG_FILL_MASK, 0, 0, window_width(), window_height());
113    vgMask(image, VG_SET_MASK, x_pos, y_pos, 100, 100);
114
115    vgDrawPath(box, VG_FILL_PATH);
116
117    //vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
118    //vgTranslate(-10, -10);
119    //vgDrawImage(image);
120
121
122    vgDestroyPaint(fill);
123    vgDestroyPath(box);
124}
125
126
127int main(int argc, char **argv)
128{
129    set_window_size(64, 64);
130    return run(argc, argv, init, reshape,
131               draw, key_press);
132}
133