[clutter/wip/apocalypses/apocalypse-1: 29/43] actor: Background color



commit 22814d1d3382f259f7b1a41ae3b9fc23efef440a
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Dec 5 08:41:51 2011 +0000

    actor: Background color
    
    Each actor should have a background color property, disabled by default.
    
    This property allows us to cover 99% of the use cases for
    ClutterRectangle, and brings us one step closer to being able to
    instantiate ClutterActor directly.

 clutter/clutter-actor.c |  137 ++++++++++++++++++++++++++++++++++++++++++++++-
 clutter/clutter-actor.h |    5 ++
 2 files changed, 141 insertions(+), 1 deletions(-)
---
diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c
index 5708f7a..d4c6951 100644
--- a/clutter/clutter-actor.c
+++ b/clutter/clutter-actor.c
@@ -306,6 +306,8 @@
 #include "clutter-actor-meta-private.h"
 #include "clutter-animatable.h"
 #include "clutter-behaviour.h"
+#include "clutter-color-static.h"
+#include "clutter-color.h"
 #include "clutter-constraint.h"
 #include "clutter-container.h"
 #include "clutter-debug.h"
@@ -481,6 +483,8 @@ struct _ClutterActorPrivate
 
   ClutterStageQueueRedrawEntry *queue_redraw_entry;
 
+  ClutterColor bg_color;
+
   /* bitfields */
 
   /* fixed position and sizes */
@@ -517,6 +521,7 @@ struct _ClutterActorPrivate
   guint y_expand_set                : 1;
   guint y_expand_effective          : 1;
   guint needs_compute_expand        : 1;
+  guint bg_color_set                : 1;
 };
 
 enum
@@ -616,6 +621,9 @@ enum
   PROP_MARGIN_LEFT,
   PROP_MARGIN_RIGHT,
 
+  PROP_BACKGROUND_COLOR,
+  PROP_BACKGROUND_COLOR_SET,
+
   PROP_LAST
 };
 
