eina_tiler_example_01

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);
Eina_Tiler * eina_tiler_new(int w, int h)
Creates a new tiler with w width and h height.
Definition eina_tiler.c:1132
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)
{
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;
}
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition eina_types.h:293
unsigned char Eina_Bool
Type to mimic a boolean.
Definition eina_types.h:287
structure of an iterator
Definition eina_iterator.h:159
Definition eina_rectangle.h:47

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);
int h
height of rectangle
Definition eina_rectangle.h:51
int x
top-left x co-ordinate of rectangle
Definition eina_rectangle.h:48
int y
top-left y co-ordinate of rectangle
Definition eina_rectangle.h:49
int w
width of rectangle
Definition eina_rectangle.h:50

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);
Eina_Bool eina_tiler_rect_add(Eina_Tiler *t, const Eina_Rectangle *r)
Adds a rectangle to a tiler.
Definition eina_tiler.c:1172
Eina_Iterator * eina_tiler_iterator_new(const Eina_Tiler *t)
Create a iterator to access the tilers calculated rectangles.
Definition eina_tiler.c:1219

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

{
printf("\tOutput #%u: %dx%d%+d%+d\n", out, r1->w, r1->h, r1->x, r1->y);
add_output_rect(r1);
out++;
}
#define EINA_ITERATOR_FOREACH(itr, data)
Macro to iterate over all elements easily.
Definition eina_iterator.h:332

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

return EINA_TRUE;
}
void eina_iterator_free(Eina_Iterator *iterator)
Free an iterator.
Definition eina_iterator.c:96
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition eina_types.h:299

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