Thanks Tom,

I'll do that if I have to, but I don't like it. I can't help but feel that
there should be a way to pass user data without doing the connection in
code. They accomplish it in the Clutter Cookbook in C using a gpointer for
the ui param. I really don't want to have to retrieve every object I define
and hook up their handlers in code. But again, thanks for showing me a way
of getting it done.

On Thu, Jan 26, 2012 at 5:06 AM, tomw <[email protected]> wrote:

> Hi,
>
> if you want to pass user data to a signal handler you should connect the
> signal in the code rather than by the script. The vala code may look
> like this:
>
> using Clutter;
> using GLib;
>
> public bool button_press (Actor actor, Script ui) {
>   stdout.printf("button press event");
>    Rectangle rect = (Rectangle)ui.get_object ("rectangle");
>    rect.set_color(Color.from_string("white"));
>
>   return true;
> }
>
> public bool key_pressed (KeyEvent event) {
>        stdout.printf ("Key pressed : %d \n", event.hardware_keycode);
>        Clutter.main_quit ();
>
>        return true;
>
>        }
>
> int main (string[] args) {
>
>  //Stage stage = Stage.get_default();
>  string filename = "gui_test.json";
>
>  if (Clutter.init(ref args) != Clutter.InitError.SUCCESS) {
>     stdout.printf("Error Initializing Clutter");
>     return 1;
>  }
>
>  Script ui = new Script();
>  uint merge_id = ui.load_from_file (filename);
>  if (merge_id == 0)
>    {
>       stdout.printf("%s", "Error Loading ClutterScript");
>       return 1;
>    }
>
>   //ui.connect_signals (null);
>
>  Stage stage = (Stage)ui.get_object ("stage");
>   stage.button_press_event.connect (() => {button_press (stage, ui);
> return true;});
>  stage.key_press_event.connect (key_pressed);
>  stage.show_all();
>  Clutter.main();
>  return 0;
> }
>
>
> and the json-file (slightly simpler) like this:
>
> [
>  {
>    "id" : "stage",
>    "type" : "ClutterStage",
>    "width" : 300,
>    "height" : 300,
>    "color" : "#335",
>    "signals" : [
>        { "name" : "hide", "handler" : "clutter_main_quit" }
>    ],
>    "children" : [
>         {
>                "id" : "rectangle",
>                "type" : "ClutterRectangle",
>                "width" : 200,
>                "height" : 200,
>                "x" : 50,
>                "y" : 50,
>                "color" : "#a90",
>                "rotation-center-z-gravity" : "center",
>                "reactive" : true
>        }
>
>     ]
>  }
> ]
>
>
>
>
> On Mi, 2012-01-25 at 16:55 -0500, Brian Duffy wrote:
> > using Clutter;
> > using GLib;
> >
> >
> > bool button_press (ButtonEvent event, Script ui) {   // wrong
> >    stdout.printf("%s", "button press event");
> >    Rectangle rect = (Rectangle)ui.get_object ("rectangle");  // this
> > segfaults
> >    //rect.set_color(Color.from_string("white"));
> >    return true;
> > }
> >
> >
> > int main (string[] args) {
> >
> >   //Stage stage = Stage.get_default();
> >   string filename = "gui_test.json";
> >
> >   if (Clutter.init(ref args) != Clutter.InitError.SUCCESS) {
> >     stdout.printf("%s", "Error Initializing Clutter");
> >     return 1;
> >   }
> >
> >   Script ui = new Script();
> >   uint merge_id = ui.load_from_file (filename);
> >   if (merge_id == 0)
> >     {
> >        stdout.printf("%s", "Error Loading ClutterScript");
> >        return 1;
> >     }
> >
> >   ui.connect_signals (ui);
> >
> >   Stage stage = (Stage)ui.get_object ("stage");
> >   /* make the objects in the script available to all signals
> >    * by passing the script as the second argument
> >    * to clutter_script_connect_signals()
> >    */
> >
> >   stage.show_all();
> >
> >   Clutter.main();
> >
> >   return 0;
> > }
>
>


-- 
Duff
_______________________________________________
clutter-app-devel-list mailing list
[email protected]
http://lists.clutter-project.org/listinfo/clutter-app-devel-list

Reply via email to