[Xfce4-commits] [xfce/xfdesktop] 07/16: iconview: switch to drawing the icon labels with CSS

noreply at xfce.org noreply at xfce.org
Wed Apr 19 17:46:24 CEST 2017


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfdesktop.

commit 5cb865ace179c43af9e0cf0559b4aced308b4ab3
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Wed Apr 19 08:54:34 2017 +0300

    iconview: switch to drawing the icon labels with CSS
    
    When drawing the icon taxt we dynamically add the
    GTK_STYLE_CLASS_LABEL and set the label state based on whatever
    the icon state is (selected, active, or normal).
---
 src/Makefile.am           |   4 +-
 src/gtkcairoblur.c        | 287 ----------------------------------------------
 src/gtkcairoblurprivate.h |  47 --------
 src/xfdesktop-icon-view.c | 269 ++++---------------------------------------
 4 files changed, 26 insertions(+), 581 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 5e03975..53310aa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,9 +45,7 @@ desktop_icon_sources = \
 	xfdesktop-window-icon.c \
 	xfdesktop-window-icon.h \
 	xfdesktop-window-icon-manager.c \
-	xfdesktop-window-icon-manager.h \
-	gtkcairoblur.c \
-	gtkcairoblurprivate.h
+	xfdesktop-window-icon-manager.h
 
 desktop_file_icon_sources = \
 	xfdesktop-clipboard-manager.c \
