Have you tried the clutter sample code from the vala site?
https://live.gnome.org/Vala/ClutterSamples
 


Am Dienstag, den 09.04.2013, 16:37 +0200 schrieb Donn:
> Greetings, hope this is the right list for getting help.
> 
> I'm fiddling with Vala and am interested in Clutter + Cairo. (I come 
> from Python, so this whole gObject and C world is very scary.)
> 
> Below's the short code I am trying to get working. I wanted to create an 
> Actor class and then add it to the stage - just to get into the swing of 
> this thing.
>   I am working from the Clutter docs (which is C) and just hacking 
> across to Vala (using the Vala docs). It's tough going.
> 
> Can anyone help me get this code to draw the custom actor? Right now 
> it's just drawing nothing. (The clutter.rectangle in red does work.)
> 
> --code--
> 
> /*
> 
> Working from the sample code at:
> https://developer.gnome.org/clutter/stable/ClutterCanvas.html
> 
> */
> 
> public class AnActor : Clutter.Actor {
> 
>       public Clutter.Canvas canvas;
> 
>       public AnActor() {
>               canvas = new Clutter.Canvas();
>               canvas.set_size(300,300);
> 
>               //Kosher???
>               this.set_content( canvas );
>       
>               //Connect to the draw signal.
>               canvas.draw.connect(drawme);
>       }
> 
>       private bool drawme( Cairo.Context ctx, int w, int h) {
>               stdout.printf("Just to test this ran at all: %d\n", w);
> 
>               ctx.scale(w,h);
>               ctx.set_source_rgb(0,0,0);
> 
>               //Rect doesn't draw.
>               //ctx.rectangle(0,0,200,200);
>               //ctx.fill();
> 
>               //paint doesn't draw.
>               ctx.paint();
> 
>               return true;
>       }
> }
> 
> 
> 
> int main(string [] args) {
>      // Start clutter.
>      var result = Clutter.init(ref args);
>      if (result != Clutter.InitError.SUCCESS) {
>          stderr.printf("Error: %s\n", result.to_string());
>          return 1;
>      }
> 
>       var stage = Clutter.Stage.get_default();
>       stage.destroy.connect(Clutter.main_quit);
> 
>       //Make my custom Actor:
>       var a = new AnActor();
> 
>       //This is dodgy:
>       stage.add_child(a);
>               
>               
>       //This works:
>       var r1 = new Clutter.Rectangle();
>       r1.width = 50;
>       r1.height = 50;
>       r1.color = Clutter.Color.from_string("rgb(255, 0, 0)");
>       stage.add_child(r1);
> 
>       a.canvas.invalidate();
>       
>       stage.show_all();
> 
>       Clutter.main();
>       return 0;
> }
> 
> 
> Compile with:
> $ valac --pkg clutter-1.0 clutter_canvas.vala
> 
> --ends--
> 
> 
> 
> 
> Thanks,
> \d


_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to