[cairo-commit] cairo-ocaml/test cube.ml,1.1.1.1,1.2

Olivier Andrieu commit at pdx.freedesktop.org
Wed Dec 3 14:17:54 PST 2003


Committed by: oandrieu

Update of /cvs/cairo/cairo-ocaml/test
In directory pdx:/tmp/cvs-serv9809/test

Modified Files:
	cube.ml 
Log Message:
support redraw signal of GtkCairo

Index: cube.ml
===================================================================
RCS file: /cvs/cairo/cairo-ocaml/test/cube.ml,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** cube.ml	18 Nov 2003 19:02:27 -0000	1.1.1.1
--- cube.ml	3 Dec 2003 22:17:52 -0000	1.2
***************
*** 2,32 ****
  let animate_frame_delay = 40
  let rotate_max = 8. *. atan 1.
! let box_size = 100
! let margin   = 20
  
! let setup_transform cr =
    cr#default_matrix ;
!   let off = float (box_size + margin) in
!   cr#translate off off
! 
! let expose_cb c _ =
!   let cr = c#cairo in
!   cr#rectangle 0. 0. (float box_size) (float box_size) ;
    cr#set_rgb_color 1. 1. 1. ;
!   cr#fill ;
!   false
! 
! let setup packing =
!   let size = 2 * box_size + margin in
!   let c = Ocairo_gtkcairo.cairo ~width:size ~height:size ~packing () in
!   setup_transform c#cairo ;
!   c#event#connect#after#expose (expose_cb c) ;
!   c
  
! let slider_changed range c () =
!   let cr = c#cairo in
!   setup_transform cr ;
!   cr#rotate range#adjustment#value ;
!   c#queue_draw
  
  let animate_step range () =
--- 2,22 ----
  let animate_frame_delay = 40
  let rotate_max = 8. *. atan 1.
! let initial_size = 200
  
! let redraw w range c =
!   let { Gtk.width = width ; Gtk.height = height } =
!     w#misc#allocation in
!   let cr = new Ocairo.cairo c in
!   let box_size = float (width + height) /. 6. in
    cr#default_matrix ;
!   let off = float width /. 2. in
!   cr#translate off off ;
!   cr#rotate range#adjustment#value ;
!   cr#rectangle (~-. box_size) (~-. box_size) box_size box_size ;
    cr#set_rgb_color 1. 1. 1. ;
!   cr#fill
  
! let slider_changed cr () =
!   cr#queue_draw
  
  let animate_step range () =
***************
*** 40,49 ****
      match !timeout with
      | None when button#active ->
! 	let id = 
! 	  Glib.Timeout.add animate_frame_delay
! 	    (animate_step range) in
! 	timeout := Some id
      | Some id when not button#active ->
! 	Glib.Timeout.remove id
      | _ -> ()
  
--- 30,39 ----
      match !timeout with
      | None when button#active ->
! 	timeout := Some (
! 	  Glib.Timeout.add animate_frame_delay 
! 	    (animate_step range))
      | Some id when not button#active ->
! 	Glib.Timeout.remove id ;
! 	timeout := None
      | _ -> ()
  
***************
*** 57,64 ****
        ~packing:w#add () in
  
!   let f = GBin.frame ~shadow_type:`IN ~packing:b#pack () in
! 
!   let cairo = setup f#add in
  
    let slider = GRange.scale `HORIZONTAL 
        ~draw_value:false ~packing:b#pack () in
--- 47,56 ----
        ~packing:w#add () in
  
!   let f = GBin.frame ~shadow_type:`IN 
!       ~packing:(b#pack ~expand:true ~fill:true) () in
  
+   let cairo = Ocairo_gtkcairo.cairo 
+       ~width:initial_size ~height:initial_size 
+       ~packing:f#add () in
    let slider = GRange.scale `HORIZONTAL 
        ~draw_value:false ~packing:b#pack () in
***************
*** 66,74 ****
      ~lower:0. ~upper:rotate_max
      ~step_incr:animate_rotate_step () ;
-   slider#connect#value_changed 
-     (slider_changed slider cairo) ;
- 
    let button = GButton.check_button ~label:"Animate" 
        ~packing:b#pack () in
    button#connect#toggled (animate_toggled button slider) ;
  
--- 58,67 ----
      ~lower:0. ~upper:rotate_max
      ~step_incr:animate_rotate_step () ;
    let button = GButton.check_button ~label:"Animate" 
        ~packing:b#pack () in
+ 
+   cairo#connect#redraw (redraw cairo slider) ;
+   slider#connect#value_changed 
+     (slider_changed cairo) ;
    button#connect#toggled (animate_toggled button slider) ;
  





More information about the cairo-commit mailing list