summaryrefslogtreecommitdiff
path: root/progs/egl/openvg/trivial/mask4.c
blob: fe6db39648cc22c36a436fecc5e6e1e3dbed2690 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "eglcommon.h"

#include <VG/openvg.h>
#include <VG/vgu.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#include <X11/keysym.h>

//VGint x_pos = -10, y_pos = -10;
VGint x_pos = 0, y_pos = 4;
VGint img_width = 120, img_height = 120;

static void RectToPath(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height)
{
    static const VGubyte segments[5] = {VG_MOVE_TO_ABS,
                                        VG_HLINE_TO_ABS,
                                        VG_VLINE_TO_ABS,
                                        VG_HLINE_TO_ABS,
                                        VG_CLOSE_PATH};
    VGfloat data[5];

    data[0] = x;
    data[1] = y;
    data[2] = x + width;
    data[3] = y + height;
    data[4] = x;

    vgAppendPathData(path, 5, segments, data);
}

static void
init(void)
{
}

/* new window size or exposure */
static void
reshape(int w, int h)
{
}

int  key_press(unsigned key)
{
    switch(key) {
    case XK_Right:
        x_pos +=1;
        break;
    case XK_Left:
        x_pos -=1;
        break;
    case XK_Up:
        y_pos +=1;
        break;
    case XK_Down:
        y_pos -=1;
        break;
    case 'a':
        img_width  -= 5;
        img_height -= 5;
        break;
    case 's':
        img_width  += 5;
        img_height += 5;
        break;
    default:
        break;
    }
    fprintf(stderr, "Posi = %dx%d\n", x_pos, y_pos);
    fprintf(stderr, "Size = %dx%d\n", img_width, img_height);
    return VG_FALSE;
}

static void
draw(void)
{
    VGint WINDSIZEX = window_width();
    VGint WINDSIZEY = window_height();

    VGPaint fill;
    VGPath box;
    VGfloat color[4]		= {1.f, 0.f, 0.f, 1.f};
    VGfloat bgCol[4]		= {0.7f, 0.7f, 0.7f, 1.0f};
    VGfloat transCol[4]         = {0.f, 0.f, 0.f, 0.f};
    VGImage image = vgCreateImage(VG_sRGBA_8888, img_width, img_height,
                                  VG_IMAGE_QUALITY_NONANTIALIASED);

    /* Background clear */
    fill = vgCreatePaint();
    vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color);
    vgSetPaint(fill, VG_FILL_PATH);

    box = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
                       1, 0, 0, 0, VG_PATH_CAPABILITY_ALL);
    /* Rectangle to cover completely 16x16 pixel area. */
    RectToPath(box, 0, 0, 64, 64);

    vgSetfv(VG_CLEAR_COLOR, 4, transCol);
    vgClearImage(image, 0, 0, img_width, img_height);
    vgSetfv(VG_CLEAR_COLOR, 4, color);
    vgClearImage(image, 10, 10, 12, 12);
    //vgImageSubData(image, pukki_64x64_data, pukki_64x64_stride,
    //               VG_sRGBA_8888, 0, 0, 32, 32);
    vgSeti(VG_MASKING, VG_TRUE);
    vgLoadIdentity();

    vgSetfv(VG_CLEAR_COLOR, 4, bgCol);
    vgClear(0, 0, WINDSIZEX, WINDSIZEY);


    vgMask(image, VG_FILL_MASK, 0, 0, window_width(), window_height());
    vgMask(image, VG_SET_MASK, x_pos, y_pos, 100, 100);

    vgDrawPath(box, VG_FILL_PATH);

    //vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
    //vgTranslate(-10, -10);
    //vgDrawImage(image);


    vgDestroyPaint(fill);
    vgDestroyPath(box);
}


int main(int argc, char **argv)
{
    set_window_size(64, 64);
    return run(argc, argv, init, reshape,
               draw, key_press);
}