Commits

Reid van Melle  committed 72b1fdc

have two working examples

  • Participants
  • Parent commits 70aeaa6

Comments (0)

Files changed (9)

+examples/actor1.native
+examples/actor2.native
 examples/pong.native
 examples/ripples.native

File clutter/_tags

+<clutter.*>: use_gtk
+<bindings.*>: use_gtk2, use_clutter

File clutter/bindings.c

 #include <string.h>
 #include <stdarg.h>
 
+#include <gtk/gtk.h>
+#include <clutter/clutter.h>
+
 typedef int* serialize_func;
 typedef int* deserialize_func;
 
+//value ml_clutter_container_add_actor(value _container, value _actor)
+//{
+//  CAMLparam2(_container, _actor);
+//  ClutterActor *container = (ClutterActor *)_container;
+//  ClutterActor *actor = (ClutterActor *)_actor;
+//  clutter_container_add_actor (CLUTTER_CONTAINER (container), actor);
+//  CAMLreturn(Val_unit);
+//}
+
+value ml_clutter_init(value arguments)
+{
+  int argc, i;
+  char ** argv;
+  argc = Wosize_val(arguments);
+  argv = stat_alloc((argc + 1) * sizeof(char *));
+  for (i = 0; i < argc; i++) argv[i] = String_val(Field(arguments, i));
+  argv[i] = NULL;
+  clutter_init(&argc, &argv);
+  return Val_unit;
+}
+
+value ml_get_pixbuf(value _fn)
+{
+  CAMLparam1(_fn);
+  char* fn = String_val(_fn);
+  GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (fn, NULL);
+  CAMLreturn((value)pixbuf);
+}
+
+
 CAMLprim value ml_serialize(serialize_func sf, void* v) {
   CAMLparam0();
   CAMLreturn((value)0);

File clutter/clutter.ml

+
+(* Initialization *)
+external init : string array -> unit = "ml_clutter_init"
+let finalize () = ()
+    
+let _ =
+  init Sys.argv;
+  at_exit finalize
+
 external boom : unit -> 'a = "ml_abort"
 
+type actor
+type container
+type pixbuf
 
+external main : unit -> unit = "clutter_main"
+  
+module Actor = struct
+  external set_position : actor -> int -> int -> unit
+    = "clutter_actor_set_position"
+  external get_pixbuf : string -> pixbuf = "ml_get_pixbuf"
+  (*external rotate_z : actor -> float -> float -> float -> unit
+    = "clutter_actor_rotate_z"*)
+  external show_all : actor -> unit = "clutter_actor_show_all"
+  external get_width : actor -> int = "clutter_actor_get_width"
+  external get_height : actor -> int = "clutter_actor_get_height"    
+end;;
 
+module Group = struct
+  external create : unit -> actor = "clutter_group_new"
+end;;
+
+module Texture = struct
+  external new_from_pixbuf : pixbuf -> actor
+    = "clutter_texture_new_from_pixbuf"
+    
+end;;
+
+module Container = struct
+  external add_actor : actor -> actor -> unit
+    = "clutter_container_add_actor"
+  let add c actors =
+    List.iter (add_actor c) actors
+
+end;;
+
+module Stage = struct
+  external get_default : unit -> actor = "clutter_stage_get_default"
+end;;
+
+
+

File config/myocamlbuild_config.ml.in

   add_c_lib "use_gtk2" "@GTK2_CFLAGS@" "" "@GTK2_LIBS@";
   add_c_lib "use_gthread2" "@GTHREAD2_CFLAGS@" "" "@GTHREAD2_LIBS@";
   add_c_lib "use_cairo" "@CAIRO_CFLAGS@" "" "@CAIRO_LIBS@";
-  add_c_lib "use_clutter" "@CLUTTER_CFLAGS" "" "@CLUTTER_LIBS@";
-  add_c_lib "use_cluttercairo" "@CLUTTER_CAIRO_CFLAGS" "" "@CLUTTER_CAIRO_LIBS@";  
+  add_c_lib "use_clutter" "@CLUTTER_CFLAGS@" "" "@CLUTTER_LIBS@";
+  add_c_lib "use_cluttercairo" "@CLUTTER_CAIRO_CFLAGS@" "" "@CLUTTER_CAIRO_LIBS@";  
   ()

File examples/_tags

-<*>: use_clutter, use_clutterml
+<*>: use_clutter, use_clutterml
+<actor-1.*>: use_gtk

File examples/actor1.ml

+
+(*
+
+int
+main (int argc, char *argv[])
+{
+  ClutterActor    *stage, *actor;
+  GdkPixbuf       *pixbuf;
+
+  clutter_init (&argc, &argv);
+  stage = clutter_stage_get_default ();
+  pixbuf = gdk_pixbuf_new_from_file ("ohpowers.png", NULL);
+  actor  = clutter_texture_new_from_pixbuf (pixbuf);
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
+  clutter_actor_set_position (actor, 100, 100);
+  clutter_actor_rotate_z (actor, 180.0, 
+			  clutter_actor_get_width (actor)/2,
+			  clutter_actor_get_height (actor)/2);
+
+  clutter_actor_show_all (stage);
+  clutter_main();
+  return 0;
+}
+  
+*)
+
+open Printf
+  
+let _ =
+  let stage = Clutter.Stage.get_default () in
+  (*let pixbuf = GdkPixbuf.from_file "./examples/ohpowers.png" in*)
+  let pixbuf = Clutter.Actor.get_pixbuf "./examples/ohpowers.png" in
+  let actor = Clutter.Texture.new_from_pixbuf pixbuf in
+  Clutter.Container.add_actor stage actor;
+  Clutter.Actor.set_position actor 100 100;
+  (*Clutter.Actor.rotate_z actor 180.
+    ((Clutter.Actor.get_width actor) /. 2.)
+    ((Clutter.Actor.get_height actor) /. 2.);*)
+  Clutter.Actor.show_all stage;
+  Clutter.main ()
+

File examples/actor2.ml

+(*
+
+  ClutterActor    *stage, *actor1, *actor2, *group;
+  GdkPixbuf       *pixbuf;
+
+  clutter_init (&argc, &argv);
+
+  stage = clutter_stage_get_default ();
+
+  pixbuf = gdk_pixbuf_new_from_file ("ohpowers.png", NULL);
+
+  group = clutter_group_new ();
+
+  actor1  = clutter_texture_new_from_pixbuf (pixbuf);
+  actor2  = clutter_texture_new_from_pixbuf (pixbuf);
+
+  clutter_container_add (CLUTTER_CONTAINER (group), actor1 ,actor2, NULL);
+  
+  clutter_actor_set_position (actor1, 0, 0);
+  clutter_actor_set_position (actor2, 200, 0);
+
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
+  clutter_actor_set_position (group, 100, 100);
+
+  clutter_actor_rotate_z (group, 45.0, 
+			  clutter_actor_get_width (group)/2,
+			  clutter_actor_get_height (group)/2);
+
+  clutter_actor_show_all (group);
+  clutter_actor_show_all (stage);
+
+  clutter_main();
+*)
+
+let _ =
+  let stage = Clutter.Stage.get_default () in
+  let pixbuf = Clutter.Actor.get_pixbuf "./examples/ohpowers.png" in
+  
+  let group = Clutter.Group.create () in
+  let actor1 = Clutter.Texture.new_from_pixbuf pixbuf
+  and actor2 = Clutter.Texture.new_from_pixbuf pixbuf in
+  Clutter.Container.add group [actor1; actor2];
+  Clutter.Actor.set_position actor1 0 0;
+  Clutter.Actor.set_position actor2 200 0;
+
+  Clutter.Container.add_actor stage group;
+  Clutter.Actor.set_position group 100 100;
+
+  Clutter.Actor.show_all group;
+  Clutter.Actor.show_all stage;
+
+  Clutter.main ()

File examples/ohpowers.png

Added
New image