diff --git a/src/gtkcairoblur.c b/src/gtkcairoblur.c
deleted file mode 100644
index 2ad5eb8..0000000
--- a/src/gtkcairoblur.c
+++ /dev/null
@@ -1,287 +0,0 @@
-/* GTK - The GIMP Toolkit
- *
- * Copyright (C) 2014 Red Hat
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Written by:
- *     Jasper St. Pierre <jstpierre at mecheye.net>
- *     Owen Taylor <otaylor at redhat.com>
- */
-
-/*
- * All code in this file is based on Gtk+-3 code.
- * Files: gtk/gtkcairoblur.c and gtk/gtkcssshadowvalue.c
- */
-
-#include "gtkcairoblurprivate.h"
-
-#include <math.h>
-#include <string.h>
-
-/* This applies a single box blur pass to a horizontal range of pixels;
- * since the box blur has the same weight for all pixels, we can
- * implement an efficient sliding window algorithm where we add
- * in pixels coming into the window from the right and remove
- * them when they leave the windw to the left.
- *
- * d is the filter width; for even d shift indicates how the blurred
- * result is aligned with the original - does ' x ' go to ' yy' (shift=1)
- * or 'yy ' (shift=-1)
- */
-static void
-blur_xspan (guchar *row,
-            guchar *tmp_buffer,
-            int     row_width,
-            int     d,
-            int     shift)
-{
-  int offset;
-  int sum = 0;
-  int i;
-
-  if (d % 2 == 1)
-    offset = d / 2;
-  else
-    offset = (d - shift) / 2;
-
-  /* All the conditionals in here look slow, but the branches will
-   * be well predicted and there are enough different possibilities
-   * that trying to write this as a series of unconditional loops
-   * is hard and not an obvious win. The main slow down here seems
-   * to be the integer division per pixel; one possible optimization
-   * would be to accumulate into two 16-bit integer buffers and
-   * only divide down after all three passes. (SSE parallel implementation
-   * of the divide step is possible.)
-   */
-  for (i = -d + offset; i < row_width + offset; i++)
-    {
-      if (i >= 0 && i < row_width)
-        sum += row[i];
-
-      if (i >= offset)
-        {
-          if (i >= d)
-            sum -= row[i - d];
-
-          tmp_buffer[i - offset] = (sum + d / 2) / d;
-        }
-    }
-
-  memcpy (row, tmp_buffer, row_width);
-}
-
-static void
-blur_rows (guchar *dst_buffer,
-           guchar *tmp_buffer,
-           int     buffer_width,
-           int     buffer_height,
-           int     d)
-{
-  int i;
-
-  for (i = 0; i < buffer_height; i++)
-    {
-      guchar *row = dst_buffer + i * buffer_width;
-
-      /* We want to produce a symmetric blur that spreads a pixel
-       * equally far to the left and right. If d is odd that happens
-       * naturally, but for d even, we approximate by using a blur
-       * on either side and then a centered blur of size d + 1.
-       * (technique also from the SVG specification)
-       */
-      if (d % 2 == 1)
-        {
-          blur_xspan (row, tmp_buffer, buffer_width, d, 0);
-          blur_xspan (row, tmp_buffer, buffer_width, d, 0);
-          blur_xspan (row, tmp_buffer, buffer_width, d, 0);
-        }
-      else
-        {
-          blur_xspan (row, tmp_buffer, buffer_width, d, 1);
-          blur_xspan (row, tmp_buffer, buffer_width, d, -1);
-          blur_xspan (row, tmp_buffer, buffer_width, d + 1, 0);
-        }
-    }
-}
-
-/* Swaps width and height.
- */
-static void
-flip_buffer (guchar *dst_buffer,
-             guchar *src_buffer,
-             int     width,
-             int     height)
-{
-  /* Working in blocks increases cache efficiency, compared to reading
-   * or writing an entire column at once
-   */
-#define BLOCK_SIZE 16
-
-  int i0, j0;
-
-  for (i0 = 0; i0 < width; i0 += BLOCK_SIZE)
-    for (j0 = 0; j0 < height; j0 += BLOCK_SIZE)
-      {
-        int max_j = MIN(j0 + BLOCK_SIZE, height);
-        int max_i = MIN(i0 + BLOCK_SIZE, width);
-        int i, j;
-
-        for (i = i0; i < max_i; i++)
-          for (j = j0; j < max_j; j++)
-            dst_buffer[i * height + j] = src_buffer[j * width + i];
-      }
-#undef BLOCK_SIZE
-}
-
-static void
-_boxblur (guchar  *buffer,
-          int      width,
-          int      height,
-          int      radius)
-{
-  guchar *flipped_buffer;
-
-  flipped_buffer = g_malloc (width * height);
-
-  /* Step 1: swap rows and columns */
-  flip_buffer (flipped_buffer, buffer, width, height);
-
-  /* Step 2: blur rows (really columns) */
-  blur_rows (flipped_buffer, buffer, height, width, radius);
-
-  /* Step 3: swap rows and columns */
-  flip_buffer (buffer, flipped_buffer, height, width);
-
-  /* Step 4: blur rows */
-  blur_rows (buffer, flipped_buffer, width, height, radius);
-
-  g_free (flipped_buffer);
-}
-
-static const cairo_user_data_key_t original_cr_key;
-
-cairo_t *
-gtk_css_shadow_value_start_drawing (cairo_t *cr, gdouble radius)
-{
-  cairo_rectangle_int_t clip_rect;
-  cairo_surface_t *surface;
-  cairo_t *blur_cr;
-  gdouble clip_radius;
-
-  gdk_cairo_get_clip_rectangle (cr, &clip_rect);
-
-  clip_radius = _gtk_cairo_blur_compute_pixels (radius);
-
-  /* Create a larger surface to center the blur. */
-  surface = cairo_image_surface_create (CAIRO_FORMAT_A8,
-                                        clip_rect.width + 2 * clip_radius,
-                                        clip_rect.height + 2 * clip_radius);
-  cairo_surface_set_device_offset (surface, clip_radius - clip_rect.x, clip_radius - clip_rect.y);
-  blur_cr = cairo_create (surface);
-  cairo_set_user_data (blur_cr, &original_cr_key, cairo_reference (cr), (cairo_destroy_func_t) cairo_destroy);
-
-  if (cairo_has_current_point (cr))
-    {
-      double x, y;
-
-      cairo_get_current_point (cr, &x, &y);
-      cairo_move_to (blur_cr, x, y);
-    }
-
-  return blur_cr;
-}
-
-cairo_t *
-gtk_css_shadow_value_finish_drawing (cairo_t *cr, gdouble radius, GdkColor *color)
-{
-  cairo_t *original_cr;
-  cairo_surface_t *surface;
-
-  original_cr = cairo_get_user_data (cr, &original_cr_key);
-
-  /* Blur the surface. */
-  surface = cairo_get_target (cr);
-
-   _gtk_cairo_blur_surface (surface, radius);
-
-  gdk_cairo_set_source_color(original_cr, color);
-  cairo_mask_surface (original_cr, surface, 0, 0);
-
-  cairo_destroy (cr);
-  cairo_surface_destroy (surface);
-
-  return original_cr;
-}
-
-/*
- * _gtk_cairo_blur_surface:
- * @surface: a cairo image surface.
- * @radius: the blur radius.
- *
- * Blurs the cairo image surface at the given radius.
- */
-void
-_gtk_cairo_blur_surface (cairo_surface_t* surface,
-                         double           radius_d)
-{
-  cairo_format_t format;
-  int radius = radius_d;
-
-  g_return_if_fail (surface != NULL);
-  g_return_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE);
-
-  format = cairo_image_surface_get_format (surface);
-  g_return_if_fail (format == CAIRO_FORMAT_A8);
-
-  if (radius == 0)
-    return;
-
-  /* Before we mess with the surface, execute any pending drawing. */
-  cairo_surface_flush (surface);
-
-  _boxblur (cairo_image_surface_get_data (surface),
-            cairo_image_surface_get_stride (surface),
-            cairo_image_surface_get_height (surface),
-            radius);
-
-  /* Inform cairo we altered the surface contents. */
-  cairo_surface_mark_dirty (surface);
-}
-
-/*
- * _gtk_cairo_blur_compute_pixels:
- * @radius: the radius to compute the pixels for
- *
- * Computes the number of pixels necessary to extend an image in one
- * direction to hold the image with shadow.
- *
- * This is just the number of pixels added by the blur radius, shadow
- * offset and spread are not included.
- *
- * Much of this, the 3 * sqrt(2 * pi) / 4, is the known value for
- * approximating a Gaussian using box blurs.  This yields quite a good
- * approximation for a Gaussian.  Then we multiply this by 1.5 since our
- * code wants the radius of the entire triple-box-blur kernel instead of
- * the diameter of an individual box blur.  For more details, see:
- * http://www.w3.org/TR/SVG11/filters.html#feGaussianBlurElement
- * https://bugzilla.mozilla.org/show_bug.cgi?id=590039#c19
- */
-#define GAUSSIAN_SCALE_FACTOR ((3.0 * sqrt(2 * G_PI) / 4) * 1.5)
-
-int
-_gtk_cairo_blur_compute_pixels (double radius)
-{
-  return floor (radius * GAUSSIAN_SCALE_FACTOR + 0.5);
-}
diff --git a/src/gtkcairoblurprivate.h b/src/gtkcairoblurprivate.h
deleted file mode 100644
index 7bfb770..0000000
--- a/src/gtkcairoblurprivate.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2012 Canonical Ltd
- *
- * This  library is free  software; you can  redistribute it and/or
- * modify it  under  the terms  of the  GNU Lesser  General  Public
- * License  as published  by the Free  Software  Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed  in the hope that it will be useful,
- * but  WITHOUT ANY WARRANTY; without even  the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License  along  with  this library;  if not,  write to  the Free
- * Software Foundation, Inc., 51  Franklin St, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * Authored by Andrea Cimitan <andrea.cimitan at canonical.com>
- * Original code from Mirco Mueller <mirco.mueller at canonical.com>
- *
- */
-
-#ifndef _GTK_CAIRO_BLUR_H
-#define _GTK_CAIRO_BLUR_H
-
-#include <gdk/gdk.h>
-#include <glib.h>
-#include <cairo.h>
-
-G_BEGIN_DECLS
-
-cairo_t         *gtk_css_shadow_value_start_drawing  (cairo_t         *cr,
-                                                      gdouble          radius);
-
-cairo_t         *gtk_css_shadow_value_finish_drawing (cairo_t         *cr,
-                                                      gdouble          radius,
-                                                      GdkColor        *color);
-
-void            _gtk_cairo_blur_surface              (cairo_surface_t *surface,
-                                                      double           radius);
-
-int             _gtk_cairo_blur_compute_pixels       (double           radius);
-
-G_END_DECLS
-
-#endif /* _GTK_CAIRO_BLUR_H */
diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c
index b30b055..387046d 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -48,7 +48,6 @@
 #include "xfce-desktop.h"
 #include "xfdesktop-volume-icon.h"
 #include "xfdesktop-common.h"
