自定义容器不绘图

时间:2011-12-31 22:51:57

标签: vala clutter

过去几天我一直在阅读关于Vala的内容,并决定深入研究并在此过程中制作一些Clutter小部件。我正在尝试从我的自定义actor子类中绘制一个私有actor。这是我到目前为止的简化版本。

public class MyContainer : Clutter.Actor, Clutter.Container {
    private Clutter.Group group;

    public MyContainer() {
        group = new Clutter.Group();
        group.set_parent(this);
    }

    public void add_actor(Clutter.Actor actor) {
        group.add_actor(actor);
        actor.show();
        set_size(group.width, group.height);

        actor_added(actor);
        queue_redraw();
    }

    public void foreach(Clutter.Callback callback) {
        group.foreach(callback);
        queue_redraw();
    }

    public override void get_preferred_height(
            float for_width,
            out float min_height_p,
            out float natural_height_p) {
        group.get_preferred_height(
                for_width,
                out min_height_p,
                out natural_height_p);
    }

    public override void get_preferred_width(
            float for_height,
            out float min_width_p,
            out float natural_width_p) {
        group.get_preferred_width(
                for_height,
                out min_width_p,
                out natural_width_p);
    }

    public override void paint() {
        group.paint();
    }

    public void remove_actor(Clutter.Actor actor) {
        group.remove_actor(actor);
        set_size(group.width, group.height);

        actor_removed(actor);
        queue_redraw();
    }

    public void sort_depth_order() {
        group.sort_depth_order();
        queue_redraw();
    }
}

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

    // Build a MyCollection object.
    var myc = new MyContainer();
    myc.x = 100;
    myc.y = 100;
    var r1 = new Clutter.Rectangle();
    r1.width = 50;
    r1.height = 50;
    r1.color = Clutter.Color.from_string("rgb(255, 0, 0)");
    var t1 = new Clutter.Text();
    t1.text = "The red square.";
    t1.y = r1.height;

    // Build a Group object similar to the previous.
    var group = new Clutter.Group();
    group.x = 300;
    group.y = 100;
    var r2 = new Clutter.Rectangle();
    r2.width = 50;
    r2.height = 50;
    r2.color = Clutter.Color.from_string("rgb(255, 0, 0)");
    var t2 = new Clutter.Text();
    t2.text = "The red square.";
    t2.y = r2.height;

    // Display.
    myc.add_actor(r1);
    myc.add_actor(t1);
    group.add_actor(r2);
    group.add_actor(t2);
    stage.add_actor(myc);
    stage.add_actor(group);
    stage.show_all();

    Clutter.main();
    return 0;
}

该示例绘制直接添加到舞台的组,但不绘制添加到舞台的自定义集合包装的组。我怎样才能使这个工作以及上面有什么问题?

我一直在使用valac --pkg clutter-1.0 above_code_example.vala开发ubuntu 11.10。

1 个答案:

答案 0 :(得分:1)

这个答案来自gnome.irc的#clutter房间的buz。 问题是分配函数缺少覆盖。