edje - support map color set
authorChunEon Park <hermet@hermet.pe.kr>
Thu, 6 Jun 2013 09:18:36 +0000 (18:18 +0900)
committerChunEon Park <hermet@hermet.pe.kr>
Thu, 6 Jun 2013 09:18:36 +0000 (18:18 +0900)
ChangeLog
NEWS
src/bin/edje/edje_cc_handlers.c
src/lib/edje/edje_calc.c
src/lib/edje/edje_data.c
src/lib/edje/edje_edit.c
src/lib/edje/edje_private.h

index 948b2b8..db45391 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-06-06  ChunEon Park (Hermet)
+
+        * Edje: support edc map color set
+
 2013-06-05  Jiyou Park
 
         * Evas: Fix gif cannot decode alpha value correctly.
diff --git a/NEWS b/NEWS
index 2229803..5a1e7c5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -108,6 +108,7 @@ Additions:
      - Add edje_object_part_text_input_panel_layout_variation_set/get API
      - Add EDJE_INPUT_PANEL_LAYOUT_DATETIME layout
      - support edc proxy.source_visible, proxy.source_clip
+     - support edc map color set
     * Eeze:
      - Add a dummy libmount replacement for when libmount is not there.
     * Ecore_Con:
index 9ebf19d..1968d6f 100644 (file)
@@ -355,6 +355,7 @@ static void st_collections_group_parts_part_description_map_smooth(void);
 static void st_collections_group_parts_part_description_map_alpha(void);
 static void st_collections_group_parts_part_description_map_backface_cull(void);
 static void st_collections_group_parts_part_description_map_perspective_on(void);
+static void st_collections_group_parts_part_description_map_color(void);
 static void st_collections_group_parts_part_description_perspective_zplane(void);
 static void st_collections_group_parts_part_description_perspective_focal(void);
 static void st_collections_group_parts_part_api(void);
@@ -669,6 +670,7 @@ New_Statement_Handler statement_handlers[] =
      {"collections.group.parts.part.description.map.alpha", st_collections_group_parts_part_description_map_alpha},
      {"collections.group.parts.part.description.map.backface_cull", st_collections_group_parts_part_description_map_backface_cull},
      {"collections.group.parts.part.description.map.perspective_on", st_collections_group_parts_part_description_map_perspective_on},
+     {"collections.group.parts.part.description.map.color", st_collections_group_parts_part_description_map_color},
      {"collections.group.parts.part.description.perspective.zplane", st_collections_group_parts_part_description_perspective_zplane},
      {"collections.group.parts.part.description.perspective.focal", st_collections_group_parts_part_description_perspective_focal},
      {"collections.group.parts.part.description.params.int", st_collections_group_parts_part_description_params_int},
@@ -4800,6 +4802,27 @@ static void st_collections_group_parts_part_table_items_item_span(void)
    current_item->rowspan = parse_int_range(1, 1, 0xffff);
 }
 
+static Eina_List *
+_copied_map_colors_get(Edje_Part_Description_Common *parent)
+{
+   Eina_List *colors = NULL;
+   Eina_List *l;
+   Edje_Map_Color *color;
+   EINA_LIST_FOREACH(parent->map.colors, l, color)
+     {
+        Edje_Map_Color *c = mem_alloc(SZ(Edje_Map_Color));
+        if (!color)
+          {
+             ERR("not enough memory");
+             exit(-1);
+             return NULL;
+          }
+        memcpy(c, color, sizeof(Edje_Map_Color));
+        colors = eina_list_append(colors, c);
+     }
+   return colors;
+}
+
 /**
    @edcsubsection{collections_group_parts_description,Description}
  */
@@ -4907,6 +4930,7 @@ ob_collections_group_parts_part_description(void)
    ed->map.alpha = 1;
    ed->map.backcull = 0;
    ed->map.persp_on = 0;
+   ed->map.colors = NULL;
    ed->persp.zplane = 0;
    ed->persp.focal = 1000;
    ed->minmul.have = 1;
@@ -5037,6 +5061,8 @@ st_collections_group_parts_part_description_inherit(void)
 #define STRDUP(x) x ? strdup(x) : NULL
 
    ed->color_class = STRDUP(ed->color_class);
+   ed->map.colors = _copied_map_colors_get(parent);
+
    switch (ep->type)
      {
       case EDJE_PART_TYPE_SPACER:
@@ -8262,6 +8288,39 @@ st_collections_group_parts_part_description_map_perspective_on(void)
    current_desc->map.persp_on = parse_bool(0);
 }
 
