clutter-ocaml / tests / test-effect.ml

open Clutter
open ClutterEnums

open Printf
module Timeline = ClutterTimeline
module Actor = ClutterActor
module Alpha = ClutterAlpha
module Rectangle = ClutterRectangle

let _ =
  let stage_color = Color.rgba (0xcc,0xcc,0xcc,0xff) in
  let rect_color = Color.rgba (0,0,0,0xdd) in
  let red = Color.rgba (0xff,0,0,0xff) in

  let timeline = Timeline.create ~duration:5000 () in
  timeline#set_loop true;

  let i = ref 1. in
  let tmpl = ClutterEffects.template timeline
    (`CUSTOM (fun obj ->
		i := min (!i *. 1.01) (float max_alpha);
		(int_of_float !i)))
  in

  let stage = ClutterStage.get_default () in

  let _ = stage#connect#button_press_event
    (fun _ -> printf "got a button press\n%!"; Clutter.quit (); true) in
  stage#set_color stage_color;
  stage#set_use_fog true;
  stage#set_size ~width:800 ~height:600;
  stage#show_all;

  let actor = Rectangle.create ~width:50 ~height:50 ~x:50 ~y:10
    ~color:rect_color () in
  stage#add_actor actor; (* container operation *)

  let _ = tmpl#fade (actor :> Actor.actor) 0x22
    ~done_cb:(fun _ -> printf "fade done\n%!") in
  actor#show;
  

  let actor = Rectangle.create ~color:rect_color ~width:50
    ~height:50 ~x:750 ~y:70 () in
  stage#add_actor actor;
  let _ = tmpl#depth (actor :> Actor.actor) ~depth:(-500)
    ~done_cb:(fun _ -> printf "depth done\n%!") in
  actor#show;

  let actor = Rectangle.create ~color:rect_color ~width:50
    ~height:50 ~x:50 ~y:140 () in
  stage#add_actor actor;
  let _ = tmpl#move (actor :> Actor.actor) ~x:750 ~y:140
    ~done_cb:(fun _ -> printf "move done\n%!") in
  actor#show;

  let actor = Rectangle.create ~color:red ~width:50
    ~height:50 ~x:750 ~y:210 () in
  stage#add_actor actor;
  let _ = tmpl#path (actor :> Actor.actor) ~knots:[|(750,210); (350,210)|]
    ~done_cb:(fun _ -> printf "path done\n%!") in
  actor#show;

  let actor = Rectangle.create ~color:rect_color ~width:50
    ~height:50 ~x:50 ~y:280 () in
  stage#add_actor actor;
  actor#set_anchor_point_from_gravity `GRAVITY_CENTER;
  let _ = tmpl#scale (actor :> Actor.actor) ~xscale:2. ~yscale:2.
    ~done_cb:(fun _ -> printf "scale done\n%!") in
  actor#show;

  let actor = Rectangle.create ~color:rect_color ~width:50
    ~height:50 ~x:750 ~y:350 () in
  stage#add_actor actor;
  let _ = tmpl#rotate (actor :> Actor.actor) ~axis:`Z_AXIS ~angle:180.
    ~x:25 ~y:25 ~z:0 ~dir:`ROTATE_CW
    ~done_cb:(fun _ -> printf "rotate done\n%!") in
  actor#show;

  main ()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.