-#include "gtkcairoblurprivate.h"
 
 #include <libwnck/libwnck.h>
 #include <libxfce4ui/libxfce4ui.h>
@@ -180,14 +179,6 @@ struct _XfdesktopIconViewPrivate
     guchar    label_alpha;
     guchar    selected_label_alpha;
 
-    gchar     shadow_x_offset;
-    gchar     shadow_y_offset;
-    GdkColor *shadow_color;
-    gchar     selected_shadow_x_offset;
-    gchar     selected_shadow_y_offset;
-    GdkColor *selected_shadow_color;
-    gchar     shadow_blur_radius;
-
     gint cell_padding;
     gint cell_spacing;
     gdouble label_radius;
@@ -532,55 +523,6 @@ xfdesktop_icon_view_class_init(XfdesktopIconViewClass *klass)
                                                                G_PARAM_READABLE));
 
     gtk_widget_class_install_style_property(widget_class,
-                                            g_param_spec_char("shadow-x-offset",
-                                                               "Shadow X offset",
-                                                               "Shadow X offset for label text",
-                                                               G_MININT8, G_MAXINT8, 0,
-                                                               G_PARAM_READABLE));
-
-    gtk_widget_class_install_style_property(widget_class,
-                                            g_param_spec_char("shadow-y-offset",
-                                                               "Shadow Y offset",
-                                                               "Shadow Y offset for label text",
-                                                               G_MININT8, G_MAXINT8, 0,
-                                                               G_PARAM_READABLE));
-
-    gtk_widget_class_install_style_property(widget_class,
-                                            g_param_spec_char("selected-shadow-x-offset",
-                                                               "Selected shadow X offset",
-                                                               "Shadow X offset for selected label text",
-                                                               G_MININT8, G_MAXINT8, 0,
-                                                               G_PARAM_READABLE));
-
-    gtk_widget_class_install_style_property(widget_class,
-                                            g_param_spec_char("selected-shadow-y-offset",
-                                                               "Selected shadow Y offset",
-                                                               "Shadow Y offset for selected label text",
-                                                               G_MININT8, G_MAXINT8, 0,
-                                                               G_PARAM_READABLE));
-
-    gtk_widget_class_install_style_property(widget_class,
-                                            g_param_spec_char("shadow-blur-radius",
-                                                              "shadow blur radius",
-                                                              "Blur radius for label text",
-                                                              G_MININT8, G_MAXINT8, 0,
-                                                              G_PARAM_READABLE));
-
-    gtk_widget_class_install_style_property(widget_class,
-                                            g_param_spec_boxed("shadow-color",
-                                                               "Shadow color",
-                                                               "Color for label text shadows",
-                                                               GDK_TYPE_COLOR,
-                                                               G_PARAM_READABLE));
-
-    gtk_widget_class_install_style_property(widget_class,
-                                            g_param_spec_boxed("selected-shadow-color",
-                                                               "Selected shadow color",
-                                                               "Color for selected label text shadows",
-                                                               GDK_TYPE_COLOR,
-                                                               G_PARAM_READABLE));
-
-    gtk_widget_class_install_style_property(widget_class,
                                             g_param_spec_int("cell-spacing",
                                                              "Cell spacing",
                                                              "Spacing between desktop icon cells",
@@ -1927,63 +1869,14 @@ xfdesktop_icon_view_style_updated(GtkWidget *widget)
 
     gtk_widget_style_get(GTK_WIDGET(icon_view),
                          "label-alpha",   &icon_view->priv->label_alpha,
-                         "shadow-x-offset", &icon_view->priv->shadow_x_offset,
-                         "shadow-y-offset", &icon_view->priv->shadow_y_offset,
-                         "shadow-blur-radius", &icon_view->priv->shadow_blur_radius,
-                         "shadow-color",  &icon_view->priv->shadow_color,
                          NULL);
 
-    icon_view->priv->shadow_extents =
-      (icon_view->priv->shadow_blur_radius > 1) ?
-      _gtk_cairo_blur_compute_pixels(icon_view->priv->shadow_blur_radius) : 0;
-
-    /* default the shadow color to the inverse of the text color */
-    if (!icon_view->priv->shadow_color) {
-        icon_view->priv->shadow_color = gdk_color_copy(&gtk_widget_get_style(widget)->fg[GTK_STATE_NORMAL]);
-        icon_view->priv->shadow_color->red   ^= 0xffff;
-        icon_view->priv->shadow_color->green ^= 0xffff;
-        icon_view->priv->shadow_color->blue  ^= 0xffff;
-    }
-
     XF_DEBUG("label alpha is %d\n",   (gint)(icon_view->priv->label_alpha));
-    XF_DEBUG("shadow x offset is %d\n", (gint)(icon_view->priv->shadow_x_offset));
-    XF_DEBUG("shadow y offset is %d\n", (gint)(icon_view->priv->shadow_y_offset));
-#if defined(DEBUG) && (DEBUG > 0)
-    {
-        gchar *color = gdk_color_to_string(icon_view->priv->shadow_color);
-        XF_DEBUG("shadow color is %s\n", color);
-        g_free(color);
-    }
-#endif
 
     gtk_widget_style_get(GTK_WIDGET(icon_view),
                          "selected-label-alpha", &icon_view->priv->selected_label_alpha,
-                         "selected-shadow-x-offset", &icon_view->priv->selected_shadow_x_offset,
-                         "selected-shadow-y-offset", &icon_view->priv->selected_shadow_y_offset,
-                         "selected-shadow-color", &icon_view->priv->selected_shadow_color,
                          NULL);
 
-    /* default the shadow color to the inverse of the text color */
-    if (!icon_view->priv->selected_shadow_color) {
-        icon_view->priv->selected_shadow_color = gdk_color_copy(&gtk_widget_get_style(widget)->fg[GTK_STATE_SELECTED]);
-        icon_view->priv->selected_shadow_color->red   ^= 0xffff;
-        icon_view->priv->selected_shadow_color->green ^= 0xffff;
-        icon_view->priv->selected_shadow_color->blue  ^= 0xffff;
-    }
-
-    XF_DEBUG("selected label alpha is %d\n",
-             (gint)(icon_view->priv->selected_label_alpha));
-    XF_DEBUG("selected shadow x offset is %d\n",
-             (gint)(icon_view->priv->selected_shadow_x_offset));
-    XF_DEBUG("selected shadow y offset is %d\n",
-             (gint)(icon_view->priv->selected_shadow_y_offset));
-#if defined(DEBUG) && (DEBUG > 0)
-    {
-        gchar *color = gdk_color_to_string(icon_view->priv->selected_shadow_color);
-        XF_DEBUG("shadow color is %s\n", color);
-        g_free(color);
-    }
-#endif
     
     gtk_widget_style_get(widget,
                          "cell-spacing", &icon_view->priv->cell_spacing,
@@ -2007,15 +1900,6 @@ xfdesktop_icon_view_style_updated(GtkWidget *widget)
     }
     icon_view->priv->selection_box_alpha = DEFAULT_RUBBERBAND_ALPHA;
 
-    /* this is super lame */
-    dummy = gtk_icon_view_new();
-    gtk_widget_ensure_style(dummy);
-    gtk_widget_style_get(dummy,
-                         "selection-box-color", &icon_view->priv->selection_box_color,
-                         "selection-box-alpha", &icon_view->priv->selection_box_alpha,
-                         NULL);
-    gtk_widget_destroy(dummy);
-
     GTK_WIDGET_CLASS(xfdesktop_icon_view_parent_class)->style_updated(widget);
 
     /* do this after we're sure we have a style set */
@@ -2170,16 +2054,6 @@ xfdesktop_icon_view_unrealize(GtkWidget *widget)
         gdk_color_free(icon_view->priv->selection_box_color);
         icon_view->priv->selection_box_color = NULL;
     }
-
-    if(icon_view->priv->shadow_color) {
-        gdk_color_free(icon_view->priv->shadow_color);
-        icon_view->priv->shadow_color = NULL;
-    }
-
-    if(icon_view->priv->selected_shadow_color) {
-        gdk_color_free(icon_view->priv->selected_shadow_color);
-        icon_view->priv->selected_shadow_color = NULL;
-    }
     
     gtk_widget_set_window(widget, NULL);
     gtk_widget_set_realized(widget, FALSE);
@@ -2881,67 +2755,6 @@ xfdesktop_icon_view_invalidate_icon_pixbuf(XfdesktopIconView *icon_view,
     }
 }
 
