0

我想使用 cairo 图形创建自定义演员。我正在使用 cluttermm 和 clutter-gtkmm。根据朋友的一些建议和代码,这种方式可以在clutter(不是cluttermm)中实现。瓦拉的一个例子:

using Clutter;

void
main(string[] args)
{
    Clutter.init(ref args);
    
    // note: the Clutter.Texture API is deprecrated, but the API that
    // replaced it is very cumbersome, so we just stick with
    // Clutter.Texture
    var linus = new Texture.from_file("Linus_Torvalds.jpeg");
    
    int width, height;
    linus.get_base_size(out width, out height);
    
    var stage = new Stage() {
        width = width,
        height = height};
    
    stage.add_child(linus);
    
    var canvas = new Canvas() {
        width = width,
        height = height };
    canvas.draw.connect((cr, width, height) => {
        cr.set_line_width(10);
        cr.set_source_rgba(0, 0, 0, 1);
        cr.move_to(310, 355);
        cr.line_to(260, 340);
        cr.stroke();
        return true;
    });
    var canvasActor = new Actor() {
        x = 0,
        y = 0,
        width = width,
        height = height,
        content = canvas };
    stage.add_child(canvasActor);
    canvas.invalidate();
        stage.show();
    stage.destroy.connect(Clutter.main_quit);
    Clutter.main();
}

但是当我想在 cluttermm 和 clutter-gtkmm 中执行此操作时,我遇到了错误。

Cannot initialize a member subobject of type 'Clutter::Content *' with an rvalue of type 'Clutter::Canvas *'

我知道我可以使用 cogl api,但我认为 Cairo 是 2d 绘图的更好选择。请帮我。

4

0 回答 0