自定义容器未绘制

发布于 2024-12-23 15:25:18 字数 2940 浏览 0 评论 0 原文

在过去的几天里,我一直在阅读有关 Vala 的文章,并决定深入研究它并在此过程中制作一些 Clutter 小部件。我目前正在尝试从我的自定义演员子类中绘制一个私人演员。这是我迄今为止所得到的简化版本。

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。

I've been reading about Vala over the past couple of days and decided to dive into it and make some Clutter widgets along the way. I'm currently trying to draw a private actor from my custom actor subclass. Here is a simplified version of what I've got so far.

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;
}

The example paints the group added directly to the stage, but not the group wrapped by the custom collection that is added to the stage. How can I get this to work and what is wrong with the above?

I've been working on ubuntu 11.10 with valac --pkg clutter-1.0 above_code_example.vala.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凝望流年 2024-12-30 15:25:18

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

This answer is from buz on gnome.irc's #clutter room.
The problem is a missing override for the allocate function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文