shadow: Make this a GtkCssValue

This commit is contained in:
Benjamin Otte 2012-03-28 01:56:57 +02:00
parent 38ac68790e
commit ccd443796c
7 changed files with 86 additions and 148 deletions

View File

@ -428,7 +428,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
guint i;
if (_gtk_css_parser_try (parser, "none", TRUE))
return _gtk_css_value_new_take_shadow (NULL);
return _gtk_shadow_new_none ();
shadow = _gtk_shadow_new ();
@ -453,7 +453,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
if (!_gtk_css_parser_try_double (parser, &voffset))
{
_gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
_gtk_shadow_unref (shadow);
_gtk_css_value_unref (shadow);
return NULL;
}
@ -477,7 +477,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
if (color == NULL)
{
_gtk_shadow_unref (shadow);
_gtk_css_value_unref (shadow);
return NULL;
}
}
@ -486,7 +486,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
if (!have_color || !have_lengths)
{
_gtk_css_parser_error (parser, "Must specify at least color and offsets");
_gtk_shadow_unref (shadow);
_gtk_css_value_unref (shadow);
return NULL;
}
@ -500,22 +500,7 @@ shadow_value_parse (GtkCssStyleProperty *property,
}
while (_gtk_css_parser_try (parser, ",", TRUE));
return _gtk_css_value_new_take_shadow (shadow);
}
static void
shadow_value_print (GtkCssStyleProperty *property,
const GtkCssValue *value,
GString *string)
{
GtkShadow *shadow;
shadow = _gtk_css_value_get_shadow (value);
if (shadow == NULL)
g_string_append (string, "none");
else
_gtk_shadow_print (shadow, string);
return shadow;
}
static GtkCssValue *
@ -523,13 +508,7 @@ shadow_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
GtkShadow *shadow;
shadow = _gtk_css_value_get_shadow (specified);
if (shadow)
shadow = _gtk_shadow_resolve (shadow, context);
return _gtk_css_value_new_take_shadow (shadow);
return _gtk_shadow_resolve (specified, context);
}
static GtkCssValue *
@ -1310,31 +1289,31 @@ _gtk_css_style_property_init_properties (void)
G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT,
shadow_value_parse,
shadow_value_print,
NULL,
shadow_value_compute,
NULL,
NULL,
_gtk_css_value_new_take_shadow (NULL));
_gtk_shadow_new_none ());
gtk_css_style_property_register ("icon-shadow",
G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT,
shadow_value_parse,
shadow_value_print,
NULL,
shadow_value_compute,
NULL,
NULL,
_gtk_css_value_new_take_shadow (NULL));
_gtk_shadow_new_none ());
gtk_css_style_property_register ("box-shadow",
G_TYPE_NONE,
0,
shadow_value_parse,
shadow_value_print,
NULL,
shadow_value_compute,
NULL,
NULL,
_gtk_css_value_new_take_shadow (NULL));
_gtk_shadow_new_none ());
gtk_css_style_property_register ("margin-top",
G_TYPE_INT,

View File

@ -269,17 +269,6 @@ _gtk_css_value_new_take_pattern (cairo_pattern_t *v)
return value;
}
GtkCssValue *
_gtk_css_value_new_take_shadow (GtkShadow *v)
{
GtkCssValue *value;
value = gtk_css_value_new (GTK_TYPE_SHADOW);
value->u.ptr = v;
return value;
}
GtkCssValue *
_gtk_css_value_new_take_image (GtkCssImage *v)
{
@ -664,9 +653,3 @@ _gtk_css_value_get_gradient (const GtkCssValue *value)
return value->u.ptr;
}
GtkShadow *
_gtk_css_value_get_shadow (const GtkCssValue *value)
{
g_return_val_if_fail (_gtk_css_value_holds (value, GTK_TYPE_SHADOW), NULL);
return value->u.ptr;
}

View File

