[mutter/wip/gcampax/background: 6/8] background-actor: add input & output box properties



commit f8f57d656ca38380746ca084617fa93b8fb2bf7a
Author: Lionel Landwerlin <llandwerlin gmail com>
Date:   Wed Nov 14 11:12:05 2012 +0000

    background-actor: add input & output box properties
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688309

 src/compositor/meta-background-actor.c |   60 +++++++++++++++++++++++++++-----
 1 files changed, 51 insertions(+), 9 deletions(-)
---
diff --git a/src/compositor/meta-background-actor.c b/src/compositor/meta-background-actor.c
index 5beed50..4e20961 100644
--- a/src/compositor/meta-background-actor.c
+++ b/src/compositor/meta-background-actor.c
@@ -73,6 +73,7 @@ struct _MetaBackgroundActorPrivate
   CoglMaterialWrapMode wrap_mode;
 
   cairo_region_t *visible_region;
+  ClutterActorBox *input_box;
   float dim_factor;
   float crossfade_progress;
   guint is_crossfading : 1;
@@ -88,6 +89,8 @@ enum
   PROP_DIM_FACTOR,
   PROP_CROSSFADE_PROGRESS,
 
+  PROP_INPUT_BOX,
+
   PROP_LAST
 };
 
@@ -336,6 +339,12 @@ meta_background_actor_dispose (GObject *object)
   g_clear_pointer (&priv->crossfade_pipeline, cogl_object_unref);
   g_clear_object (&priv->settings);
 
+  if (priv->input_box)
+    {
+      clutter_actor_box_free (priv->input_box);
+      priv->input_box = NULL;
+    }
+
   G_OBJECT_CLASS (meta_background_actor_parent_class)->dispose (object);
 }
 
@@ -383,13 +392,12 @@ meta_background_actor_paint (ClutterActor *actor)
   MetaBackgroundActorPrivate *priv = self->priv;
   guint8 opacity = clutter_actor_get_paint_opacity (actor);
   guint8 color_component;
-  int width, height;
+  float width, height;
+  ClutterActorBox *input, alloc;
   CoglColor crossfade_color;
 
   meta_background_ensure_rendered (priv->background);
 
-  meta_screen_get_size (priv->screen, &width, &height);
-
   color_component = (int)(0.5 + opacity * priv->dim_factor);
 
   cogl_pipeline_set_color4ub (priv->pipeline,
@@ -411,8 +419,15 @@ meta_background_actor_paint (ClutterActor *actor)
 
   cogl_set_source (priv->pipeline);
 
+  clutter_actor_get_allocation_box (actor, &alloc);
+  clutter_actor_box_get_size (&alloc, &width, &height);
+
+  input = (priv->input_box != NULL) ? priv->input_box : &alloc;
+
   if (priv->visible_region)
     {
+      gdouble scale_x = width / (input->x2 - input->x1);
+      gdouble scale_y = height / (input->y2 - input->y1);
       int n_rectangles = cairo_region_num_rectangles (priv->visible_region);
       int i;
 
@@ -421,21 +436,26 @@ meta_background_actor_paint (ClutterActor *actor)
           cairo_rectangle_int_t rect;
           cairo_region_get_rectangle (priv->visible_region, i, &rect);
 
-          cogl_rectangle_with_texture_coords (rect.x, rect.y,
-                                              rect.x + rect.width, rect.y + rect.height,
+          cogl_rectangle_with_texture_coords (scale_x * rect.x,
+                                              scale_y * rect.y,
+                                              scale_x * (rect.x + rect.width),
+                                              scale_x * (rect.y + rect.height),
+
                                               rect.x / priv->background->texture_width,
                                               rect.y / priv->background->texture_height,
+
                                               (rect.x + rect.width) / priv->background->texture_width,
                                               (rect.y + rect.height) / priv->background->texture_height);
         }
     }
   else
     {
-      cogl_rectangle_with_texture_coords (0.0f, 0.0f,
+      cogl_rectangle_with_texture_coords (0, 0,
                                           width, height,
-                                          0.0f, 0.0f,
-                                          width / priv->background->texture_width,
-                                          height / priv->background->texture_height);
+                                          input->x1 / priv->background->texture_width,
+                                          input->y1 / priv->background->texture_height,
+                                          input->x2 / priv->background->texture_width,
+                                          input->y2 / priv->background->texture_height);
     }
 }
 
@@ -535,6 +555,9 @@ meta_background_actor_get_property(GObject         *object,
     case PROP_SCREEN:
       g_value_set_object (value, priv->screen);
       break;
+    case PROP_INPUT_BOX:
+      g_value_set_boxed (value, priv->input_box);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -548,6 +571,7 @@ meta_background_actor_set_property(GObject         *object,
                                    GParamSpec      *pspec)
 {
   MetaBackgroundActor *self = META_BACKGROUND_ACTOR (object);
+  MetaBackgroundActorPrivate *priv = self->priv;
 
   switch (prop_id)
     {
@@ -563,6 +587,12 @@ meta_background_actor_set_property(GObject         *object,
     case PROP_SCREEN:
       meta_background_actor_set_screen (self, META_SCREEN (g_value_get_object (value)));
       break;
+    case PROP_INPUT_BOX:
+      if (priv->input_box)
+        clutter_actor_box_free (priv->input_box);
+      priv->input_box = g_value_dup_boxed (value);
+      clutter_actor_queue_redraw (CLUTTER_ACTOR (self));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -636,6 +666,18 @@ meta_background_actor_class_init (MetaBackgroundActorClass *klass)
                               G_PARAM_READWRITE);
   obj_props[PROP_CROSSFADE_PROGRESS] = pspec;
 
+  /**
+   * MetaBackgroundActor:input-box:
+   *
+   * Input box to draw from in screen coordinates
+   */
+  pspec = g_param_spec_boxed ("input-box",
+                              "Input box",
+                              "Input box to draw from",
+                              CLUTTER_TYPE_ACTOR_BOX,
+                              G_PARAM_READWRITE);
+  obj_props[PROP_INPUT_BOX] = pspec;
+
   g_object_class_install_properties (object_class, PROP_LAST, obj_props);
 }
 



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