[gtk+] image: Implement clipping support for icon-shadow



commit 7afac9670bc5c0295070edc7f357ccafc2e7beec
Author: Benjamin Otte <otte redhat com>
Date:   Wed Oct 1 06:04:19 2014 +0200

    image: Implement clipping support for icon-shadow
    
    Testcase is attached.

 gtk/gtkimage.c                                     |   26 ++++++++++++++++
 testsuite/reftests/Makefile.am                     |    3 ++
 testsuite/reftests/image-icon-shadow-clipping.css  |    5 +++
 .../reftests/image-icon-shadow-clipping.ref.ui     |   18 +++++++++++
 testsuite/reftests/image-icon-shadow-clipping.ui   |   32 ++++++++++++++++++++
 5 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 80b514d..a50298c 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -38,6 +38,9 @@
 #include "gtkintl.h"
 #include "gtkprivate.h"
 #include "gtktypebuiltins.h"
+#include "gtkcssshadowsvalueprivate.h"
+#include "gtkstylecontextprivate.h"
+#include "gtkwidgetprivate.h"
 
 #include "a11y/gtkimageaccessible.h"
 
@@ -146,6 +149,8 @@ struct _GtkImagePrivate
 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
 static gint gtk_image_draw                 (GtkWidget    *widget,
                                             cairo_t      *cr);
+static void gtk_image_size_allocate        (GtkWidget    *widget,
+                                            GtkAllocation*allocation);
 static void gtk_image_unmap                (GtkWidget    *widget);
 static void gtk_image_realize              (GtkWidget    *widget);
 static void gtk_image_unrealize            (GtkWidget    *widget);
@@ -218,6 +223,7 @@ gtk_image_class_init (GtkImageClass *class)
   widget_class->get_preferred_width = gtk_image_get_preferred_width;
   widget_class->get_preferred_height = gtk_image_get_preferred_height;
   widget_class->get_preferred_height_and_baseline_for_width = 
gtk_image_get_preferred_height_and_baseline_for_width;
+  widget_class->size_allocate = gtk_image_size_allocate;
   widget_class->unmap = gtk_image_unmap;
   widget_class->realize = gtk_image_realize;
   widget_class->unrealize = gtk_image_unrealize;
@@ -1523,6 +1529,26 @@ gtk_image_reset_anim_iter (GtkImage *image)
 }
 
 static void
+gtk_image_size_allocate (GtkWidget     *widget,
+                         GtkAllocation *allocation)
+{
+  GtkBorder extents;
+  GtkAllocation clip;
+
+  GTK_WIDGET_CLASS (gtk_image_parent_class)->size_allocate (widget, allocation);
+
+  /* XXX: This is not strictly correct, we could compute the area
+   * actually occupied by the image, but I'm lazy...
+   */
+  _gtk_css_shadows_value_get_extents (_gtk_style_context_peek_property (gtk_widget_get_style_context 
(widget), GTK_CSS_PROPERTY_ICON_SHADOW), &extents);
+  clip.x = allocation->x - extents.left;
+  clip.width = allocation->width + extents.left + extents.right;
+  clip.y = allocation->y - extents.top;
+  clip.height = allocation->height + extents.top + extents.bottom;
+  _gtk_widget_set_simple_clip (widget, &clip);
+}
+
+static void
 gtk_image_unmap (GtkWidget *widget)
 {
   gtk_image_reset_anim_iter (GTK_IMAGE (widget));
diff --git a/testsuite/reftests/Makefile.am b/testsuite/reftests/Makefile.am
index 39cd5f1..47c4864 100644
--- a/testsuite/reftests/Makefile.am
+++ b/testsuite/reftests/Makefile.am
@@ -268,6 +268,9 @@ testdata = \
        iconview-empty.css \
        iconview-empty.ui \
        iconview-empty.ref.ui \
+       image-icon-shadow-clipping.css \
+       image-icon-shadow-clipping.ref.ui \
+       image-icon-shadow-clipping.ui \
        image-load-from-file.css \
        image-load-from-file.ref.ui \
        image-load-from-file.ui \
diff --git a/testsuite/reftests/image-icon-shadow-clipping.css 
b/testsuite/reftests/image-icon-shadow-clipping.css
new file mode 100644
index 0000000..4770cc1
--- /dev/null
+++ b/testsuite/reftests/image-icon-shadow-clipping.css
@@ -0,0 +1,5 @@
+ import "reset-to-defaults.css";
+
+GtkImage {
+  icon-shadow: 20px 20px tomato;
+}
diff --git a/testsuite/reftests/image-icon-shadow-clipping.ref.ui 
b/testsuite/reftests/image-icon-shadow-clipping.ref.ui
new file mode 100644
index 0000000..c670508
--- /dev/null
+++ b/testsuite/reftests/image-icon-shadow-clipping.ref.ui
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">100</property>
+    <property name="height_request">100</property>
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <child>
+      <object class="GtkImage" id="image1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="icon_name">edit-delete</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/image-icon-shadow-clipping.ui 
b/testsuite/reftests/image-icon-shadow-clipping.ui
new file mode 100644
index 0000000..1bddc5a
--- /dev/null
+++ b/testsuite/reftests/image-icon-shadow-clipping.ui
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">100</property>
+    <property name="height_request">100</property>
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <child>
+      <object class="GtkBox" id="box2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">center</property>
+        <property name="valign">center</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkImage" id="image1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="icon_name">edit-delete</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>


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