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:
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:
{
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);
}
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
structure of an iterator
Definition: eina_iterator.h:159
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:
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_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_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:
{
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)
Definition for the macro to iterate over all elements easily.
Definition: eina_iterator.h:448
int h
height of rectangle
Definition: eina_rectangle.h:113
int x
top-left x coordinate of rectangle
Definition: eina_rectangle.h:110
int y
top-left y coordinate of rectangle
Definition: eina_rectangle.h:111
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_API void eina_iterator_free(Eina_Iterator *iterator)
Frees an iterator.
Definition: eina_iterator.c:98
#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