cssvalue: Convert border-image-width to border value

This commit is contained in:
Benjamin Otte 2012-04-04 17:42:45 +02:00
parent 56f79fecce
commit 1170ecfd2e
6 changed files with 68 additions and 55 deletions

View File

@ -41,22 +41,12 @@ gboolean
_gtk_border_image_init (GtkBorderImage *image,
GtkThemingEngine *engine)
{
GtkBorder *width;
image->source = _gtk_css_image_value_get_image (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_SOURCE));
if (image->source == NULL)
return FALSE;
image->slice = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_SLICE);
width = _gtk_css_value_get_boxed (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_WIDTH));
if (width)
{
image->width = *width;
image->has_width = TRUE;
}
else
image->has_width = FALSE;
image->width = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_WIDTH);
image->repeat = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_REPEAT);
return TRUE;
@ -69,20 +59,38 @@ struct _GtkBorderImageSliceSize {
};
static void
gtk_border_image_compute_border_size (GtkBorderImageSliceSize sizes[3],
double offset,
double area_size,
int start_border,
int end_border)
gtk_border_image_compute_border_size (GtkBorderImageSliceSize sizes[3],
double offset,
double area_size,
int start_border_width,
int end_border_width,
const GtkCssValue *start_border,
const GtkCssValue *end_border)
{
/* This code assumes area_size >= start_border + end_border */
double start, end;
if (_gtk_css_number_value_get_unit (start_border) == GTK_CSS_NUMBER)
start = start_border_width * _gtk_css_number_value_get (start_border, 100);
else
start = _gtk_css_number_value_get (start_border, area_size);
if (_gtk_css_number_value_get_unit (end_border) == GTK_CSS_NUMBER)
end = end_border_width * _gtk_css_number_value_get (end_border, 100);
else
end = _gtk_css_number_value_get (end_border, area_size);
/* XXX: reduce vertical and horizontal by the same factor */
if (start + end > area_size)
{
start = start * area_size / (start + end);
end = end * area_size / (start + end);
}
sizes[0].offset = offset;
sizes[0].size = start_border;
sizes[1].offset = offset + start_border;
sizes[1].size = area_size - start_border - end_border;
sizes[2].offset = offset + area_size - end_border;
sizes[2].size = end_border;
sizes[0].size = start;
sizes[1].offset = offset + start;
sizes[1].size = area_size - start - end;
sizes[2].offset = offset + area_size - end;
sizes[2].size = end;
}
static void
@ -240,9 +248,6 @@ _gtk_border_image_render (GtkBorderImage *image,
double source_width, source_height;
int h, v;
if (image->has_width)
border_width = &image->width;
_gtk_css_image_get_concrete_size (image->source,
0, 0,
width, height,
@ -266,12 +271,16 @@ _gtk_border_image_render (GtkBorderImage *image,
x,
width,
border_width->left,
border_width->right);
border_width->right,
_gtk_css_border_value_get_left (image->width),
_gtk_css_border_value_get_right (image->width));
gtk_border_image_compute_border_size (vertical_border,
y,
height,
border_width->top,
border_width->bottom);
border_width->bottom,
_gtk_css_border_value_get_top (image->width),
_gtk_css_border_value_get_bottom(image->width));
for (v = 0; v < 3; v++)
{

View File

@ -35,8 +35,7 @@ struct _GtkBorderImage {
GtkCssImage *source;
GtkCssValue *slice;
gboolean has_width;
GtkBorder width;
GtkCssValue *width;
GtkCssValue *repeat;
};

View File

@ -141,6 +141,14 @@ _gtk_css_number_value_parse (GtkCssParser *parser,
return _gtk_css_number_value_new (number.value, number.unit);
}
GtkCssUnit
_gtk_css_number_value_get_unit (const GtkCssValue *value)
{
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_NUMBER, GTK_CSS_NUMBER);
return value->unit;
}
double
_gtk_css_number_value_get (const GtkCssValue *number,
double one_hundred_percent)

View File

@ -31,6 +31,7 @@ GtkCssValue * _gtk_css_number_value_new (double val
GtkCssValue * _gtk_css_number_value_parse (GtkCssParser *parser,
GtkCssNumberParseFlags flags);
GtkCssUnit _gtk_css_number_value_get_unit (const GtkCssValue *value);
double _gtk_css_number_value_get (const GtkCssValue *number,
double one_hundred_percent);
GtkCssValue * _gtk_css_number_value_compute (GtkCssValue *number,

View File

@ -34,9 +34,7 @@
#include "gtkcssrepeatvalueprivate.h"
#include "gtkcssstringvalueprivate.h"
#include "gtkcssstylefuncsprivate.h"
#include "gtkcsstypesprivate.h"
#include "gtkcssvalueprivate.h"
#include "gtkprivatetypebuiltins.h"
#include "gtkstylepropertiesprivate.h"
#include "gtksymboliccolorprivate.h"
#include "gtktypebuiltins.h"
@ -316,13 +314,15 @@ parse_border_image (GtkCssShorthandProperty *shorthand,
if (_gtk_css_parser_try (parser, "/", TRUE))
{
GValue value = G_VALUE_INIT;
g_value_init (&value, GTK_TYPE_BORDER);
if (!_gtk_css_style_parse_value (&value, parser, base))
values[2] = _gtk_css_border_value_parse (parser,
GTK_CSS_PARSE_PERCENT
| GTK_CSS_PARSE_LENGTH
| GTK_CSS_PARSE_NUMBER
| GTK_CSS_POSITIVE_ONLY,
TRUE,
FALSE);
if (values[2] == NULL)
return FALSE;
values[2] = _gtk_css_value_new_from_gvalue (&value);
g_value_unset (&value);
}
}
else

View File

@ -729,20 +729,13 @@ border_image_width_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
GValue value = G_VALUE_INIT;
GtkCssValue *result;
g_value_init (&value, GTK_TYPE_BORDER);
if (!_gtk_css_style_parse_value (&value, parser, base))
{
g_value_unset (&value);
return NULL;
}
result = _gtk_css_value_new_from_gvalue (&value);
g_value_unset (&value);
return result;
return _gtk_css_border_value_parse (parser,
GTK_CSS_PARSE_PERCENT
| GTK_CSS_PARSE_LENGTH
| GTK_CSS_PARSE_NUMBER
| GTK_CSS_POSITIVE_ONLY,
TRUE,
FALSE);
}
static GtkCssValue *
@ -1543,11 +1536,14 @@ _gtk_css_style_property_init_properties (void)
0,
border_image_width_parse,
NULL,
compute_border,
query_border,
assign_border,
NULL,
query_simple,
assign_simple,
NULL,
_gtk_css_value_new_from_boxed (GTK_TYPE_BORDER, NULL));
_gtk_css_border_value_new (_gtk_css_number_value_new (1, GTK_CSS_NUMBER),
_gtk_css_number_value_new (1, GTK_CSS_NUMBER),
_gtk_css_number_value_new (1, GTK_CSS_NUMBER),
_gtk_css_number_value_new (1, GTK_CSS_NUMBER)));
gtk_css_style_property_register ("transition-property",
GTK_CSS_PROPERTY_TRANSITION_PROPERTY,