From: Stalkern 2 Reply-To: stalkern2 at tin.it To: lablgtk at kaba.or.jp Subject: Re: animation: pixmap transparency? Date: Tue, 8 Jul 2003 09:26:20 +0200 References: <200307021756.22997.stalkern2 at tin.it> <200307071941.13532.stalkern2 at tin.it> <20030708093841E.garrigue at kurims.kyoto-u.ac.jp> In-Reply-To: <20030708093841E.garrigue at kurims.kyoto-u.ac.jp> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Content-Disposition: inline Message-Id: <200307080926.20760.stalkern2 at tin.it> Il Tuesday 08 July 2003 02:38, Jacques Garrigue ha scritto: [...] > Did you set a mask on your pixmap? > Transparency is controlled by the mask. If there is no mask, there is > no transparency. By the way, alpha-blending at the X11 level is not > supported. OK, I've been merging this by a previous code sample from Claude Marché and now I get transparency: but it seems that setting the clip mask fools the callback that restores the background. So, before having transparency I had a background that could recover from exposure, now it can not. Another buggy feature is that I have to hide the footprints of the moving pixmap by hand. To test this code, one can download the images bkg.xpm and fly.xpm from http://www.connettivo.net/cntdownload/XPMs/ Any commentary, suggestion, hint is welcome. Thank you Ernesto ------------------------------------------------------------------------------------ animate.ml ------------------------------------------------------------------------------------ let (theRefBkgPixmap:(GDraw.pixmap option ref) ) = ref None;; let (theRefMovingPixmap:(GDraw.pixmap option ref) ) = ref None;; let (windowWidth,windowHeight) = (300,300);; let (movingImgWidth,movingImgHeight) = (22,21);; let refCounter = ref 0;; let (baseX,baseY) = (10,100);; let aXUnit = 10;; let m_pi = acos (-1.);; (*from J.Garrigues' lissajous.ml*) let c = ref 0.;; (*from J.Garrigues' lissajous.ml*) (**) open GMain;; let window = GWindow.window ~width:windowWidth ~height:windowHeight ();; let area = GMisc.drawing_area ~packing:window#add ();; let (w:Gdk.window) = (area#misc#realize (); area#misc#window);; let (theDrawing:[ `window] GDraw.drawable) = new GDraw.drawable w;; theRefBkgPixmap := Some (GDraw.pixmap_from_xpm "bkg.xpm" ());; theRefMovingPixmap := Some (GDraw.pixmap_from_xpm "fly.xpm" ());; let redraw_on_exposure (aDrawing:[ `window] GDraw.drawable) aConnectEventArea = match !theRefBkgPixmap with | None -> false | Some bkgpxm -> ( let exposedAreaX = (Gdk.Rectangle.x aConnectEventArea) in let exposedAreaY = (Gdk.Rectangle.y aConnectEventArea) in let exposedAreaWidth = (Gdk.Rectangle.width aConnectEventArea) in let exposedAreaHeight = (Gdk.Rectangle.height aConnectEventArea) in (*use ~xsrc:0 ~ysrc:0 for checking the behaviour*) let () = aDrawing#put_pixmap ~x:exposedAreaX ~y:exposedAreaY ~xsrc:exposedAreaX ~ysrc:exposedAreaY ~width:exposedAreaWidth ~height:exposedAreaHeight bkgpxm#pixmap in false );; let move_on_expose (aDrawing:[ `window] GDraw.drawable) aRefCounter _ = match (!theRefBkgPixmap,!theRefMovingPixmap) with | (Some bkgpxm, Some movpxm) -> ( (*hiding the footprints... let's restore the background after passage*) let pastX = (windowWidth - ((baseX + ((!aRefCounter - 1) * aXUnit)) mod (windowWidth + movingImgWidth))) in let pastY = baseY in let () = aDrawing#put_pixmap ~x:pastX ~y:pastY ~xsrc:pastX ~ysrc:baseY ~width:movingImgWidth ~height:movingImgHeight bkgpxm#pixmap in let newX = (windowWidth - ((baseX + (!aRefCounter * aXUnit)) mod (windowWidth + movingImgWidth))) in let newY = baseY in let () = match movpxm#mask with (*mask is for transparency; thanks also to Claude Marché*) | None -> () | Some m -> (aDrawing#set_clip_origin ~x:newX ~y:newY; aDrawing#set_clip_mask m) in let () = aDrawing#put_pixmap ~x:newX ~y:newY ~xsrc:0 ~ysrc:0 ~width:movingImgWidth ~height:movingImgHeight movpxm#pixmap in let () = incr aRefCounter in false ) | _ -> false ;; let init_gui () = let () = ignore (window#connect#destroy ~callback:Main.quit) in let () = ignore (area#event#connect#expose ~callback: (fun event -> redraw_on_exposure theDrawing (GdkEvent.Expose.area event))) in let () = ignore (area#event#connect#expose ~callback: (fun event -> move_on_expose theDrawing refCounter () ) ) in let timeout _ = (c := !c +. 0.01 *. m_pi; (*J.Garrigues'*) move_on_expose theDrawing refCounter () ; true) in let () = ignore (Timeout.add ~ms:500 ~callback:timeout) in let () = window#show () in Main.main ();; let _ = init_gui ();; ------------------------------------------------------------------------------------