Author: kelnos Date: 2008-10-12 10:05:26 +0000 (Sun, 12 Oct 2008) New Revision: 28169
Modified: xfdesktop/trunk/NEWS xfdesktop/trunk/README xfdesktop/trunk/src/xfdesktop-icon-view.c Log: add style props for icon text label shadow (bug 4412). patch from andrea santilli <yawara quipo it> Modified: xfdesktop/trunk/NEWS =================================================================== --- xfdesktop/trunk/NEWS 2008-10-12 09:44:04 UTC (rev 28168) +++ xfdesktop/trunk/NEWS 2008-10-12 10:05:26 UTC (rev 28169) @@ -29,6 +29,8 @@ * Add the ellipsize-icon-labels style property to control whether or not unselected icons get their labels truncated (bug 2886). Patch from Daniel Gibson. + * Add style properties to enable painting a text shadow 'under' the + desktop icon text labels (bug 4412). Patch from Andrea Santilli. Xfce 4.6alpha (Xfce 4.5.90): Modified: xfdesktop/trunk/README =================================================================== --- xfdesktop/trunk/README 2008-10-12 09:44:04 UTC (rev 28168) +++ xfdesktop/trunk/README 2008-10-12 10:05:26 UTC (rev 28169) @@ -39,8 +39,16 @@ style "xfdesktop-icon-view" { XfdesktopIconView::label-alpha = 75 + XfdesktopIconView::selected-label-alpha = 100 XfdesktopIconVIew::ellipsize-icon-labels = 1 + XfdesktopIconView::shadow-x-offset = 1 + XfdesktopIconView::shadow-y-offset = 1 + XfdesktopIconView::shadow-color = "#ff0000" + XfdesktopIconView::selected-shadow-x-offset = 2 + XfdesktopIconView::selected-shadow-y-offset = 2 + XfdesktopIconView::selected-shadow-color = "#00ff00" + XfdesktopIconVIew::cell-spacing = 6 XfdesktopIconView::cell-padding = 6 XfdesktopIconView::cell-text-width-proportion = 2.5 @@ -55,12 +63,18 @@ } widget_class "*XfdesktopIconView*" style "xfdesktop-icon-view" -The first two entries set the opacity of the rounded text background +The first three entries set the opacity of the rounded text background (allowed values are from 0 (totally transparent) to 255 (totally opaque), and whether or not unselected icons get their labels ellipsized -(truncated) to fit on one line. +(truncated) to fit on one line. (The 'selected-' version controls the +opacity of icons that have been selected with the mouse.) -The second four entries set spacing and sizing for individual icons on +The second six entries can be used to enable a text shadow to be painted +with the icon labels. The offsets are in pixels. Setting them to 0 (the +defaults) will disable the shadows entirely. Again, the 'selected-' +versions apply to icons that have been selected with the mouse. + +The third four entries set spacing and sizing for individual icons on the grid. The 'cell-spacing' property specifies the spacing between each 'cell' in the grid of icons. The 'cell-padding' property sets extra padding placed around each icon+text. The units for these two are in @@ -69,7 +83,7 @@ width (so for 30px icons, '2.5' would leave a 75px wide area underneath for the text). -The third three entries set the color of the rounded text background. +The fourth three entries set the color of the rounded text background. * NORMAL sets the color for the regular, unselected state. * SELECTED sets the color for when the icon is selected, and the desktop has keyboard/mouse focus. Modified: xfdesktop/trunk/src/xfdesktop-icon-view.c =================================================================== --- xfdesktop/trunk/src/xfdesktop-icon-view.c 2008-10-12 09:44:04 UTC (rev 28168) +++ xfdesktop/trunk/src/xfdesktop-icon-view.c 2008-10-12 10:05:26 UTC (rev 28169) @@ -152,7 +152,17 @@ GdkDragAction foreign_dest_actions; GdkPixbuf *rounded_frame; - gint label_alpha; + + 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; + gint cell_padding; gint cell_spacing; gdouble cell_text_width_proportion; @@ -355,14 +365,63 @@ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + gtk_widget_class_install_style_property(widget_class, + g_param_spec_uchar("label-alpha", + "Label alpha", + "Alpha value for the text label's background", + 0, 255, 155, + G_PARAM_READABLE)); + + gtk_widget_class_install_style_property(widget_class, + g_param_spec_uchar("selected-label-alpha", + "Selected label alpha", + "Alpha value for the selected text label's background", + 0, 255, 155, + G_PARAM_READABLE)); + gtk_widget_class_install_style_property(widget_class, - g_param_spec_int("label-alpha", - "Label alpha", - "Alpha value for the text label's background", - 0, 255, 155, - G_PARAM_READABLE)); - + 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_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", @@ -1320,16 +1379,69 @@ { XfdesktopIconView *icon_view = XFDESKTOP_ICON_VIEW(widget); GtkWidget *dummy; + + 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-color", &icon_view->priv->shadow_color, + NULL); + + /* 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(&widget->style->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; + } + + DBG("label alpha is %d\n", (gint)(icon_view->priv->label_alpha)); + DBG("shadow x offset is %d\n", (gint)(icon_view->priv->shadow_x_offset)); + DBG("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); + DBG("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(&widget->style->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; + } + + DBG("selected label alpha is %d\n", + (gint)(icon_view->priv->selected_label_alpha)); + DBG("selected shadow x offset is %d\n", + (gint)(icon_view->priv->selected_shadow_x_offset)); + DBG("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); + DBG("shadow color is %s\n", color); + g_free(color); + } +#endif gtk_widget_style_get(widget, - "label-alpha", &icon_view->priv->label_alpha, "cell-spacing", &icon_view->priv->cell_spacing, "cell-padding", &icon_view->priv->cell_padding, "cell-text-width-proportion", &icon_view->priv->cell_text_width_proportion, "ellipsize-icon-labels", &icon_view->priv->ellipsize_icon_labels, NULL); - DBG("label alpha is %d", icon_view->priv->label_alpha); DBG("cell spacing is %d", icon_view->priv->cell_spacing); DBG("cell padding is %d", icon_view->priv->cell_padding); DBG("cell text width proportion is %f", icon_view->priv->cell_text_width_proportion); @@ -1524,6 +1636,16 @@ 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; + } widget->window = NULL; GTK_WIDGET_UNSET_FLAGS(widget, GTK_REALIZED); @@ -1959,6 +2081,7 @@ GdkRectangle *expose_area) { GdkRectangle intersection; + guchar alpha; /* make sure to undo this before returning */ text_area->x -= CORNER_ROUNDNESS; @@ -1978,14 +2101,18 @@ icon_view->priv->rounded_frame = gdk_pixbuf_new_from_file(DATADIR \ "/pixmaps/xfce4/xfdesktop/text-selection-frame.png", NULL); - + if (state == GTK_STATE_NORMAL) + alpha = icon_view->priv->label_alpha; + else + alpha = icon_view->priv->selected_label_alpha; + xfdesktop_clear_rounded_corners(box_pix, icon_view->priv->rounded_frame); xfdesktop_multiply_pixbuf_rgba(box_pix, EEL_RGBA_COLOR_PACK(style->base[state].red >> 8, style->base[state].green >> 8, style->base[state].blue >> 8, - icon_view->priv->label_alpha)); + alpha)); gdk_draw_pixbuf(GDK_DRAWABLE(GTK_WIDGET(icon_view)->window), NULL, box_pix, intersection.x - text_area->x, @@ -2016,6 +2143,8 @@ GdkRectangle pix_area, text_area, intersection, adj_area; const gchar *label; guint16 row, col; + gchar x_offset = 0, y_offset = 0; + GdkColor *sh_text_col = NULL; /*TRACE("entering (%s)", xfdesktop_icon_peek_label(icon));*/ @@ -2101,6 +2230,45 @@ adj_area.height += CORNER_ROUNDNESS * 2; } else memcpy(&adj_area, area, sizeof(GdkRectangle)); + + 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) { + GdkGC *tmp_gc; + + /* FIXME: it's probably not good for performance to create and + * destroy a GC every time an icon gets painted. might want + * to cache this somewhere. */ + + /* save the original gc */ + tmp_gc = gdk_gc_new(GDK_DRAWABLE(widget->window)); + gdk_gc_copy(tmp_gc, widget->style->text_gc[state]); + + /* set the new foreground color */ + gdk_gc_set_rgb_fg_color(widget->style->text_gc[state], sh_text_col); + + /* paint the shadow */ + gtk_paint_layout(widget->style, widget->window, state, TRUE, + &adj_area, widget, "label", + text_area.x + x_offset, + text_area.y + y_offset, + playout); + + /* restore the original gc */ + gdk_gc_copy(widget->style->text_gc[state], tmp_gc); + + /* clean */ + g_object_unref(G_OBJECT(tmp_gc)); + } xfdesktop_paint_rounded_box(icon_view, state, &text_area, &adj_area); gtk_paint_layout(widget->style, widget->window, state, FALSE, _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits