Draw custom Clutter::Actor using cairo

41 views Asked by At

I want to create a custom actor using cairo graphic. I am using cluttermm and clutter-gtkmm. According to some recommendations and codes of friends, this way it can be implemented in the clutter(not cluttermm). an example in vala :

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

but when i want to do this in cluttermm and clutter-gtkmm, I'm getting an error.

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

I know i can use cogl api but i think Cairo is better option for 2d drawing. Please help me.

0

There are 0 answers