/[mldonkey]/mldonkey/src/gtk2/gui/guiArt.ml
ViewVC logotype

Diff of /mldonkey/src/gtk2/gui/guiArt.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by spiralvoice, Mon Oct 10 16:22:25 2005 UTC revision 1.5 by spiralvoice, Mon Oct 31 18:34:01 2005 UTC
# Line 556  let clean_avail_bars list = Line 556  let clean_avail_bars list =
556               lprintf' "   -----------------------\n   avail_bars : %d bars\n"  (List.length l)               lprintf' "   -----------------------\n   avail_bars : %d bars\n"  (List.length l)
557             end             end
558         end         end
   
   
   
 (*  
 doesn't work ! pixbuf are freed as soon as they are rendered !!!!  
   
 open Gui_types  
   
 let dummy_bar =  
   {  
    finder = ("", "", true);  
    pixbuf = GdkPixbuf.create ~width:1 ~height:1 ();  
   }  
   
 module H = Weak.Make(struct  
   type t = avail_bar  
   let hash s = Hashtbl.hash s.finder  
               
   let equal x y = x.finder = y.finder  
 end)  
   
 let avail_bars = H.create 1023  
   
 let f = (fun _ ->  
   Printf.printf "Finalising availability bar\n";  
   flush stdout  
   )  
   
 let get_availability_of availability chunks is_file =  
   let height = 16 in  
   let nchunks = String.length chunks in  
   let avail =  
     if is_file  
       then begin  
         let s = String.copy availability in  
         normalize_availability s;  
         s  
       end else availability  
   in  
   let key = (avail, chunks, is_file) in  
   try  
     Printf.printf "Trying to use an existing availability bar\n";  
     flush stdout;  
     let bar = {dummy_bar with finder = (avail, chunks, is_file)} in  
     let pixb = H.find avail_bars bar in  
     pixb  
   with _ ->  
     begin  
       Printf.printf "Creating new availability bar\n";  
       flush stdout;  
       let pixmap = GDraw.pixmap ~width:nchunks ~height  
         ~colormap:(Gdk.Color.get_system_colormap ()) ()  
       in  
       (try  
         for i = 0 to (nchunks - 1) do  
           if is_file  
             then if chunks.[i] >= '2'  
               then pixmap#put_pixmap  
                      ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height  
                      color_green#pixmap  
               else begin  
                 let h = int_of_char (avail.[i]) in  
                 if h = 0  
                   then if chunks.[i] = '0'  
                     then pixmap#put_pixmap  
                            ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height  
                            color_red#pixmap  
                     else pixmap#put_pixmap  
                            ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height  
                            color_orange#pixmap  
                   else begin  
                     let color_blue = !color_blue_relative.(!!O.gtk_misc_availability_max - h) in  
                     pixmap#put_pixmap  
                       ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height  
                       color_blue#pixmap  
                   end  
               end  
             else if int_of_char avail.[i] >= 49  
               then if chunks.[i] >= '2'  
                 then pixmap#put_pixmap  
                        ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height  
                        color_black#pixmap  
                 else pixmap#put_pixmap  
                        ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height  
                        color_green#pixmap  
               else if chunks.[i] > '2'  
                 then pixmap#put_pixmap  
                        ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height  
                        color_orange#pixmap  
                 else pixmap#put_pixmap  
                        ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height  
                        color_red#pixmap  
           done;  
   
       with _ ->  
           begin  
             for i = 0 to nchunks do  
               pixmap#put_pixmap  
                 ~x:i ~y:0 ~xsrc:0 ~ysrc:0 ~width:1 ~height:height  
                 color_grey#pixmap  
             done  
           end);  
     let pb = GdkPixbuf.create ~width:nchunks ~height ~has_alpha:false () in  
     GdkPixbuf.get_from_drawable  
        ~dest:pb ~dest_x:0 ~dest_y:0  
        ~width:nchunks ~height ~src_x:0 ~src_y:0  
        ~colormap:(Gdk.Color.get_system_colormap ())  
        pixmap#pixmap;  
     let bar = {dummy_bar with finder = key; pixbuf = pb} in  
     Gc.finalise f bar;  
     H.add avail_bars bar;  
     bar  
   end  
 *)  

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26