+static void
+st_collections_group_parts_part_description_map_color(void)
+{
+   check_arg_count(5);
+
+   Edje_Map_Color *color = mem_alloc(SZ(Edje_Map_Color));
+   if (!color)
+     {
+        ERR("not enough memory");
+        exit(-1);
+        return;
+     }
+   color->idx = parse_int(0);
+   color->r = parse_int_range(1, 0, 255);
+   color->g = parse_int_range(2, 0, 255);
+   color->b = parse_int_range(3, 0, 255);
+   color->a = parse_int_range(4, 0, 255);
+
+   Eina_List *l;
+   Edje_Map_Color *ex_color;
+   EINA_LIST_FOREACH(current_desc->map.colors, l, ex_color)
+     {
+        if (ex_color->idx != color->idx) continue;
+        ex_color->r = color->r;
+        ex_color->g = color->g;
+        ex_color->b = color->b;
+        ex_color->a = color->a;
+        return;
+     }
+   current_desc->map.colors = eina_list_append(current_desc->map.colors, color);
+}
+
+
 /**
    @edcsubsection{collections_group_parts_description_map_rotation,Rotation}
  */
index c38c18a..ca4451d 100644 (file)
@@ -2161,6 +2161,7 @@ _edje_part_recalc_single_map(Edje *ed,
                   params_write->persp.focal = persp->param1.description->persp.focal;
                }
           }
+        params_write->colors = desc->map.colors;
      }
    EINA_COW_CALC_MAP_END(params, params_write);
 }
@@ -2733,10 +2734,121 @@ _edje_physics_body_add(Edje *ed, Edje_Real_Part *rp, EPhysics_World *world)
 }
 #endif
 
+#define FINTP(_x1, _x2, _p)                     \
+        (((_x1) == (_x2))                       \
+         ? FROM_INT((_x1))                      \
+         : ADD(FROM_INT(_x1),                   \
+               SCALE((_p), (_x2) - (_x1))))
+
+#define FFP(_x1, _x2, _p)                       \
+        (((_x1) == (_x2))                       \
+         ? (_x1)                                \
+         : ADD(_x1, MUL(_p, SUB(_x2, _x1))));
+
+#define INTP(_x1, _x2, _p) TO_INT(FINTP(_x1, _x2, _p))
+
+static Eina_Bool
+map_colors_interp(Edje_Calc_Params *p1, Edje_Calc_Params *p2,
+                  Edje_Calc_Params_Map *pmap, FLOAT_T pos)
+{
+   Eina_List *l, *l2;
+   Edje_Map_Color *col, *col2, *col3;
+   Eina_Bool matched = EINA_FALSE;
+
+   if (p1->map->colors || p2->map->colors)
+     {
+        EINA_LIST_FOREACH(p1->map->colors, l, col)
+          {
+             col3 = calloc(1, sizeof(Edje_Map_Color));
+             col3->idx = col->idx;
+
+             EINA_LIST_FOREACH(p2->map->colors, l2, col2)
+               {
+                  if (col->idx != col2->idx) continue;
+                  col3->r = INTP(col->r, col2->r, pos);
+                  col3->g = INTP(col->g, col2->g, pos);
+                  col3->b = INTP(col->b, col2->b, pos);
+                  col3->a = INTP(col->a, col2->a, pos);
+                  pmap->colors = eina_list_append(pmap->colors, col3);
+                  matched = EINA_TRUE;
+                  break;
+               }
+             if (!matched)
+               {
+                  col3->r = INTP(col->r, 255, pos);
+                  col3->g = INTP(col->g, 255, pos);
+                  col3->b = INTP(col->b, 255, pos);
+                  col3->a = INTP(col->a, 255, pos);
+                  pmap->colors = eina_list_append(pmap->colors, col3);
+               }
+             matched = EINA_FALSE;
+          }
+        EINA_LIST_FOREACH(p2->map->colors, l, col)
+          {
+             EINA_LIST_FOREACH(p1->map->colors, l2, col2)
+               {
+                  if (col->idx != col2->idx) continue;
+                  matched = EINA_TRUE;
+                  break;
+               }
+             if (!matched)
+               {
+                  col3 = calloc(1, sizeof(Edje_Map_Color));
+                  col3->idx = col->idx;
+                  col3->r = INTP(255, col->r, pos);
+                  col3->g = INTP(255, col->g, pos);
+                  col3->b = INTP(255, col->b, pos);
+                  col3->a = INTP(255, col->a, pos);
+                  pmap->colors = eina_list_append(pmap->colors, col3);
+               }
+             matched = EINA_FALSE;
+          }
+        return EINA_TRUE;
+     }
+
+   return EINA_FALSE;
+}
+
+static void
+_edje_map_color_update(Evas_Map *map, const  Edje_Calc_Params_Map *pmap,
+                       Eina_Bool map_colors_free)
+{
+   Eina_List *colors = pmap->colors;
+   Edje_Map_Color *color;
+   Eina_List *l;
+
+   if (!colors)
+     {
+        evas_map_point_color_set(map, 0, 255, 255, 255, 255);
+        evas_map_point_color_set(map, 1, 255, 255, 255, 255);
+        evas_map_point_color_set(map, 2, 255, 255, 255, 255);
+        evas_map_point_color_set(map, 3, 255, 255, 255, 255);
+        return;
+     }
+
+   if (map_colors_free)
+     {
+        EINA_LIST_FREE(colors, color)
+          {
+             evas_map_point_color_set(map, color->idx, color->r, color->g,
+                                      color->b, color->a);
+             free(color);
+          }
+     }
+   else
+     {
+        EINA_LIST_FOREACH(colors, l, color)
+          {
+             evas_map_point_color_set(map, color->idx, color->r, color->g,
+                                      color->b, color->a);
+          }
+     }
+}
+
 #define Rel1X 0
 #define Rel1Y 1
