Subversion Repositories Kolibri OS

Rev

Rev 4718 | Blame | Last modification | View Log | Download | RSS feed

  1. struct s_image
  2. {
  3.         dword *image;
  4.         char path[4096];
  5. };
  6.  
  7. s_image pics[100]; //pics = mem_Alloc( 100*sizeof(s_image) );
  8.  
  9. struct ImageCache {
  10.         int pics_count;
  11.         void Free();
  12.         int GetImage();
  13.         void Images();
  14. };
  15.  
  16. void ImageCache::Free()
  17. {
  18.         for ( ; pics_count>0; pics_count--)
  19.         {
  20.                 if (pics[pics_count].image) img_destroy stdcall (pics[pics_count].image);
  21.                 pics[pics_count].path = NULL;
  22.         }
  23. }
  24.  
  25. int ImageCache::GetImage(dword i_path)
  26. {
  27.         int i;
  28.         for (i=0; i<=pics_count; i++) if (!strcmp(#pics[i].path, i_path)) return i; //image exists
  29.         // Load image and add it to Cache
  30.         pics_count++;
  31.         pics[pics_count].image = load_image(i_path);
  32.         strcpy(#pics[pics_count].path, i_path);
  33.         return pics_count;
  34. }
  35.  
  36.  
  37. void ImageCache::Images(int left1, top1, width1)
  38. {
  39.         dword image;
  40.     char img_path[4096], alt[4096];
  41.     int imgw=0, imgh=0, img_lines_first=0, cur_pic=0;
  42.        
  43.         do{
  44.                 if (!strcmp(#parametr,"src="))   //íàäî îáúåäèíèòü ñ GetNewUrl()
  45.                 {
  46.                         if (http_transfer!=0)
  47.                                 strcpy(#img_path, #history_list[BrowserHistory.current-1].Item);
  48.                         else
  49.                         {
  50.                                 //if (strcmp(#options))
  51.                                         strcpy(#img_path, #options);
  52.                         }
  53.                         PageLinks.GetAbsoluteURL(#img_path);
  54.                         cur_pic = GetImage(#img_path);
  55.                 }
  56.                 if (!strcmp(#parametr,"alt="))
  57.                 {
  58.                         strcpy(#alt, "[");
  59.                         strcat(#alt, #options);
  60.                         strcat(#alt, "]");
  61.                 }
  62.  
  63.         } while(GetNextParam());
  64.        
  65.         if (!pics[cur_pic].image)
  66.         {
  67.                 if (alt) && (link) strcat(#line, #alt);
  68.                 return;
  69.         }
  70.        
  71.         imgw = DSWORD[pics[cur_pic].image+4];
  72.         imgh = DSWORD[pics[cur_pic].image+8];
  73.         if (imgw > width1) imgw = width1;
  74.        
  75.         if (stroka==0) DrawBar(WB1.list.x, WB1.list.y, WB1.list.w-15, 5, bg_color); //fill first line
  76.         stroka += imgh / WB1.list.line_h;
  77.         if (imgh % WB1.list.line_h) stroka++;
  78.         if (top1+imgh<WB1.list.y) || (top1>WB1.list.y+WB1.list.h-10) return; //if all image is out of visible area
  79.         if (top1<WB1.list.y) //if image partly visible (at the top)
  80.         {
  81.                 img_lines_first=WB1.list.y-top1;
  82.                 imgh=imgh-img_lines_first;
  83.                 top1=WB1.list.y;
  84.         }
  85.         if (top1>WB1.list.y+WB1.list.h-imgh-5) //if image partly visible (at the bottom)
  86.         {
  87.                 imgh=WB1.list.y+WB1.list.h-top1-5;
  88.         }      
  89.         if (imgh<=0) return;
  90.         if (anchor) return;
  91.        
  92.         img_draw stdcall (pics[cur_pic].image, left1-5, top1, imgw, imgh,0,img_lines_first);
  93.         DrawBar(left1+imgw - 5, top1, WB1.list.w-imgw, imgh, bg_color);
  94.         DrawBar(WB1.list.x, top1+imgh, WB1.list.w, -imgh % WB1.list.line_h + WB1.list.line_h, bg_color);
  95.         if (link)
  96.         {
  97.                 UnsafeDefineButton(left1 - 5, top1, imgw, imgh-1, PageLinks.count + 400 + BT_HIDE, 0xB5BFC9);
  98.                 PageLinks.AddText(0, imgw, imgh-1, NOLINE);    
  99.                 //WB1.DrawPage();
  100.         }
  101. }
  102.  
  103. ImageCache ImgCache;