1
(***********************************************************************)
5
(* Fran�ois Pessaux, projet Cristal, INRIA Rocquencourt *)
6
(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)
7
(* Jun Furuse, projet Cristal, INRIA Rocquencourt *)
9
(* Copyright 1999-2004, *)
10
(* Institut National de Recherche en Informatique et en Automatique. *)
11
(* Distributed only by permission. *)
13
(***********************************************************************)
15
(* $Id: oXimage2.ml,v 1.2 2004/09/24 10:02:55 weis Exp $*)
22
class ximage xim = object
23
method width = xim.width
24
method height = xim.height
25
method unsafe_get = Ximage2.unsafe_get xim
26
method unsafe_set = Ximage2.unsafe_set xim
27
method get = Ximage2.get xim
28
method set = Ximage2.set xim
29
method data = xim.data
30
method destroy = Ximage2.destroy xim
33
let create ~kind ~visual ~width ~height =
34
let xim = Ximage2.create ~kind ~visual ~width ~height in
37
let get_image drawable ~x ~y ~width ~height =
38
new ximage (Ximage2.get_image drawable ~x ~y ~width ~height);;
40
let of_image visual progress img =
41
new ximage (Ximage2.of_image visual progress img#image);;
45
let mask_of_image win img = (* It is really inefficient *)
46
let mono_gc = get_mono_gc win in
47
let width, height = img#width, img#height in
49
prerr_endline "making mask";
50
let bmp = Bitmap.create ~window:win ~width ~height () in
51
let ximg = get_image bmp ~x:0 ~y:0 ~width ~height in
52
for x = 0 to width - 1 do
53
for y = 0 to height - 1 do
54
if i#unsafe_get x y = i#transparent
55
then ximg#unsafe_set x y 0
56
else ximg#unsafe_set x y 1
59
Gdk.Draw.image bmp mono_gc ximg#data
60
~xsrc:0 ~ysrc:0 ~xdest:0 ~ydest:0 ~width ~height;
63
(* BUG ? of gtk or lablgtk? Using None for mask does not work *)
64
begin match OImages.tag img with
66
if i#transparent >= 0 then draw_mask i
67
else Some (plain_mask win img#width img#height)
69
let i = OImages.index16 img in
70
if i#transparent >= 0 then draw_mask i
71
else Some (plain_mask win img#width img#height)
73
Some (plain_mask win img#width img#height)
76
let pixmap_of win ximage =
78
{ width= ximage#width; height= ximage#height;
79
data= ximage#data; (* finalised= false*) };;
81
let pixmap_of_image win progress img =
82
let visual = Gdk.Window.get_visual win in
83
let ximage = of_image visual progress img in
84
let msk = mask_of_image win img in
85
let pixmap = new GDraw.pixmap ?mask: msk (pixmap_of win ximage) in