add linear gradient specific fill options

used (inside a part description) as follows:

Horizontal from left to right filling entire part:

  gradient {
    spectrum: "black_to_white";
    rel1 {
      relative: 0 0.5;
      offset: 0 0;
    }
    rel2 {
      relative: 1 0.5;
      offset: -1 0;
    }
  }

Diagonal from top left to bottom right:


  gradient {
    spectrum: "black_to_white";
    rel1 {
      relative: 0 0;
      offset: 0 0;
    }
    rel2 {
      relative: 1 1;
      offset: -1 -1;
    }
  }

If either rel1 or rel2 is present in the gradient block of a linear gradient, these will override any angle/origin/size specified in the fill block ('spread' is still honored).


SVN revision: 24975
This commit is contained in:
rephorm 2006-08-21 03:00:01 +00:00 committed by rephorm
parent fce2cb192b
commit 46b3c5f1a0
4 changed files with 231 additions and 12 deletions

View File

@ -97,6 +97,11 @@ static void st_collections_group_parts_part_description_text_text_source(void);
static void st_collections_group_parts_part_description_text_elipsis(void);
static void st_collections_group_parts_part_description_gradient_type(void);
static void st_collections_group_parts_part_description_gradient_spectrum(void);
static void ob_collections_group_parts_part_description_gradient_rel(void);
static void st_collections_group_parts_part_description_gradient_rel1_relative(void);
static void st_collections_group_parts_part_description_gradient_rel1_offset(void);
static void st_collections_group_parts_part_description_gradient_rel2_relative(void);
static void st_collections_group_parts_part_description_gradient_rel2_offset(void);
static void ob_collections_group_programs_program(void);
static void st_collections_group_programs_program_name(void);
@ -236,6 +241,10 @@ New_Statement_Handler statement_handlers[] =
{"collections.group.parts.part.description.text.fonts.font", st_fonts_font}, /* dup */
{"collections.group.parts.part.description.text.elipsis", st_collections_group_parts_part_description_text_elipsis},
{"collections.group.parts.part.description.gradient.type", st_collections_group_parts_part_description_gradient_type},
{"collections.group.parts.part.description.gradient.rel1.relative", st_collections_group_parts_part_description_gradient_rel1_relative},
{"collections.group.parts.part.description.gradient.rel1.offset", st_collections_group_parts_part_description_gradient_rel1_offset},
{"collections.group.parts.part.description.gradient.rel2.relative", st_collections_group_parts_part_description_gradient_rel2_relative},
{"collections.group.parts.part.description.gradient.rel2.offset", st_collections_group_parts_part_description_gradient_rel2_offset},
{"collections.group.parts.part.description.gradient.spectrum", st_collections_group_parts_part_description_gradient_spectrum},
{"collections.group.parts.part.description.images.image", st_images_image}, /* dup */
{"collections.group.parts.part.description.font", st_fonts_font}, /* dup */
@ -386,6 +395,8 @@ New_Object_Handler object_handlers[] =
{"collections.group.parts.part.description.styles", NULL}, /* dup */
{"collections.group.parts.part.description.styles.style", ob_styles_style}, /* dup */
{"collections.group.parts.part.description.gradient", NULL},
{"collections.group.parts.part.description.gradient.rel1", ob_collections_group_parts_part_description_gradient_rel},
{"collections.group.parts.part.description.gradient.rel2", ob_collections_group_parts_part_description_gradient_rel},
{"collections.group.parts.part.description.color_classes", NULL}, /* dup */
{"collections.group.parts.part.description.color_classes.color_class", ob_color_class}, /* dup */
{"collections.group.parts.part.description.program", ob_collections_group_programs_program}, /* dup */
@ -2349,6 +2360,148 @@ st_collections_group_parts_part_description_gradient_spectrum(void)
}
}
static void
ob_collections_group_parts_part_description_gradient_rel(void)
{
Edje_Part_Collection *pc;
Edje_Part *ep;
Edje_Part_Description *ed;
pc = evas_list_data(evas_list_last(edje_collections));
ep = evas_list_data(evas_list_last(pc->parts));
if (ep->type != EDJE_PART_TYPE_GRADIENT)
{
fprintf(stderr, "%s: Error. parse error %s:%i. "
"gradient attributes in non-GRADIENT part.\n",
progname, file_in, line - 1);
exit(-1);
}
ed = ep->default_desc;
if (ep->other_desc) ed = evas_list_data(evas_list_last(ep->other_desc));
{
ed->gradient.use_rel = 1;
}
}
static void
st_collections_group_parts_part_description_gradient_rel1_relative(void)
{
Edje_Part_Collection *pc;
Edje_Part *ep;
Edje_Part_Description *ed;
check_arg_count(2);
pc = evas_list_data(evas_list_last(edje_collections));
ep = evas_list_data(evas_list_last(pc->parts));
if (ep->type != EDJE_PART_TYPE_GRADIENT)
{
fprintf(stderr, "%s: Error. parse error %s:%i. "
"gradient attributes in non-GRADIENT part.\n",
progname, file_in, line - 1);
exit(-1);
}
ed = ep->default_desc;
if (ep->other_desc) ed = evas_list_data(evas_list_last(ep->other_desc));
{
ed->gradient.rel1.relative_x = parse_float(0);
ed->gradient.rel1.relative_y = parse_float(1);
}
}
static void
st_collections_group_parts_part_description_gradient_rel1_offset(void)
{
Edje_Part_Collection *pc;
Edje_Part *ep;
Edje_Part_Description *ed;
check_arg_count(2);
pc = evas_list_data(evas_list_last(edje_collections));
ep = evas_list_data(evas_list_last(pc->parts));
if (ep->type != EDJE_PART_TYPE_GRADIENT)
{
fprintf(stderr, "%s: Error. parse error %s:%i. "
"gradient attributes in non-GRADIENT part.\n",
progname, file_in, line - 1);
exit(-1);
}
ed = ep->default_desc;
if (ep->other_desc) ed = evas_list_data(evas_list_last(ep->other_desc));
{
ed->gradient.rel1.offset_x = parse_int(0);
ed->gradient.rel1.offset_y = parse_int(1);
}
}
static void
st_collections_group_parts_part_description_gradient_rel2_relative(void)
{
Edje_Part_Collection *pc;
Edje_Part *ep;
Edje_Part_Description *ed;
check_arg_count(2);
pc = evas_list_data(evas_list_last(edje_collections));
ep = evas_list_data(evas_list_last(pc->parts));
if (ep->type != EDJE_PART_TYPE_GRADIENT)
{
fprintf(stderr, "%s: Error. parse error %s:%i. "
"gradient attributes in non-GRADIENT part.\n",
progname, file_in, line - 1);
exit(-1);
}
ed = ep->default_desc;
if (ep->other_desc) ed = evas_list_data(evas_list_last(ep->other_desc));
{
ed->gradient.rel2.relative_x = parse_float(0);
ed->gradient.rel2.relative_y = parse_float(1);
}
}
static void
st_collections_group_parts_part_description_gradient_rel2_offset(void)
{
Edje_Part_Collection *pc;
Edje_Part *ep;
Edje_Part_Description *ed;
check_arg_count(2);
pc = evas_list_data(evas_list_last(edje_collections));
ep = evas_list_data(evas_list_last(pc->parts));
if (ep->type != EDJE_PART_TYPE_GRADIENT)
{
fprintf(stderr, "%s: Error. parse error %s:%i. "
"gradient attributes in non-GRADIENT part.\n",
progname, file_in, line - 1);
exit(-1);
}
ed = ep->default_desc;
if (ep->other_desc) ed = evas_list_data(evas_list_last(ep->other_desc));
{
ed->gradient.rel2.offset_x = parse_int(0);
ed->gradient.rel2.offset_y = parse_int(1);
}
}
static void
ob_collections_group_programs_program(void)

