eina_tiler_example_01

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

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_new
EINA_API Eina_Tiler * eina_tiler_new(int w, int h)
Creates a new tiler with w width and h height.
Definition: eina_tiler.c:1140

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;
}
EINA_FALSE
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533
Eina_Bool
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
_Eina_Iterator
structure of an iterator
Definition: eina_iterator.h:159
_Eina_Rectangle
Definition: eina_rectangle.h:109

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

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++;
}
EINA_ITERATOR_FOREACH
#define EINA_ITERATOR_FOREACH(itr, data)
Definition for the macro to iterate over all elements easily.
Definition: eina_iterator.h:448
_Eina_Rectangle::h
int h
height of rectangle
Definition: eina_rectangle.h:113
_Eina_Rectangle::x
int x
top-left x coordinate of rectangle
Definition: eina_rectangle.h:110
_Eina_Rectangle::y
int y
top-left y coordinate of rectangle
Definition: eina_rectangle.h:111
_Eina_Rectangle::w
int w
width of rectangle
Definition: eina_rectangle.h:112

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

eina_iterator_free(itr);
return EINA_TRUE;
}
eina_iterator_free
EINA_API void eina_iterator_free(Eina_Iterator *iterator)
Frees an iterator.
Definition: eina_iterator.c:98
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539

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