132001f49Smrg#include "eglcommon.h"
232001f49Smrg
332001f49Smrg#include <VG/openvg.h>
432001f49Smrg#include <VG/vgu.h>
532001f49Smrg#include <stdio.h>
632001f49Smrg#include <math.h>
732001f49Smrg#include <stdlib.h>
832001f49Smrg
932001f49Smrg#include <X11/keysym.h>
1032001f49Smrg
1132001f49Smrg//VGint x_pos = -10, y_pos = -10;
1232001f49SmrgVGint x_pos = 0, y_pos = 4;
1332001f49SmrgVGint img_width = 120, img_height = 120;
1432001f49Smrg
1532001f49Smrgstatic void RectToPath(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height)
1632001f49Smrg{
1732001f49Smrg    static const VGubyte segments[5] = {VG_MOVE_TO_ABS,
1832001f49Smrg                                        VG_HLINE_TO_ABS,
1932001f49Smrg                                        VG_VLINE_TO_ABS,
2032001f49Smrg                                        VG_HLINE_TO_ABS,
2132001f49Smrg                                        VG_CLOSE_PATH};
2232001f49Smrg    VGfloat data[5];
2332001f49Smrg
2432001f49Smrg    data[0] = x;
2532001f49Smrg    data[1] = y;
2632001f49Smrg    data[2] = x + width;
2732001f49Smrg    data[3] = y + height;
2832001f49Smrg    data[4] = x;
2932001f49Smrg
3032001f49Smrg    vgAppendPathData(path, 5, segments, data);
3132001f49Smrg}
3232001f49Smrg
3332001f49Smrgstatic void
3432001f49Smrginit(void)
3532001f49Smrg{
3632001f49Smrg}
3732001f49Smrg
3832001f49Smrg/* new window size or exposure */
3932001f49Smrgstatic void
4032001f49Smrgreshape(int w, int h)
4132001f49Smrg{
4232001f49Smrg}
4332001f49Smrg
4432001f49Smrgint  key_press(unsigned key)
4532001f49Smrg{
4632001f49Smrg    switch(key) {
4732001f49Smrg    case XK_Right:
4832001f49Smrg        x_pos +=1;
4932001f49Smrg        break;
5032001f49Smrg    case XK_Left:
5132001f49Smrg        x_pos -=1;
5232001f49Smrg        break;
5332001f49Smrg    case XK_Up:
5432001f49Smrg        y_pos +=1;
5532001f49Smrg        break;
5632001f49Smrg    case XK_Down:
5732001f49Smrg        y_pos -=1;
5832001f49Smrg        break;
5932001f49Smrg    case 'a':
6032001f49Smrg        img_width  -= 5;
6132001f49Smrg        img_height -= 5;
6232001f49Smrg        break;
6332001f49Smrg    case 's':
6432001f49Smrg        img_width  += 5;
6532001f49Smrg        img_height += 5;
6632001f49Smrg        break;
6732001f49Smrg    default:
6832001f49Smrg        break;
6932001f49Smrg    }
7032001f49Smrg    fprintf(stderr, "Posi = %dx%d\n", x_pos, y_pos);
7132001f49Smrg    fprintf(stderr, "Size = %dx%d\n", img_width, img_height);
7232001f49Smrg    return VG_FALSE;
7332001f49Smrg}
7432001f49Smrg
7532001f49Smrgstatic void
7632001f49Smrgdraw(void)
7732001f49Smrg{
7832001f49Smrg    VGint WINDSIZEX = window_width();
7932001f49Smrg    VGint WINDSIZEY = window_height();
8032001f49Smrg
8132001f49Smrg    VGPaint fill;
8232001f49Smrg    VGPath box;
8332001f49Smrg    VGfloat color[4]		= {1.f, 0.f, 0.f, 1.f};
8432001f49Smrg    VGfloat bgCol[4]		= {0.7f, 0.7f, 0.7f, 1.0f};
8532001f49Smrg    VGfloat transCol[4]         = {0.f, 0.f, 0.f, 0.f};
8632001f49Smrg    VGImage image = vgCreateImage(VG_sRGBA_8888, img_width, img_height,
8732001f49Smrg                                  VG_IMAGE_QUALITY_NONANTIALIASED);
8832001f49Smrg
8932001f49Smrg    /* Background clear */
9032001f49Smrg    fill = vgCreatePaint();
9132001f49Smrg    vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color);
9232001f49Smrg    vgSetPaint(fill, VG_FILL_PATH);
9332001f49Smrg
9432001f49Smrg    box = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
9532001f49Smrg                       1, 0, 0, 0, VG_PATH_CAPABILITY_ALL);
9632001f49Smrg    /* Rectangle to cover completely 16x16 pixel area. */
9732001f49Smrg    RectToPath(box, 0, 0, 64, 64);
9832001f49Smrg
9932001f49Smrg    vgSetfv(VG_CLEAR_COLOR, 4, transCol);
10032001f49Smrg    vgClearImage(image, 0, 0, img_width, img_height);
10132001f49Smrg    vgSetfv(VG_CLEAR_COLOR, 4, color);
10232001f49Smrg    vgClearImage(image, 10, 10, 12, 12);
10332001f49Smrg    //vgImageSubData(image, pukki_64x64_data, pukki_64x64_stride,
10432001f49Smrg    //               VG_sRGBA_8888, 0, 0, 32, 32);
10532001f49Smrg    vgSeti(VG_MASKING, VG_TRUE);
10632001f49Smrg    vgLoadIdentity();
10732001f49Smrg
10832001f49Smrg    vgSetfv(VG_CLEAR_COLOR, 4, bgCol);
10932001f49Smrg    vgClear(0, 0, WINDSIZEX, WINDSIZEY);
11032001f49Smrg
11132001f49Smrg
11232001f49Smrg    vgMask(image, VG_FILL_MASK, 0, 0, window_width(), window_height());
11332001f49Smrg    vgMask(image, VG_SET_MASK, x_pos, y_pos, 100, 100);
11432001f49Smrg
11532001f49Smrg    vgDrawPath(box, VG_FILL_PATH);
11632001f49Smrg
11732001f49Smrg    //vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
11832001f49Smrg    //vgTranslate(-10, -10);
11932001f49Smrg    //vgDrawImage(image);
12032001f49Smrg
12132001f49Smrg
12232001f49Smrg    vgDestroyPaint(fill);
12332001f49Smrg    vgDestroyPath(box);
12432001f49Smrg}
12532001f49Smrg
12632001f49Smrg
12732001f49Smrgint main(int argc, char **argv)
12832001f49Smrg{
12932001f49Smrg    set_window_size(64, 64);
13032001f49Smrg    return run(argc, argv, init, reshape,
13132001f49Smrg               draw, key_press);
13232001f49Smrg}
133