eina_tiler_01.c
//Compile with:
//gcc eina_tiler_01.c -o eina_tiler_01 `pkg-config --cflags --libs ecore-evas ecore evas eina`
#include <Ecore_Evas.h>
#include <Ecore.h>
#include <Evas.h>
#include <Eina.h>
#define WINDOW_PAD (20)
static Eina_Tiler *tiler;
static Eina_Rectangle *input_rects;
static unsigned int input_count;
static unsigned int input_idx = 0, input_color_idx = 0, output_color_idx = 0;
static Eina_List *output_objs = NULL;
static Evas_Coord maxw, maxh, winw, winh;
static Evas *evas;
static const struct color {
unsigned char r, g, b;
} colors[] = {
{255, 0, 0},
{0, 255, 0},
{0, 0, 255},
{255, 128, 0},
{0, 255, 128},
{128, 0, 255},
{255, 255, 0},
{0, 255, 255},
{255, 0, 255},
{255, 0, 128},
{128, 255, 0},
{0, 128, 255},
{128, 128, 0},
{0, 128, 128},
{128, 0, 128},
{128, 0, 0},
{0, 128, 0},
{0, 0, 128},
{255, 128, 0},
{0, 255, 128},
{128, 0, 255},
{64, 64, 0},
{0, 64, 64},
{64, 0, 64},
{128, 128, 0},
{0, 128, 128},
{128, 0, 128},
{255, 0, 128},
{128, 255, 0},
{0, 128, 255},
{128, 64, 0},
{0, 128, 64},
{64, 0, 128},
{128, 0, 64},
{64, 128, 0},
{0, 64, 128}
};
#define MAX_COLORS (sizeof(colors) / sizeof(colors[0]))
static void
add_text(const char *text, int x, int y, int w)
{
evas_object_color_set(o, 0, 0, 0, 255);
evas_object_move(o, x, y);
evas_object_resize(o, w, WINDOW_PAD);
evas_object_text_font_set(o, "Sans", 10);
}
static void
output_rects_reset(void)
{
EINA_LIST_FREE(output_objs, o)
output_color_idx = 0;
}
static void
add_input_rect(const Eina_Rectangle *r)
{
Evas_Coord bx, by;
bx = WINDOW_PAD;
by = WINDOW_PAD;
#define C(comp) (((int)colors[input_color_idx].comp * 128) / 255)
evas_object_color_set(o, C(r), C(g), C(b), 128);
#undef C
evas_object_move(o, r->x + bx, r->y + by);
evas_object_resize(o, r->w, r->h);
input_color_idx = (input_color_idx + 1) % MAX_COLORS;
bx += maxw + WINDOW_PAD;
evas_object_color_set(o, 32, 32, 32, 128);
evas_object_move(o, r->x + bx, r->y + by);
evas_object_resize(o, r->w, 1);
evas_object_color_set(o, 32, 32, 32, 128);
evas_object_move(o, r->x + bx, r->y + by);
evas_object_resize(o, 1, r->h);
evas_object_color_set(o, 32, 32, 32, 128);
evas_object_move(o, r->x + bx, r->y + by + r->h);
evas_object_resize(o, r->w, 1);
evas_object_color_set(o, 32, 32, 32, 128);
evas_object_move(o, r->x + bx + r->w, r->y + by);
evas_object_resize(o, 1, r->h);
}
static void
add_output_rect(const Eina_Rectangle *r)
{
#define C(comp) (((int)colors[output_color_idx].comp * 128) / 255)
evas_object_color_set(o, C(r), C(g), C(b), 128);
#undef C
evas_object_move(o, r->x + maxw + 2 * WINDOW_PAD, r->y + WINDOW_PAD);
evas_object_resize(o, r->w, r->h);
output_color_idx = (output_color_idx + 1) % MAX_COLORS;
output_objs = eina_list_append(output_objs, o);
}
static Eina_Bool
process_input(void *data EINA_UNUSED)
{
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;
}
output_rects_reset();
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);
eina_tiler_rect_add(tiler, &r);
{
printf("\tOutput #%u: %dx%d%+d%+d\n", out, r1->w, r1->h, r1->x, r1->y);
add_output_rect(r1);
out++;
}
return EINA_TRUE;
}
static void
usage(const char *progname)
{
fprintf(stderr,
"Usage:\n\n"
"\t%s <rect1> ... <rectN>\n\n"
"with rectangles being in the format:\n"
"\tWIDTHxHEIGHT<+->X<+->Y\n"
"examples:\n"
"\t100x100+10+10 - width=100, height=100 at x=10, y=10\n"
"\t150x50+5+6 - width=150, height=50 at x=5, y=6\n",
progname);
}
int
main(int argc, char *argv[])
{
Ecore_Evas *ee;
int i;
if (argc < 2)
{
usage(argv[0]);
return -2;
}
input_rects = calloc(argc - 1, sizeof(Eina_Rectangle));
input_count = 0;
maxw = 0;
maxh = 0;
for (i = 1; i < argc; i++)
{
Eina_Rectangle *r = input_rects + input_count;
char sx, sy;
if (sscanf(argv[i], "%dx%d%c%d%c%d",
&(r->w), &(r->h), &sx, &(r->x), &sy, &(r->y)) == 6)
{
if (sx == '-') r->x *= -1;
if (sy == '-') r->y *= -1;
if (maxw < r->x + r->w) maxw = r->x + r->w;
if (maxh < r->y + r->h) maxh = r->y + r->h;
input_count++;
}
else
fprintf(stderr, "ERROR: invalid rectangle ignored: %s\n", argv[i]);
}
if (input_count == 0)
{
fputs("ERROR: Could not find any valid rectangle. Exit!\n", stderr);
usage(argv[0]);
free(input_rects);
return -3;
}
if ((maxw == 0) || (maxh == 0))
{
fputs("ERROR: All rectangles with size 0x0. Exit!\n", stderr);
usage(argv[0]);
free(input_rects);
return -3;
}
winw = 2 * maxw + 3 * WINDOW_PAD;
winh = maxh + 2 * WINDOW_PAD;
ee = ecore_evas_new(NULL, 0, 0, winw, winh, NULL);
if (!ee)
{
fputs("ERROR: Could not create window. Check ecore-evas install.\n",
stderr);
goto end;
}
evas = ecore_evas_get(ee);
evas_object_color_set(o, 255, 255, 255, 255);
evas_object_resize(o, winw, winh);
add_text("Input", WINDOW_PAD, 0, maxw);
evas_object_color_set(o, 200, 200, 200, 255);
evas_object_move(o, WINDOW_PAD, WINDOW_PAD);
evas_object_resize(o, maxw, maxh);
add_text("Output", maxw + 2 * WINDOW_PAD, 0, maxw);
evas_object_color_set(o, 200, 200, 200, 255);
evas_object_move(o, maxw + 2 * WINDOW_PAD, WINDOW_PAD);
evas_object_resize(o, maxw, maxh);
tiler = eina_tiler_new(maxw, maxh);
ecore_timer_add(2.0, process_input, NULL);
eina_list_free(output_objs);
end:
free(input_rects);
return 0;
}
Evas wrapper functions.
Eina Utility library.
#define EVAS_LAYER_MAX
top-most layer number
Definition: Evas_Common.h:290
int Evas_Coord
Type used for coordinates (in pixels, int).
Definition: Evas_Common.h:116
EAPI int ecore_evas_init(void)
Inits the Ecore_Evas system.
Definition: ecore_evas.c:602
EAPI void ecore_evas_show(Ecore_Evas *ee)
Shows an Ecore_Evas' window.
Definition: ecore_evas.c:1480
EAPI Evas * ecore_evas_get(const Ecore_Evas *ee)
Gets an Ecore_Evas's Evas.
Definition: ecore_evas.c:1300
EAPI Ecore_Evas * ecore_evas_new(const char *engine_name, int x, int y, int w, int h, const char *extra_options)
Creates a new Ecore_Evas based on engine name and common parameters.
Definition: ecore_evas.c:1039
EAPI int ecore_evas_shutdown(void)
Shuts down the Ecore_Evas system.
Definition: ecore_evas.c:666
EAPI void ecore_evas_free(Ecore_Evas *ee)
Frees an Ecore_Evas.
Definition: ecore_evas.c:1083
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition: ecore.c:371
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:230
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
Ecore_Timer * ecore_timer_add(double in, Ecore_Task_Cb func, const void *data)
Creates a timer to call the given function in the given period of time.
Definition: ecore_timer.c:189
EINA_API void eina_iterator_free(Eina_Iterator *iterator)
Frees an iterator.
Definition: eina_iterator.c:98
#define EINA_ITERATOR_FOREACH(itr, data)
Definition for the macro to iterate over all elements easily.
Definition: eina_iterator.h:448
EINA_API Eina_List * eina_list_append(Eina_List *list, const void *data)
Appends the given data to the given linked list.
Definition: eina_list.c:584
EINA_API Eina_List * eina_list_free(Eina_List *list)
Frees an entire list and all the nodes, ignoring the data contained.
Definition: eina_list.c:823
#define EINA_LIST_FREE(list, data)
Definition for the macro to remove each list node while having access to each node's data.
Definition: eina_list.h:1629
EINA_API int eina_shutdown(void)
Shuts down the Eina library.
Definition: eina_main.c:379
EINA_API int eina_init(void)
Initializes the Eina library.
Definition: eina_main.c:291
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
EINA_API void eina_tiler_free(Eina_Tiler *t)
Frees a tiler.
Definition: eina_tiler.c:1161
struct _Eina_Tiler Eina_Tiler
Tiler type.
Definition: eina_tiler.h:154
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
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
#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
Eo Evas
An opaque handle to an Evas canvas.
Definition: Evas_Common.h:163
EVAS_API int evas_init(void)
Directly initialize Evas and its required dependencies.
Definition: evas_main.c:152
EVAS_API int evas_shutdown(void)
Directly shutdown Evas.
Definition: evas_main.c:239
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_del(Evas_Object *obj)
Marks the given Evas object for deletion (when Evas will free its memory).
Definition: evas_object_main.c:928
EVAS_API void evas_object_color_set(Evas_Object *obj, int r, int g, int b, int a)
Sets the general/main color of the given Evas object to the given one.
Definition: evas_object_main.c:2024
EVAS_API void evas_object_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
Move the given Evas object to the given location inside its canvas' viewport.
Definition: evas_object_main.c:1171
EVAS_API void evas_object_layer_set(Evas_Object *obj, short l)
Sets the layer of its canvas that the given object will be part of.
Definition: evas_layer.c:212
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
EVAS_API Evas_Object * evas_object_rectangle_add(Evas *e)
Adds a rectangle to the given evas.
Definition: evas_object_rectangle.c:78
EVAS_API void evas_object_text_text_set(Eo *obj, const char *text)
Sets the text string to be displayed by the given text object.
Definition: evas_object_text.c:2356
EVAS_API void evas_object_text_font_set(Eo *obj, const char *font, Evas_Font_Size size)
Set the font family or filename, and size on a given text object.
Definition: evas_object_text.c:2340
EVAS_API Evas_Object * evas_object_text_add(Evas *e)
Creates a new text object on the provided canvas.
Definition: evas_object_text.c:366
structure of an iterator
Definition: eina_iterator.h:159
Type for a generic double linked list.
Definition: eina_list.h:318
Definition: eina_rectangle.h:109
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