-static void
-xfdesktop_paint_rounded_box(XfdesktopIconView *icon_view,
-                            GtkStateType state,
-                            GdkRectangle *box_area,
-                            GdkRectangle *expose_area,
-                            cairo_t *cr)
-{
-    GdkRectangle intersection;
-    
-    if(gdk_rectangle_intersect(box_area, expose_area, &intersection)) {
-        cr = cairo_reference(cr);
-        GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(icon_view));
-        double alpha;
-
-        if(state == GTK_STATE_NORMAL)
-            alpha = icon_view->priv->label_alpha / 255.;
-        else
-            alpha = icon_view->priv->selected_label_alpha / 255.;
-
-        cairo_set_source_rgba(cr, style->base[state].red / 65535.,
-                              style->base[state].green / 65535.,
-                              style->base[state].blue / 65535.,
-                              alpha);
-
-        /* restrict painting to expose area */
-        gdk_cairo_rectangle(cr, expose_area);
-        cairo_clip(cr);
-
-        if(LABEL_RADIUS < 0.1)
-            gdk_cairo_rectangle(cr, box_area);
-        else {
-            cairo_move_to(cr, box_area->x, box_area->y + LABEL_RADIUS);
-            cairo_arc(cr, box_area->x + LABEL_RADIUS,
-                      box_area->y + LABEL_RADIUS, LABEL_RADIUS,
-                      M_PI, 3.0*M_PI/2.0);
-            cairo_line_to(cr, box_area->x + box_area->width - LABEL_RADIUS,
-                          box_area->y);
-            cairo_arc(cr, box_area->x + box_area->width - LABEL_RADIUS,
-                      box_area->y + LABEL_RADIUS, LABEL_RADIUS,
-                      3.0+M_PI/2.0, 0.0);
-            cairo_line_to(cr, box_area->x + box_area->width,
-                          box_area->y + box_area->height - LABEL_RADIUS);
-            cairo_arc(cr, box_area->x + box_area->width - LABEL_RADIUS,
-                      box_area->y + box_area->height - LABEL_RADIUS,
-                      LABEL_RADIUS,
-                      0.0, M_PI/2.0);
-            cairo_line_to(cr, box_area->x + LABEL_RADIUS,
-                          box_area->y + box_area->height);
-            cairo_arc(cr, box_area->x + LABEL_RADIUS,
-                      box_area->y + box_area->height - LABEL_RADIUS,
-                      LABEL_RADIUS,
-                      M_PI/2.0, M_PI);
-            cairo_close_path(cr);
-        }
-
-        cairo_fill(cr);
-
-        cairo_destroy(cr);
-    }
-}
-
 static gboolean
 xfdesktop_icon_view_calculate_icon_pixbuf_area(XfdesktopIconView *icon_view,
                                                XfdesktopIcon *icon,
@@ -3012,10 +2825,10 @@ xfdesktop_icon_view_calculate_icon_text_area(XfdesktopIconView *icon_view,
     xfdesktop_icon_view_setup_pango_layout(icon_view, icon, playout);
     pango_layout_get_pixel_extents(playout, NULL, &prect);
 
-    text_area->x = prect.x - SHADOW_X_OFFSET;
-    text_area->y = prect.y - SHADOW_Y_OFFSET;
-    text_area->width = prect.width + 2 * SHADOW_X_OFFSET;
-    text_area->height = prect.height + 2 * SHADOW_Y_OFFSET;
+    text_area->x = prect.x;
+    text_area->y = prect.y;
+    text_area->width = prect.width + 2;
+    text_area->height = prect.height + 2;
 
     return TRUE;
 }
@@ -3102,34 +2915,27 @@ xfdesktop_icon_view_draw_image(cairo_t *cr, GdkPixbuf *pix, GdkRectangle *rect)
 }
 
 static void
