[StThemeNode] Add basic background-position support
Add basic support for background-position, which only supports absolute values. Also don't require an unit to be specified for 0 (because the unit does not really matter here 0 is 0 regardless of the unit). https://bugzilla.gnome.org/show_bug.cgi?id=624375
This commit is contained in:
parent
c779dcb608
commit
9f9067e29b
@ -466,8 +466,8 @@ get_background_position (StThemeNode *self,
|
||||
w = cogl_texture_get_width (self->background_texture);
|
||||
h = cogl_texture_get_height (self->background_texture);
|
||||
|
||||
/* scale the background into the allocated bounds */
|
||||
if (w > result->x2 || h > result->y2)
|
||||
/* scale the background into the allocated bounds, when not being absolutely positioned */
|
||||
if ((w > result->x2 || h > result->y2) && !self->background_position_set)
|
||||
{
|
||||
gint new_h, new_w, offset;
|
||||
gint box_w, box_h;
|
||||
@ -498,11 +498,20 @@ get_background_position (StThemeNode *self,
|
||||
result->x2 = box_w;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* honor the specified position if any */
|
||||
if (self->background_position_set)
|
||||
{
|
||||
result->x1 = self->background_position_x;
|
||||
result->y1 = self->background_position_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* center the background on the widget */
|
||||
result->x1 = (int)(((allocation->x2 - allocation->x1) / 2) - (w / 2));
|
||||
result->y1 = (int)(((allocation->y2 - allocation->y1) / 2) - (h / 2));
|
||||
}
|
||||
result->x2 = result->x1 + w;
|
||||
result->y2 = result->y1 + h;
|
||||
}
|
||||
|
@ -22,6 +22,10 @@ struct _StThemeNode {
|
||||
StGradientType background_gradient_type;
|
||||
ClutterColor background_gradient_end;
|
||||
|
||||
int background_position_x;
|
||||
int background_position_y;
|
||||
gboolean background_position_set : 1;
|
||||
|
||||
ClutterColor foreground_color;
|
||||
ClutterColor border_color[4];
|
||||
ClutterColor outline_color;
|
||||
|
@ -679,8 +679,19 @@ get_length_from_term (StThemeNode *node,
|
||||
return VALUE_NOT_FOUND;
|
||||
|
||||
case NUM_GENERIC:
|
||||
{
|
||||
if (num->val != 0)
|
||||
{
|
||||
g_warning ("length values must specify a unit");
|
||||
return VALUE_NOT_FOUND;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = ABSOLUTE;
|
||||
multiplier = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case NUM_PERCENTAGE:
|
||||
g_warning ("percentage lengths not currently supported");
|
||||
@ -1424,6 +1435,7 @@ _st_theme_node_ensure_background (StThemeNode *node)
|
||||
node->background_computed = TRUE;
|
||||
node->background_color = TRANSPARENT_COLOR;
|
||||
node->background_gradient_type = ST_GRADIENT_NONE;
|
||||
node->background_position_set = FALSE;
|
||||
|
||||
ensure_properties (node);
|
||||
|
||||
@ -1450,6 +1462,7 @@ _st_theme_node_ensure_background (StThemeNode *node)
|
||||
node->background_color = TRANSPARENT_COLOR;
|
||||
g_free (node->background_image);
|
||||
node->background_image = NULL;
|
||||
node->background_position_set = FALSE;
|
||||
|
||||
for (term = decl->value; term; term = term->next)
|
||||
{
|
||||
@ -1478,6 +1491,27 @@ _st_theme_node_ensure_background (StThemeNode *node)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (strcmp (property_name, "-position") == 0)
|
||||
{
|
||||
GetFromTermResult result = get_length_from_term_int (node, decl->value, FALSE, &node->background_position_x);
|
||||
if (result == VALUE_NOT_FOUND)
|
||||
{
|
||||
node->background_position_set = FALSE;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
node->background_position_set = TRUE;
|
||||
|
||||
result = get_length_from_term_int (node, decl->value->next, FALSE, &node->background_position_y);
|
||||
|
||||
if (result == VALUE_NOT_FOUND)
|
||||
{
|
||||
node->background_position_set = FALSE;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
node->background_position_set = TRUE;
|
||||
}
|
||||
else if (strcmp (property_name, "-color") == 0)
|
||||
{
|
||||
GetFromTermResult result;
|
||||
|
Loading…
Reference in New Issue
Block a user