Commits

Reid van Melle committed f764deb

Got the test-scale working... needed to add a few functions to actor
and make some other various fixes

Comments (0)

Files changed (8)

   class color obj = object
     method as_color : t = obj
     method obj : t = obj
+    method set_alpha = set_alpha obj
   end
     
   let rgba (red,green,blue,alpha) =

src/clutter.props

   method set_anchor_point : "x:int -> y:int -> unit"
   method get_anchor_point : "int*int"
   method set_anchor_point_from_gravity : "ClutterEnums.gravity_type -> unit"
+  method move_anchor_point : "x:int -> y:int -> unit"
+  method move_anchor_point_from_gravity : "ClutterEnums.gravity_type -> unit"
   (* much more *)
 }
 

src/clutterActor.ml

 class virtual ['a] actor_skel (obj : actor obj) = object(self)
   inherit actor_props
   method virtual obj : 'a obj
+  method set_anchor_point = Actor.set_anchor_point obj
   method set_anchor_point_from_gravity =
     Actor.set_anchor_point_from_gravity obj
+  method move_anchor_point = Actor.move_anchor_point obj
+  method move_anchor_point_from_gravity =
+    Actor.move_anchor_point_from_gravity obj
   method id = Gobject.get_oid obj
   method as_actor = obj
   method allocate box = Actor.allocate obj (ActorBox.unwrap box)

src/clutterBehaviour.ml

 	   (fun pl () ->
 	      let (e : #scale_skel) = create pl in e))
 
-  let create =
-    make_scale [] ~create:(fun pl -> new scale (BehaviourScale.create pl))
+  let create ~alpha =
+    make_scale [] ~alpha:(alpha#obj) ~create:(fun pl -> new scale (BehaviourScale.create pl))
 
 end
 
 ML_1(clutter_actor_get_height, ClutterActor_val, Val_int)
 ML_2(clutter_actor_set_anchor_point_from_gravity,  ClutterActor_val,
      Gravity_type_val, Unit)
+ML_3(clutter_actor_set_anchor_point, ClutterActor_val, Int_val, Int_val, Unit)
+ML_2(clutter_actor_move_anchor_point_from_gravity,  ClutterActor_val,
+     Gravity_type_val, Unit)
+ML_3(clutter_actor_move_anchor_point, ClutterActor_val, Int_val, Int_val, Unit)
 ML_1(clutter_actor_hide, ClutterActor_val, Unit)
 ML_1(clutter_actor_realize, ClutterActor_val, Unit)
 ML_1(clutter_actor_unrealize, ClutterActor_val, Unit)

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-rotate test-score test-scale
 BYTE_TARGETS    := $(TARGETS:=.byte)
 OPT_TARGETS	:= $(TARGETS:=.opt)
 
 test-behave.opt: test-behave.cmx
 	ocamlfind ocamlopt $(OCAMLOPTPACKAGES) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) -o $@ $^
 
+test-scale: test-scale.cmo
+	ocamlfind ocamlc $(OCAMLCPACKAGES) $(OCAMLCFLAGS) $(OCAMLCLIBS) -o $@ $^
+
+test-scale.opt: test-scale.cmx
+	ocamlfind ocamlopt $(OCAMLOPTPACKAGES) $(OCAMLOPTFLAGS) $(OCAMLOPTLIBS) -o $@ $^
+
 test-events: test-events.cmo
 	ocamlfind ocamlc $(OCAMLCPACKAGES) $(OCAMLCFLAGS) $(OCAMLCLIBS) -o $@ $^
 

tests/test-scale.c

-#include <stdlib.h>
-#include <clutter/clutter.h>
-
-static const ClutterGravity gravities[] = {
-  CLUTTER_GRAVITY_NORTH_EAST,
-  CLUTTER_GRAVITY_NORTH,
-  CLUTTER_GRAVITY_NORTH_WEST,
-  CLUTTER_GRAVITY_WEST,
-  CLUTTER_GRAVITY_SOUTH_WEST,
-  CLUTTER_GRAVITY_SOUTH,
-  CLUTTER_GRAVITY_SOUTH_EAST,
-  CLUTTER_GRAVITY_EAST,
-  CLUTTER_GRAVITY_CENTER,
-  CLUTTER_GRAVITY_NONE
-};
-
-static gint gindex = 0;
-
-static void
-on_timeline_completed (ClutterTimeline *cluttertimeline,
-		       gpointer         data)
-{
-  ClutterActor *actor = CLUTTER_ACTOR (data);
-
-  if (++gindex >= G_N_ELEMENTS (gravities))
-    gindex = 0;
-
-  clutter_actor_move_anchor_point_from_gravity (actor, gravities[gindex]);
-}
-
-int
-main (int argc, char *argv[])
-{
-  ClutterActor    *stage, *rect;
-  ClutterColor     stage_color = { 0x0, 0x0, 0x0, 0xff };
-  ClutterColor     rect_color = { 0xff, 0xff, 0xff, 0x99 };
-  ClutterTimeline *timeline;
-  ClutterAlpha    *alpha;
-  ClutterBehaviour *behave;
-
-  clutter_init (&argc, &argv);
-
-  stage = clutter_stage_get_default ();
-
-  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
-  clutter_actor_set_size (stage, 300, 300);
-
-  rect = clutter_rectangle_new_with_color (&rect_color);
-  clutter_actor_set_size (rect, 100, 100);
-  clutter_actor_set_position (rect, 100, 100);
-
-  clutter_group_add (CLUTTER_GROUP (stage), rect);
-
-  rect_color.alpha = 0xff;
-  rect = clutter_rectangle_new_with_color (&rect_color);
-  clutter_actor_set_position (rect, 100, 100);
-  clutter_actor_set_size (rect, 100, 100);
-  clutter_actor_move_anchor_point_from_gravity (rect, CLUTTER_GRAVITY_CENTER);
-
-  clutter_group_add (CLUTTER_GROUP (stage), rect);
-
-  timeline = clutter_timeline_new_for_duration (750);
-  alpha    = clutter_alpha_new_full (timeline,
-				     CLUTTER_ALPHA_RAMP,
-				     NULL, NULL);
-
-  behave = clutter_behaviour_scale_new (alpha,
-					0.0, 0.0,  /* scale start */
-					1.0, 1.0); /* scale end */
-
-  clutter_behaviour_apply (behave, rect);
-
-  clutter_timeline_set_loop (timeline, TRUE);
-  g_signal_connect (timeline, "completed",
-		    G_CALLBACK(on_timeline_completed), rect);
-  clutter_timeline_start (timeline);
-
-  clutter_actor_show_all (stage);
-
-  clutter_main();
-
-  g_object_unref (timeline);
-  g_object_unref (behave);
-
-  return EXIT_SUCCESS;
-}

tests/test-scale.ml

+
+module Stage = ClutterStage
+module Rectangle = ClutterRectangle
+module Timeline = ClutterTimeline
+module Alpha = ClutterAlpha
+module Behaviour = ClutterBehaviour
+  
+open Clutter
+
+let _ =
+  let stage_color = Color.rgba (0x0,0x0,0x0,0xff)
+  and rect_color = Color.rgba (0xff,0xff,0xff,0x99) in
+
+  let stage = Stage.get_default () in
+  stage#set_color stage_color;
+  stage#set_size 300 300;
+
+  let rect = Rectangle.new_with_color rect_color () in
+  rect#set_size 100 100;
+  rect#set_position 100 100;
+
+  stage#add rect;
+
+  rect_color#set_alpha 0xff;
+  let rect = Rectangle.new_with_color rect_color () in
+  rect#set_position 100 100;
+  rect#set_size 100 100;
+  rect#move_anchor_point_from_gravity `GRAVITY_CENTER;
+
+  stage#add rect;
+
+  let timeline = Timeline.new_for_duration 750 () in
+  let alpha = Alpha.create ~timeline ~alpha_func:`RAMP in
+  let behave = Behaviour.Scale.create ~alpha ~x_scale_start:0.
+    ~y_scale_start:0. ~x_scale_end:1. ~y_scale_end:1. () in
+  behave#apply rect;
+
+  timeline#set_loop true;
+  let index = ref 0 in
+  let gravities = [|`GRAVITY_NORTH_EAST;
+		    `GRAVITY_NORTH;
+		    `GRAVITY_NORTH_WEST;
+		    `GRAVITY_WEST;
+		    `GRAVITY_SOUTH_WEST;
+		    `GRAVITY_SOUTH;
+		    `GRAVITY_SOUTH_EAST;
+		    `GRAVITY_EAST;
+		    `GRAVITY_CENTER;
+		    `GRAVITY_NONE |] in
+  let _ = timeline#connect#completed
+    (fun _ ->
+       incr index;
+       rect#move_anchor_point_from_gravity gravities.(!index mod 10);
+    ) in
+  timeline#start;
+  stage#show_all;
+
+  clutter_main ()
+