我正在玩杂物/开罗,我正在尝试绘制一个矩形;set_source_rgb
但是,无论我是否告诉它绘制一个矩形,它似乎都会自动使用其源绘制整个画布(也就是说,即使我删除了ctx.rectangle()
和ctx.fill()
线,矩形仍然被绘制)。为什么是这样?我需要做什么才能让矩形而不是 set_source_rgb 进行绘画?
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);
//Why is this rectangle drawn even when I remove these lines?
ctx.rectangle(0,0,200,200);
ctx.fill();
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();
stage.add_child(a);
a.canvas.invalidate();
stage.show_all();
Clutter.main();
return 0;
}