New feature: part descriptions can inherit attributes from other descriptions of...
authortsauerbeck <tsauerbeck>
Tue, 19 Oct 2004 16:37:20 +0000 (16:37 +0000)
committertsauerbeck <tsauerbeck@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 19 Oct 2004 16:37:20 +0000 (16:37 +0000)
Syntax: inherit, "desc_name" desc_value;

SVN revision: 11908

legacy/edje/data/edc.vim
legacy/edje/src/bin/edje_cc.h
legacy/edje/src/bin/edje_cc_handlers.c
legacy/edje/src/bin/edje_cc_out.c

index ffe8e48..7ca1d89 100644 (file)
@@ -25,7 +25,7 @@ syn keyword   cLabel          state visible align step aspect
 syn keyword    cLabel          relative offset to to_x to_y normal tween
 syn keyword    cLabel          border color color2 color3 font size fit align
 syn keyword    cLabel          signal source action transition in target after
-syn keyword    cLabel          text smooth
+syn keyword    cLabel          text smooth inherit
 
 syn keyword    cConditional    if else switch
 syn keyword    cRepeat         while for do
index 0dee41a..de2cf41 100644 (file)
 #include <alloca.h>
 #endif
 
+#ifndef ABS
+#define ABS(x) x < 0 ? -x : x
+#endif
+
 /* types */
 typedef struct _New_Object_Handler    New_Object_Handler;
 typedef struct _New_Statement_Handler New_Statement_Handler;
@@ -86,6 +90,8 @@ void    data_write(void);
 void    data_queue_part_lookup(Edje_Part_Collection *pc, char *name, int *dest);
 void    data_queue_program_lookup(Edje_Part_Collection *pc, char *name, int *dest);
 void    data_queue_image_lookup(char *name, int *dest);
+void    data_queue_part_slave_lookup(int *master, int *slave);
+void    data_queue_image_slave_lookup(int *master, int *slave);
 void    data_process_lookups(void);
 void    data_process_scripts(void);
 void    data_process_script_lookups(void);
index 84ef5cb..7e7f088 100644 (file)
@@ -32,6 +32,7 @@ static void st_collections_group_parts_part_dragable_y(void);
 static void st_collections_group_parts_part_dragable_confine(void);
 
 static void ob_collections_group_parts_part_description(void);
+static void st_collections_group_parts_part_description_inherit(void);
 static void st_collections_group_parts_part_description_state(void);
 static void st_collections_group_parts_part_description_visible(void);
 static void st_collections_group_parts_part_description_align(void);
@@ -120,6 +121,7 @@ New_Statement_Handler statement_handlers[] =
      {"collections.group.parts.part.images.image", st_images_image}, /* dup */
      {"collections.group.parts.part.font", st_fonts_font}, /* dup */
      {"collections.group.parts.part.fonts.font", st_fonts_font}, /* dup */
+     {"collections.group.parts.part.description.inherit", st_collections_group_parts_part_description_inherit},
      {"collections.group.parts.part.description.state", st_collections_group_parts_part_description_state},
      {"collections.group.parts.part.description.visible", st_collections_group_parts_part_description_visible},
      {"collections.group.parts.part.description.align", st_collections_group_parts_part_description_align},
@@ -744,6 +746,115 @@ ob_collections_group_parts_part_description(void)
 }
 
 static void
