Edje calc: Simplify code readability with eo_do

This removes an absolutely crazy use of eo_do where all calls
to the efl_gfx_filter functions where factorized in an unreadable
manner. Hopefully eo_do will disappear soon.
This commit is contained in:
Jean-Philippe Andre 2016-02-29 18:41:28 +09:00
parent 77db872754
commit 07a8d6a5da
1 changed files with 119 additions and 121 deletions

View File

@ -2588,129 +2588,127 @@ _edje_part_recalc_single_filter(Edje *ed,
prev_sources = NULL; prev_sources = NULL;
} }
eo_do(obj, /* pass extra data items */
/* pass extra data items */ if (filter->data)
if (filter->data) {
{ unsigned int k;
unsigned int k; for (k = 0; k < filter->data_count; k++)
for (k = 0; k < filter->data_count; k++) {
{ Edje_Part_Description_Spec_Filter_Data *data = &(filter->data[k]);
Edje_Part_Description_Spec_Filter_Data *data = &(filter->data[k]); if (data->invalid_cc)
if (data->invalid_cc) continue;
continue; if (!data->value)
if (!data->value) {
{ eo_do(obj, efl_gfx_filter_data_set(data->name, NULL, EINA_FALSE));
efl_gfx_filter_data_set(data->name, NULL, EINA_FALSE); }
} else if (!strncmp(data->value, "color_class('", sizeof("color_class('") - 1))
else if (!strncmp(data->value, "color_class('", sizeof("color_class('") - 1)) {
{ /* special handling for color classes even tho they're not that great */
/* special handling for color classes even tho they're not that great */ char *ccname, *buffer, *r;
char *ccname, *buffer, *r; Edje_Color_Class *cc;
Edje_Color_Class *cc;
ccname = strdup(data->value + sizeof("color_class('") - 1); ccname = strdup(data->value + sizeof("color_class('") - 1);
if (ccname) if (ccname)
{ {
r = strchr(ccname, '\''); r = strchr(ccname, '\'');
if (r && (r[1] == ')') && (r[2] == '\0')) if (r && (r[1] == ')') && (r[2] == '\0'))
{ {
*r = '\0'; *r = '\0';
cc = _edje_color_class_find(ed, ccname); cc = _edje_color_class_find(ed, ccname);
if (cc) if (cc)
{ {
static const char fmt[] = static const char fmt[] =
"%s={r=%d,g=%d,b=%d,a=%d," "%s={r=%d,g=%d,b=%d,a=%d,"
"r2=%d,g2=%d,b2=%d,a2=%d," "r2=%d,g2=%d,b2=%d,a2=%d,"
"r3=%d,g3=%d,b3=%d,a3=%d}"; "r3=%d,g3=%d,b3=%d,a3=%d}";
int len = sizeof(fmt) + 20; int len = sizeof(fmt) + 20;
len += strlen(data->name); len += strlen(data->name);
buffer = alloca(len); buffer = alloca(len);
snprintf(buffer, len - 1, fmt, data->name, snprintf(buffer, len - 1, fmt, data->name,
(int) cc->r, (int) cc->g, (int) cc->b, (int) cc->a, (int) cc->r, (int) cc->g, (int) cc->b, (int) cc->a,
(int) cc->r2, (int) cc->g2, (int) cc->b2, (int) cc->a2, (int) cc->r2, (int) cc->g2, (int) cc->b2, (int) cc->a2,
(int) cc->r3, (int) cc->g3, (int) cc->b3, (int) cc->a3); (int) cc->r3, (int) cc->g3, (int) cc->b3, (int) cc->a3);
buffer[len - 1] = 0; buffer[len - 1] = 0;
efl_gfx_filter_data_set(data->name, buffer, EINA_TRUE); eo_do(obj, efl_gfx_filter_data_set(data->name, buffer, EINA_TRUE));
} }
else else
{ {
ERR("Unknown color class: %s", ccname); ERR("Unknown color class: %s", ccname);
data->invalid_cc = EINA_TRUE; data->invalid_cc = EINA_TRUE;
} }
} }
else else
{ {
ERR("Failed to parse color class: %s", data->value); ERR("Failed to parse color class: %s", data->value);
data->invalid_cc = EINA_TRUE; data->invalid_cc = EINA_TRUE;
} }
free(ccname); free(ccname);
} }
} }
else else
efl_gfx_filter_data_set(data->name, data->value, EINA_FALSE); eo_do(obj, efl_gfx_filter_data_set(data->name, data->value, EINA_FALSE));
} }
} }
efl_gfx_filter_program_set(code, filter->name); eo_do(obj, efl_gfx_filter_program_set(code, filter->name));
if (prev_sources != filter_sources) if (prev_sources != filter_sources)
{ {
/* remove sources that are not there anymore /* remove sources that are not there anymore
* this O(n^2) loop assumes a very small number of sources */ * this O(n^2) loop assumes a very small number of sources */
EINA_LIST_FOREACH(prev_sources, li1, src1) EINA_LIST_FOREACH(prev_sources, li1, src1)
{ {
Eina_Bool found = 0; Eina_Bool found = 0;
EINA_LIST_FOREACH(filter_sources, li2, src2) EINA_LIST_FOREACH(filter_sources, li2, src2)
{ {
if (!strcmp(src1, src2)) if (!strcmp(src1, src2))
{ {
found = 1; found = 1;
break; break;
} }
} }
if (!found) if (!found)
{ {
part = strchr(src1, ':'); part = strchr(src1, ':');
if (!part) if (!part)
efl_gfx_filter_source_set(src1, NULL); eo_do(obj, efl_gfx_filter_source_set(src1, NULL));
else else
{ {
char *name = strdup(src1); char *name = strdup(src1);
name[part - src1] = 0; name[part - src1] = 0;
efl_gfx_filter_source_set(name, NULL); eo_do(obj, efl_gfx_filter_source_set(name, NULL));
free(name); free(name);
} }
} }
} }
/* add all sources by part name */ /* add all sources by part name */
EINA_LIST_FOREACH(filter_sources, li1, src1) EINA_LIST_FOREACH(filter_sources, li1, src1)
{ {
Edje_Real_Part *rp; Edje_Real_Part *rp;
char *name = NULL; char *name = NULL;
if ((part = strchr(src1, ':')) != NULL) if ((part = strchr(src1, ':')) != NULL)
{ {
name = strdup(src1); name = strdup(src1);
name[part - src1] = 0; name[part - src1] = 0;
part++; part++;
} }
else else
part = src1; part = src1;
rp = _edje_real_part_get(ed, part); rp = _edje_real_part_get(ed, part);
efl_gfx_filter_source_set(name ? name : part, rp ? rp->object : NULL); eo_do(obj, efl_gfx_filter_source_set(name ? name : part, rp ? rp->object : NULL));
free(name); free(name);
} }
} }
/* pass edje state for transitions */ /* pass edje state for transitions */
if (ep->param2) if (ep->param2)
{ {
efl_gfx_filter_state_set(chosen_desc->state.name, chosen_desc->state.value, eo_do(obj, efl_gfx_filter_state_set(chosen_desc->state.name, chosen_desc->state.value,
ep->param2->description->state.name, ep->param2->description->state.value, ep->param2->description->state.name, ep->param2->description->state.value,
pos); pos));
} }
else else
{ {
efl_gfx_filter_state_set(chosen_desc->state.name, chosen_desc->state.value, eo_do(obj, efl_gfx_filter_state_set(chosen_desc->state.name, chosen_desc->state.value,
NULL, 0.0, pos); NULL, 0.0, pos));
} }
);
} }
static void static void