Commits

Reid van Melle committed a135bc3

Added the test-clip.ml example and associated fixes/additions

Comments (0)

Files changed (5)

src/clutterActor.ml

   method queue_redraw = Actor.queue_redraw obj
   method queue_relayout = Actor.queue_relayout obj
   method destroy = Actor.destroy obj
-
+  method set_geometry = Actor.set_geometry obj
+  method get_geometry = Actor.get_geometry obj
 end
 
 let to_actor a = (a :> [< `actor] actor_skel)
   CAMLreturn(Val_ClutterActorBox(b));
 }
 
+/** Geometry object */
+Make_Val_final_pointer(ClutterGeometry, Ignore, free, 5)
+CAMLprim value ml_clutter_geometry_create(value _geom)
+{
+  CAMLparam1(_geom);
+  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));
+}
+
+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);
+}
+
+CAMLprim value ml_clutter_actor_get_geometry(value _a)
+{
+  CAMLparam1(_a);
+  CAMLlocal1(result);
+  ClutterActor *a = ClutterActor_val(_a);
+  ClutterGeometry *geom = malloc(sizeof(ClutterGeometry));
+  clutter_actor_get_geometry(a, 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);
+}
+
+CAMLprim value ml_clutter_actor_set_geometry(value _a, value _geom)
+{
+  CAMLparam2(_a, _geom);
+  ClutterActor *a = ClutterActor_val(_a);
+  ClutterGeometry geom;
+  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));
+  clutter_actor_set_geometry(a, &geom);
+  CAMLreturn(Val_unit);
+}
+
 ML_1(clutter_actor_raise_top, ClutterActor_val, Unit)
 ML_1(clutter_actor_show_all, ClutterActor_val, Unit)
 ML_1(clutter_actor_show, ClutterActor_val, Unit)
 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

 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-viewport
+	test-viewport test-clip
 BYTE_TARGETS    := $(TARGETS:=.byte)
 OPT_TARGETS	:= $(TARGETS:=.opt)
 

tests/test-clip.ml

+
+open Clutter
+module Rectangle = ClutterRectangle
+module Texture = ClutterTexture
+module Timeline = ClutterTimeline
+module Stage = ClutterStage
+module Group = ClutterGroup
+module CloneTexture = ClutterActor.CloneTexture
+
+let _ =
+  let tl_scale = 5 in
+  let blue = Color.rgb (0x40,0x40,0xff) in
+  let stage = Stage.get_default () in
+  let group = Group.create () in
+
+  let geom = stage#get_geometry in
+  let geom = {left=geom.width / 4; top=geom.height / 4;
+	      width=geom.width / 2; height=geom.height / 2;} in
+  group#set_geometry geom;
+
+  let rect = Rectangle.new_with_color blue () in
+  rect#set_geometry geom;
+
+  stage#add rect;
+  stage#add group;
+  group#set_clip {left=0; top=0; width=geom.width; height=geom.height};
+
+  let hand = Texture.new_from_file "./examples/redhand.png" () in
+  group#add hand;
+
+  for y=0 to 1 do
+    for x=0 to 1 do
+      let other_hand = CloneTexture.create hand () in
+      other_hand#set_anchor_point_from_gravity `GRAVITY_CENTER;
+      other_hand#set_position (x * geom.width) (y * geom.height);
+      group#add other_hand
+    done
+  done;
+
+  hand#raise_top;
+  let tl = Timeline.create ~num_frames:(360 * tl_scale) ~fps:60 () in
+  tl#start;
+  tl#set_loop true;
+
+  let _ = tl#connect#new_frame
+    (fun _ frame_num ->
+       (*Printf.printf "frame=%d\n%!" frame_num;*)
+       let stage_width = float stage#width
+       and stage_height = float stage#height in
+       let progress = tl#progress in
+       let angle = progress *. 2. *. 3.14159 *. (float tl_scale) in
+       let xpos = stage_width *. 0.45 *. (sin angle) +. (stage_width /. 8.)
+       and ypos = stage_height *. 0.45 *. (sin angle) +. (stage_height /. 8.)
+       and zpos = stage_width *. (cos angle) -. (stage_width /. 2.) in
+
+       hand#set_position (int_of_float xpos) (int_of_float ypos);
+       hand#set_depth (int_of_float zpos);
+       hand#set_rotation `Y_AXIS (angle /. 3.14159 *. 180. *. 3.)
+	 (hand#width / 2) (hand#height / 2) 0;
+       let rotation = if progress < (1. /. 3.) then
+	 [|0.; 0.; 360. *. progress *. 3.|]
+       else if progress < (2. /. 3.) then
+	 [|0.; 360. *. progress *. 3.; 0.|]
+       else
+	 [|360. *. progress *. 3.; 0.; 0.|] in
+       let axis = [|`X_AXIS; `Y_AXIS; `Z_AXIS|] in
+       for i = 0 to 2 do
+	 group#set_rotation axis.(i) rotation.(i) (rect#width / 2)
+	   (rect#height / 2) 0;
+	 rect#set_rotation axis.(i) rotation.(i) (rect#width / 2)
+	   (rect#height / 2) 0;
+       done;
+
+	 
+    ) in
+  stage#show_all;
+  clutter_main ()