summaryrefslogtreecommitdiff
path: root/src/examples/evas/evas-vg-simple.c
blob: 2c0c7026b0c6ae01678c02a3e6d29fdbedc56246 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/**
 * Simple Evas example illustrating a Evas_VG basic node usage.
 *
 * You'll need at least one engine built for it (excluding the buffer
 * one). See stdout/stderr for output.
 *
 * @verbatim
 * gcc -o evas_vg_simple evas-vg-simple.c `pkg-config --libs --cflags evas ecore ecore-evas eina ector eo efl` -lm
 * @endverbatim
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#endif

#define WIDTH 400
#define HEIGHT 400

#ifndef EFL_BETA_API_SUPPORT
#define EFL_BETA_API_SUPPORT 1
#endif

#ifndef EFL_EO_API_SUPPORT
#define EFL_EO_API_SUPPORT 1
#endif

#include <Eo.h>
#include <Efl.h>
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Evas.h>


#include <math.h>
#include <Eina.h>

#define PATH_KAPPA 0.5522847498
#define PI         3.1415926535

typedef struct _Bezier
{
float x1, y1, x2, y2, x3, y3, x4, y4;
}Bezier;

typedef struct _Point
{
    int x;
    int y;
}Point;

static Efl_VG *beginning = NULL;
static Efl_VG *end = NULL;
static Efl_VG *root = NULL;
static double start_time = 0;
static Ecore_Animator *anim = NULL;

static
Bezier bezierFromPoints(Point p1, Point p2,
                            Point p3, Point p4)
{
    Bezier b;
    b.x1 = p1.x;
    b.y1 = p1.y;
    b.x2 = p2.x;
    b.y2 = p2.y;
    b.x3 = p3.x;
    b.y3 = p3.y;
    b.x4 = p4.x;
    b.y4 = p4.y;
    return b;
}

static inline void
parameterSplitLeft(Bezier *b, float t, Bezier *left)
{
    left->x1 = b->x1;
    left->y1 = b->y1;

    left->x2 = b->x1 + t * ( b->x2 - b->x1 );
    left->y2 = b->y1 + t * ( b->y2 - b->y1 );

    left->x3 = b->x2 + t * ( b->x3 - b->x2 ); // temporary holding spot
    left->y3 = b->y2 + t * ( b->y3 - b->y2 ); // temporary holding spot

    b->x3 = b->x3 + t * ( b->x4 - b->x3 );
    b->y3 = b->y3 + t * ( b->y4 - b->y3 );

    b->x2 = left->x3 + t * ( b->x3 - left->x3);
    b->y2 = left->y3 + t * ( b->y3 - left->y3);

    left->x3 = left->x2 + t * ( left->x3 - left->x2 );
    left->y3 = left->y2 + t * ( left->y3 - left->y2 );

    left->x4 = b->x1 = left->x3 + t * (b->x2 - left->x3);
    left->y4 = b->y1 = left->y3 + t * (b->y2 - left->y3);
}
static
Bezier bezierOnInterval(Bezier *b, float t0, float t1)
{
    if (t0 == 0 && t1 == 1)
        return *b;

    Bezier result;
    parameterSplitLeft(b, t0, &result);
    float trueT = (t1-t0)/(1-t0);
    parameterSplitLeft(b, trueT, &result);

    return result;
}

static inline void
_bezier_coefficients(float t, float *ap, float *bp, float *cp, float *dp)
{
    float a,b,c,d;
    float m_t = 1. - t;
    b = m_t * m_t;
    c = t * t;
    d = c * t;
    a = b * m_t;
    b *= 3. * t;
    c *= 3. * m_t;
    *ap = a;
    *bp = b;
    *cp = c;
    *dp = d;
}

static
float _t_for_arc_angle(float angle)
{
    if (angle < 0.00001)
        return 0;

    if (angle == 90.0)
        return 1;

    float radians = PI * angle / 180;
    float cosAngle = cos(radians);
    float sinAngle = sin(radians);

    // initial guess
    float tc = angle / 90;
    // do some iterations of newton's method to approximate cosAngle
    // finds the zero of the function b.pointAt(tc).x() - cosAngle
    tc -= ((((2-3*PATH_KAPPA) * tc + 3*(PATH_KAPPA-1)) * tc) * tc + 1 - cosAngle) // value
         / (((6-9*PATH_KAPPA) * tc + 6*(PATH_KAPPA-1)) * tc); // derivative
    tc -= ((((2-3*PATH_KAPPA) * tc + 3*(PATH_KAPPA-1)) * tc) * tc + 1 - cosAngle) // value
         / (((6-9*PATH_KAPPA) * tc + 6*(PATH_KAPPA-1)) * tc); // derivative

    // initial guess
    float ts = tc;
    // do some iterations of newton's method to approximate sinAngle
    // finds the zero of the function b.pointAt(tc).y() - sinAngle
    ts -= ((((3*PATH_KAPPA-2) * ts -  6*PATH_KAPPA + 3) * ts + 3*PATH_KAPPA) * ts - sinAngle)
         / (((9*PATH_KAPPA-6) * ts + 12*PATH_KAPPA - 6) * ts + 3*PATH_KAPPA);
    ts -= ((((3*PATH_KAPPA-2) * ts -  6*PATH_KAPPA + 3) * ts + 3*PATH_KAPPA) * ts - sinAngle)
         / (((9*PATH_KAPPA-6) * ts + 12*PATH_KAPPA - 6) * ts + 3*PATH_KAPPA);

    // use the average of the t that best approximates cosAngle
    // and the t that best approximates sinAngle
    float t = 0.5 * (tc + ts);
    return t;
}

static void
_find_ellipse_coords(int x, int y, int w, int h, float angle, float length,
                            Point* startPoint, Point *endPoint)
{
    if (!w || !h ) {
        if (startPoint)
            startPoint->x = 0 , startPoint->y = 0;
        if (endPoint)
            endPoint->x = 0 , endPoint->y = 0;
        return;
    }

    int w2 = w / 2;
    int h2 = h / 2;

    float angles[2] = { angle, angle + length };
    Point *points[2] = { startPoint, endPoint };
    int i =0;
    for (i = 0; i < 2; ++i) {
        if (!points[i])
            continue;

        float theta = angles[i] - 360 * floor(angles[i] / 360);
        float t = theta / 90;
        // truncate
        int quadrant = (int)t;
        t -= quadrant;

        t = _t_for_arc_angle(90 * t);

        // swap x and y?
        if (quadrant & 1)
            t = 1 - t;

        float a, b, c, d;
        _bezier_coefficients(t, &a, &b, &c, &d);
        float px = a + b + c*PATH_KAPPA;
        float py = d + c + b*PATH_KAPPA;

        // left quadrants
        if (quadrant == 1 || quadrant == 2)
            px = -px;

        // top quadrants
        if (quadrant == 0 || quadrant == 1)
            py = -py;
           int cx = x+w/2;
           int cy = y+h/2;
         points[i]->x = cx + w2 * px;
         points[i]->y = cy + h2 * py;
    }
}


//// The return value is the starting point of the arc
static
Point _curves_for_arc(int x, int y, int w, int h,
                      float startAngle, float sweepLength,
                      Point *curves, int *point_count)
{
    *point_count = 0;
    int w2 = w / 2;
    int w2k = w2 * PATH_KAPPA;

    int h2 = h / 2;
    int h2k = h2 * PATH_KAPPA;

    Point points[16] =
    {
      // start point
      { x + w, y + h2 },

      // 0 -> 270 degrees
      { x + w, y + h2 + h2k },
      { x + w2 + w2k, y + h },
      { x + w2, y + h },

      // 270 -> 180 degrees
      { x + w2 - w2k, y + h },
      { x, y + h2 + h2k },
      { x, y + h2 },

      // 180 -> 90 degrees
      { x, y + h2 - h2k },
      { x + w2 - w2k, y },
      { x + w2, y },

      // 90 -> 0 degrees
      { x + w2 + w2k, y },
      { x + w, y + h2 - h2k },
      { x + w, y + h2 }
    };

    if (sweepLength > 360) sweepLength = 360;
    else if (sweepLength < -360) sweepLength = -360;

    // Special case fast paths
    if (startAngle == 0) {
        if (sweepLength == 360) {
	    int i;
            for (i = 11; i >= 0; --i)
                curves[(*point_count)++] = points[i];
            return points[12];
        } else if (sweepLength == -360) {
	    int i ;
            for (i = 1; i <= 12; ++i)
                curves[(*point_count)++] = points[i];
            return points[0];
        }
    }

    int startSegment = (int)(floor(startAngle / 90));
    int endSegment = (int)(floor((startAngle + sweepLength) / 90));

    float startT = (startAngle - startSegment * 90) / 90;
    float endT = (startAngle + sweepLength - endSegment * 90) / 90;

    int delta = sweepLength > 0 ? 1 : -1;
    if (delta < 0) {
        startT = 1 - startT;
        endT = 1 - endT;
    }

    // avoid empty start segment
    if (startT == 1.0) {
        startT = 0;
        startSegment += delta;
    }

    // avoid empty end segment
    if (endT == 0) {
        endT = 1;
        endSegment -= delta;
    }

    startT = _t_for_arc_angle(startT * 90);
    endT = _t_for_arc_angle(endT * 90);

    Eina_Bool splitAtStart = !(fabs(startT) <= 0.00001f);
    Eina_Bool splitAtEnd = !(fabs(endT - 1.0) <= 0.00001f);

    const int end = endSegment + delta;

    // empty arc?
    if (startSegment == end) {
        const int quadrant = 3 - ((startSegment % 4) + 4) % 4;
        const int j = 3 * quadrant;
        return delta > 0 ? points[j + 3] : points[j];
    }


    Point startPoint, endPoint;
    _find_ellipse_coords(x, y, w, h, startAngle, sweepLength, &startPoint, &endPoint);
    int i;
    for (i = startSegment; i != end; i += delta) {
        const int quadrant = 3 - ((i % 4) + 4) % 4;
        const int j = 3 * quadrant;

        Bezier b;
        if (delta > 0)
            b = bezierFromPoints(points[j + 3], points[j + 2], points[j + 1], points[j]);
        else
            b = bezierFromPoints(points[j], points[j + 1], points[j + 2], points[j + 3]);

        // empty arc?
        if (startSegment == endSegment && (startT == endT))
            return startPoint;

        if (i == startSegment) {
            if (i == endSegment && splitAtEnd)
                b = bezierOnInterval(&b, startT, endT);
            else if (splitAtStart)
                b = bezierOnInterval(&b, startT, 1);
        } else if (i == endSegment && splitAtEnd) {
            b = bezierOnInterval(&b, 0, endT);
        }

        // push control points
        curves[(*point_count)].x = b.x2;
        curves[(*point_count)++].y = b.y2;
        curves[(*point_count)].x = b.x3;
        curves[(*point_count)++].y = b.y3;
        curves[(*point_count)].x = b.x4;
        curves[(*point_count)++].y = b.y4;
    }

    curves[*(point_count)-1] = endPoint;

    return startPoint;
}

void _arcto(Efl_VG *obj, int x, int y, int width, int height, int startAngle, int sweepLength)
{
    int point_count;

    Point pts[15];
    Point curve_start = _curves_for_arc(x, y, width, height, startAngle, sweepLength, pts, &point_count);
    int cx = x + (width)/2;
    int cy = y + (height)/2;
    int i;

    evas_vg_shape_shape_append_move_to(obj, cx, cy);
    evas_vg_shape_shape_append_line_to(obj, curve_start.x, curve_start.y);
    for (i = 0; i < point_count; i += 3)
      {
         evas_vg_shape_shape_append_cubic_to(obj,
                                             pts[i].x, pts[i].y,
                                             pts[i+1].x, pts[i+1].y,
                                             pts[i+2].x, pts[i+2].y);
      }
    evas_vg_shape_shape_append_close(obj);
}

void _rect_add(Efl_VG *obj, int x, int y, int w, int h)
{
   evas_vg_shape_shape_append_move_to(obj, x, y);
   evas_vg_shape_shape_append_line_to(obj, x + w, y);
   evas_vg_shape_shape_append_line_to(obj, x + w, y +h);
   evas_vg_shape_shape_append_line_to(obj, x, y +h);
   evas_vg_shape_shape_append_close(obj);
}


struct example_data
{
   Ecore_Evas  *ee;
   Evas        *evas;
   Evas_Object *bg;
   Evas_Object *vg;
};

static struct example_data d;

static void
_on_delete(Ecore_Evas *ee EINA_UNUSED)
{
   ecore_main_loop_quit();
}

static void /* adjust canvas' contents on resizes */
_canvas_resize_cb(Ecore_Evas *ee)
{
   int w, h;

   ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
   evas_object_resize(d.bg, w, h);
   evas_object_resize(d.vg, w, h);
}