-#define Rel2X 2 
-#define Rel2Y 3 
+#define Rel2X 2
+#define Rel2Y 3
 
 void
 _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *state)
@@ -2766,6 +2878,7 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
    FLOAT_T pos = ZERO, pos2;
    Edje_Calc_Params lp3;
    Evas_Coord mmw = 0, mmh = 0;
+   Eina_Bool map_colors_free = EINA_FALSE;
 
    /* GRADIENT ARE GONE, WE MUST IGNORE IT FROM OLD FILE. */
    if (ep->part->type == EDJE_PART_TYPE_GRADIENT)
@@ -3127,18 +3240,6 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
         p3->smooth = (beginning_pos) ? p1->smooth : p2->smooth;
 
         /* FIXME: do x and y separately base on flag */
-#define FINTP(_x1, _x2, _p)                     \
-        (((_x1) == (_x2))                       \
-         ? FROM_INT((_x1))                      \
-         : ADD(FROM_INT(_x1),                   \
-               SCALE((_p), (_x2) - (_x1))))
-
-#define FFP(_x1, _x2, _p)                       \
-        (((_x1) == (_x2))                       \
-         ? (_x1)                                \
-         : ADD(_x1, MUL(_p, SUB(_x2, _x1))));
-
-#define INTP(_x1, _x2, _p) TO_INT(FINTP(_x1, _x2, _p))
 
         p3->x = INTP(p1->x, p2->x, pos);
         p3->y = INTP(p1->y, p2->y, pos);
@@ -3275,6 +3376,7 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
 
 #define MIX(P1, P2, P3, pos, info)                                      \
                   P3->info = P1->map->info + TO_INT(SCALE(pos, P2->map->info - P1->map->info));
+                  map_colors_free = map_colors_interp(p1, p2, p3_write, pos);
 
                   if (p1->lighted && p2->lighted)
                     {
@@ -3322,7 +3424,6 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
         eina_cow_free(_edje_calc_params_physics_cow, lp2.physics);
 #endif
 #endif
-
         pf = p3;
      }
    else
@@ -3600,6 +3701,9 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
                   evas_map_point_image_uv_set(map, 2, iw , ih );
                   evas_map_point_image_uv_set(map, 3, 0.0, ih );
                }
+
+             _edje_map_color_update(map, pf->map, map_colors_free);
+
              evas_map_util_3d_rotate(map,
                                      TO_DOUBLE(pf->map->rotation.x),
                                      TO_DOUBLE(pf->map->rotation.y),
index 324c2a2..954958c 100644 (file)
@@ -57,6 +57,7 @@ Eet_Data_Descriptor *_edje_edd_edje_part_image_id_pointer = NULL;
 Eet_Data_Descriptor *_edje_edd_edje_external_param = NULL;
 Eet_Data_Descriptor *_edje_edd_edje_part_limit = NULL;
 Eet_Data_Descriptor *_edje_edd_edje_physics_face = NULL;
+Eet_Data_Descriptor *_edje_edd_edje_map_colors = NULL;
 
 #define EMP(Type, Minus)                               \
   EAPI Eina_Mempool *_emp_##Type = NULL;               \
@@ -222,6 +223,7 @@ _edje_edd_shutdown(void)
    FREED(_edje_edd_edje_image_directory_set_entry);
    FREED(_edje_edd_edje_part_limit);
    FREED(_edje_edd_edje_physics_face);
+   FREED(_edje_edd_edje_map_colors);
 }
 
 #define EDJE_DEFINE_POINTER_TYPE(Type, Name)                           \
