设定xfce工具栏图标背景的几种方法
来源:互联网 发布:java基础入门 编辑:程序博客网 时间:2024/05/20 07:59
现在有这么一个需求,需要将xfce工具栏上图标的背景设置成指定的背景,那么可以用下面几种方法:
1.修改~/.gtkrc-2.0,这个方法最简单,可以参考:
http://wiki.archlinux.org/index.php/Xfce_%28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%29#.E5.A6.82.E4.BD.95.E8.AE.A9.E6.A1.8C.E9.9D.A2.E5.9B.BE.E6.A0.87.E6.A0.87.E7.AD.BE.E5.AD.97.E4.BD.93.E8.83.8C.E6.99.AF.E9.80.8F.E6.98.8E
2.
- gtk_widget_set_app_paintable (GTK_WIDGET (item), TRUE);
- //设定控件显示时的回调函数
- g_signal_connect(item, "expose-event",G_CALLBACK(transparent_expose), NULL)
- static gboolean
- transparent_expose (GtkWidget *item,
- GdkEventExpose *event)
- {
- GdkPixmap *gdk_pixmap;
- GdkPixbuf *gdk_pixbuf,*gdk_pixbuf_tmp;
- GdkBitmap *mask;
- gint w, h;
- gtk_window_get_size (GTK_WINDOW (item), &w, &h);
- gdk_pixbuf_tmp = gdk_pixbuf_new_from_file (“./background.png”, NULL);
- gdk_pixbuf = gdk_pixbuf_scale_simple (gdk_pixbuf_tmp, w, h, GDK_INTERP_BILINEAR);
- g_object_unref (G_OBJECT(gdk_pixbuf_tmp));
- gdk_pixbuf_render_pixmap_and_mask (gdk_pixbuf, &gdk_pixmap,&mask, 255);
- gdk_window_set_back_pixmap (GTK_WIDGET (item)->window, gdk_pixmap, FALSE);
- gtk_widget_shape_combine_mask (GTK_WIDGET (item), mask, 0, 0);
- //将widget->window背景设定为 ./background.png
- }
或者
- static gboolean
- transparent_expose (GtkWidget *widget,
- GdkEventExpose *event)
- {
- GdkPixbuf *gdk_pixbuf, *gdk_pixbuf_tmp;
- GdkPixmap *gdk_pixmap;
- gdk_pixbuf_tmp = gdk_pixbuf_new_from_file("./background.png", NULL);
- gdk_pixbuf = gdk_pixbuf_scale_simple (gdk_pixbuf_tmp, widget->allocation.width, widget->allocation.height , GDK_INTERP_BILINEAR);
- gdk_pixbuf_render_pixmap_and_mask ( gdk_pixbuf, &gdk_pixmap,NULL, 127);
- g_object_unref(G_OBJECT(gdk_pixbuf_tmp));
- g_object_unref(G_OBJECT(gdk_pixbuf));
- gdk_draw_drawable (widget->window,
- widget->style->black_gc,
- gdk_pixmap,
- 0,
- 0,
- widget->allocation.x,
- widget->allocation.y,
- widget->allocation.width,
- widget->allocation.height );
- g_object_unref(G_OBJECT(gdk_pixmap));
- return FALSE;
- }
3.
- static void
- update_background(GtkWidget *widget, gchar *img_file, gint size)
- {
- GdkPixbuf *style_pixbuf_tmp, *style_pixbuf;
- GdkPixmap *style_pixmap;
- GtkStyle *style;
- // 从文件读取背景图
- style_pixbuf_tmp = gdk_pixbuf_new_from_file(img_file, NULL);
- gint pic_width, pic_height;
- gboolean pic_alpha;
- pic_width = gdk_pixbuf_get_width(style_pixbuf_tmp);
- pic_height = gdk_pixbuf_get_height(style_pixbuf_tmp);
- pic_alpha = gdk_pixbuf_get_has_alpha(style_pixbuf_tmp);
- style_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, pic_alpha, 8, size, size + 2);
- // 将style_pixbuf_tmp复制到style_pixbuf
- gdk_pixbuf_scale(style_pixbuf_tmp, style_pixbuf, 0, 0, size, size + 2,
- 0, -2, (double)size/pic_width, (double)(size + 4)/pic_height,
- GDK_INTERP_BILINEAR);
- g_object_unref(style_pixbuf_tmp);
- // 从style_pixbuf,获取style_pixmap
- gdk_pixbuf_render_pixmap_and_mask(style_pixbuf, &style_pixmap, NULL, 0);
- g_object_unref(style_pixbuf);
- // 获得控件的初始style
- style = gtk_style_copy(GTK_WIDGET (widget)->style);
- if (style->bg_pixmap[GTK_STATE_NORMAL])
- g_object_unref(G_OBJECT(style->bg_pixmap[GTK_STATE_NORMAL]));
- // 将style_pixmap画到控件背景上
- style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref(style_pixmap);
- gtk_widget_set_style(GTK_WIDGET (widget), style);
- g_object_unref(style_pixmap);
- }
另外,在GNOME开发手册中,对于expose-event事件中实现图片背景的例子也可以借鉴一下:
http://library.gnome.org/devel/gdk-pixbuf/stable/gdk-pixbuf-scaling.html#gdk-pixbuf-scale
- gboolean
- expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
- {
- GdkPixbuf *dest;
- dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height);
- gdk_pixbuf_composite_color (pixbuf, dest,
- 0, 0, event->area.width, event->area.height,
- -event->area.x, -event->area.y,
- (double) widget->allocation.width / gdk_pixbuf_get_width (pixbuf),
- (double) widget->allocation.height / gdk_pixbuf_get_height (pixbuf),
- GDK_INTERP_BILINEAR, 255,
- event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);
- gdk_draw_pixbuf (widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], dest,
- 0, 0, event->area.x, event->area.y,
- event->area.width, event->area.height,
- GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y);
- gdk_pixbuf_unref (dest);
- return TRUE;
- }
函数原型,以及参数的含义:
- void gdk_pixbuf_scale (const GdkPixbuf *src,
- GdkPixbuf *dest,
- int dest_x,//目的图片的偏移量
- int dest_y,
- int dest_width,//源图片复制到目的图片的宽度
- int dest_height,
- double offset_x,//源图片的偏移量
- double offset_y,
- double scale_x,//要复制的源图片倍数
- double scale_y,
- GdkInterpType interp_type);
Figure 1. Compositing of pixbufs
src
:
dest
:
dest_x
:
dest_y
:
dest_width
:
dest_height
:
offset_x
:
offset_y
:
scale_x
:
scale_y
:
interp_type
:
overall_alpha
:
- 设定xfce工具栏图标背景的几种方法
- 工具栏图标背景透明化
- WPF工具栏图标托盘图标的添加方法
- Ubuntu下程序图标的设定方法
- xfce的panel图标置右操作
- 设置对话框背景的几种方法
- OpenCV背景去除的几种方法
- OpenCV背景去除的几种方法
- OpenCV背景去除的几种方法
- OpenCV背景去除的几种方法
- MediaPlayer中设定数据源的几种方法
- 设置工具栏图标背景颜色为透明
- 工具栏图标的加载
- 如何设定Fckeditor的工具栏
- 最近做了几套工具栏图标
- 在notification显示音乐图标,设置图标背景的方法
- 网站 浏览器 头部 的小图标 设定 方法
- 添加工具栏的图标按钮
- jQuery UI Layout
- C++中虚函数的作用
- char[] 与char*的区别
- #include <filename.h> 和 #include “filename.h” 有什么区别?
- C语言深度解剖读书笔记之——C语言基础测试题
- 设定xfce工具栏图标背景的几种方法
- C#编写的发送手机短信的类库 && C#开发短信的方法和简介 &&短信编程实例
- html中制表符(TAB)的转义字符
- hdu 1532Drainage Ditches
- 基于Socket的UDP和TCP编程介绍
- JAVA在类继承中类成员变量“重写”的问题
- BASH命令和SHELL脚本总结(17)在BASH中计算两天的间隔天数
- 技术出身的项目经理容易犯的一个错误
- 关于火狐firework屏蔽非80端口含有AJAX页面运行的解决之道