Subversion Repositories Kolibri OS

Rev

Rev 4491 | 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 w=0, h=0, img_lines_first=0, cur_pic=0;
  42.        
  43.         do{
  44.                 if (!strcmp(#parametr,"src="))   //íàäî îáúåäèíèòü ñ GetNewUrl()
  45.                 {
  46.                         if (downloader_id) strcpy(#img_path, #history_list[history_current-1].Item);
  47.                                 else strcpy(#img_path, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
  48.                        
  49.                         if (strcmpn(#img_path, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0)
  50.                         {
  51.                                 //get path: absolute or relative
  52.                                 if (options[0]=='/')
  53.                                         strcpy(#img_path, #options);
  54.                                 else
  55.                                 {
  56.                                         img_path[strrchr(#img_path, '/')] = '\0';
  57.                                         strcat(#img_path, #options);
  58.                                 }
  59.                                 cur_pic = GetImage(#img_path);
  60.                         }
  61.                 }
  62.                 if (!strcmp(#parametr,"alt="))
  63.                 {
  64.                         strcpy(#alt, "[");
  65.                         strcat(#alt, #options);
  66.                         strcat(#alt, "]");
  67.                 }
  68.  
  69.         } while(GetNextParam());
  70.        
  71.         if (!pics[cur_pic].image)
  72.         {
  73.                 if (alt) && (link) strcat(#line, #alt);
  74.                 return;
  75.         }
  76.        
  77.         w = DSWORD[pics[cur_pic].image+4];
  78.         h = DSWORD[pics[cur_pic].image+8];
  79.         if (w > width1) w = width1;
  80.        
  81.         if (stroka==0) DrawBar(WB1.list.x, WB1.list.y, WB1.list.w-15, 5, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
  82.         stroka += h/10;
  83.         if (top1+h<WB1.list.y) || (top1>WB1.list.y+WB1.list.h-10) return; //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
  84.         if (top1<WB1.list.y) //åñëè ÷àñòü èçîáðàæåíèÿ ñâåðõó
  85.         {
  86.                 img_lines_first=WB1.list.y-top1;
  87.                 h=h-img_lines_first;
  88.                 top1=WB1.list.y;
  89.         }
  90.         if (top1>WB1.list.y+WB1.list.h-h-5) //åñëè ÷àñòü èçîáðàæåíèÿ ñíèçó
  91.         {
  92.                 h=WB1.list.y+WB1.list.h-top1-5;
  93.         }      
  94.         if (h<=0) return;
  95.         if (anchor) return;
  96.        
  97.         img_draw stdcall (pics[cur_pic].image, left1-5, top1, w, h,0,img_lines_first);
  98.         DrawBar(left1+w - 5, top1, WB1.list.w-w, h, bg_color);
  99.         IF (link) UnsafeDefineButton(left1 - 5, top1, w, h-1, PageLinks.count + 400 + BT_HIDE, 0xB5BFC9);
  100. }
  101.  
  102. ImageCache ImgCache;