2 //gcc eina_tiler_01.c -o eina_tiler_01 `pkg-config --cflags --libs ecore-evas ecore evas eina`
4 #include <Ecore_Evas.h>
9 #define WINDOW_PAD (20)
11 static Eina_Tiler *tiler;
12 static Eina_Rectangle *input_rects;
13 static unsigned int input_count;
14 static unsigned int input_idx = 0, input_color_idx = 0, output_color_idx = 0;
15 static Eina_List *output_objs = NULL;
16 static Evas_Coord maxw, maxh, winw, winh;
19 static const struct color {
20 unsigned char r, g, b;
71 #define MAX_COLORS (sizeof(colors) / sizeof(colors[0]))
74 add_text(const char *text, int x, int y, int w)
76 Evas_Object *o = evas_object_text_add(evas);
77 evas_object_color_set(o, 0, 0, 0, 255);
78 evas_object_move(o, x, y);
79 evas_object_resize(o, w, WINDOW_PAD);
80 evas_object_text_font_set(o, "Sans", 10);
81 evas_object_text_text_set(o, text);
86 output_rects_reset(void)
89 EINA_LIST_FREE(output_objs, o)
95 add_input_rect(const Eina_Rectangle *r)
103 o = evas_object_rectangle_add(evas);
104 #define C(comp) (((int)colors[input_color_idx].comp * 128) / 255)
105 evas_object_color_set(o, C(r), C(g), C(b), 128);
107 evas_object_move(o, r->x + bx, r->y + by);
108 evas_object_resize(o, r->w, r->h);
111 input_color_idx = (input_color_idx + 1) % MAX_COLORS;
113 bx += maxw + WINDOW_PAD;
115 o = evas_object_rectangle_add(evas);
116 evas_object_color_set(o, 32, 32, 32, 128);
117 evas_object_move(o, r->x + bx, r->y + by);
118 evas_object_resize(o, r->w, 1);
119 evas_object_layer_set(o, EVAS_LAYER_MAX);
122 o = evas_object_rectangle_add(evas);
123 evas_object_color_set(o, 32, 32, 32, 128);
124 evas_object_move(o, r->x + bx, r->y + by);
125 evas_object_resize(o, 1, r->h);
126 evas_object_layer_set(o, EVAS_LAYER_MAX);
129 o = evas_object_rectangle_add(evas);
130 evas_object_color_set(o, 32, 32, 32, 128);
131 evas_object_move(o, r->x + bx, r->y + by + r->h);
132 evas_object_resize(o, r->w, 1);
133 evas_object_layer_set(o, EVAS_LAYER_MAX);
136 o = evas_object_rectangle_add(evas);
137 evas_object_color_set(o, 32, 32, 32, 128);
138 evas_object_move(o, r->x + bx + r->w, r->y + by);
139 evas_object_resize(o, 1, r->h);
140 evas_object_layer_set(o, EVAS_LAYER_MAX);
145 add_output_rect(const Eina_Rectangle *r)
147 Evas_Object *o = evas_object_rectangle_add(evas);
148 #define C(comp) (((int)colors[output_color_idx].comp * 128) / 255)
149 evas_object_color_set(o, C(r), C(g), C(b), 128);
151 evas_object_move(o, r->x + maxw + 2 * WINDOW_PAD, r->y + WINDOW_PAD);
152 evas_object_resize(o, r->w, r->h);
155 output_color_idx = (output_color_idx + 1) % MAX_COLORS;
157 output_objs = eina_list_append(output_objs, o);
161 process_input(void *data)
164 Eina_Rectangle r, *r1;
165 unsigned int out = 0;
167 if (input_idx == input_count)
169 add_text("Done. Close the window to exit",
170 WINDOW_PAD, winh - WINDOW_PAD, winw - 2 * WINDOW_PAD);
174 output_rects_reset();
176 r = input_rects[input_idx];
177 printf("Iteration #%u: %dx%d%+d%+d\n", input_idx, r.w, r.h, r.x, r.y);
181 eina_tiler_rect_add(tiler, &r);
182 itr = eina_tiler_iterator_new(tiler);
183 EINA_ITERATOR_FOREACH(itr, r1)
185 printf("\tOutput #%u: %dx%d%+d%+d\n", out, r1->w, r1->h, r1->x, r1->y);
189 eina_iterator_free(itr);
195 usage(const char *progname)
199 "\t%s <rect1> ... <rectN>\n\n"
200 "with rectangles being in the format:\n"
201 "\tWIDTHxHEIGHT<+->X<+->Y\n"
203 "\t100x100+10+10 - width=100, height=100 at x=10, y=10\n"
204 "\t150x50+5+6 - width=150, height=50 at x=5, y=6\n",
209 main(int argc, char *argv[])
221 input_rects = calloc(argc - 1, sizeof(Eina_Rectangle));
225 for (i = 1; i < argc; i++)
227 Eina_Rectangle *r = input_rects + input_count;
230 if (sscanf(argv[i], "%dx%d%c%d%c%d",
231 &(r->w), &(r->h), &sx, &(r->x), &sy, &(r->y)) == 6)
233 if (sx == '-') r->x *= -1;
234 if (sy == '-') r->y *= -1;
236 if (maxw < r->x + r->w) maxw = r->x + r->w;
237 if (maxh < r->y + r->h) maxh = r->y + r->h;
241 fprintf(stderr, "ERROR: invalid rectangle ignored: %s\n", argv[i]);
244 if (input_count == 0)
246 fputs("ERROR: Could not find any valid rectangle. Exit!\n", stderr);
252 if ((maxw == 0) || (maxh == 0))
254 fputs("ERROR: All rectangles with size 0x0. Exit!\n", stderr);
265 winw = 2 * maxw + 3 * WINDOW_PAD;
266 winh = maxh + 2 * WINDOW_PAD;
268 ee = ecore_evas_new(NULL, 0, 0, winw, winh, NULL);
271 fputs("ERROR: Could not create window. Check ecore-evas install.\n",
276 evas = ecore_evas_get(ee);
278 o = evas_object_rectangle_add(evas);
279 evas_object_color_set(o, 255, 255, 255, 255);
280 evas_object_resize(o, winw, winh);
283 add_text("Input", WINDOW_PAD, 0, maxw);
284 o = evas_object_rectangle_add(evas);
285 evas_object_color_set(o, 200, 200, 200, 255);
286 evas_object_move(o, WINDOW_PAD, WINDOW_PAD);
287 evas_object_resize(o, maxw, maxh);
290 add_text("Output", maxw + 2 * WINDOW_PAD, 0, maxw);
291 o = evas_object_rectangle_add(evas);
292 evas_object_color_set(o, 200, 200, 200, 255);
293 evas_object_move(o, maxw + 2 * WINDOW_PAD, WINDOW_PAD);
294 evas_object_resize(o, maxw, maxh);
297 tiler = eina_tiler_new(maxw, maxh);
298 ecore_timer_add(2.0, process_input, NULL);
301 ecore_main_loop_begin();
303 eina_list_free(output_objs);
304 eina_tiler_free(tiler);
313 ecore_evas_shutdown();