Chinaunix首页 | 论坛 | 博客
  • 博客访问: 191088
  • 博文数量: 49
  • 博客积分: 2065
  • 博客等级: 大尉
  • 技术积分: 413
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-08 17:04
文章分类

全部博文(49)

文章存档

2012年(2)

2010年(17)

2009年(30)

我的朋友

分类:

2009-10-26 17:51:51

   要想摒弃控件默认的效果,实现自己想要的任意效果,就只能自己对控件进行重绘
   做了gtkcheckbutton和gtkscale控件,顺便总结如下:

checkbutton的实现:

const char *sound_on    = "./skin/res/sound_on.png";
const char *sound_off   = "./skin/res/sound_off.png";

static gboolean sound_check_button_expose_event_cb(GtkWidget *widget,
                                                   GdkEventExpose *event,
                                                   gpointer user_data)
{
    gboolean bActive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));

    cairo_surface_t *surface = NULL;
    cairo_t *cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));

    if(bActive)
    {
        surface = cairo_image_surface_create_from_png(sound_on);   
    }
    else
    {
        surface = cairo_image_surface_create_from_png(sound_off);               
    }

    cairo_set_source_surface(cr, surface, widget->allocation.x, widget->allocation.y);
    cairo_paint(cr);

    cairo_surface_destroy(surface);
    cairo_destroy(cr);

    return TRUE;
}
在此有点取巧:创建的checkbutton和对应的button效果图的大小是一样大的,由于是触摸设备,未实现鼠标hover效果


gtkscale的重绘制:

static gboolean sound_scale_expose_event_cb(GtkWidget *widget,
                                            GdkEventExpose *event,
                                            gpointer user_data)
{
    GtkRange *pRange = (GtkRange*) widget;
    cairo_surface_t *surface = NULL;
    cairo_t *cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));

    //
    surface = cairo_image_surface_create_from_png(sound_left);
    cairo_set_source_surface(cr, surface, widget->allocation.x,
                             widget->allocation.y);
    cairo_paint(cr);
    cairo_surface_destroy(surface);

    //
    surface = cairo_image_surface_create_from_png(sound_btn);
    cairo_set_source_surface(cr, surface,
                              widget->allocation.x + pRange->slider_start,
                             widget->allocation.y);
    cairo_paint(cr);
    cairo_surface_destroy(surface);

    cairo_destroy(cr);
    return TRUE;
}
阅读(2232) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~