1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(***********************************************************************)(* *)(* Objective Caml *)(* *)(* François Pessaux, projet Cristal, INRIA Rocquencourt *)(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)(* Jun Furuse, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1999-2004, *)(* Institut National de Recherche en Informatique et en Automatique. *)(* Distributed only by permission. *)(* *)(***********************************************************************)(* $Id: oXimage.ml,v 1.1.2.1 2010/05/13 13:14:47 furuse Exp $*)openOImagesopenXimageopenGdkclassximagexim=objectmethodwidth=xim.widthmethodheight=xim.heightmethodunsafe_get=Ximage.unsafe_getximmethodunsafe_set=Ximage.unsafe_setximmethodget=Ximage.getximmethodset=Ximage.setximmethoddata=xim.datamethoddestroy=Ximage.destroyximendletcreate~kind~visual~width~height=letxim=Ximage.create~kind~visual~width~heightinnewximageximletget_imagedrawable~x~y~width~height=newximage(Ximage.get_imagedrawable~x~y~width~height)letof_imagevisualprogressimg=newximage(Ximage.of_imagevisualprogressimg#image)letmask_of_imagewinimg=(* It is really inefficient *)letmono_gc=get_mono_gcwininletwidth,height=img#width,img#heightinletdraw_maski=prerr_endline"making mask";letbmp=Bitmap.create~window:win~width~height()inletximg=get_imagebmp~x:0~y:0~width~heightinforx=0towidth-1dofory=0toheight-1doifi#unsafe_getxy=i#transparentthenximg#unsafe_setxy0elseximg#unsafe_setxy1done;done;Gdk.Draw.imagebmpmono_gcximg#data~xsrc:0~ysrc:0~xdest:0~ydest:0~width~height;Somebmpin(* BUG ? of gtk or lablgtk? Using None for mask does not work *)beginmatchOImages.tagimgwith|Index8i->ifi#transparent>=0thendraw_maskielseSome(plain_maskwinimg#widthimg#height)|Index16_i->leti=OImages.index16imginifi#transparent>=0thendraw_maskielseSome(plain_maskwinimg#widthimg#height)|_->Some(plain_maskwinimg#widthimg#height)endletpixmap_ofwinximage=pixmap_ofwin{width=ximage#width;height=ximage#height;data=ximage#data;(* finalised= false*)}letpixmap_of_imagewinprogressimg=letvisual=Gdk.Window.get_visualwininletximage=of_imagevisualprogressimginletmsk=mask_of_imagewinimginletpixmap=newGDraw.pixmap?mask:msk(pixmap_ofwinximage)inpixmap