Re: launcher-style icons



Here is a simple, working example (with GNome 1.4Beta, anyway), for
Gnome programmers' archive-searching pleasure; thanks to everyone who
helped!


/*
 *
 * rudimentary alpha-blended gnome panel icon example
 *
 * (c) Michael Rothwell, 2001
 * rothwell holly-springs nc us
 * Freely reusable under the GPL
 *
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif
#ifdef HAVE_FCNTL_H
#	include <fcntl.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#	include <sys/types.h>
#endif
#include <gnome.h>
#include <gnome-panel.h>
#include <applet-widget.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

GtkWidget *applet;
GtkWidget	*da;
GtkWidget	*parent;
GtkWidget	*parentwindow;
GdkPixbuf *pb = NULL;
GdkPixbuf *panel_pb = NULL;
GdkPixbuf *rendered_pb = NULL;


void get_panel_graphic()
{
	guchar *rgb = NULL;
	int w, h, rs;
	printf("get_panel_graphic\n");

	applet_widget_get_rgb_bg(APPLET_WIDGET(applet),
				 &rgb, &w, &h, &rs);
	if (rgb == NULL)
	{	
		printf("rgb==NULL\n");
		return;
	};
	printf("details: %d x %d, %d\n",w,h,rs);
	panel_pb = gdk_pixbuf_new_from_data(rgb, GDK_COLORSPACE_RGB, FALSE, 8,
					   w, h, rs, NULL, NULL);
	gdk_pixbuf_composite(pb,panel_pb,0,0,w,h,0,0,1,1,GDK_INTERP_BILINEAR,255);
	gdk_pixbuf_render_to_drawable_alpha 
	(
		panel_pb,
		da->window,
		0, 0,
		0, 0,
		48, 48,
		GDK_PIXBUF_ALPHA_FULL,
		1, 
		GDK_RGB_DITHER_MAX,
		0, 0
	);
	gdk_pixbuf_unref(panel_pb);
	return;
};

int
main(int argc, char **argv)
{
	char			*iconfilename=NULL;
	

	iconfilename=gnome_pixmap_file("gtele-icon.png");
	pb=gdk_pixbuf_new_from_file("gtele-icon.png");
	if (pb==NULL)
	{
		printf("cannot load image\n");
		exit(1);
	};
	
	/* widget goodness */
	applet_widget_init("gtele",NULL,argc,argv,NULL,0,NULL);

	gdk_rgb_init();
	
	applet=applet_widget_new("gtele");
	if (!applet)
		g_error("cannot create applet\n\n");

	applet_widget_send_position(APPLET_WIDGET(applet),TRUE);
	applet_widget_send_draw(APPLET_WIDGET(applet),TRUE);

	gtk_signal_connect (	GTK_OBJECT(applet),
												"do_draw",
												GTK_SIGNAL_FUNC(get_panel_graphic), 
												NULL);

	da=gtk_drawing_area_new();
	gtk_drawing_area_size(GTK_DRAWING_AREA(da),48,48); /* FIXME */
	applet_widget_add(APPLET_WIDGET(applet),GTK_WIDGET(da));
	gtk_widget_show(da);
	gtk_widget_show(applet);

	while (gtk_events_pending())
	{	
		gtk_main_iteration();
	};

	get_panel_graphic();

	parent=applet->parent;
	if (parent==NULL)
	{
		printf("no parent\n");
	};
	
	while (gtk_events_pending())
	{	
		gtk_main_iteration();
	};

	applet_widget_gtk_main();
	return 0;
}; /* main */



On 18 Apr 2001 17:13:32 -0400, Michael Rothwell wrote:
> 
> Thanks. I found a useful example in gnome-applets/clockmail/skin.c ...
> 
> -M
> 
> On 18 Apr 2001 13:55:23 -0400, jacob berkman wrote:
> > 
> > On 18 Apr 2001 11:41:40 -0400, Michael Rothwell wrote:
> > > 
> > > I've been reading the panel source. It appears that the button widget
> > > does what I want. Ive still got a couple of questions, if you have the
> > > time/inclination to answer. 
> > > 
> > > * Does the panel ever have a pixmap background?
> > 
> > yes
> > 
> > > * How do I get a copy of what's underneath my applet to composite onto?
> > 
> > from applet-widget.h:
> > 
> > /* sets if the do_draw signal is sent*/
> > void            applet_widget_send_draw         (AppletWidget *applet,
> >                                                  gboolean enable);
> > 
> > /* gets the rgb background, useful in conjunction with the do_draw
> > signal */
> > void            applet_widget_get_rgb_bg        (AppletWidget *applet,
> >                                                  guchar **rgb,
> >                                                  int *w, int *h,
> >                                                  int *rowstride);
> > 
> > there is a divider applet which uses this written by the author of
> > gqview and i believe it is on his web page.
> > 
> > jacob
> > -- 
> > "...it shoulda been 'Glee Club'." -- David Fincher
> > 
> > 
> > 
> > 
> > _______________________________________________
> > gnome-devel-list mailing list
> > gnome-devel-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gnome-devel-list
> 
> 
> _______________________________________________
> gnome-devel-list mailing list
> gnome-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-devel-list





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