Source

clutter-ocaml / 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 ()