diff --git a/ChangeLog b/ChangeLog index 9f58fe40b..301178dbd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-11-17 Emmanuele Bassi + + * clutter/clutter-entry.c: + * clutter/clutter-label.c: + * clutter/clutter-rectangle.c: + * clutter/clutter-script.c: + * clutter/clutter-stage.c: Use the ParamSpecColor and GValue + API for ClutterColor-based properties. + 2008-11-14 Robert Bragg * tests/interactive/Makefile.am diff --git a/clutter/clutter-entry.c b/clutter/clutter-entry.c index 9160a11fc..b4fa377fa 100644 --- a/clutter/clutter-entry.c +++ b/clutter/clutter-entry.c @@ -61,6 +61,8 @@ G_DEFINE_TYPE (ClutterEntry, clutter_entry, CLUTTER_TYPE_ACTOR); /* Probably move into main */ static PangoContext *_context = NULL; +static const ClutterColor default_text_color = { 0, 0, 0, 255 }; + enum { PROP_0, @@ -170,7 +172,7 @@ clutter_entry_set_property (GObject *object, clutter_entry_set_text (entry, g_value_get_string (value)); break; case PROP_COLOR: - clutter_entry_set_color (entry, g_value_get_boxed (value)); + clutter_entry_set_color (entry, clutter_value_get_color (value)); break; case PROP_ALIGNMENT: clutter_entry_set_alignment (entry, g_value_get_enum (value)); @@ -208,7 +210,6 @@ clutter_entry_get_property (GObject *object, { ClutterEntry *entry; ClutterEntryPrivate *priv; - ClutterColor color; entry = CLUTTER_ENTRY(object); priv = entry->priv; @@ -222,8 +223,7 @@ clutter_entry_get_property (GObject *object, g_value_set_string (value, priv->text); break; case PROP_COLOR: - clutter_entry_get_color (entry, &color); - g_value_set_boxed (value, &color); + clutter_value_set_color (value, &priv->fgcol); break; case PROP_ALIGNMENT: g_value_set_enum (value, priv->alignment); @@ -671,6 +671,7 @@ clutter_entry_class_init (ClutterEntryClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); + GParamSpec *pspec; klass->paint_cursor = clutter_entry_paint_cursor; @@ -719,13 +720,12 @@ clutter_entry_class_init (ClutterEntryClass *klass) * * Since: 0.4 */ - g_object_class_install_property - (gobject_class, PROP_COLOR, - g_param_spec_boxed ("color", - "Font Colour", - "Font Colour", - CLUTTER_TYPE_COLOR, - CLUTTER_PARAM_READWRITE)); + pspec = clutter_param_spec_color ("color", + "Color", + "The color of the text", + &default_text_color, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_COLOR, pspec); /** * ClutterEntry:alignment: * @@ -923,10 +923,7 @@ clutter_entry_init (ClutterEntry *self) priv->entry_padding = ENTRY_PADDING; priv->x_align = 0.0; - priv->fgcol.red = 0; - priv->fgcol.green = 0; - priv->fgcol.blue = 0; - priv->fgcol.alpha = 255; + priv->fgcol = default_text_color; priv->font_name = g_strdup (DEFAULT_FONT_NAME); priv->desc = pango_font_description_from_string (priv->font_name); diff --git a/clutter/clutter-label.c b/clutter/clutter-label.c index f7ac993b4..3a7cd409c 100644 --- a/clutter/clutter-label.c +++ b/clutter/clutter-label.c @@ -50,6 +50,8 @@ G_DEFINE_TYPE (ClutterLabel, clutter_label, CLUTTER_TYPE_ACTOR) /* Probably move into main */ static PangoContext *_context = NULL; +static const ClutterColor default_text_color = { 0, 0, 0, 255 }; + enum { PROP_0, @@ -98,6 +100,12 @@ struct _ClutterLabelPrivate gchar *text; gchar *font_name; + + PangoAttrList *attrs; + PangoAttrList *effective_attrs; + + ClutterLabelCachedLayout cached_layouts[CLUTTER_LABEL_N_CACHED_LAYOUTS]; + guint cache_age; guint alignment : 2; guint wrap : 1; @@ -107,12 +115,6 @@ struct _ClutterLabelPrivate guint single_line_mode : 1; guint wrap_mode : 3; guint justify : 1; - - PangoAttrList *attrs; - PangoAttrList *effective_attrs; - - ClutterLabelCachedLayout cached_layouts[CLUTTER_LABEL_N_CACHED_LAYOUTS]; - guint cache_age; }; /* @@ -441,7 +443,7 @@ clutter_label_set_property (GObject *object, clutter_label_set_text (label, g_value_get_string (value)); break; case PROP_COLOR: - clutter_label_set_color (label, g_value_get_boxed (value)); + clutter_label_set_color (label, clutter_value_get_color (value)); break; case PROP_ATTRIBUTES: clutter_label_set_attributes (label, g_value_get_boxed (value)); @@ -478,7 +480,6 @@ clutter_label_get_property (GObject *object, { ClutterLabel *label; ClutterLabelPrivate *priv; - ClutterColor color; label = CLUTTER_LABEL (object); priv = label->priv; @@ -492,8 +493,7 @@ clutter_label_get_property (GObject *object, g_value_set_string (value, priv->text); break; case PROP_COLOR: - clutter_label_get_color (label, &color); - g_value_set_boxed (value, &color); + clutter_value_set_color (value, &priv->fgcol); break; case PROP_ATTRIBUTES: g_value_set_boxed (value, priv->attrs); @@ -527,6 +527,7 @@ clutter_label_class_init (ClutterLabelClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); + GParamSpec *pspec; actor_class->paint = clutter_label_paint; actor_class->get_preferred_width = clutter_label_get_preferred_width; @@ -538,76 +539,119 @@ clutter_label_class_init (ClutterLabelClass *klass) gobject_class->set_property = clutter_label_set_property; gobject_class->get_property = clutter_label_get_property; - g_object_class_install_property - (gobject_class, PROP_FONT_NAME, - g_param_spec_string ("font-name", - "Font Name", - "Pango font description", - NULL, - CLUTTER_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_TEXT, - g_param_spec_string ("text", - "Text", - "Text to render", - NULL, - CLUTTER_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_COLOR, - g_param_spec_boxed ("color", - "Font Colour", - "Font Colour", - CLUTTER_TYPE_COLOR, - CLUTTER_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_ATTRIBUTES, - g_param_spec_boxed ("attributes", - "Attributes", - "A list of style attributes to apply to the " - "text of the label", - PANGO_TYPE_ATTR_LIST, - CLUTTER_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_USE_MARKUP, - g_param_spec_boolean ("use-markup", - "Use markup", - "The text of the label includes XML markup. " - "See pango_parse_markup()", - FALSE, - CLUTTER_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_WRAP, - g_param_spec_boolean ("wrap", - "Line wrap", - "If set, wrap lines if the text becomes too wide", - FALSE, - CLUTTER_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_WRAP_MODE, - g_param_spec_enum ("wrap-mode", - "Line wrap mode", - "If wrap is set, controls how line-wrapping is done", - PANGO_TYPE_WRAP_MODE, - PANGO_WRAP_WORD, - CLUTTER_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_ELLIPSIZE, - g_param_spec_enum ( "ellipsize", - "Ellipsize", - "The preferred place to ellipsize the string, " - "if the label does not have enough room to " - "display the entire string", - PANGO_TYPE_ELLIPSIZE_MODE, - PANGO_ELLIPSIZE_NONE, - CLUTTER_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, PROP_ALIGNMENT, - g_param_spec_enum ( "alignment", - "Alignment", - "The preferred alignment for the string", - PANGO_TYPE_ALIGNMENT, - PANGO_ALIGN_LEFT, - CLUTTER_PARAM_READWRITE)); + /** + * ClutterLabel:font-name: + * + * The font to be used by the #ClutterLabel, as a string + * that can be parsed by pango_font_description_from_string(). + * + * Since: 0.2 + */ + pspec = g_param_spec_string ("font-name", + "Font Name", + "The font to be used by the label", + NULL, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_FONT_NAME, pspec); + + pspec = g_param_spec_string ("text", + "Text", + "The text to render", + NULL, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_TEXT, pspec); + + pspec = clutter_param_spec_color ("color", + "Font Color", + "Color of the font used by the label", + &default_text_color, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_COLOR, pspec); + + pspec = g_param_spec_boxed ("attributes", + "Attributes", + "A list of style attributes to apply to " + "the text of the label", + PANGO_TYPE_ATTR_LIST, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_ATTRIBUTES, pspec); + + /** + * ClutterLabel:use-markup: + * + * Whether the text of the label includes Pango markup. See + * pango_layout_set_markup() in the Pango documentation. + * + * Since: 0.2 + */ + pspec = g_param_spec_boolean ("use-markup", + "Use markup", + "Whether or not the text of the label " + "includes Pango markup", + FALSE, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_USE_MARKUP, pspec); + + /** + * ClutterLabel:wrap: + * + * Whether to wrap the lines of #ClutterLabel:text if the contents + * exceed the available allocation. The wrapping strategy is + * controlled by the #ClutterLabel:wrap-mode property. + * + * Since: 0.2 + */ + pspec = g_param_spec_boolean ("wrap", + "Line wrap", + "If set, wrap the lines if the text " + "becomes too wide", + FALSE, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_WRAP, pspec); + + /** + * ClutterLabel:wrap-mode: + * + * If #ClutterLabel:wrap is set to %TRUE, this property will + * control how the text is wrapped. + * + * Since: 0.2 + */ + pspec = g_param_spec_enum ("wrap-mode", + "Line wrap mode", + "Control how line-wrapping is done", + PANGO_TYPE_WRAP_MODE, + PANGO_WRAP_WORD, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_WRAP_MODE, pspec); + + pspec = g_param_spec_enum ("ellipsize", + "Ellipsize", + "The preferred place to ellipsize the string, " + "if the label does not have enough room to " + "display the entire string", + PANGO_TYPE_ELLIPSIZE_MODE, + PANGO_ELLIPSIZE_NONE, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_ELLIPSIZE, pspec); + + /** + * ClutterLabel:alignment: + * + * The preferred alignment for the text. This property controls + * the alignment of multi-line paragraphs. + * + * Since: 0.2 + */ + pspec = g_param_spec_enum ("alignment", + "Alignment", + "The preferred alignment for the string, " + "for multi-line text", + PANGO_TYPE_ALIGNMENT, + PANGO_ALIGN_LEFT, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_ALIGNMENT, pspec); + /** * ClutterLabel:justify: * @@ -616,13 +660,13 @@ clutter_label_class_init (ClutterLabelClass *klass) * * Since: 0.6 */ - g_object_class_install_property (gobject_class, - PROP_JUSTIFY, - g_param_spec_boolean ("justify", - "Justify", - "Whether the contents of the label should be justified", - FALSE, - CLUTTER_PARAM_READWRITE)); + pspec = g_param_spec_boolean ("justify", + "Justify", + "Whether the contents of the label " + "should be justified", + FALSE, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_JUSTIFY, pspec); g_type_class_add_private (gobject_class, sizeof (ClutterLabelPrivate)); } @@ -652,10 +696,7 @@ clutter_label_init (ClutterLabel *self) priv->text = NULL; priv->attrs = NULL; - priv->fgcol.red = 0; - priv->fgcol.green = 0; - priv->fgcol.blue = 0; - priv->fgcol.alpha = 255; + priv->fgcol = default_text_color; priv->font_name = g_strdup (DEFAULT_FONT_NAME); priv->font_desc = pango_font_description_from_string (priv->font_name); diff --git a/clutter/clutter-rectangle.c b/clutter/clutter-rectangle.c index f50b886ce..6bcf92921 100644 --- a/clutter/clutter-rectangle.c +++ b/clutter/clutter-rectangle.c @@ -33,10 +33,11 @@ #include "config.h" #endif -#include "clutter-rectangle.h" +#include "clutter-color.h" +#include "clutter-debug.h" #include "clutter-main.h" #include "clutter-private.h" -#include "clutter-debug.h" +#include "clutter-rectangle.h" #include "cogl/cogl.h" @@ -67,6 +68,9 @@ struct _ClutterRectanglePrivate guint has_border : 1; }; +static const ClutterColor default_color = { 255, 255, 255, 255 }; +static const ClutterColor default_border_color = { 0, 0, 0, 255 }; + static void clutter_rectangle_paint (ClutterActor *self) { @@ -163,11 +167,11 @@ clutter_rectangle_set_property (GObject *object, switch (prop_id) { case PROP_COLOR: - clutter_rectangle_set_color (rectangle, g_value_get_boxed (value)); + clutter_rectangle_set_color (rectangle, clutter_value_get_color (value)); break; case PROP_BORDER_COLOR: clutter_rectangle_set_border_color (rectangle, - g_value_get_boxed (value)); + clutter_value_get_color (value)); break; case PROP_BORDER_WIDTH: clutter_rectangle_set_border_width (rectangle, @@ -188,24 +192,21 @@ clutter_rectangle_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - ClutterRectangle *rectangle = CLUTTER_RECTANGLE(object); - ClutterColor color; + ClutterRectanglePrivate *priv = CLUTTER_RECTANGLE(object)->priv; switch (prop_id) { case PROP_COLOR: - clutter_rectangle_get_color (rectangle, &color); - g_value_set_boxed (value, &color); + clutter_value_set_color (value, &priv->color); break; case PROP_BORDER_COLOR: - clutter_rectangle_get_border_color (rectangle, &color); - g_value_set_boxed (value, &color); + clutter_value_set_color (value, &priv->border_color); break; case PROP_BORDER_WIDTH: - g_value_set_uint (value, rectangle->priv->border_width); + g_value_set_uint (value, priv->border_width); break; case PROP_HAS_BORDER: - g_value_set_boolean (value, rectangle->priv->has_border); + g_value_set_boolean (value, priv->has_border); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -230,8 +231,9 @@ clutter_rectangle_dispose (GObject *object) static void clutter_rectangle_class_init (ClutterRectangleClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); + GParamSpec *pspec; actor_class->paint = clutter_rectangle_paint; @@ -245,13 +247,13 @@ clutter_rectangle_class_init (ClutterRectangleClass *klass) * * The color of the rectangle. */ - g_object_class_install_property (gobject_class, - PROP_COLOR, - g_param_spec_boxed ("color", - "Color", - "The color of the rectangle", - CLUTTER_TYPE_COLOR, - CLUTTER_PARAM_READWRITE)); + pspec = clutter_param_spec_color ("color", + "Color", + "The color of the rectangle", + &default_color, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_COLOR, pspec); + /** * ClutterRectangle:border-color: * @@ -259,13 +261,13 @@ clutter_rectangle_class_init (ClutterRectangleClass *klass) * * Since: 0.2 */ - g_object_class_install_property (gobject_class, - PROP_BORDER_COLOR, - g_param_spec_boxed ("border-color", - "Border Color", - "The color of the border of the rectangle", - CLUTTER_TYPE_COLOR, - CLUTTER_PARAM_READWRITE)); + pspec = clutter_param_spec_color ("border-color", + "Border Color", + "The color of the border of the rectangle", + &default_border_color, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_BORDER_COLOR, pspec); + /** * ClutterRectangle:border-width: * @@ -306,15 +308,8 @@ clutter_rectangle_init (ClutterRectangle *self) self->priv = priv = CLUTTER_RECTANGLE_GET_PRIVATE (self); - priv->color.red = 0xff; - priv->color.green = 0xff; - priv->color.blue = 0xff; - priv->color.alpha = 0xff; - - priv->border_color.red = 0x00; - priv->border_color.green = 0x00; - priv->border_color.blue = 0x00; - priv->border_color.alpha = 0xff; + priv->color = default_color; + priv->border_color = default_border_color; priv->border_width = 0; diff --git a/clutter/clutter-script.c b/clutter/clutter-script.c index 62028f532..35915c6f1 100644 --- a/clutter/clutter-script.c +++ b/clutter/clutter-script.c @@ -882,7 +882,7 @@ clutter_script_parse_node (ClutterScript *script, return TRUE; } } - else if (G_VALUE_HOLDS (value, CLUTTER_TYPE_COLOR)) + else if (CLUTTER_VALUE_HOLDS_COLOR (value)) { ClutterColor color = { 0, }; @@ -934,7 +934,7 @@ clutter_script_parse_node (ClutterScript *script, return TRUE; } } - else if (G_VALUE_HOLDS (value, CLUTTER_TYPE_COLOR)) + else if (CLUTTER_VALUE_HOLDS_COLOR (value)) { ClutterColor color = { 0, }; diff --git a/clutter/clutter-stage.c b/clutter/clutter-stage.c index 6249c8a76..665d637e6 100644 --- a/clutter/clutter-stage.c +++ b/clutter/clutter-stage.c @@ -120,6 +120,8 @@ enum static guint stage_signals[LAST_SIGNAL] = { 0, }; +static const ClutterColor default_stage_color = { 255, 255, 255, 255 }; + static void clutter_stage_get_preferred_width (ClutterActor *self, ClutterUnit for_height, @@ -354,7 +356,7 @@ clutter_stage_set_property (GObject *object, switch (prop_id) { case PROP_COLOR: - clutter_stage_set_color (stage, g_value_get_boxed (value)); + clutter_stage_set_color (stage, clutter_value_get_color (value)); break; case PROP_OFFSCREEN: if (priv->is_offscreen == g_value_get_boolean (value)) @@ -414,7 +416,6 @@ clutter_stage_get_property (GObject *object, { ClutterStage *stage; ClutterStagePrivate *priv; - ClutterColor color; ClutterPerspective perspective; stage = CLUTTER_STAGE(object); @@ -423,8 +424,7 @@ clutter_stage_get_property (GObject *object, switch (prop_id) { case PROP_COLOR: - clutter_stage_get_color (stage, &color); - g_value_set_boxed (value, &color); + clutter_value_set_color (value, &priv->color); break; case PROP_OFFSCREEN: g_value_set_boolean (value, priv->is_offscreen); @@ -497,6 +497,7 @@ clutter_stage_class_init (ClutterStageClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); + GParamSpec *pspec; gobject_class->set_property = clutter_stage_set_property; gobject_class->get_property = clutter_stage_get_property; @@ -569,13 +570,12 @@ clutter_stage_class_init (ClutterStageClass *klass) * * The color of the main stage. */ - g_object_class_install_property - (gobject_class, PROP_COLOR, - g_param_spec_boxed ("color", - "Color", - "The color of the main stage", - CLUTTER_TYPE_COLOR, - CLUTTER_PARAM_READWRITE)); + pspec = clutter_param_spec_color ("color", + "Color", + "The color of the stage", + &default_stage_color, + CLUTTER_PARAM_READWRITE); + g_object_class_install_property (gobject_class, PROP_COLOR, pspec); /** * ClutterStage:perspective: @@ -729,10 +729,7 @@ clutter_stage_init (ClutterStage *self) priv->is_cursor_visible = TRUE; priv->use_fog = FALSE; - priv->color.red = 0xff; - priv->color.green = 0xff; - priv->color.blue = 0xff; - priv->color.alpha = 0xff; + priv->color = default_stage_color; priv->perspective.fovy = COGL_FIXED_60; /* 60 Degrees */ priv->perspective.aspect = COGL_FIXED_1;