-xfdesktop_icon_view_draw_text(cairo_t *cr, PangoLayout *playout, GdkRectangle *text_area,
-                              GdkRectangle *box_area, gint x_offset, gint y_offset,
-                              gint blur_radius, GdkColor *color)
+xfdesktop_icon_view_draw_text(GtkWidget *icon_view, cairo_t *cr,
+                              PangoLayout *playout, GdkRectangle *text_area,
+                              GdkRectangle *box_area, GtkStateFlags state)
 {
+    GtkStyleContext *context;
+
     cairo_save(cr);
 
-    /*  Clip the cairo area to blur the minimum surface */
+    /*  Clip the cairo area */
     gdk_cairo_rectangle(cr, box_area);
     cairo_clip(cr);
 
-    cairo_move_to(cr,
-                  text_area->x + x_offset,
-                  text_area->y + y_offset);
+    context = gtk_widget_get_style_context(icon_view);
+    gtk_style_context_save(context);
+    gtk_style_context_add_class(context, GTK_STYLE_CLASS_LABEL);
+    gtk_style_context_set_state (context, state);
 
-    if (blur_radius > 1) {
-        cr = gtk_css_shadow_value_start_drawing (cr, blur_radius);
-        pango_cairo_show_layout (cr, playout);
-        cairo_set_line_width(cr, 1);
-        cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
-        pango_cairo_layout_path(cr, playout);
-        cairo_stroke(cr);
-        cr = gtk_css_shadow_value_finish_drawing (cr, blur_radius, color);
-    }
-    else {
-        gdk_cairo_set_source_color(cr, color);
-        pango_cairo_show_layout(cr, playout);
-    }
+    gtk_render_background(context, cr, box_area->x, box_area->y, box_area->width, box_area->height);
+    gtk_render_layout(context, cr, text_area->x, text_area->y, playout);
 
+    gtk_style_context_restore(context);
     cairo_restore(cr);
 }
 
