forked from enlightenment/efl
New feature: part descriptions can inherit attributes from other descriptions of the same part. All attributes are inherited, except description name and value, of course.
Syntax: inherit, "desc_name" desc_value; SVN revision: 11908
This commit is contained in:
parent
0a01bac149
commit
f375a9fe2c
|
@ -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
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
#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);
|
||||
|
|
|
@ -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},
|
||||
|
@ -743,6 +745,115 @@ ob_collections_group_parts_part_description(void)
|
|||
ed->text.id_text_source = -1;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -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); \
|
||||
|
@ -708,6 +717,42 @@ data_queue_image_lookup(char *name, int *dest)
|
|||
il->dest = 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)
|
||||
{
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue