如何在gtk中绘制纹理作为背景?

时间:2012-10-25 18:58:41

标签: background gtk vala

我想在gtk容器中添加纹理作为背景,是否可能?

我想要的是类似于css中的repeat-x repeat-y属性,但是在gtk中它还不支持,所以,如何在没有任何丑陋的黑客的情况下做到这一点?另一个例子是鹦鹉螺有什么,你可以在哪里改变背景。

谢谢:)

pd:抱歉4 ma english

1 个答案:

答案 0 :(得分:0)

我是这样做的:

    private bool draw_background (Cairo.Context cr) {

    int width = this.get_allocated_width ();
    int height = this.get_allocated_height ();

    cr.set_operator (Cairo.Operator.CLEAR);
    cr.paint ();
    cr.set_operator (Cairo.Operator.OVER);

    var background_style = this.get_style_context ();
    background_style.render_background (cr, 0, 0, width, height);
    background_style.render_frame (cr, 0, 0, width, height);

    var pat = new Cairo.Pattern.for_surface (new Cairo.ImageSurface.from_png (Build.PKGDATADIR + "/files/texture.png"));
    pat.set_extend (Cairo.Extend.REPEAT);
    cr.set_source (pat);
    cr.paint_with_alpha (0.6);

    return false;
}