I have been using Clutter together with Vala for some time now.

It is a pleasure to work with Vala, but I have had some problems with clutter (especially with signals that do not seem to work for some reason).

I'm having a hard time finding examples on how to use signals in clutter-vala.

Google and this site didn't come up with anything useful.

Can someone give me a working clutter-vala example where button_press_event is used? (I assume this is the event that is triggered when clicking an actor)

有帮助吗?

解决方案

private static int main (string[] args) {
  Clutter.init (ref args);

  var stage = new Clutter.Stage ();
  var rect = new Clutter.Actor ();
  rect.set_size (100, 100);
  rect.set_position (100, 100);
  rect.set_background_color ({ 0xcc, 0xcc, 0xcc, 0xff });
  stage.add_child (rect);
  stage.show_all ();

  rect.reactive = true; // <- probably what you're missing
  rect.button_press_event.connect ((evt) => {
      GLib.message ("Button pressed");
      return true;
    });

  Clutter.main ();

  return 0;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top