我正在玩雜波/開羅,我試圖畫一個矩形;但是,看起來set_source_rgb
會自動繪製整個畫布及其來源,無論我是否告訴它繪製矩形(即,即使刪除了ctx.rectangle()
和ctx.fill()
線條,矩形仍然繪製)。爲什麼是這樣?我需要做什麼才能讓矩形做繪畫而不是set_source_rgb?爲什麼Cairo.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;
}
這解決了它。謝謝!我去掉了調用'paint()'和'scale()'。 – weberc2