[Vala] Access Clutter Script Actor in Event handler
- From: Brian Duffy <brduffy gmail com>
- To: clutter-app-devel-list clutter-project org, vala-list <vala-list gnome org>
- Subject: [Vala] Access Clutter Script Actor in Event handler
- Date: Wed, 25 Jan 2012 16:55:12 -0500
Hi again,
I'm trying to get clutter script working with vala. I can't figure out how
to access my rectangle in its button-press-event handler. how can I define
the params of the handler to get access to the ui object? ...
thnx
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;
}
[clutter script]
[
{
"id" : "stage",
"type" : "ClutterStage",
"width" : 300,
"height" : 300,
"color" : "#335",
"signals" : [
{ "name" : "hide", "handler" : "clutter_main_quit" }
],
"children" : [ "rectangle" ]
},
{
"id" : "rectangle",
"type" : "ClutterRectangle",
"width" : 200,
"height" : 200,
"x" : 50,
"y" : 50,
"color" : "#a90",
"rotation-center-z-gravity" : "center",
"reactive" : true,
"signals" : [
{ "name" : "button-press-event", "handler" : "button_press" }
],
"actions" : [
{
"type" : "ClutterClickAction",
"signals" : [
{ "name" : "clicked", "handler" : "button_press" }
]
}
]
}
]
--
Duff
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]