@@ -465,6 +467,19 @@ _edje_edd_init(void)
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_physics_face, Edje_Physics_Face, "type", type, EET_T_UCHAR);
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_physics_face, Edje_Physics_Face, "source", source, EET_T_STRING);
 
+   EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Map_Color);
+   _edje_edd_edje_map_colors = eet_data_descriptor_file_new(&eddc);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_map_colors, Edje_Map_Color,
+                                 "idx", idx, EET_T_UINT);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_map_colors, Edje_Map_Color,
+                                 "r", r, EET_T_UCHAR);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_map_colors, Edje_Map_Color,
+                                 "g", g, EET_T_UCHAR);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_map_colors, Edje_Map_Color,
+                                 "b", b, EET_T_UCHAR);
+   EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_map_colors, Edje_Map_Color,
+                                 "a", a, EET_T_UCHAR);
+
 #define EDJE_DATA_DESCRIPTOR_DESCRIPTION_COMMON_FIELDS(Edd, Type) \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "state.name", state.name, EET_T_STRING); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "state.value", state.value, EET_T_DOUBLE); \
@@ -520,6 +535,7 @@ _edje_edd_init(void)
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.alpha", map.alpha, EET_T_UCHAR); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.persp_on", map.persp_on, EET_T_UCHAR); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.backcull", map.backcull, EET_T_UCHAR); \
+      EET_DATA_DESCRIPTOR_ADD_LIST(Edd, Type, "map.color", map.colors, _edje_edd_edje_map_colors); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "persp.zplane", persp.zplane, EET_T_INT); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "persp.focal", persp.focal, EET_T_INT);
 
@@ -606,6 +622,7 @@ _edje_edd_init(void)
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.alpha", Dec.map.alpha, EET_T_UCHAR); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.persp_on", Dec.map.persp_on, EET_T_UCHAR); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.backcull", Dec.map.backcull, EET_T_UCHAR); \
+      EET_DATA_DESCRIPTOR_ADD_LIST(Edd, Type, "map.color", Dec.map.colors, _edje_edd_edje_map_colors); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "persp.zplane", Dec.persp.zplane, EET_T_INT); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "persp.focal", Dec.persp.focal, EET_T_INT); \
 
index 7d87fd5..9252a0a 100644 (file)
@@ -3038,6 +3038,7 @@ edje_edit_state_add(Evas_Object *obj, const char *part, const char *name, double
    pd->map.rot.x = FROM_DOUBLE(0.0);
    pd->map.rot.y = FROM_DOUBLE(0.0);
    pd->map.rot.z = FROM_DOUBLE(0.0);
+   pd->map.colors = NULL;
    pd->map.on = EINA_FALSE;
    pd->map.smooth = EINA_TRUE;
    pd->map.alpha = EINA_TRUE;
index c60c56b..f47e3eb 100644 (file)
@@ -222,6 +222,15 @@ struct _Edje_Color
    unsigned char  r, g, b, a;
 };
 
+struct _Edje_Map_Color
+{
+   int idx;
+   unsigned char r;
+   unsigned char g;
+   unsigned char b;
+   unsigned char a;
+};
+
 struct _Edje_Aspect_Prefer
 {
    FLOAT_T min, max;
@@ -246,6 +255,7 @@ typedef struct _Edje_Position                        Edje_Position;
 typedef struct _Edje_Size                            Edje_Size;
 typedef struct _Edje_Rectangle                       Edje_Rectangle;
 typedef struct _Edje_Color                           Edje_Color;
+typedef struct _Edje_Map_Color                       Edje_Map_Color;
 typedef struct _Edje_Aspect_Prefer                   Edje_Aspect_Prefer;
 typedef struct _Edje_Aspect                          Edje_Aspect;
 typedef struct _Edje_String                          Edje_String;
@@ -1022,7 +1032,7 @@ struct _Edje_Part_Description_Common
 
    struct {
       FLOAT_T        relative_x;
-      FLOAT_T       relative_y;
+      FLOAT_T        relative_y;
       int            offset_x;
       int            offset_y;
       int            id_x; /* -1 = whole part collection, or part ID */
@@ -1036,6 +1046,7 @@ struct _Edje_Part_Description_Common
          int id_center;
          FLOAT_T x, y, z;
       } rot;
+      Eina_List *colors;    //Edje_Map_Color, consider to apply Eina_Hash
       Eina_Bool backcull;
       Eina_Bool on;
       Eina_Bool persp_on;
@@ -1360,6 +1371,7 @@ struct _Edje_Calc_Params_Map
       int x, y, z;
       int focal;
    } persp; // 16
+   Eina_List *colors;
 };
 
 struct _Edje_Calc_Params_Physics