seed r95 - in trunk: examples/ide examples/lightsoff libseed



Author: racarr
Date: Tue Nov  4 02:16:16 2008
New Revision: 95
URL: http://svn.gnome.org/viewvc/seed?rev=95&view=rev

Log:
Add Seed.setTimeout, and gives lightsoff an animation. Thanks matt!. 
Some random IDE changes from Tim.


Modified:
   trunk/examples/ide/ide.js
   trunk/examples/lightsoff/lightsoff.js
   trunk/libseed/seed-builtins.c

Modified: trunk/examples/ide/ide.js
==============================================================================
--- trunk/examples/ide/ide.js	(original)
+++ trunk/examples/ide/ide.js	Tue Nov  4 02:16:16 2008
@@ -112,6 +112,8 @@
     this.source_view.set_right_margin_position(80);
     this.source_view.set_mark_category_pixbuf("exception", epb.pixbuf);
     this.source_view.set_show_line_marks(true);
+    this.source_view.set_auto_indent(true);
+    this.source_view.set_indent_width(4);
     
     this.source_view.modify_font(Pango.font_description_from_string("monospace 10"));
     

Modified: trunk/examples/lightsoff/lightsoff.js
==============================================================================
--- trunk/examples/lightsoff/lightsoff.js	(original)
+++ trunk/examples/lightsoff/lightsoff.js	Tue Nov  4 02:16:16 2008
@@ -8,6 +8,7 @@
 var size = 5;
 var wincount = 0;
 var moves = 0;
+var timeout = 0;
 
 function create_board_size_menu()
 {
@@ -97,7 +98,7 @@
 	wincount = 0;
 	  
 	clear_board();
-	random_clicks(); // generate random puzzle
+	Seed.setTimeout("random_clicks()", timeout); // generate random puzzle
 	
 	moves = 0;
 }
@@ -125,6 +126,7 @@
 	if ( wincount == 0 )
 	{
 		Seed.print("GLORIOUS VICTORY in " + moves + " moves!");
+		win_animation();
 		initialize_game();
 	}
 }
@@ -196,3 +198,42 @@
 
 Gtk.main();
 
+function lightrow(start, end, col)
+{
+	if ( end > start )
+		for ( i = start; i <= end; ++i )
+			Seed.setTimeout("turn_on(buttons["+col+"]["+i+"])", timeout += 30);
+	else
+		for ( i = start; i >= end; --i )
+			Seed.setTimeout("turn_on(buttons["+col+"]["+i+"])", timeout += 30);
+}
+
+function turn_on(button)
+{
+	button.lit = true;
+	button.set_image(new Gtk.Image({"pixbuf": image_on.pixbuf}));
+}
+
+function lightcol(start, end, row)
+{
+	if ( end > start )
+		for ( var i = start; i <= end; ++i )
+			Seed.setTimeout("turn_on(buttons["+i+"]["+row+"])", timeout += 30);
+	else
+		for ( var i = start; i >= end; --i )
+			Seed.setTimeout("turn_on(buttons["+i+"]["+row+"])", timeout += 30);
+}
+
+function win_animation()
+{
+	timeout = 0;
+	var max = size - 1;
+	var i, j;
+	for ( i = 0; i <= max; ++i )
+	{
+		lightrow(i, max - i, i);
+		lightcol(i, max - i, max - i);
+		lightrow(max - i, i, max - i); 
+		lightcol(max - i, i, i);
+	}
+}

Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c	(original)
+++ trunk/libseed/seed-builtins.c	Tue Nov  4 02:16:16 2008
@@ -276,6 +276,46 @@
 	return seed_value_from_int(child);
 }
 
+static gboolean seed_timeout_function(gpointer user_data)
+{
+	// Evaluate timeout script
+	
+	const JSStringRef script = (const JSStringRef) user_data;
+	JSEvaluateScript(eng->context, script, NULL, NULL, 0, NULL);
+	JSStringRelease(script);
+
+	return FALSE; // remove timeout from main loop
+}
+
+JSValueRef
+seed_set_timeout(JSContextRef ctx,
+			  JSObjectRef function,
+			  JSObjectRef this_object,
+			  size_t argumentCount,
+			  const JSValueRef arguments[],
+			  JSValueRef * exception)
+{
+	// TODO: check if a main loop is running. if not, return failure.
+	
+	//GMainLoop* loop = g_main_loop_new(NULL,FALSE);
+	//if (!g_main_loop_is_running(loop))
+	//	return JSValueMakeBoolean(ctx, 0);
+
+	// TODO: convert to use an exception! (Matt!)
+
+	if (argumentCount != 2)
+		return JSValueMakeBoolean(ctx, 0);
+
+	JSStringRef jsstr = JSValueToStringCopy(eng->context,
+											arguments[0],
+											exception);
+	
+	guint interval = seed_value_to_uint(arguments[1]);
+	g_timeout_add(interval, &seed_timeout_function, jsstr);
+
+	return JSValueMakeBoolean(ctx, 1);
+}
+
 void seed_init_builtins(int * argc, char *** argv)
 {
 	int i;
@@ -290,6 +330,7 @@
 	seed_create_function("check_syntax", &seed_check_syntax, obj);
 	seed_create_function("introspect", &seed_introspect, obj);
 	seed_create_function("fork", &seed_fork, obj);
+	seed_create_function("setTimeout", &seed_set_timeout, obj);
 	
 	arrayObj = JSObjectMake(eng->context, NULL, NULL);
 	



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]