概述
#define NUM_PIXBUF 6
void register_stock_icons (void)
{
static gboolean registered = FALSE;
if (!registered)
{
gint i;
GdkPixbuf *pixbuf[NUM_PIXBUF];
GtkIconFactory *factory[NUM_PIXBUF];
static GtkStockItem items[] =
{
{ "demo_3d", "3D", 0, 0, NULL },
{ "demo_top", "TOP", 0, 0, NULL },
{ "demo_left", "LEFT", 0, 0, NULL },
{ "demo_front", "FRONT",0, 0, NULL },
{ "demo_run", "RUN", 0, 0, NULL },
{ "demo_show", "SHOW", 0, 0, NULL }
};
registered = TRUE;
/* Register our stock items */
gtk_stock_add (items, G_N_ELEMENTS (items));
for(i=0;i<NUM_PIXBUF;i++)
{
/* Add our custom icon factory to the list of defaults */
factory[i] = gtk_icon_factory_new ();
gtk_icon_factory_add_default (factory[i]);
//
pixbuf[i] = NULL;
}
pixbuf[0] = gdk_pixbuf_new_from_file ("./image/3D.png", NULL);
pixbuf[1] = gdk_pixbuf_new_from_file ("./image/top.png", NULL);
pixbuf[2] = gdk_pixbuf_new_from_file ("./image/left.png", NULL);
pixbuf[3] = gdk_pixbuf_new_from_file ("./image/front.png", NULL);
pixbuf[4] = gdk_pixbuf_new_from_file ("./image/run.png", NULL);
pixbuf[5] = gdk_pixbuf_new_from_file ("./image/show.png", NULL);
/* Register icon to accompany stock item */
GtkIconSet *icon_set[NUM_PIXBUF];
GdkPixbuf *transparent[NUM_PIXBUF];
for(i=0;i<NUM_PIXBUF;i++)
{
if (pixbuf[i] != NULL)
{
/* The gtk-logo-rgb icon has a white background, make it transparent */
transparent[i] = gdk_pixbuf_add_alpha (pixbuf[i], TRUE, 0xff, 0xff, 0xff);
icon_set[i] = gtk_icon_set_new_from_pixbuf (transparent[i]);
switch(i)
{
case 0 :
gtk_icon_factory_add (factory[i], "demo_3d", icon_set[i]);
break;
case 1 :
gtk_icon_factory_add (factory[i], "demo_top", icon_set[i]);
break;
case 2 :
gtk_icon_factory_add (factory[i], "demo_left", icon_set[i]);
break;
case 3 :
gtk_icon_factory_add (factory[i], "demo_front", icon_set[i]);
break;
case 4 :
gtk_icon_factory_add (factory[i], "demo_run", icon_set[i]);
break;
case 5 :
gtk_icon_factory_add (factory[i], "demo_show", icon_set[i]);
break;
}
gtk_icon_set_unref (icon_set[i]);
g_object_unref (pixbuf[i]);
g_object_unref (transparent[i]);
}
else
g_warning ("failed to load GTK logo for toolbar");
/* Drop our reference to the factory, GTK will hold a reference. */
g_object_unref (factory[i]);
}
}
}
最后
以上就是自觉草丛为你收集整理的GTK+ 自定义图标函数的全部内容,希望文章能够帮你解决GTK+ 自定义图标函数所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复