开罗:把整个画作为一种模式 [英] Cairo: grabbing the whole drawing as a pattern

查看:173
本文介绍了开罗:把整个画作为一种模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能缺少关于 cairo 的概念。我使用以下帮助类绘制:

I am probably missing something conceptual about cairo. I draw using the following helper class:

struct GroupLock {
    GroupLock(Graphics &g) : g_(g) {
        cairo_push_group(g_.cr);
    }

    ~GroupLock() {
        cairo_pop_group_to_source(g_.cr);
        cairo_paint(g_.cr);
        cairo_surface_flush(g_.surface);
        XFlush(g_.display);
    }
private:
    Graphics &g_;
};

我的所有绘图函数都是以下形式:

All my drawing functions are of the form:

void drawSomething(Graphics &g) {
    GroupLock lock{g}; (void)lock;
    ... // some drawing
}

绘图函数设置(通过使用 GroupLock ),并使之前的无法访问。如何修改此代码以并置?我希望能够通过执行以下操作来抓取整个绘图:

Each call to such a drawing function sets the source (by virtue of using GroupLock) and makes the previous source unreachable. How can I modify this code to "concatenate" the sources instead? I would like be able to grab the whole drawing as a pattern by doing:

cairo_pattern_t *p_ = cairo_get_source(g_.cr);
cairo_pattern_reference(p_);


推荐答案

经过几个小时的努力后,所有需要做的是修改构造函数读取这样:

After struggling for hours, here it is! All that needed to be done is to modify the constructor to read like this:

p_ = cairo_get_source(g_.cr);
cairo_pattern_reference(p_);

cairo_push_group(g_.cr);
cairo_set_source (g_.cr, p_);
cairo_paint(g_.cr);
cairo_pattern_destroy(p_);

这篇关于开罗:把整个画作为一种模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