2 * Simple @c Ecore_Evas example illustrating how to deal with window
5 * You'll need at least one engine built for it (excluding the buffer
6 * one). See stdout/stderr for output.
9 * gcc -o evas-smart-object evas-smart-object.c `pkg-config --libs --cflags evas ecore ecore-evas`
21 #include <Ecore_Evas.h>
26 static Ecore_Evas *ee;
27 static Evas_Object *text, *bg;
28 static Eina_Bool min_set = EINA_FALSE;
29 static Eina_Bool max_set = EINA_FALSE;
30 static Eina_Bool base_set = EINA_FALSE;
31 static Eina_Bool step_set = EINA_FALSE;
33 static const char commands[] = \
35 "\tm - impose a minumum size to the window\n"
36 "\tx - impose a maximum size to the window\n"
37 "\tb - impose a base size to the window\n"
38 "\ts - impose a step size (different than 1 px) to the window\n"
41 /* to inform current window's size */
43 _canvas_resize_cb(Ecore_Evas *ee)
48 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
49 snprintf(buf, sizeof(buf), "%d x %d", w, h);
50 evas_object_text_text_set(text, buf);
51 evas_object_move(text, (w - 150) / 2, (h - 50) / 2);
53 evas_object_resize(bg, w, h);
57 _on_destroy(Ecore_Evas *ee __UNUSED__)
59 ecore_main_loop_quit();
63 _on_keydown(void *data __UNUSED__,
64 Evas *evas __UNUSED__,
65 Evas_Object *o __UNUSED__,
68 Evas_Event_Key_Down *ev = einfo;
70 if (strcmp(ev->keyname, "h") == 0) /* print help */
72 fprintf(stdout, commands);
76 if (strcmp(ev->keyname, "m") == 0) /* impose a minimum size on the window */
82 ecore_evas_size_min_set(ee, WIDTH / 2, HEIGHT / 2);
83 fprintf(stdout, "Imposing a minimum size of %d x %d\n",
84 WIDTH / 2, HEIGHT / 2);
88 ecore_evas_size_min_set(ee, 0, 0);
89 fprintf(stdout, "Taking off minimum size restriction from the"
95 if (strcmp(ev->keyname, "x") == 0) /* impose a maximum size on the window */
101 ecore_evas_size_max_set(ee, WIDTH * 2, HEIGHT * 2);
102 fprintf(stdout, "Imposing a maximum size of %d x %d\n",
103 WIDTH * 2, HEIGHT * 2);
107 ecore_evas_size_max_set(ee, 0, 0);
108 fprintf(stdout, "Taking off maximum size restriction from the"
114 if (strcmp(ev->keyname, "b") == 0) /* impose a base size on the window */
116 base_set = !base_set;
120 ecore_evas_size_base_set(ee, WIDTH * 2, HEIGHT * 2);
121 fprintf(stdout, "Imposing a base size of %d x %d\n",
122 WIDTH * 2, HEIGHT * 2);
126 ecore_evas_size_base_set(ee, 0, 0);
127 fprintf(stdout, "Taking off base size restriction from the"
133 if (strcmp(ev->keyname, "s") == 0) /* impose a step size on the window */
135 step_set = !step_set;
139 ecore_evas_size_step_set(ee, 40, 40);
140 fprintf(stdout, "Imposing a step size of %d x %d\n", 40, 40);
144 ecore_evas_size_step_set(ee, 0, 0);
145 fprintf(stdout, "Taking off step size restriction from the"
157 if (!ecore_evas_init())
160 /* this will give you a window with an Evas canvas under the first
161 * engine available */
162 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
165 ecore_evas_callback_delete_request_set(ee, _on_destroy);
166 ecore_evas_title_set(ee, "Ecore_Evas window sizes example");
167 ecore_evas_callback_resize_set(ee, _canvas_resize_cb);
170 evas = ecore_evas_get(ee);
172 bg = evas_object_rectangle_add(evas);
173 evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
174 evas_object_move(bg, 0, 0); /* at canvas' origin */
175 evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
176 evas_object_show(bg);
178 evas_object_focus_set(bg, EINA_TRUE);
179 evas_object_event_callback_add(
180 bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
182 text = evas_object_text_add(evas);
183 evas_object_color_set(text, 0, 0, 0, 255);
184 evas_object_resize(text, 150, 50);
185 evas_object_text_font_set(text, "Sans", 20);
186 evas_object_show(text);
188 _canvas_resize_cb(ee);
189 fprintf(stdout, commands);
190 ecore_main_loop_begin();
193 ecore_evas_shutdown();
198 fprintf(stderr, "You got to have at least one Evas engine built"
199 " and linked up to ecore-evas for this example to run"
201 ecore_evas_shutdown();