title: Howto sub class a Clutter.Actor (involves Cairo/Clutter.Canvas)
body: <p>Can anyone help me get this to run? I'm aiming for a custom Actor. (I have only just started hacking with Vala in the last few days and Clutter is a mystery too.)</p>
  
  <p>The drawme method is being run (when invalidate is called) but there doesn't seem to be any drawing happening (via the Cairo context).</p>
  
  <p>ETA: I added one line in the constructor to show the fix - this.set_size.</p>
  
  <pre><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);
  
          this.set_content( canvas );
          this.set_size(300,300);
  
          //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;
  }
  </code></pre>