From 1ff37554b8d5b09a09e1224aeab3df61eb4d9bb1 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Tue, 14 Apr 1998 19:08:15 +0000 Subject: [PATCH] 1998-04-14 Federico Mena Quintero * gdesktop.h: Added extern declarations for the want_transparent_icons and want_transparent_text variables. * gtrans.c (set_window_text): Now we use the new global variables want_transparent_icons and want_transparent_text to decide how to paint the pixmap and mask. The want_transparent_* variables can thus be configured for the smartness/speed of your X server when using shaped windows. --- gnome/ChangeLog | 11 ++++ gnome/gdesktop.h | 4 ++ gnome/gtrans.c | 155 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 131 insertions(+), 39 deletions(-) diff --git a/gnome/ChangeLog b/gnome/ChangeLog index 3519a0894..26448280b 100644 --- a/gnome/ChangeLog +++ b/gnome/ChangeLog @@ -1,3 +1,14 @@ +1998-04-14 Federico Mena Quintero + + * gdesktop.h: Added extern declarations for the + want_transparent_icons and want_transparent_text variables. + + * gtrans.c (set_window_text): Now we use the new global variables + want_transparent_icons and want_transparent_text to decide how to + paint the pixmap and mask. The want_transparent_* variables can + thus be configured for the smartness/speed of your X server when + using shaped windows. + Fri Apr 12 02:40:41 1998 Norbert Warmuth * gwidget.c (x_create_input): return 1 if the widget has been diff --git a/gnome/gdesktop.h b/gnome/gdesktop.h index dac9ca1b0..a14ccb6b9 100644 --- a/gnome/gdesktop.h +++ b/gnome/gdesktop.h @@ -33,6 +33,10 @@ typedef struct { /* gtrans.c */ + +extern int want_transparent_icons; +extern int want_transparent_text; + GtkWidget *create_transparent_text_window (char *file, char *text, int extra_events); GtkWidget *make_transparent_window (char *file); diff --git a/gnome/gtrans.c b/gnome/gtrans.c index 38c018800..408ea8f60 100644 --- a/gnome/gtrans.c +++ b/gnome/gtrans.c @@ -10,14 +10,18 @@ #include "gdesktop.h" #include "gcache.h" #include + /* The spacing between the cute little icon and the text */ #define SPACING 2 -int want_transparent = 0; -/* - * Most of this code was yanked from the gtktooltips module in Gtk+. - * I have tweaked it a bit for MC's purposes - Federico +int want_transparent_icons = 1; +int want_transparent_text = 0; + + +/* Most of the word-wrapping code was yanked from the gtktooltips + * module in Gtk+. I have tweaked it a bit for MC's purposes + * - Federico */ struct text_info { @@ -178,7 +182,7 @@ set_window_text (GtkWidget *window, GdkImlibImage *im, char *text) GdkBitmap *im_mask; struct text_info *ti; GdkColor color; - GdkGC *gc; + GdkGC *p_gc, *m_gc; int width, height; ti = layout_text (window, text); @@ -186,60 +190,133 @@ set_window_text (GtkWidget *window, GdkImlibImage *im, char *text) width = MAX (ti->width, im->rgb_width); height = im->rgb_height + SPACING + ti->height; - /* pixmap */ + /* Create pixmap, mask, and gc's */ pixmap = gdk_pixmap_new (window->window, width, height, gdk_imlib_get_visual ()->depth); - - gc = gdk_gc_new (pixmap); - - gdk_color_white (gdk_imlib_get_colormap (), &color); - gdk_gc_set_foreground (gc, &color); - gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, width, height); - - im_pixmap = gdk_imlib_move_image (im); - gdk_window_copy_area (pixmap, gc, - (width - im->rgb_width) / 2, - 0, - im_pixmap, - 0, 0, - im->rgb_width, im->rgb_height); - gdk_imlib_free_pixmap (im_pixmap); - - /* mask */ - mask = gdk_pixmap_new (window->window, width, height, 1); - gc = gdk_gc_new (mask); + p_gc = gdk_gc_new (pixmap); + m_gc = gdk_gc_new (mask); + + /* Fill mask with transparent */ color.pixel = 0; - gdk_gc_set_foreground (gc, &color); - gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height); + gdk_gc_set_foreground (m_gc, &color); + gdk_draw_rectangle (mask, + m_gc, + TRUE, + 0, 0, + width, height); + /* Icon */ + + im_pixmap = gdk_imlib_move_image (im); im_mask = gdk_imlib_move_mask (im); + + if (!want_transparent_icons) { + /* black background */ + + gdk_color_black (gdk_imlib_get_colormap (), &color); + gdk_gc_set_foreground (p_gc, &color); + gdk_draw_rectangle (pixmap, + p_gc, + TRUE, + (width - im->rgb_width) / 2, + 0, + im->rgb_width, + im->rgb_height); + + /* opaque mask */ + + color.pixel = 1; + gdk_gc_set_foreground (m_gc, &color); + gdk_draw_rectangle (mask, + m_gc, + TRUE, + (width - im->rgb_width) / 2, + 0, + im->rgb_width, + im->rgb_height); + } else if (im_mask) + gdk_draw_pixmap (mask, + m_gc, + im_mask, + 0, 0, + (width - im->rgb_width) / 2, + 0, + im->rgb_width, + im->rgb_height); + if (im_mask) { - gdk_window_copy_area (mask, gc, - (width - im->rgb_width) / 2, - 0, - im_mask, - 0, 0, - im->rgb_width, im->rgb_height); + gdk_gc_set_clip_mask (p_gc, im_mask); + gdk_gc_set_clip_origin (p_gc, (width - im->rgb_width) / 2, 0); + } + + gdk_draw_pixmap (pixmap, + p_gc, + im_pixmap, + 0, 0, + (width - im->rgb_width) / 2, + 0, + im->rgb_width, + im->rgb_height); + + if (im_mask) { + gdk_gc_set_clip_mask (p_gc, NULL); gdk_imlib_free_bitmap (im_mask); } + + gdk_imlib_free_pixmap (im_pixmap); - color.pixel = 1; - gdk_gc_set_foreground (gc, &color); - paint_text (ti, mask, gc, + /* Text */ + + if (!want_transparent_text) { + /* black background */ + + gdk_color_black (gdk_imlib_get_colormap (), &color); + gdk_gc_set_foreground (p_gc, &color); + gdk_draw_rectangle (pixmap, + p_gc, + TRUE, + (width - ti->width) / 2, + im->rgb_height + SPACING, + ti->width, + ti->height); + + /* opaque mask */ + + color.pixel = 1; + gdk_gc_set_foreground (m_gc, &color); + gdk_draw_rectangle (mask, + m_gc, + TRUE, + (width - ti->width) / 2, + im->rgb_height + SPACING, + ti->width, + ti->height); + } else { + color.pixel = 1; + gdk_gc_set_foreground (m_gc, &color); + paint_text (ti, mask, m_gc, + (width - ti->width) / 2, + im->rgb_height + SPACING); + } + + gdk_color_white (gdk_imlib_get_colormap (), &color); + gdk_gc_set_foreground (p_gc, &color); + paint_text (ti, pixmap, p_gc, (width - ti->width) / 2, im->rgb_height + SPACING); - gdk_gc_destroy (gc); - - /* set contents */ + /* Set contents of window */ gtk_widget_set_usize (window, width, height); gdk_window_set_back_pixmap (window->window, pixmap, FALSE); gdk_window_shape_combine_mask (window->window, mask, 0, 0); + gdk_gc_destroy (p_gc); + gdk_gc_destroy (m_gc); + gdk_pixmap_unref (pixmap); gdk_pixmap_unref (mask);