static void
vector_set(int x, int y, int w, int h)
{
   int vg_w = w, vg_h = h;

   //Create VG Object

   Evas_Object *tmp = evas_object_rectangle_add(d.evas);
   evas_object_resize(tmp, vg_w, vg_h);
   evas_object_color_set(tmp, 100, 100, 50, 100);
   evas_object_move(tmp, x,y);
   evas_object_show(tmp);

   d.vg = evas_object_vg_add(d.evas);
   evas_object_resize(d.vg, vg_w, vg_h);
   evas_object_move(d.vg, x,y);
   evas_object_show(d.vg);
   evas_object_clip_set(d.vg, tmp);

     // Applying map on the evas_object_vg
//   Evas_Map *m = evas_map_new(4);
//   evas_map_smooth_set(m, EINA_TRUE);
//   evas_map_util_points_populate_from_object_full(m, d.vg, 0);
//   evas_map_util_rotate(m, 10, 0,0);
//   evas_object_map_enable_set(d.vg, EINA_TRUE);
//   evas_object_map_set(d.vg, m);

   // apply some transformation
   double radian = 30.0 * 2 * 3.141 / 360.0;
   Eina_Matrix3 matrix;
   eina_matrix3_identity(&matrix);
   eina_matrix3_rotate(&matrix, radian);

   root = evas_object_vg_root_node_get(d.vg);
   //evas_vg_node_transformation_set(root, &matrix);

   Efl_VG *bg = eo_add(EFL_VG_SHAPE_CLASS, root, efl_vg_name_set(eoid, "bg"));
   _rect_add(bg, 0, 0 , vg_w, vg_h);
   evas_vg_node_origin_set(bg, 0,0);
   evas_vg_shape_stroke_width_set(bg, 1.0);
   evas_vg_node_color_set(bg, 80, 80, 80, 80);

   Efl_VG *shape = eo_add(EFL_VG_SHAPE_CLASS, root, efl_vg_name_set(eoid, "shape"));
   Efl_VG *rgradient = eo_add(EFL_VG_GRADIENT_RADIAL_CLASS, NULL, efl_vg_name_set(eoid, "rgradient"));
   Efl_VG *lgradient = eo_add(EFL_VG_GRADIENT_LINEAR_CLASS, NULL, efl_vg_name_set(eoid, "lgradient"));

   _arcto(shape, 0, 0, 100, 100, 25, 330);

   Efl_Gfx_Gradient_Stop stops[3];
   stops[0].r = 255;
   stops[0].g = 0;
   stops[0].b = 0;
   stops[0].a = 255;
   stops[0].offset = 0;
   stops[1].r = 0;
   stops[1].g = 255;
   stops[1].b = 0;
   stops[1].a = 255;
   stops[1].offset = 0.5;
   stops[2].r = 0;
   stops[2].g = 0;
   stops[2].b = 255;
   stops[2].a = 255;
   stops[2].offset = 1;

   evas_vg_node_origin_set(rgradient, 10, 10);
   evas_vg_gradient_spread_set(rgradient, EFL_GFX_GRADIENT_SPREAD_REFLECT);
   evas_vg_gradient_stop_set(rgradient, stops, 3);
   evas_vg_gradient_radial_center_set(rgradient, 30, 30);
   evas_vg_gradient_radial_radius_set(rgradient, 80);

   evas_vg_node_origin_set(lgradient, 10, 10);
   evas_vg_gradient_stop_set(lgradient, stops, 3);
   evas_vg_gradient_spread_set(lgradient, EFL_GFX_GRADIENT_SPREAD_REFLECT);
   evas_vg_gradient_stop_set(lgradient, stops, 3);
   evas_vg_gradient_linear_start_set(lgradient, 10, 10);
   evas_vg_gradient_linear_end_set(lgradient, 50, 50);

   evas_vg_node_origin_set(shape, 10, 10);
   evas_vg_shape_fill_set(shape, rgradient);
   evas_vg_shape_stroke_scale_set(shape, 2.0);
   evas_vg_shape_stroke_width_set(shape, 1.0);
   evas_vg_node_color_set(shape, 0, 0, 255, 255);
   evas_vg_shape_stroke_color_set(shape, 0, 0, 255, 128);

   Efl_VG *rect = eo_add(EFL_VG_SHAPE_CLASS, root, efl_vg_name_set(eoid, "rect"));
   _rect_add(rect, 0, 0, 100, 100);
   evas_vg_node_origin_set(rect, 100, 100);
   evas_vg_shape_fill_set(rect, lgradient);
   evas_vg_shape_stroke_width_set(rect, 2.0);
   evas_vg_shape_stroke_join_set(rect, EFL_GFX_JOIN_ROUND);
   evas_vg_shape_stroke_color_set(rect, 255, 255, 255, 255);

   Efl_VG *rect1 = eo_add(EFL_VG_SHAPE_CLASS, root, efl_vg_name_set(eoid, "rect1"));
   _rect_add(rect1, 0, 0, 70, 70);
   evas_vg_node_origin_set(rect1, 50, 70);
   evas_vg_shape_stroke_scale_set(rect1, 2);
   evas_vg_shape_stroke_width_set(rect1, 8.0);
   evas_vg_shape_stroke_join_set(rect1, EFL_GFX_JOIN_ROUND);
   evas_vg_shape_stroke_color_set(rect1, 0, 100, 80, 100);

   Efl_VG *circle = eo_add(EFL_VG_SHAPE_CLASS, root, efl_vg_name_set(eoid, "circle"));
   _arcto(circle, 0, 0, 250, 100, 30, 300);
   evas_vg_shape_fill_set(circle, lgradient);
   //evas_vg_node_transformation_set(&matrix),
   evas_vg_node_origin_set(circle, 50,50);
   evas_vg_node_color_set(circle, 50, 0, 0, 50);

   // Foreground
   Efl_VG *fg = eo_add(EFL_VG_SHAPE_CLASS, root, efl_vg_name_set(eoid, "fg"));
   _rect_add(fg, 0, 0, vg_w, vg_h);
   evas_vg_node_origin_set(fg, 0, 0);
   evas_vg_shape_stroke_width_set(fg, 5.0);
   evas_vg_shape_stroke_join_set(fg, EFL_GFX_JOIN_ROUND);
   evas_vg_shape_stroke_color_set(fg, 70, 70, 0, 70);

   Efl_VG *tst = eo_add(EFL_VG_SHAPE_CLASS, root, efl_vg_name_set(eoid, "tst"));
   evas_vg_shape_shape_append_rect(tst, 50, 25, 200, 200, 3, 5);
   evas_vg_node_color_set(tst, 0, 0, 200, 200);
   evas_vg_shape_stroke_width_set(tst, 2);
   evas_vg_shape_stroke_color_set(tst, 255, 0, 0, 255);

   Efl_VG *vc = eo_add(EFL_VG_SHAPE_CLASS, root, efl_vg_name_set(eoid, "vc"));
   evas_vg_shape_shape_append_circle(vc, 100, 100, 23);
   evas_vg_node_color_set(vc, 0, 200, 0, 255);
   evas_vg_shape_stroke_width_set(vc, 4);
   evas_vg_shape_stroke_color_set(vc, 255, 0, 0, 255);

   beginning = eo_add(EFL_VG_CONTAINER_CLASS, NULL, efl_vg_dup(eoid, root));
   end = eo_add(EFL_VG_CONTAINER_CLASS, NULL, efl_vg_dup(eoid, root));

   circle = efl_vg_container_child_get(end, "circle");
   efl_vg_transformation_set(circle, &matrix);
}

