Bug fix TIVI-976 ,TIVI-974 and addition of the window animation interface.
[profile/ivi/ico-uxf-weston-plugin.git] / tests / test-eflapp.c
1 #ifdef HAVE_CONFIG_H
2 #undef HAVE_CONFIG_H
3 #endif
4
5 #ifdef HAVE_CONFIG_H
6
7 #include "config.h"
8 #else
9 #define __UNUSED__
10 #define PACKAGE_EXAMPLES_DIR "."
11 #endif
12
13 #include <Ecore.h>
14 #include <Ecore_Evas.h>
15 #include <stdio.h>
16
17 #define WIDTH  (520)
18 #define HEIGHT (380)
19
20 static Ecore_Evas *ee;
21 static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
22
23 static Evas_Object *bg, *r1, *r2, *r3; /* "sub" canvas objects */
24 static Evas_Object *border, *img; /* canvas objects */
25
26 static void
27 _on_destroy(Ecore_Evas *ee __UNUSED__)
28 {
29     ecore_main_loop_quit();
30 }
31
32 static void
33 _resize_cb(Ecore_Evas *ee)
34 {
35     int x, y, w, h, ow, oh;
36     int rw, rh;
37
38     evas_object_geometry_get(img, &x, &y, &ow, &oh);
39     ecore_evas_geometry_get(ee, &x, &y, &w, &h);
40     ecore_evas_request_geometry_get(ee, NULL, NULL, &rw, &rh);
41     fprintf(stderr, "EFL-App resize x/y=%d/%d req=%d/%d w/h=%d/%d obj=%d/%d\n", x, y, rw, rh, w, h, ow, oh); fflush(stderr);
42 }
43
44 int
45 main(int argc, char *argv[])
46 {
47     Evas *canvas, *sub_canvas;
48     Ecore_Evas *sub_ee;
49     int     i;
50     int     width;
51     int     height;
52     unsigned int    color;
53     int     r, g, b, a;
54     int     appno = 1;
55     char    sTitle[64];
56
57     width = WIDTH;
58     height = HEIGHT;
59     color = 0xc0c0c0c0;
60     for (i = 1; i < argc; i++)  {
61         if (argv[i][0] == '@')  {
62             appno = strtol(&argv[i][1], (char **)0, 0);
63         }
64         if (argv[i][0] != '-')  continue;
65         if (strncasecmp(argv[i], "-width=", 7) == 0)    {
66             width = strtol(&argv[i][7], (char **)0, 0);
67         }
68         else if (strncasecmp(argv[i], "-height=", 8) == 0)  {
69             height = strtol(&argv[i][8], (char **)0, 0);
70         }
71         else if (strncasecmp(argv[i], "-color=", 7) == 0)   {
72             color = strtoul(&argv[i][7], (char **)0, 0);
73         }
74     }
75
76     ecore_evas_init();
77
78     /* this will give you a window with an Evas canvas under the first
79      * engine available */
80     ee = ecore_evas_new(NULL, 0, 0, width, height, "frame=0");
81     if (!ee) goto error;
82
83     ecore_evas_size_min_set(ee, width/4, height/4);
84     ecore_evas_size_max_set(ee, width*4, height*4);
85
86     ecore_evas_callback_resize_set(ee, _resize_cb);
87
88     ecore_evas_callback_delete_request_set(ee, _on_destroy);
89     sprintf(sTitle, "EFL Native Application %d", appno);
90     ecore_evas_title_set(ee, sTitle);
91     ecore_evas_show(ee);
92
93     canvas = ecore_evas_get(ee);
94
95     bg = evas_object_rectangle_add(canvas);
96     r = (color>>16)&0x0ff;
97     g = (color>>8)&0x0ff;
98     b = color&0x0ff;
99     a = (color>>24)&0x0ff;
100     if (a != 255)   {
101         r = (r * a) / 255;
102         g = (g * a) / 255;
103         b = (b * a) / 255;
104     }
105     evas_object_color_set(bg, r, g, b, a); /* bg color */
106     evas_object_move(bg, 0, 0); /* at origin */
107     evas_object_resize(bg, width, height); /* covers full canvas */
108     evas_object_show(bg);
109
110     /* this is a border around the image containing a scene of another
111      * canvas */
112     border = evas_object_image_filled_add(canvas);
113     evas_object_image_file_set(border, border_img_path, NULL);
114     evas_object_image_border_set(border, 3, 3, 3, 3);
115     evas_object_image_border_center_fill_set(border, EVAS_BORDER_FILL_NONE);
116
117     evas_object_move(border, width / 6, height / 6);
118     evas_object_resize(border, (2 * width) / 3, (2 * height) / 3);
119     evas_object_show(border);
120
121     img = ecore_evas_object_image_new(ee);
122     evas_object_image_filled_set(img, EINA_TRUE);
123     evas_object_image_size_set(
124         img, ((2 * width) / 3) - 6, ((2 * height) / 3) - 6);
125     sub_ee = ecore_evas_object_ecore_evas_get(img);
126     sub_canvas = ecore_evas_object_evas_get(img);
127
128     evas_object_move(img, (width / 6) + 3, (height / 6) + 3);
129
130     /* apply the same size on both! */
131     evas_object_resize(img, ((2 * width) / 3) - 6, ((2 * height) / 3) - 6);
132     ecore_evas_resize(sub_ee, ((2 * width) / 3) - 6, ((2 * height) / 3) - 6);
133
134     r1 = evas_object_rectangle_add(sub_canvas);
135     evas_object_color_set(r1, g, b, r, 255);
136     evas_object_move(r1, 10, 10);
137     evas_object_resize(r1, 100, 100);
138     evas_object_show(r1);
139
140     r2 = evas_object_rectangle_add(sub_canvas);
141     evas_object_color_set(r2, b/2, g/2, r/2, 128);
142     evas_object_move(r2, 10, 10);
143     evas_object_resize(r2, 50, 50);
144     evas_object_show(r2);
145
146     r3 = evas_object_rectangle_add(sub_canvas);
147     evas_object_color_set(r3, b, r, g, 255);
148     evas_object_move(r3, 60, 60);
149     evas_object_resize(r3, 50, 50);
150     evas_object_show(r3);
151
152     evas_object_show(img);
153     ecore_main_loop_begin();
154
155     ecore_evas_free(ee);
156     ecore_evas_shutdown();
157
158     return 0;
159
160 error:
161     fprintf(stderr, "You got to have at least one Evas engine built"
162             " and linked up to ecore-evas for this example to run properly.\n");
163     ecore_evas_shutdown();
164     return -1;
165 }
166