[gnome-shell] [StThemeNode] Add helper method to get the paint allocation



commit af3ca027a1ddf98ada344316a0c9a99ae596988f
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jun 4 15:21:59 2010 +0200

    [StThemeNode] Add helper method to get the paint allocation
    
    StThemeNodes may have properties - namely shadows - which paint
    outside an actor's allocation. This is not a problem unless drawing
    is redirected to an offscreen buffer, in which case the actually
    painted size is needed in advance when setting up the buffer.
    
    Add a convenience method to calculate an allocation large enough to
    paint the node.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=619025

 src/st/st-shadow.c             |   29 +++++++++++++++++++++++++++++
 src/st/st-shadow.h             |    4 ++++
 src/st/st-theme-node-drawing.c |   10 ++--------
 src/st/st-theme-node.c         |   38 ++++++++++++++++++++++++++++++++++++++
 src/st/st-theme-node.h         |    4 ++++
 5 files changed, 77 insertions(+), 8 deletions(-)
---
diff --git a/src/st/st-shadow.c b/src/st/st-shadow.c
index 5add5c7..49fd5b2 100644
--- a/src/st/st-shadow.c
+++ b/src/st/st-shadow.c
@@ -77,6 +77,35 @@ st_shadow_free (StShadow *shadow)
   g_slice_free (StShadow, shadow);
 }
 
+/**
+ * st_shadow_get_box:
+ * @shadow: a #StShadow
+ * @actor_box: the box allocated to a #ClutterAlctor
+ * @shadow_box: computed box occupied by @shadow
+ *
+ * Gets the box used to paint @shadow, which will be partly
+ * outside of @actor_box
+ */
+void
+st_shadow_get_box (StShadow              *shadow,
+                   const ClutterActorBox *actor_box,
+                   ClutterActorBox       *shadow_box)
+{
+  g_return_if_fail (shadow != NULL);
+  g_return_if_fail (actor_box != NULL);
+  g_return_if_fail (shadow_box != NULL);
+
+  shadow_box->x1 = actor_box->x1 + shadow->xoffset
+                   - shadow->blur - shadow->spread;
+  shadow_box->x2 = actor_box->x2 + shadow->xoffset
+                   + shadow->blur + shadow->spread;
+  shadow_box->y1 = actor_box->y1 + shadow->yoffset
+                   - shadow->blur - shadow->spread;
+  shadow_box->y2 = actor_box->y2 + shadow->yoffset
+                   + shadow->blur + shadow->spread;
+}
+
+
 GType
 st_shadow_get_type (void)
 {
diff --git a/src/st/st-shadow.h b/src/st/st-shadow.h
index 85fabef..97cecf8 100644
--- a/src/st/st-shadow.h
+++ b/src/st/st-shadow.h
@@ -41,6 +41,10 @@ StShadow *st_shadow_new      (ClutterColor   *color,
 StShadow *st_shadow_copy     (const StShadow *shadow);
 void      st_shadow_free     (StShadow       *shadow);
 
+void      st_shadow_get_box  (StShadow              *shadow,
+                              const ClutterActorBox *actor_box,
+                              ClutterActorBox       *shadow_box);
+
 G_END_DECLS
 
 #endif /* __ST_SHADOW__ */
diff --git a/src/st/st-theme-node-drawing.c b/src/st/st-theme-node-drawing.c
index 1295497..f55174f 100644
--- a/src/st/st-theme-node-drawing.c
+++ b/src/st/st-theme-node-drawing.c
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <math.h>
 
+#include "st-shadow.h"
 #include "st-theme-private.h"
 #include "st-theme-context.h"
 #include "st-texture-cache.h"
@@ -822,14 +823,7 @@ paint_shadow_with_opacity (CoglHandle       shadow_material,
   ClutterActorBox shadow_box;
   CoglColor       color;
 
-  shadow_box.x1 = box->x1 + shadow_spec->xoffset
-                  - shadow_spec->blur - shadow_spec->spread;
-  shadow_box.y1 = box->y1 + shadow_spec->yoffset
-                  - shadow_spec->blur - shadow_spec->spread;
-  shadow_box.x2 = box->x2 + shadow_spec->xoffset
-                  + shadow_spec->blur + shadow_spec->spread;
-  shadow_box.y2 = box->y2 + shadow_spec->yoffset
-                  + shadow_spec->blur + shadow_spec->spread;
+  st_shadow_get_box (shadow_spec, box, &shadow_box);
 
   cogl_color_set_from_4ub (&color,
                            shadow_spec->color.red   * paint_opacity / 255,
diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c
index e2b0378..5c4768a 100644
--- a/src/st/st-theme-node.c
+++ b/src/st/st-theme-node.c
@@ -2508,6 +2508,44 @@ st_theme_node_get_content_box (StThemeNode           *node,
   content_box->y2 = (int)(0.5 + content_box->y1 + content_height);
 }
 
+/**
+ * st_theme_node_get_paint_box:
+ * @node: a #StThemeNode
+ * @allocation: the box allocated to a #ClutterAlctor
+ * @paint_box: computed box occupied when painting the actor
+ *
+ * Gets the box used to paint the actor, including the area occupied by
+ * properties which paint outside the actor's assigned allocation
+ * (currently only st-shadow). When painting @node to an offscreen buffer,
+ * this function can be used to determine the necessary size of the buffer.
+ */
+void
+st_theme_node_get_paint_box (StThemeNode           *node,
+                             const ClutterActorBox *actor_box,
+                             ClutterActorBox       *paint_box)
+{
+  StShadow *shadow;
+
+  g_return_if_fail (ST_IS_THEME_NODE (node));
+  g_return_if_fail (actor_box != NULL);
+  g_return_if_fail (paint_box != NULL);
+
+  shadow = st_theme_node_get_shadow (node);
+  if (shadow)
+    {
+      ClutterActorBox shadow_box;
+
+      st_shadow_get_box (shadow, actor_box, &shadow_box);
+
+      paint_box->x1 = MIN (actor_box->x1, shadow_box.x1);
+      paint_box->x2 = MAX (actor_box->x2, shadow_box.x2);
+      paint_box->y1 = MIN (actor_box->y1, shadow_box.y1);
+      paint_box->y2 = MAX (actor_box->y2, shadow_box.y2);
+    }
+  else
+    *paint_box = *actor_box;
+}
+
 
 /**
  * st_theme_node_geometry_equal:
diff --git a/src/st/st-theme-node.h b/src/st/st-theme-node.h
index 3fbeb81..e560f87 100644
--- a/src/st/st-theme-node.h
+++ b/src/st/st-theme-node.h
@@ -169,6 +169,10 @@ void st_theme_node_adjust_preferred_height (StThemeNode  *node,
 void st_theme_node_get_content_box         (StThemeNode        *node,
                                             const ClutterActorBox *actor_box,
                                             ClutterActorBox       *content_box);
+/* Helper for StThemeNodeTransition */
+void st_theme_node_get_paint_box           (StThemeNode           *node,
+                                            const ClutterActorBox *actor_box,
+                                            ClutterActorBox       *paint_box);
 
 gboolean st_theme_node_geometry_equal (StThemeNode *node,
                                        StThemeNode *other);



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