@ -24,7 +24,7 @@
#include "gtkcsstypesprivate.h"
#include "gtksymboliccolor.h"
#include "gtkcssimageprivate.h"
#include "gtkshadowprivate.h"
#include "gtkthemingengine.h"
G_BEGIN_DECLS
@ -85,7 +85,6 @@ GtkCssValue *_gtk_css_value_new_from_rgba (const GdkRGBA
GtkCssValue *_gtk_css_value_new_from_color (const GdkColor *v);
GtkCssValue *_gtk_css_value_new_take_symbolic_color (GtkSymbolicColor *v);
GtkCssValue *_gtk_css_value_new_take_pattern (cairo_pattern_t *v);
GtkCssValue *_gtk_css_value_new_take_shadow (GtkShadow *v);
GtkCssValue *_gtk_css_value_new_take_image (GtkCssImage *v);
GtkCssValue *_gtk_css_value_new_from_theming_engine (GtkThemingEngine *v);
GtkCssValue *_gtk_css_value_new_take_binding_sets (GPtrArray *array);
@ -118,7 +117,6 @@ PangoWeight _gtk_css_value_get_pango_weight (const
const GdkRGBA *_gtk_css_value_get_rgba (const GtkCssValue *value);
cairo_pattern_t *_gtk_css_value_get_pattern (const GtkCssValue *value);
GtkGradient *_gtk_css_value_get_gradient (const GtkCssValue *value);
GtkShadow *_gtk_css_value_get_shadow (const GtkCssValue *value);
G_END_DECLS

View File

@ -108,49 +108,74 @@ shadow_element_new (gdouble hoffset,
* GtkShadow *
****************/
G_DEFINE_BOXED_TYPE (GtkShadow, _gtk_shadow,
_gtk_shadow_ref, _gtk_shadow_unref)
struct _GtkShadow {
struct _GtkCssValue {
GTK_CSS_VALUE_BASE
GList *elements;
guint ref_count;
gboolean resolved;
};
static void
gtk_css_value_shadow_free (GtkCssValue *shadow)
{
g_list_free_full (shadow->elements,
(GDestroyNotify) shadow_element_free);
g_slice_free (GtkShadow, shadow);
}
static gboolean
gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
const GtkCssValue *shadow2)
{
/* FIXME */
return shadow1 == shadow2;
}
static void
gtk_css_value_shadow_print (const GtkCssValue *shadow,
GString *string)
{
gint length;
GList *l;
length = g_list_length (shadow->elements);
if (length == 0)
{
g_string_append (string, "none");
return;
}
shadow_element_print (shadow->elements->data, string);
if (length == 1)
return;
for (l = g_list_next (shadow->elements); l != NULL; l = l->next)
{
g_string_append (string, ", ");
shadow_element_print (l->data, string);
}
}
static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
gtk_css_value_shadow_free,
gtk_css_value_shadow_equal,
gtk_css_value_shadow_print
};
static GtkCssValue none_singleton = { &GTK_CSS_VALUE_SHADOW, 1, NULL, FALSE };
GtkShadow *
_gtk_shadow_new (void)
{
GtkShadow *retval;
retval = g_slice_new0 (GtkShadow);
retval->ref_count = 1;
return retval;
return _gtk_css_value_new (GtkShadow, &GTK_CSS_VALUE_SHADOW);
}
GtkShadow *
_gtk_shadow_ref (GtkShadow *shadow)
_gtk_shadow_new_none (void)
{
g_return_val_if_fail (shadow != NULL, NULL);
shadow->ref_count++;
return shadow;
}
void
_gtk_shadow_unref (GtkShadow *shadow)
{
g_return_if_fail (shadow != NULL);
shadow->ref_count--;
if (shadow->ref_count == 0)
{
g_list_free_full (shadow->elements,
(GDestroyNotify) shadow_element_free);
g_slice_free (GtkShadow, shadow);
}
return _gtk_css_value_ref (&none_singleton);
}
void
@ -193,7 +218,7 @@ _gtk_shadow_resolve (GtkShadow *shadow,
element->symbolic_color,
&color))
{
_gtk_shadow_unref (resolved_shadow);
_gtk_css_value_unref (resolved_shadow);
return NULL;
}
@ -206,33 +231,11 @@ _gtk_shadow_resolve (GtkShadow *shadow,
g_list_append (resolved_shadow->elements, resolved_element);
}
resolved_shadow->resolved = TRUE;
return resolved_shadow;
}
void
_gtk_shadow_print (GtkShadow *shadow,
GString *str)
{
gint length;
GList *l;
length = g_list_length (shadow->elements);
if (length == 0)
return;
shadow_element_print (shadow->elements->data, str);
if (length == 1)
return;
for (l = g_list_next (shadow->elements); l != NULL; l = l->next)
{
g_string_append (str, ", ");
shadow_element_print (l->data, str);
}
}
void
_gtk_text_shadow_paint_layout (GtkShadow *shadow,
cairo_t *cr,

View File

@ -26,19 +26,15 @@
#include "gtksymboliccolor.h"
#include "gtkicontheme.h"
#include "gtkcsstypesprivate.h"
#include "gtkcssvalueprivate.h"
#include "gtkroundedboxprivate.h"
G_BEGIN_DECLS
typedef struct _GtkShadow GtkShadow;
#define GTK_TYPE_SHADOW (_gtk_shadow_get_type ())
GType _gtk_shadow_get_type (void) G_GNUC_CONST;
typedef GtkCssValue GtkShadow;
GtkShadow *_gtk_shadow_new (void);
GtkShadow *_gtk_shadow_ref (GtkShadow *shadow);
void _gtk_shadow_unref (GtkShadow *shadow);
GtkShadow *_gtk_shadow_new_none (void);
void _gtk_shadow_append (GtkShadow *shadow,
gdouble hoffset,
@ -48,9 +44,6 @@ void _gtk_shadow_append (GtkShadow *shadow,
gboolean inset,
GtkSymbolicColor *color);
void _gtk_shadow_print (GtkShadow *shadow,
GString *string);
GtkShadow *_gtk_shadow_resolve (GtkShadow *shadow,
GtkStyleContext *context);

View File

@ -301,14 +301,9 @@ static void
_gtk_theming_background_apply_shadow (GtkThemingBackground *bg,
cairo_t *cr)
{
GtkShadow *box_shadow;
box_shadow = _gtk_css_value_get_shadow (_gtk_style_context_peek_property (bg->context, "box-shadow"));
if (box_shadow != NULL)
{
_gtk_box_shadow_render (box_shadow, cr, &bg->padding_box);
}
_gtk_box_shadow_render (_gtk_style_context_peek_property (bg->context, "box-shadow"),
cr,
&bg->padding_box);
}
static void

View File

@ -2132,14 +2132,11 @@ gtk_theming_engine_render_layout (GtkThemingEngine *engine,
fg_color.alpha = CLAMP (fg_color.alpha + ((other_fg.alpha - fg_color.alpha) * progress), 0, 1);
}
text_shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "text-shadow"));
text_shadow = _gtk_theming_engine_peek_property (engine, "text-shadow");
prepare_context_for_layout (cr, x, y, layout);
if (text_shadow != NULL)
{
_gtk_text_shadow_paint_layout (text_shadow, cr, layout);
}
_gtk_text_shadow_paint_layout (text_shadow, cr, layout);
gdk_cairo_set_source_rgba (cr, &fg_color);
pango_cairo_show_layout (cr, layout);
@ -2766,17 +2763,14 @@ render_spinner (GtkThemingEngine *engine,
radius = MIN (width / 2, height / 2);
gtk_theming_engine_get_color (engine, state, &color);
shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "icon-shadow"));
shadow = _gtk_theming_engine_peek_property (engine, "icon-shadow");
cairo_save (cr);
cairo_translate (cr, x + width / 2, y + height / 2);
if (shadow != NULL)
{
_gtk_icon_shadow_paint_spinner (shadow, cr,
radius,
progress);
}
_gtk_icon_shadow_paint_spinner (shadow, cr,
radius,
progress);
_gtk_theming_engine_paint_spinner (cr,
radius,
@ -2943,18 +2937,11 @@ gtk_theming_engine_render_icon (GtkThemingEngine *engine,
gdouble x,
gdouble y)
{
GtkShadow *icon_shadow;
cairo_save (cr);
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
icon_shadow = _gtk_css_value_get_shadow (_gtk_theming_engine_peek_property (engine, "icon-shadow"));
if (icon_shadow != NULL)
{
_gtk_icon_shadow_paint (icon_shadow, cr);
}
_gtk_icon_shadow_paint (_gtk_theming_engine_peek_property (engine, "icon-shadow"), cr);
cairo_paint (cr);