Commits

Reid van Melle committed a322a6b

Added a new test-viewport.ml... a number of minor fixes and changes along the way
- adding support for the ClutterGeomtry data structure

Comments (0)

Files changed (11)

examples/actor1.ml

   test_fixed ();
   let stage = ClutterStage.get_default () in
   stage#set_size ~width:800 ~height:600;
-  let actor = ClutterTexture.texture ~filename:"./examples/ohpowers.png" () in
+  let actor = ClutterTexture.create ~filename:"./examples/ohpowers.png" () in
   stage#add_actor actor;
   actor#set_position ~x:100 ~y:100;
   actor#set_rotation `Z_AXIS ~angle:180. ~x:(actor#width / 2)

examples/actor2.ml

   let group = Group.create ()
   and group2 = Group.create () in
   let _ = group#connect#add (fun _ _ -> Printf.printf "added\n%!") in
-  let actor1 = ClutterTexture.texture
+  let actor1 = ClutterTexture.create
     ~filename:"./examples/ohpowers.png" ~x:0 ~y:0 ()
-  and actor2 = ClutterTexture.texture
+  and actor2 = ClutterTexture.create
     ~filename:"./examples/ohpowers.png" ~x:200 ~y:0 () in
-  let actor3 = ClutterTexture.texture
+  let actor3 = ClutterTexture.create
     ~filename:"./examples/ohpowers.png" ~x:0 ~y:0 ()
-  and actor4 = ClutterTexture.texture
+  and actor4 = ClutterTexture.create
     ~filename:"./examples/ohpowers.png" ~x:200 ~y:0 () in
   
   group#add_many [|actor1#as_actor; actor2#as_actor|];

examples/behave.ml

   
 let _ =
   let stage = ClutterStage.get_default () in
-  let actor = ClutterTexture.texture ~filename:"./examples/ohpowers.png" () in
+  let actor = ClutterTexture.create ~filename:"./examples/ohpowers.png" () in
   stage#add_actor actor;
   let timeline = Timeline.create ~num_frames:100 ~fps:15 () in
   let _ =

examples/cogl-actor.ml

     ) in
   let c = new ClutterActor.actor (as_actor c) in
   stage#add_actor c;
-  let actor = ClutterTexture.texture ~filename:"./examples/ohpowers.png" () in
+  let actor = ClutterTexture.create ~filename:"./examples/ohpowers.png" () in
   stage#add_actor actor;
   actor#set_position ~x:100 ~y:100;
   actor#set_rotation `Z_AXIS ~angle:180. ~x:(actor#width / 2)
   external create : (actor obj -> unit) -> coglbox obj
     = "ml_caml_coglbox_new"
 end
+
+(** Clutter geometry struct object *)
+module Geometry = struct
+  type t = Gpointer.boxed
+  external wrap : t -> geometry = "ml_clutter_geometry_get"
+  external unwrap : geometry -> t = "ml_clutter_geometry_create"
+  let conv =
+    { Gobject.kind = `POINTER;
+      proj = (function `POINTER (Some k) -> wrap k
+		| `POINTER None -> raise Gpointer.Null
+		| _ -> failwith "GObj.get_object");
+      inj = (fun k -> `POINTER (Some (unwrap k))) }
+end
   
-(**
-   ClutterActorBox wrapper object
-*)
+  (**
+     ClutterActorBox wrapper object
+  *)
 module ActorBox = struct
   type t = Gpointer.boxed
   external x1 : t -> units = "ml_clutter_actorbox_get_x1"

src/clutter.props

   ClutterUnit "int"
   ClutterKnot "Structs.conv_knot"
   ClutterColor "Clutter.Color.conv_color"
+  ClutterGeometry "Clutter.Geometry.conv"
   ClutterActorBox "Clutter.ActorBox.conv"
   (*ClutterTimeline "ClutterTimeline.conv"*)
 }
 