@@ -3145,7 +3153,26 @@ clutter_actor_continue_paint (ClutterActor *self)
   if (priv->next_effect_to_paint == NULL)
     {
       if (_clutter_context_get_pick_mode () == CLUTTER_PICK_NONE)
-        g_signal_emit (self, actor_signals[PAINT], 0);
+        {
+          /* paint the background color, if set */
+          if (priv->bg_color_set)
+            {
+              float width, height;
+
+              clutter_actor_box_get_size (&priv->allocation,
+                                          &width,
+                                          &height);
+
+              cogl_set_source_color4ub (priv->bg_color.red,
+                                        priv->bg_color.green,
+                                        priv->bg_color.blue,
+                                        priv->bg_color.alpha);
+
+              cogl_rectangle (0, 0, width, height);
+            }
+
+          g_signal_emit (self, actor_signals[PAINT], 0);
+        }
       else
         {
           ClutterColor col = { 0, };
@@ -3559,6 +3586,10 @@ clutter_actor_set_property (GObject      *object,
       clutter_actor_set_margin_right (actor, g_value_get_float (value));
       break;
 
+    case PROP_BACKGROUND_COLOR:
+      clutter_actor_set_background_color (actor, g_value_get_boxed (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -3930,6 +3961,14 @@ clutter_actor_get_property (GObject    *object,
       }
       break;
 
+    case PROP_BACKGROUND_COLOR_SET:
+      g_value_set_boolean (value, priv->bg_color_set);
+      break;
+
+    case PROP_BACKGROUND_COLOR:
+      g_value_set_boxed (value, &priv->bg_color);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -5068,6 +5107,35 @@ clutter_actor_class_init (ClutterActorClass *klass)
                         0.0,
                         CLUTTER_PARAM_READWRITE);
 
+  /**
+   * ClutterActor:background-color-set:
+   *
+   * Whether the #ClutterActor:background-color property has been set.
+   *
+   * Since: 1.10
+   */
+  obj_props[PROP_BACKGROUND_COLOR_SET] =
+    g_param_spec_boolean ("background-color-set",
+                          P_("Background Color Set"),
+                          P_("Whether the background color is set"),
+                          FALSE,
+                          CLUTTER_PARAM_READABLE);
+
+  /**
+   * ClutterActor:background-color:
+   *
+   * Paints a solid fill of the actor's allocation using the specified
+   * color.
+   *
+   * Since: 1.10
+   */
+  obj_props[PROP_BACKGROUND_COLOR] =
+    clutter_param_spec_color ("background-color",
+                              P_("Background color"),
+                              P_("The actor's background color"),
+                              CLUTTER_COLOR_Transparent,
+                              CLUTTER_PARAM_READWRITE);
+
   g_object_class_install_properties (object_class, PROP_LAST, obj_props);
 
   /**
@@ -14786,3 +14854,70 @@ clutter_actor_get_margin_right (ClutterActor *self)
 
   return _clutter_actor_get_layout_info_or_defaults (self)->margin.right;
 }
+
+/**
+ * clutter_actor_set_background_color:
+ * @self: a #ClutterActor
+ * @color: (allow-none): a #ClutterColor, or %NULL to unset a previously
+ *  set color
+ *
+ * Sets the background color of a #ClutterActor.
+ *
+ * The background color will be used to cover the whole allocation of the
+ * actor. The default background color of an actor is transparent.
+ *
+ * To check whether an actor has a background color, you can use the
+ * #ClutterActor:background-color-set actor property.
+ *
+ * Since: 1.10
+ */
+void
+clutter_actor_set_background_color (ClutterActor       *self,
+                                    const ClutterColor *color)
+{
+  ClutterActorPrivate *priv;
+
+  g_return_if_fail (CLUTTER_IS_ACTOR (self));
+
+  priv = self->priv;
+
+  if (color == NULL)
+    {
+      priv->bg_color_set = FALSE;
+      g_object_notify_by_pspec (G_OBJECT (self),
+                                obj_props[PROP_BACKGROUND_COLOR_SET]);
+      return;
+    }
+
+  if (priv->bg_color_set && clutter_color_equal (color, &priv->bg_color))
+    return;
+
+  priv->bg_color = *color;
+  priv->bg_color_set = TRUE;
+
+  clutter_actor_queue_redraw (self);
+
+  g_object_notify_by_pspec (G_OBJECT (self),
+                            obj_props[PROP_BACKGROUND_COLOR_SET]);
+  g_object_notify_by_pspec (G_OBJECT (self),
+                            obj_props[PROP_BACKGROUND_COLOR]);
+}
+
+/**
+ * clutter_actor_get_background_color:
+ * @self: a #ClutterActor
+ * @color: (out caller-allocates): return location for a #ClutterColor
+ *
+ * Retrieves the color set using clutter_actor_set_background_color().
+ *
+ * Since: 1.10
+ */
+void
+clutter_actor_get_background_color (ClutterActor *self,
+                                    ClutterColor *color)
+{
+  g_return_if_fail (CLUTTER_IS_ACTOR (self));
+  g_return_if_fail (color != NULL);
+
+  *color = self->priv->bg_color;
+}
diff --git a/clutter/clutter-actor.h b/clutter/clutter-actor.h
index d87a8f6..68c5939 100644
--- a/clutter/clutter-actor.h
+++ b/clutter/clutter-actor.h
@@ -576,6 +576,11 @@ gboolean             clutter_actor_get_paint_box      (ClutterActor         *sel
 
 gboolean             clutter_actor_has_overlaps       (ClutterActor         *self);
 
+void                    clutter_actor_set_background_color      (ClutterActor       *self,
+                                                                 const ClutterColor *color);
+void                    clutter_actor_get_background_color      (ClutterActor       *self,
+                                                                 ClutterColor       *color);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_ACTOR_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]