test: close the window at exit button
[platform/core/graphics/tizenvg.git] / test / testShape.cpp
1 #include <tizenvg.h>
2 #include <Elementary.h>
3
4 using namespace std;
5
6 #define WIDTH 800
7 #define HEIGHT 800
8
9 static uint32_t buffer[WIDTH * HEIGHT];
10
11 void tvgtest()
12 {
13     //Initialize TizenVG Engine
14     tvg::Engine::init();
15
16     //Create a Canvas
17     auto canvas = tvg::SwCanvas::gen(buffer, WIDTH, HEIGHT);
18
19     //Prepare a Shape (Rectangle)
20     auto shape1 = tvg::ShapeNode::gen();
21     shape1->appendRect(0, 0, 400, 400, 0);      //x, y, w, h, cornerRadius
22     shape1->fill(255, 0, 0, 255);               //r, g, b, a
23
24     /* Push the shape into the Canvas drawing list
25        When this shape is into the canvas list, the shape could update & prepare
26        internal data asynchronously for coming rendering.
27        Canvas keeps this shape node unless user call canvas->clear() */
28     canvas->push(move(shape1));
29
30     canvas->draw();
31     canvas->sync();
32
33     //Terminate TizenVG Engine
34     tvg::Engine::term();
35 }
36
37 void
38 win_del(void *data, Evas_Object *o, void *ev)
39 {
40    elm_exit();
41 }
42
43 int main(int argc, char **argv)
44 {
45     tvgtest();
46
47     //Show the result using EFL...
48     elm_init(argc, argv);
49
50     Eo* win = elm_win_util_standard_add(NULL, "TizenVG Test");
51     evas_object_smart_callback_add(win, "delete,request", win_del, 0);
52
53     Eo* img = evas_object_image_filled_add(evas_object_evas_get(win));
54     evas_object_image_size_set(img, WIDTH, HEIGHT);
55     evas_object_image_data_set(img, buffer);
56     evas_object_size_hint_weight_set(img, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
57     evas_object_show(img);
58
59     elm_win_resize_object_add(win, img);
60     evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
61     evas_object_show(win);
62
63     elm_run();
64     elm_shutdown();
65 }