+st_collections_group_parts_part_description_inherit(void)
+{
+   Edje_Part_Collection *pc;
+   Edje_Part *ep;
+   Edje_Part_Description *ed, *parent = NULL;
+   Evas_List *l;
+   char *parent_name, *state_name;
+   double parent_val, state_val;
+
+   pc = evas_list_data(evas_list_last(edje_collections));
+   ep = evas_list_data(evas_list_last(pc->parts));
+
+   /* inherit may not be used in the default description */
+   if (!ep->other_desc)
+     {
+       fprintf(stderr, "part %s: "
+             "inherit may not be used in the default description!\n",
+             ep->name);
+       exit(-1);
+     }
+
+   ed = evas_list_data(evas_list_last(ep->other_desc));
+
+   if (!ed->state.name)
+     {
+       fprintf(stderr, "part %s: "
+             "inherit may only be used after state!\n",
+             ep->name);
+       exit(-1);
+     }
+
+   /* find the description that we inherit from */
+   parent_name = parse_str(0);
+   parent_val = parse_float_range(1, 0.0, 1.0);
+
+   if (!strcmp (parent_name, "default") && parent_val == 0.0)
+     parent = ep->default_desc;
+   else
+     {
+       double min_dst = 999.0;
+
+       if (!strcmp(parent_name, "default"))
+         {
+            parent = ep->default_desc;
+            min_dst = ABS(ep->default_desc->state.value - parent_val);
+         }
+
+       for (l = ep->other_desc; l; l = l->next)
+         {
+            Edje_Part_Description *d = l->data;
+
+            if (!strcmp (d->state.name, parent_name))
+              {
+                 double dst;
+
+                 dst = ABS(d->state.value - parent_val);
+                 if (dst < min_dst)
+                   {
+                      parent = d;
+                      min_dst = dst;
+                   }
+              }
+         }
+     }
+
+   if (!parent)
+     {
+       fprintf (stderr, "part %s: "
+             "cannot find referenced part state %s %lf\n",
+             ep->name, parent_name, parent_val);
+       exit(-1);
+     }
+
+   free (parent_name);
+
+   /* now do a full copy, only state info will be kept */
+   state_name = ed->state.name;
+   state_val = ed->state.value;
+
+   *ed = *parent;
+
+   ed->state.name = state_name;
+   ed->state.value = state_val;
+
+   data_queue_part_slave_lookup(&parent->rel1.id_x, &ed->rel1.id_x);
+   data_queue_part_slave_lookup(&parent->rel1.id_y, &ed->rel1.id_y);
+   data_queue_part_slave_lookup(&parent->rel2.id_x, &ed->rel2.id_x);
+   data_queue_part_slave_lookup(&parent->rel2.id_y, &ed->rel2.id_y);
+   data_queue_image_slave_lookup(&parent->image.id, &ed->image.id);
+
+   /* make sure all the allocated memory is getting copied, not just
+    * referenced
+    */
+   ed->image.tween_list = NULL;
+
+   for (l = parent->image.tween_list; l; l = l->next)
+     ed->image.tween_list = evas_list_append(ed->image.tween_list, l->data);
+
+#define STRDUP(x) x ? strdup(x) : NULL
+
+   ed->color_class = STRDUP(ed->color_class);
+   ed->text.text = STRDUP(ed->text.text);
+   ed->text.text_class = STRDUP(ed->text.text_class);
+   ed->text.font = STRDUP(ed->text.font);
+
+#undef STRDUP
+}
+
+static void
 st_collections_group_parts_part_description_state(void)
 {
    Edje_Part_Collection *pc;
index e95236b..a15e918 100644 (file)
@@ -7,6 +7,7 @@
 typedef struct _Part_Lookup Part_Lookup;
 typedef struct _Program_Lookup Program_Lookup;
 typedef struct _Image_Lookup Image_Lookup;
+typedef struct _Slave_Lookup Slave_Lookup;
 typedef struct _Code_Lookup Code_Lookup;
 
 struct _Part_Lookup
@@ -29,6 +30,12 @@ struct _Image_Lookup
    int *dest;
 };
 
+struct _Slave_Lookup
+{
+   int *master;
+   int *slave;
+};
+
 struct _Code_Lookup
 {
    char *ptr;
@@ -60,6 +67,8 @@ static Eet_Data_Descriptor *edd_edje_part_image_id = NULL;
 static Evas_List *part_lookups = NULL;
 static Evas_List *program_lookups = NULL;
 static Evas_List *image_lookups = NULL;
+static Evas_List *part_slave_lookups = NULL;
+static Evas_List *image_slave_lookups= NULL;
 
 #define ABORT_WRITE(eet_file, file) \
    eet_close(eet_file); \
@@ -709,6 +718,42 @@ data_queue_image_lookup(char *name, int *dest)
 }
 
 void
+data_queue_part_slave_lookup(int *master, int *slave)
+{
+   Slave_Lookup *sl;
+
+   sl = mem_alloc(SZ(Slave_Lookup));
+   part_slave_lookups = evas_list_append(part_slave_lookups, sl);
+   sl->master = master;
+   sl->slave = slave;
+}
+
+void
+data_queue_image_slave_lookup(int *master, int *slave)
+{
+   Slave_Lookup *sl;
+
+   sl = mem_alloc(SZ(Slave_Lookup));
+   image_slave_lookups = evas_list_append(image_slave_lookups, sl);
+   sl->master = master;
+   sl->slave = slave;
+}
+
+void
+handle_slave_lookup(Evas_List *list, int *master, int value)
+{
+   Evas_List *l;
+
+   for (l = list; l; l = l->next)
+   {
+      Slave_Lookup *sl = l->data;
+
+      if (sl->master == master)
+        *sl->slave = value;
+   }
+}
+
+void
 data_process_lookups(void)
 {
    Evas_List *l;
@@ -726,6 +771,7 @@ data_process_lookups(void)
             ep = l->data;
             if ((ep->name) && (!strcmp(ep->name, pl->name)))
               {
+                 handle_slave_lookup(part_slave_lookups, pl->dest, ep->id);
                  *(pl->dest) = ep->id;
                  break;
               }
@@ -786,6 +832,7 @@ data_process_lookups(void)
                  de = l->data;
                  if ((de->entry) && (!strcmp(de->entry, il->name)))
                    {
+                      handle_slave_lookup(image_slave_lookups, il->dest, de->id);
                       *(il->dest) = de->id;
                       break;
                    }
@@ -802,6 +849,18 @@ data_process_lookups(void)
        free(il->name);
        free(il);
      }
+
+   while (part_slave_lookups)
+     {
+       free(part_slave_lookups->data);
+       part_slave_lookups = evas_list_remove_list(part_slave_lookups, part_slave_lookups);
+     }
+
+   while (image_slave_lookups)
+     {
+       free(image_slave_lookups->data);
+       image_slave_lookups = evas_list_remove_list(image_slave_lookups, image_slave_lookups);
+     }
 }
 
 static void