From c2137f09bb9351cbe5bfa9403a21f6fd960994d5 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Mon, 9 Jun 2003 11:31:33 +0000 Subject: [PATCH] more code & work on ejde. started on edje_cc. SVN revision: 7001 --- legacy/edje/src/bin/Makefile.am | 10 +- legacy/edje/src/bin/edje.h | 3 + legacy/edje/src/bin/edje_cc.c | 434 +++++++++++++++++++++++++++++ legacy/edje/src/lib/edje_main.c | 214 ++++++++++++-- legacy/edje/src/lib/edje_private.h | 36 ++- 5 files changed, 658 insertions(+), 39 deletions(-) create mode 100644 legacy/edje/src/bin/edje_cc.c diff --git a/legacy/edje/src/bin/Makefile.am b/legacy/edje/src/bin/Makefile.am index 5d0d966d9d..a4ff837c17 100644 --- a/legacy/edje/src/bin/Makefile.am +++ b/legacy/edje/src/bin/Makefile.am @@ -11,7 +11,7 @@ INCLUDES = \ -I/usr/local/include \ @my_includes@ -bin_PROGRAMS = edje +bin_PROGRAMS = edje edje_cc edje_SOURCES = \ edje_main.c @@ -20,3 +20,11 @@ edje_LDADD = \ $(top_builddir)/src/lib/libedje.la edje_DEPENDENCIES = $(top_builddir)/src/lib/libedje.la + +edje_cc_SOURCES = \ +edje_cc.c + +edje_cc_LDADD = \ +$(top_builddir)/src/lib/libedje.la + +edje_cc_DEPENDENCIES = $(top_builddir)/src/lib/libedje.la diff --git a/legacy/edje/src/bin/edje.h b/legacy/edje/src/bin/edje.h index 0cbb9f3e88..4d85c3b18b 100644 --- a/legacy/edje/src/bin/edje.h +++ b/legacy/edje/src/bin/edje.h @@ -1,4 +1,7 @@ #include #include #include +/* ... only for testing */ +#include "edje_private.h" +/* ... end testing */ #include "Edje.h" diff --git a/legacy/edje/src/bin/edje_cc.c b/legacy/edje/src/bin/edje_cc.c new file mode 100644 index 0000000000..f8e1529cb8 --- /dev/null +++ b/legacy/edje/src/bin/edje_cc.c @@ -0,0 +1,434 @@ +#include "edje.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +Evas_List *img_dirs = NULL; +char *file_in = NULL; +char *file_out = NULL; +char *progname = NULL; + +int line = 0; +Evas_List *stack = NULL; +Evas_List *params = NULL; + +void new_object(void); +void new_statement(void); +int isdelim(char c); +char *next_token(char *p, char *end, char **new_p, int *delim); +char *stack_id(void); +void stack_chop_top(void); +void parse(char *data, off_t size); +void compile(void); +void main_help(void); + +typedef struct _New_Object_Handler New_Object_Handler; +typedef struct _New_Statement_Handler New_Statement_Handler; + +struct _New_Object_Handler +{ + char *type; + void (*func)(void); +}; + +struct _New_Statement_Handler +{ + char *type; + void (*func)(void); +}; + +void +ob_images(void) +{ + printf("create images struct\n"); +} + +void +ob_images_image(void) +{ + printf("create new image\n"); +} + +void +st_images_image(void) +{ + printf("fill in new image using params\n"); +} + +New_Object_Handler object_handlers[] = +{ + {"images", ob_images}, + {"images.image", ob_images_image} +}; + +New_Statement_Handler statement_handlers[] = +{ + {"images.image", st_images_image} +}; + +void +new_object(void) +{ + char *id; + int i; + + id = stack_id(); +// printf("+++: %s\n", id); + for (i = 0; i < (sizeof(object_handlers) / sizeof (New_Object_Handler)); i++) + { + if (!strcmp(object_handlers[i].type, id)) + { + if (object_handlers[i].func) object_handlers[i].func(); + } + } + free(id); +} + +void +new_statement(void) +{ + char *id; + int i; + + id = stack_id(); +// { +// Evas_List *l; +// printf("===: %s", id); +// for (l = params; l; l = l->next) printf(" [%s]", l->data); +// printf("\n"); +// } + for (i = 0; i < (sizeof(statement_handlers) / sizeof (New_Object_Handler)); i++) + { + if (!strcmp(statement_handlers[i].type, id)) + { + if (statement_handlers[i].func) statement_handlers[i].func(); + } + } + free(id); +} + +int +isdelim(char c) +{ + const char *delims = "{},;"; + char *d; + + d = (char *)delims; + while (*d) + { + if (c == *d) return 1; + d++; + } + return 0; +} + +char * +next_token(char *p, char *end, char **new_p, int *delim) +{ + char *tok_start = NULL, *tok_end = NULL, *tok = NULL, *sa_start = NULL; + int in_tok = 0; + int in_quote = 0; + int in_comment_ss = 0; + int in_comment_sa = 0; + int had_quote = 0; + + *delim = 0; + if (p >= end) return NULL; + while (p < end) + { + if (*p == '\n') + { + in_comment_ss = 0; + line++; + } + if ((!in_comment_ss) && (!in_comment_sa)) + { + if ((!in_quote) && (*p == '/') && (p < (end - 1)) && (*(p + 1) == '/')) + in_comment_ss = 1; + if ((!in_quote) && (*p == '/') && (p < (end - 1)) && (*(p + 1) == '*')) + { + in_comment_sa = 1; + sa_start = p; + } + } + if ((!in_comment_ss) && (!in_comment_sa)) + { + if (!in_tok) + { + if (!in_quote) + { + if (!isspace(*p)) + { + if (*p == '"') + { + in_quote = 1; + had_quote = 1; + } + in_tok = 1; + tok_start = p; + if (isdelim(*p)) *delim = 1; + } + } + } + else + { + if (in_quote) + { + if (((*p) == '"') && (*(p - 1) != '\\')) + { + in_quote = 0; + had_quote = 1; + } + } + else + { + if (*p == '"') + { + in_quote = 1; + had_quote = 1; + } + if ( + (isspace(*p)) || + ((*delim) && (!isdelim(*p))) || + (isdelim(*p)) + ) + { + in_tok = 0; + tok_end = p - 1; + goto done; + } + } + } + } + if (in_comment_sa) + { + if ((*p == '/') && (*(p - 1) == '*') && ((p - sa_start) > 2)) + in_comment_sa = 0; + } + p++; + } + if (!in_tok) return NULL; + tok_end = p - 1; + + done: + *new_p = p; + + tok = malloc(tok_end - tok_start + 2); + if (!tok) + { + fprintf(stderr, "%s: Error. memory allocation of %i bytes failed. %s\n", + progname, tok_end - tok_start + 2, strerror(errno)); + exit(-1); + } + strncpy(tok, tok_start, tok_end - tok_start + 1); + tok[tok_end - tok_start + 1] = 0; + + if (had_quote) + { + p = tok; + + while (*p) + { + if (*p == '"') + strcpy(p, p + 1); + else if ((*p == '\\') && (*(p + 1) == '"')) + strcpy(p, p + 1); + else if ((*p == '\\') && (*(p + 1) == '\\')) + strcpy(p, p + 1); + p++; + } + } + return tok; +} + +char * +stack_id(void) +{ + char *id; + int len; + Evas_List *l; + + len = 0; + for (l = stack; l; l = l->next) + len += strlen(l->data) + 1; + id = malloc(len); + if (!id) + { + fprintf(stderr, "%s: Error. memory allocation of %i bytes failed. %s\n", + progname, len, strerror(errno)); + exit(-1); + } + id[0] = 0; + for (l = stack; l; l = l->next) + { + strcat(id, l->data); + if (l->next) strcat(id, "."); + } + return id; +} + +void +stack_chop_top(void) +{ + char *top; + + /* remove top from stack */ + top = evas_list_data(evas_list_last(stack)); + if (top) + { + free(top); + stack = evas_list_remove(stack, top); + } + else + { + fprintf(stderr, "%s: Error. parse error %s:%i. } marker without matching { marker\n", + progname, file_in, line); + exit(-1); + } +} + +void +parse(char *data, off_t size) +{ + char *p, *end, *token; + int delim = 0; + int do_params = 0; + + p = data; + end = data + size; + line = 1; + while ((token = next_token(p, end, &p, &delim)) != NULL) + { + if (delim) + { + if (!strcmp(token, ",")) do_params = 1; + else if (!strcmp(token, "}")) + { + if (do_params) + { + fprintf(stderr, "%s: Error. parse error %s:%i. } marker before ; marker\n", + progname, file_in, line); + exit(-1); + } + else + stack_chop_top(); + } + else if (!strcmp(token, ";")) + { + + do_params = 0; + new_statement(); + /* clear out params */ + while (params) + { + free(params->data); + params = evas_list_remove(params, params->data); + } + /* remove top from stack */ + stack_chop_top(); + } + free(token); + } + else + { + if (do_params) + params = evas_list_append(params, token); + else + { + stack = evas_list_append(stack, token); + new_object(); + } + } + } +} + +void +compile(void) +{ + int fd; + off_t size; + char *data; + + fd = open(file_in, O_RDONLY); + if (fd < 0) + { + fprintf(stderr, "%s: Error. cannot open file %s for input. %s\n", + progname, file_in, strerror(errno)); + exit(-1); + } + + size = lseek(fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + if (data) + { + parse(data, size); + munmap(data, size); + } + else + { + fprintf(stderr, "%s: Error. cannot mmap file %s for input. %s\n", + progname, file_in, strerror(errno)); + exit(-1); + } + close(fd); +} + +void +main_help(void) +{ + printf + ("Usage:\n" + "\t%s [OPTIONS] input_file.edc output_file.eet\n" + "\n" + "Where OPTIONS is one or more of:\n" + "\n" + "-id image/directory Add a directory to look in for relative path images\n" + ,progname); +} + +int +main(int argc, char **argv) +{ + int i; + + progname = argv[0]; + for (i = 1; i < argc; i++) + { + if (!strcmp(argv[i], "-h")) + { + main_help(); + exit(0); + } + else if ((!strcmp(argv[i], "-id")) && (i < (argc - 1))) + { + i++; + img_dirs = evas_list_append(img_dirs, argv[i]); + } + else if (!file_in) + file_in = argv[i]; + else if (!file_out) + file_out = argv[i]; + } + if (!file_in) + { + fprintf(stderr, "%s: Error: no input file specified.\n", progname); + main_help(); + exit(-1); + } + if (!file_out) + { + fprintf(stderr, "%s: Error: no output file specified.\n", progname); + main_help(); + exit(-1); + } + + compile(); + return 0; +} diff --git a/legacy/edje/src/lib/edje_main.c b/legacy/edje/src/lib/edje_main.c index c60b266307..465ce8ebc3 100644 --- a/legacy/edje/src/lib/edje_main.c +++ b/legacy/edje/src/lib/edje_main.c @@ -82,11 +82,14 @@ static void _edje_part_recalc_single(Edje *ed, Edje_Real_Part *ep, Edje_Part_Description *desc, + Edje_Part_Description *chosen_desc, Edje_Real_Part *rel1_to, Edje_Real_Part *rel2_to, Edje_Real_Part *confine_to, Edje_Calc_Params *params) { + int minw, minh; + /* relative coords of top left & bottom right */ if (rel1_to) { @@ -181,6 +184,62 @@ _edje_part_recalc_single(Edje *ed, params->h = new_h; } } + minw = desc->min.w; + minh = desc->min.h; + /* if we have text that wants to make the min size the text size... */ + if ((chosen_desc) && (ep->part->type == EDJE_PART_TYPE_TEXT)) + { + char *text; + char *font; + int size; + double tw, th; + + text = chosen_desc->text.text; + font = chosen_desc->text.font; + size = chosen_desc->text.size; + if (ep->text.text) text = ep->text.text; + if (ep->text.font) font = ep->text.font; + if (ep->text.size) size = ep->text.size; + evas_object_text_font_set(ep->object, font, size); + if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y)) + { + evas_object_text_text_set(ep->object, text); + evas_object_geometry_get(ep->object, NULL, NULL, &tw, &th); + if (chosen_desc->text.min_x) + { + minw = tw; + /* FIXME: account for effect */ + /* for now just add 2 */ + minw += 2; + } + if (chosen_desc->text.min_y) + { + minh = th; + /* FIXME: account for effect */ + /* for now just add 2 */ + minw += 2; + } + } + } + /* adjust for min size */ + if (minw >= 0) + { + if (params->w < minw) + { + params->x = params->x + + ((params->w - minw) * (1.0 - desc->align.x)); + params->w = minw; + } + } + if (minh >= 0) + { + if (params->h < minh) + { + params->y = params->y + + ((params->h - minh) * (1.0 - desc->align.y)); + params->h = minh; + } + } /* adjust for max size */ if (desc->max.w >= 0) { @@ -200,25 +259,6 @@ _edje_part_recalc_single(Edje *ed, params->h = desc->max.h; } } - /* adjust for min size */ - if (desc->min.w >= 0) - { - if (params->w < desc->min.w) - { - params->x = params->x + - ((params->w - desc->min.w) * (1.0 - desc->align.x)); - params->w = desc->min.w; - } - } - if (desc->min.h >= 0) - { - if (params->h < desc->min.h) - { - params->y = params->y + - ((params->h - desc->min.h) * (1.0 - desc->align.y)); - params->h = desc->min.h; - } - } /* confine */ if (confine_to) { @@ -299,14 +339,14 @@ _edje_part_recalc_single(Edje *ed, params->border.r = desc->border.r; params->border.t = desc->border.t; params->border.b = desc->border.b; - /* text */ - /* FIXME: do */ } static void _edje_part_recalc(Edje *ed, Edje_Real_Part *ep) { - Edje_Calc_Params p1, p2; + Edje_Calc_Params p1, p2, p3; + Edje_Part_Description *chosen_desc; + double pos; if (ep->calculated) return; if (ep->param1.rel1_to) _edje_part_recalc(ed, ep->param1.rel1_to); @@ -317,11 +357,115 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep) if (ep->param2.confine_to) _edje_part_recalc(ed, ep->param2.confine_to); /* actually calculate now */ - if (ep->param1.description) - _edje_part_recalc_single(ed, ep, ep->param1.description, ep->param1.rel1_to, ep->param1.rel2_to, ep->param1.confine_to, &p1); - if (ep->param2.description) - _edje_part_recalc_single(ed, ep, ep->param1.description, ep->param2.rel1_to, ep->param2.rel2_to, ep->param2.confine_to, &p2); + if (ep->description_pos == 0.0) + chosen_desc = ep->param1.description; + else + chosen_desc = ep->param2.description; + if (ep->param1.description) + _edje_part_recalc_single(ed, ep, ep->param1.description, chosen_desc, ep->param1.rel1_to, ep->param1.rel2_to, ep->param1.confine_to, &p1); + if (ep->param2.description) + { + _edje_part_recalc_single(ed, ep, ep->param2.description, chosen_desc, ep->param2.rel1_to, ep->param2.rel2_to, ep->param2.confine_to, &p2); + + /* FIXME: pos isnt just linear - depends on tween method */ + pos = ep->description_pos; + + /* visible is special */ + if ((p1.visible) && (!p2.visible)) + { + if (pos == 1.0) + p3.visible = 0; + else + p3.visible = 1; + } + else if ((!p1.visible) && (p2.visible)) + { + if (pos == 0.0) + p3.visible = 0; + else + p3.visible = 1; + } + else + p3.visible = p1.visible; + + p3.x = (p1.x * (1.0 - pos)) + (p2.x * (pos)); + p3.y = (p1.y * (1.0 - pos)) + (p2.y * (pos)); + p3.w = (p1.w * (1.0 - pos)) + (p2.w * (pos)); + p3.h = (p1.h * (1.0 - pos)) + (p2.h * (pos)); + + p3.fill.x = (p1.fill.x * (1.0 - pos)) + (p2.fill.x * (pos)); + p3.fill.y = (p1.fill.y * (1.0 - pos)) + (p2.fill.y * (pos)); + p3.fill.w = (p1.fill.w * (1.0 - pos)) + (p2.fill.w * (pos)); + p3.fill.h = (p1.fill.h * (1.0 - pos)) + (p2.fill.h * (pos)); + + p3.color.r = (p1.color.r * (1.0 - pos)) + (p2.color.r * (pos)); + p3.color.g = (p1.color.g * (1.0 - pos)) + (p2.color.g * (pos)); + p3.color.b = (p1.color.b * (1.0 - pos)) + (p2.color.b * (pos)); + p3.color.a = (p1.color.a * (1.0 - pos)) + (p2.color.a * (pos)); + + p3.color2.r = (p1.color2.r * (1.0 - pos)) + (p2.color2.r * (pos)); + p3.color2.g = (p1.color2.g * (1.0 - pos)) + (p2.color2.g * (pos)); + p3.color2.b = (p1.color2.b * (1.0 - pos)) + (p2.color2.b * (pos)); + p3.color2.a = (p1.color2.a * (1.0 - pos)) + (p2.color2.a * (pos)); + + p3.color3.r = (p1.color3.r * (1.0 - pos)) + (p2.color3.r * (pos)); + p3.color3.g = (p1.color3.g * (1.0 - pos)) + (p2.color3.g * (pos)); + p3.color3.b = (p1.color3.b * (1.0 - pos)) + (p2.color3.b * (pos)); + p3.color3.a = (p1.color3.a * (1.0 - pos)) + (p2.color3.a * (pos)); + + p3.border.l = (p1.border.l * (1.0 - pos)) + (p2.border.l * (pos)); + p3.border.r = (p1.border.r * (1.0 - pos)) + (p2.border.r * (pos)); + p3.border.t = (p1.border.t * (1.0 - pos)) + (p2.border.t * (pos)); + p3.border.b = (p1.border.b * (1.0 - pos)) + (p2.border.b * (pos)); + } + else + p3 = p1; + if (ep->part->type == EDJE_PART_TYPE_RECTANGLE) + { + evas_object_move(ep->object, ed->x + p3.x, ed->y + p3.y); + evas_object_resize(ep->object, p3.w, p3.h); + } + else if (ep->part->type == EDJE_PART_TYPE_TEXT) + { + /* FIXME: if text object calculate text now */ + /* FIXME: set other colors */ + } + else if (ep->part->type == EDJE_PART_TYPE_IMAGE) + { + char buf[4096]; + int image_id; + int image_count, image_num; + + evas_object_move(ep->object, ed->x + p3.x, ed->y + p3.y); + evas_object_resize(ep->object, p3.w, p3.h); + evas_object_image_fill_set(ep->object, p3.fill.x, p3.fill.y, p3.fill.w, p3.fill.h); + evas_object_image_border_set(ep->object, p3.border.l, p3.border.r, p3.border.t, p3.border.b); + image_id = ep->param1.description->image.id; + image_count = 2; + if (ep->param2.description) + image_count += evas_list_count(ep->param2.description->image.tween_list); + image_num = (pos * ((double)image_count - 0.5)); + if (image_num > (image_count - 1)) + image_num = image_count - 1; + if (image_num == 0) + image_id = ep->param1.description->image.id; + else if (image_num == (image_count - 1)) + image_id = ep->param2.description->image.id; + else + { + Edje_Part_Image_Id *imid; + + imid = evas_list_nth(ep->param2.description->image.tween_list, image_num - 1); + if (imid) image_id = imid->image_id; + } + + snprintf(buf, sizeof(buf), "/images/%i", image_id); + evas_object_image_file_set(ep->object, ed->file->path, buf); + } + if (p3.visible) evas_object_show(ep->object); + else evas_object_hide(ep->object); + evas_object_color_set(ep->object, p3.color.r, p3.color.g, p3.color.b, p3.color.a); ep->calculated = 1; ep->dirty = 0; } @@ -364,6 +508,24 @@ _edje_fetch(Evas_Object *obj) return ed; } +/* +Edje_File * +_edje_add(Evas (evas) +{ + Edje *ed; + + ed = calloc(1, sizeof(Edje)); + ed->evas = evas; + return ed; +} + +void +_edje_free(Edje *ed) +{ + free(ed); +} +*/ + /* evas smart object methods - required by evas smart objects to do the */ /* dirty work on smrt objects */ diff --git a/legacy/edje/src/lib/edje_private.h b/legacy/edje/src/lib/edje_private.h index 61b44cf88b..08817d54b3 100644 --- a/legacy/edje/src/lib/edje_private.h +++ b/legacy/edje/src/lib/edje_private.h @@ -184,6 +184,7 @@ struct _Edje_Part { char *name; /* the name if any of the part */ unsigned char type; /* what type (image, rect, text) */ + unsigned char mouse_events; /* it will affect/respond to mouse events */ int id; /* its id number */ char *color_class; /* how to modify the color */ char *text_class; /* how to apply/modify the font */ @@ -269,12 +270,19 @@ struct _Edje_Part_Description struct { char *text; /* if "" or NULL, then leave text unchanged */ + char *font; /* if a specific font is asked for */ int size; /* 0 = use user set size */ unsigned char effect; /* 0 = plain... */ unsigned char fit_x; /* resize font size down to fit in x dir */ unsigned char fit_y; /* resize font size down to fit in y dir */ + unsigned char min_x; /* if text size should be part min size */ + unsigned char min_y; /* if text size should be part min size */ + + struct { + double x, y; /* text alignment within bounds */ + } align; } text; }; @@ -291,6 +299,7 @@ typedef struct _Edje_Real_Part Edje_Real_Part; struct _Edje { + char *part; int layer; int x, y, w, h; unsigned char dirty : 1; @@ -304,15 +313,20 @@ struct _Edje struct _Edje_Real_Part { - int x, y, w, h; - Evas_Object *object; - unsigned char calculated : 1; - unsigned char dirty : 1; - Edje_Part *part; + int x, y, w, h; + Evas_Object *object; + unsigned char calculated : 1; + unsigned char dirty : 1; + Edje_Part *part; struct { int x, y; } drag; - double description_pos; + struct { + char *text; + char *font; + int size; + } text; + double description_pos; struct { Edje_Part_Description *description; Edje_Real_Part *rel1_to; @@ -325,19 +339,17 @@ typedef struct _Edje_Calc_Params Edje_Calc_Params; struct _Edje_Calc_Params { - double x, y, w, h; - + double x, y, w, h; + char visible : 1; struct { - double x, y, w, h; + double x, y, w, h; } fill; struct { unsigned char r, g, b, a; } color, color2, color3; struct { - int l, r, t, b; + int l, r, t, b; } border; - - char visible : 1; }; #endif