View File

@ -906,19 +906,69 @@ _edje_part_recalc_single(Edje *ed,
}
}
/* fill */
params->smooth = desc->fill.smooth;
if (flags & FLAG_X)
if (ep->part->type == EDJE_PART_TYPE_GRADIENT && desc->gradient.use_rel && (!desc->gradient.type || !strcmp(desc->gradient.type, "linear")))
{
params->fill.x = desc->fill.pos_abs_x + (params->w * desc->fill.pos_rel_x);
params->fill.w = desc->fill.abs_x + (params->w * desc->fill.rel_x);
int x2, y2;
int dx, dy;
double m;
int angle;
params->fill.x = desc->gradient.rel1.offset_x + (params->w * desc->gradient.rel1.relative_x);
params->fill.y = desc->gradient.rel1.offset_y + (params->h * desc->gradient.rel1.relative_y);
x2 = desc->gradient.rel2.offset_x + (params->w * desc->gradient.rel2.relative_x);
y2 = desc->gradient.rel2.offset_y + (params->h * desc->gradient.rel2.relative_y);
params->fill.w = 1; /* doesn't matter for linear grads */
dy = y2 - params->fill.y;
dx = x2 - params->fill.x;
params->fill.h = sqrt(dx * dx + dy * dy);
params->fill.spread = desc->fill.spread;
if (dx == 0 && dy == 0)
{
angle = 0;
}
else if (dx == 0)
{
if (dy > 0) angle = 0;
else angle = 180;
}
else if (dy == 0)
{
if (dx > 0) angle = 270;
else angle = 90;
}
else
{
m = (double)dx / (double)dy;
angle = atan(m) * 180 / M_PI;
if (dy < 0)
angle = 180 - angle;
else
angle = 360 - angle;
}
params->fill.angle = angle;
}
if (flags & FLAG_Y)
else
{
params->fill.y = desc->fill.pos_abs_y + (params->h * desc->fill.pos_rel_y);
params->fill.h = desc->fill.abs_y + (params->h * desc->fill.rel_y);
params->smooth = desc->fill.smooth;
if (flags & FLAG_X)
{
params->fill.x = desc->fill.pos_abs_x + (params->w * desc->fill.pos_rel_x);
params->fill.w = desc->fill.abs_x + (params->w * desc->fill.rel_x);
}
if (flags & FLAG_Y)
{
params->fill.y = desc->fill.pos_abs_y + (params->h * desc->fill.pos_rel_y);
params->fill.h = desc->fill.abs_y + (params->h * desc->fill.rel_y);
}
params->fill.angle = desc->fill.angle;
params->fill.spread = desc->fill.spread;
}
params->fill.angle = desc->fill.angle;
params->fill.spread = desc->fill.spread;
/* colors */
params->color.r = desc->color.r;

