$title

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files
- Examples

This is an example that illustrates how Eina_Tiler works for a given set of rectangles. The rectangles must be given in the command line in the form: <width>x<height>+<x offset>+<y offset> The example will show two panels, the first(input) will show the given rectangles(in different colors) and in the seconds(output) it will show the rectangles given by the tiler. The rectangles will be added one by one every two seconds. A lot of the example deals with actually painting the rectangles so we'll skip over quite a bit of code, but you can see all of it in eina_tiler_01.c.

The first thing of note in our example is the creation of the tiler:

tiler = eina_tiler_new(maxw, maxh);

Note
  `maxw` and `maxh` are calculated such that the tiler's size will fully encompass all given rectangles.

We'll now look at the function that actually adds rectangles to our tiler. It first checks if we added all rectangles already and if so stops right there:

static Eina_Bool
process_input(void *data EINA_UNUSED)
{
Eina_Iterator *itr;
Eina_Rectangle r, *r1;
unsigned int out = 0;
if (input_idx == input_count)
{
add_text("Done. Close the window to exit",
WINDOW_PAD, winh - WINDOW_PAD, winw - 2 * WINDOW_PAD);
return EINA_FALSE;
}

Our function then clears all rectangles given to us by tiler from the last execution. It does this because each rectangle we add may change everything about the output of eina_tiler:

output_rects_reset();

Next we get another rectangle, print it and show it in the input panel:

r = input_rects[input_idx];
printf("Iteration #%u: %dx%d%+d%+d\n", input_idx, r.w, r.h, r.x, r.y);
input_idx++;
add_input_rect(&r);

We now come to the tiler stuff, we add our new rectangle to it and get a new iterator for the tiler:

eina_tiler_rect_add(tiler, &r);
itr = eina_tiler_iterator_new(tiler);

We now iterate over our tiler printing every rect it gives us and sowing it in the output panel:

EINA_ITERATOR_FOREACH(itr, r1)
{
printf("\tOutput #%u: %dx%d%+d%+d\n", out, r1->w, r1->h, r1->x, r1->y);
add_output_rect(r1);
out++;
}

We of course must remember to free our iterator and that's it for this function:

eina_iterator_free(itr);
return EINA_TRUE;
}

You should try many different inputs to see how the tiler works, here are a few suggestions:

- 100x100+0+0 100x100+200+200
- 100x100+0+0 100x100+5+5 100x100+10+10 100x100+15+15 100x100+20+20
- 100x100+0+0 100x100+100+100 100x100+200+0 100x100+0+200 100x100+200+200
- 10x10+0+0 10x10+10+10 10x10+20+0 10x10+0+20 10x10+20+20