changeset 2629:b74421e92d55

[gaim-migrate @ 2642] just one little detail left. if you've got the panel set up to use a pixmap, when you add the applet, it gets the back_change signal, but the file is still NULL. i'm counting this as a gnome bug but can't see a workaround yet. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 27 Oct 2001 08:27:40 +0000
parents 4054a0849461
children 5004f7eb3d4d
files src/applet.c
diffstat 1 files changed, 109 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/applet.c	Sat Oct 27 02:49:01 2001 +0000
+++ b/src/applet.c	Sat Oct 27 08:27:40 2001 +0000
@@ -50,15 +50,102 @@
 static GtkAllocation *get_applet_pos(gboolean);
 static gint sizehint = 48;
 
+static PanelBackType backtype = PANEL_BACK_NONE;
+static GdkColor *backcolor = NULL;
+static char *backfile = NULL;
+
+static void make_background(guchar *dest)
+{
+	guchar *p;
+	int r,g,b,i;
+
+	if (backcolor && (backtype == PANEL_BACK_COLOR)) {
+		guchar *p;
+		int r,g,b,i;
+
+		r = backcolor->red>>8;
+		g = backcolor->green>>8;
+		b = backcolor->blue>>8;
+		p = dest;
+		for (i = 0; i < sizehint * sizehint; i++) {
+			*p++ = r;
+			*p++ = g;
+			*p++ = b;
+		}
+		return;
+	} else if (backfile && (backtype == PANEL_BACK_PIXMAP)) {
+		GdkPixbuf *pb = gdk_pixbuf_new_from_file(backfile);
+		if (pb) {
+			int dw = sizehint;
+			int dh = sizehint;
+			int offx = applet->allocation.x;
+			int offy = applet->allocation.y;
+			int drs = dw * 3;
+			guchar *tile = gdk_pixbuf_get_pixels(pb);
+			int w = gdk_pixbuf_get_width(pb);
+			int h = gdk_pixbuf_get_height(pb);
+			int rowstride = gdk_pixbuf_get_rowstride(pb);
+			int has_alpha = gdk_pixbuf_get_has_alpha(pb);
+
+			guchar *p;
+			int i,j,x,y,a;
+			guchar *imgrow;
+			int off;
+
+			p = dest;
+			y = offy % h;            
+			off = drs - (dw*3); /*the space after width ends until next row*/
+			for(j=0;j<dh;j++) {      
+				x = offx % w;    
+				imgrow = tile + y * rowstride + (has_alpha?/*x*4*/x<<2:x*3);
+				for(i=0;i<dw;i++) {
+					*(p++) = *(imgrow++);
+					*(p++) = *(imgrow++);
+					*(p++) = *(imgrow++);
+					if(has_alpha) {
+						a = *(imgrow++);
+						if(a!=255) {
+							guchar *pp = p-3;
+							pp[0] = (pp[0]*a)>>8;
+							pp[1] = (pp[1]*a)>>8;
+							pp[2] = (pp[2]*a)>>8;
+						}
+					}
+					x++;
+					if(x>=w) {
+						x = 0;
+						imgrow = tile + y * rowstride;
+					}
+				}
+				p += off; 
+				y++;
+				if(y>=h)
+					y = 0;
+			}
+			gdk_pixbuf_unref(pb);
+			return;
+		}
+	}
+
+	r = applet->style->bg[GTK_WIDGET_STATE(applet)].red>>8;
+	g = applet->style->bg[GTK_WIDGET_STATE(applet)].green>>8;
+	b = applet->style->bg[GTK_WIDGET_STATE(applet)].blue>>8;
+	p = dest;
+	for (i = 0; i < sizehint * sizehint; i++) {
+		*p++ = r;
+		*p++ = g;
+		*p++ = b;
+	}
+}
+
 static GdkPixmap *get_applet_icon(const char *name)
 {
 	GdkPixmap *cache;
 	GdkGC *gc;
 	char *path;
 	GdkPixbuf *pb, *scale;
-	guchar *dst, *p;
+	guchar *dst;
 	double affine[6];
-	int r,g,b,i;
 
 	if (!applet)
 		return NULL;
@@ -76,15 +163,7 @@
 	pb = gdk_pixbuf_scale_simple(scale, sizehint, sizehint, GDK_INTERP_HYPER);
 
 	dst = g_new0(guchar, sizehint*sizehint*3);
-	r = applet->style->bg[GTK_WIDGET_STATE(applet)].red>>8;
-	g = applet->style->bg[GTK_WIDGET_STATE(applet)].green>>8;
-	b = applet->style->bg[GTK_WIDGET_STATE(applet)].blue>>8;
-	p = dst;
-	for (i = 0; i < sizehint * sizehint; i++) {
-		*p++ = r;
-		*p++ = g;
-		*p++ = b;
-	}
+	make_background(dst);
 
 	art_affine_identity(affine);
 	if (gdk_pixbuf_get_has_alpha(pb))
@@ -161,6 +240,24 @@
 	return TRUE;
 }
 
+static void back_changed(AppletWidget *applet, PanelBackType type, char *file, GdkColor *clr)
+{
+	backtype = type;
+	if (backfile)
+		g_free(backfile);
+	if (file)
+		backfile = g_strdup(file);
+	else
+		backfile = NULL;
+	if (backcolor)
+		gdk_color_free(backcolor);
+	if (clr)
+		backcolor = gdk_color_copy(clr);
+	else
+		backcolor = NULL;
+	update_applet();
+}
+
 #ifdef HAVE_PANEL_PIXEL_SIZE
 static void applet_change_pixel_size(GtkWidget *w, int size, gpointer data)
 {
@@ -342,6 +439,7 @@
 	applet = applet_widget_new("gaim_applet");
 	if (!applet)
 		g_error(_("Can't create Gaim applet!"));
+	gtk_signal_connect(GTK_OBJECT(applet), "back_change", GTK_SIGNAL_FUNC(back_changed), NULL);
 	gtk_widget_set_events(applet, gtk_widget_get_events(applet) | GDK_BUTTON_PRESS_MASK);
 	gtk_widget_realize(applet);