View File

@ -322,6 +322,15 @@ _edje_edd_setup(void)
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "text.elipsis", text.elipsis, EET_T_DOUBLE);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.id", gradient.id, EET_T_INT);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.type", gradient.type, EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.use_rel", gradient.use_rel, EET_T_INT);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.rel1.relative_x", gradient.rel1.relative_x, EET_T_DOUBLE);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.rel1.relative_y", gradient.rel1.relative_y, EET_T_DOUBLE);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.rel1.offset_x", gradient.rel1.offset_x, EET_T_INT);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.rel1.offset_y", gradient.rel1.offset_y, EET_T_INT);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.rel2.relative_x", gradient.rel2.relative_x, EET_T_DOUBLE);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.rel2.relative_y", gradient.rel2.relative_y, EET_T_DOUBLE);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.rel2.offset_x", gradient.rel2.offset_x, EET_T_INT);
EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description, Edje_Part_Description, "gradient.rel2.offset_y", gradient.rel2.offset_y, EET_T_INT);
NEWD("Edje_Part",
Edje_Part);

View File

@ -468,9 +468,16 @@ struct _Edje_Part_Description
} image;
struct {
int id; /* the spectrum id to use */
char *type; /* type of spectrum - 'linear', 'radial', etc */
char *params; /* params for spectrum type */
int id; /* the spectrum id to use */
char *type; /* type of spectrum - 'linear', 'radial', etc */
char *params; /* params for spectrum type */
int use_rel; /* 1 - use rel1,rel2; 0 - use fill */
struct {
double relative_x;
double relative_y;
int offset_x;
int offset_y;
} rel1, rel2; /* linear gradient fill options */
} gradient;
struct {