【问题标题】:How to draw a texture as background in gtk?如何在gtk中绘制纹理作为背景?
【发布时间】:2012-10-25 18:58:40
【问题描述】:

我想在 gtk 容器中添加纹理作为背景,可以吗?

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

谢谢:)

pd:sorry 4 ma 英语

【问题讨论】:

    标签: background gtk vala


    【解决方案1】:

    我是这样做的:

        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;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-05-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 1970-01-01
      • 2018-09-20
      相关资源
      最近更新 更多