@@ -3143,9 +2949,7 @@ xfdesktop_icon_view_paint_icon(XfdesktopIconView *icon_view,
     PangoLayout *playout;
     GdkRectangle pixbuf_extents, text_extents, box_extents, total_extents;
     GdkRectangle intersection;
-    gint state;
-    gchar x_offset = 0, y_offset = 0;
-    GdkColor *sh_text_col = NULL;
+    GtkStateFlags state;
 #ifdef G_ENABLE_DEBUG
     gint16 row, col;
 #endif
@@ -3175,17 +2979,17 @@ xfdesktop_icon_view_paint_icon(XfdesktopIconView *icon_view,
 
     if(xfdesktop_icon_view_is_icon_selected(icon_view, icon)) {
         if(gtk_widget_has_focus(widget))
-            state = GTK_STATE_SELECTED;
+            state = GTK_STATE_FLAG_SELECTED;
         else
-            state = GTK_STATE_ACTIVE;
+            state = GTK_STATE_FLAG_ACTIVE;
     } else
-        state = GTK_STATE_NORMAL;
+        state = GTK_STATE_FLAG_NORMAL;
     
     if(gdk_rectangle_intersect(area, &pixbuf_extents, &intersection)) {
         GdkPixbuf *pix = xfdesktop_icon_peek_pixbuf(icon, ICON_WIDTH, ICON_SIZE);
         GdkPixbuf *pix_free = NULL;
 
-        if(state != GTK_STATE_NORMAL) {
+        if(state != GTK_STATE_FLAG_NORMAL) {
             pix_free = exo_gdk_pixbuf_colorize(pix, &gtk_widget_get_style(widget)->base[state]);
             pix = pix_free;
         }
@@ -3217,36 +3021,13 @@ xfdesktop_icon_view_paint_icon(XfdesktopIconView *icon_view,
     if(gdk_rectangle_intersect(area, &box_extents, &intersection)
        && icon_view->priv->font_size > 0)
     {
-        xfdesktop_paint_rounded_box(icon_view, state, &box_extents, area, cr);
-
-        if (state == GTK_STATE_NORMAL) {
-            x_offset = icon_view->priv->shadow_x_offset;
-            y_offset = icon_view->priv->shadow_y_offset;
-            sh_text_col = icon_view->priv->shadow_color;
-        } else {
-            x_offset = icon_view->priv->selected_shadow_x_offset;
-            y_offset = icon_view->priv->selected_shadow_y_offset;
-            sh_text_col = icon_view->priv->selected_shadow_color;
-        }
-
-        /* draw text shadow for the label text if an offset was defined */
-        if(x_offset || y_offset || (icon_view->priv->shadow_blur_radius > 1)) {
-            /* Draw the shadow */
-            xfdesktop_icon_view_draw_text(cr, playout,
-                                          &text_extents,
-                                          &box_extents,
-                                          x_offset,
-                                          y_offset,
-                                          icon_view->priv->shadow_blur_radius,
-                                          sh_text_col);
-        }
-
         DBG("painting text at %dx%d+%d+%d",
               text_extents.width, text_extents.height,
               text_extents.x, text_extents.y);
 
-        gtk_render_layout(gtk_widget_get_style_context(widget), cr,
-                          text_extents.x, text_extents.y, playout);
+        xfdesktop_icon_view_draw_text(GTK_WIDGET(icon_view), cr, playout,
+                                      &text_extents, &box_extents,
+                                      state);
     }
 
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list