+
 boxed {
   ClutterEvent "Event.any"
   ClutterVertex "Clutter.vertex"
-  ClutterGeometry "Clutter.geometry"
+  (*ClutterGeometry "Clutter.geometry"*)
   (*ClutterColor "Clutter.Color.t"*)
   (*ClutterKnot "Clutter.knot"*)
   (*ClutterActorBox "Clutter.actorbox"*)
   (* method get_rotation: "Clutter.rotate_axis -> *)
   method is_rotated: "bool"
   method get_gid: "int"
-  method set_clip: "xoff:int -> yoff:int -> width:int -> height:int -> unit"
+  (*method set_clip: "xoff:int -> yoff:int -> width:int -> height:int -> unit"*)
   method remove_clip: "unit"
   method has_clip: "bool"
   (* method get_clip: "*)

src/clutterTexture.ml

 	    e)
     )
 
-let texture =
+let create =
   make_texture [] ~create:
     (fun pl ->
        let t = ClutterProps.Texture.create pl in
        new texture t)
 
-let new_from_file fn = texture ~filename:fn
+let new_from_file filename = create ~filename
 
 Make_Extractor (ClutterCrossingEvent, ClutterEvent_arg(Crossing), x, Val_int)
 Make_Extractor (ClutterCrossingEvent, ClutterEvent_arg(Crossing), y, Val_int)
 Make_Extractor (ClutterCrossingEvent, ClutterEvent_arg(Crossing), related, Val_ClutterActor)
+
+/** Geometry object */
+Make_Val_final_pointer(ClutterGeometry, Ignore, free, 5)
+CAMLprim value ml_clutter_geometry_create(value _geom)
+{
+  //printf("ml_clutter_actor_set_clip\n");
+  CAMLparam1(_geom);
+  //ClutterActor *a = ClutterActor_val(_a);
+  ClutterGeometry *geom = malloc(sizeof(ClutterGeometry));
+  geom->x = Int_val(Field(_geom,0));
+  geom->y = Int_val(Field(_geom,1));
+  geom->width = Int_val(Field(_geom,2));
+  geom->height = Int_val(Field(_geom,3));
+
+  CAMLreturn(Val_ClutterGeometry(geom));
+  
+  // clutter_actor_set_clip(a, Int_val(Field(_geom,0)), Int_val(Field(_geom,1)),
+  //			 Int_val(Field(_geom,2)), Int_val(Field(_geom,3)));
+  //CAMLreturn();
+}
+
+CAMLprim value ml_clutter_geometry_get(value _geom)
+{
+  CAMLparam1(_geom);
+  CAMLlocal1(result);
+  ClutterGeometry *geom = Pointer_val(_geom);
+  result = caml_alloc(4,0);
+  Store_field(result, 0, Val_int(geom->x));
+  Store_field(result, 1, Val_int(geom->y));
+  Store_field(result, 2, Val_int(geom->width));
+  Store_field(result, 3, Val_int(geom->height));
+  CAMLreturn(result);
+}

tests/Makefile.in

 # test-cogl-tex-file --> need to finish this one test-events
 TARGETS	:= test-behave test-events test-cogl-primitives \
 	test-depth test-effect test-entry test-project \
-	test-rotate test-score test-scale test-unproject
+	test-rotate test-score test-scale test-unproject \
+	test-viewport
 BYTE_TARGETS    := $(TARGETS:=.byte)
 OPT_TARGETS	:= $(TARGETS:=.opt)
 

tests/test-cogl-primitives.ml

 
   let cogl = Cogl.Texture.new_with_size ~width:300 ~height:300 ~max_waste:100
     ~auto_mipmap:true in
-  let texture = ClutterTexture.texture () in
+  let texture = ClutterTexture.create () in
   (* texture#set_cogl_texture cogl;  NOT YET IMPLEMETNED *)
   stage#add texture;
 

tests/test-viewport.ml

+
+module Stage = ClutterStage
+module Texture = ClutterTexture
+module Timeline = ClutterTimeline
+module Alpha = ClutterAlpha
+module Behaviour = ClutterBehaviour
+open Clutter
+  
+let _ =
+
+  let stage_color = Color.rgb (0xcc, 0xcc, 0xcc) in
+  let stage = Stage.get_default () in
+
+  stage#set_color stage_color;
+
+  let hand = Texture.create ~filename:"./examples/redhand.png" () in
+  hand#set_position 300 200;
+  let clip = {left=20; top=21; width=132; height=170} in
+  hand#set_clip clip;
+  
+  hand#set_anchor_point 86 125;
+  hand#show;
+
+  stage#add hand;
+
+  let timeline = Timeline.create ~num_frames:200 ~fps:26 () in
+  timeline#set_loop true;
+
+  let alpha = Alpha.create ~timeline ~alpha_func:`RAMP_INC in
+  let r_behave = Behaviour.Rotate.create ~alpha ~axis:`Z_AXIS
+    ~direction:`ROTATE_CW ~angle_start:0. ~angle_end:360. () in
+  r_behave#apply hand;
+
+  timeline#start;
+  stage#show_all;
+
+  clutter_main ()
+