static Eina_Bool
_anim(void *data EINA_UNUSED)
{
   double pos, now;

   now = ecore_loop_time_get();

   if (now - start_time > 3)
     {
        Efl_VG *tmp = beginning;

        beginning = end;
        end = tmp;
        start_time = now;
     }

   pos = ecore_animator_pos_map((now - start_time) / 3, ECORE_POS_MAP_SINUSOIDAL, 0, 0);

   efl_vg_interpolate(root, beginning, end, pos);

   return EINA_TRUE;
}

static void
_keydown(void *data EINA_UNUSED, Evas *evas EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *einfo)
{
   Evas_Event_Key_Down *ev = einfo;

   if (strcmp(ev->key, "a") == 0)
     {
        if (!anim)
          {
             anim = ecore_animator_add(_anim, NULL);
             start_time = ecore_loop_time_get();
          }
        else
          {
             ecore_animator_del(anim);
             anim = NULL;
          }
        /* efl_vg_interpolate(root, beginning, end, 0.5); */
     }
   fprintf(stderr, "key: [%s]\n", ev->key);
}

int
main(void)
{
   if (!ecore_evas_init())
     return EXIT_FAILURE;

   /* this will give you a window with an Evas canvas under the first
    * engine available */
   d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
   if (!d.ee)
     goto error;

   ecore_evas_callback_delete_request_set(d.ee, _on_delete);
   ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
   ecore_evas_show(d.ee);

   d.evas = ecore_evas_get(d.ee);

   d.bg = evas_object_rectangle_add(d.evas);
   evas_object_color_set(d.bg, 70, 70, 70, 255); /* white bg */
   evas_object_focus_set(d.bg, 1);
   evas_object_event_callback_add(d.bg, EVAS_CALLBACK_KEY_DOWN, _keydown, NULL);
   evas_object_show(d.bg);

   _canvas_resize_cb(d.ee);

   vector_set(50, 50, 300 ,300);
   //vector_set(30, 90, 300 ,300);

   ecore_main_loop_begin();
   ecore_evas_shutdown();
   return 0;

error:
   ecore_evas_shutdown();
   return -1;
}