Subversion Repositories Kolibri OS

Rev

Rev 8499 | Rev 9103 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. CANVAS canvas;
  2.  
  3. void TWebBrowser::RenderLine(dword _line)
  4. {
  5.         unsigned px; //paint x coordinate
  6.         unsigned pw; //paint y coordinate
  7.            dword pc; //paint color
  8.            int zoom;
  9.  
  10.         if (style.title)
  11.         {
  12.                 strncpy(#header, _line, sizeof(TWebBrowser.header)-1);
  13.                 strncat(#header, " - ", sizeof(TWebBrowser.header)-1);
  14.                 strncat(#header, #version, sizeof(TWebBrowser.header)-1);
  15.         }
  16.         else if (t_html) && (!t_body) {
  17.                 //
  18.         }
  19.         else if (ESBYTE[_line])
  20.         {
  21.                 pw = strlen(_line) * list.font_w;
  22.                 zoom = list.font_w / BASIC_CHAR_W;
  23.  
  24.                 if (pw > draw_w) {
  25.                         draw_w = pw;
  26.                         NewLine();
  27.                 }
  28.  
  29.                 if (debug_mode) {
  30.                         canvas.DrawBar(draw_x, draw_y, pw, list.item_h, 0xCCCccc);
  31.                         debugln(_line);
  32.                 }
  33.  
  34.                 style.cur_line_h = math.max(style.cur_line_h, list.item_h);
  35.  
  36.                 if (bg_colors.get_last() - bg_colors.get(0)) {
  37.                         canvas.DrawBar(draw_x, draw_y, pw, list.item_h, bg_colors.get_last());
  38.                 }
  39.  
  40.                 if (style.image) {
  41.                         canvas.DrawBar(draw_x, draw_y, pw, list.item_h-1, 0xF9DBCB);
  42.                 }
  43.                 if (style.button) {
  44.                         canvas.DrawBar(draw_x, draw_y, pw, list.item_h - calc(zoom*2), 0xCCCccc);
  45.                         canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2), pw, zoom, 0x999999);
  46.                 }
  47.  
  48.                 pc = text_colors.get_last();
  49.                 if (link) && (pc == text_colors.get(0)) pc = link_color_default;
  50.  
  51.                 canvas.WriteText(draw_x, draw_y, list.font_type, pc, _line, NULL);
  52.                 if (style.b) canvas.WriteText(draw_x+1, draw_y, list.font_type, pc, _line, NULL);
  53.                 if (style.s) canvas.DrawBar(draw_x, list.item_h / 2 - zoom + draw_y, pw, zoom, pc);
  54.                 if (style.u) canvas.DrawBar(draw_x, list.item_h - zoom - zoom + draw_y, pw, zoom, pc);
  55.                 if (link) {
  56.                         if (ESBYTE[_line]==' ') && (ESBYTE[_line+1]==NULL) {} else {
  57.                                 canvas.DrawBar(draw_x, draw_y + list.item_h - calc(zoom*2)-1, pw, zoom, link_color_default);
  58.                                 links.add_text(draw_x, draw_y + list.y, pw, list.item_h - calc(zoom*2)-1, zoom);                               
  59.                         }
  60.                 }
  61.                 draw_x += pw;
  62.         }
  63.         ESBYTE[_line] = NULL;
  64. }
  65.  
  66. void TWebBrowser::RenderTextbuf()
  67. {
  68.         dword lbp = #linebuf;
  69.         int br; //break position
  70.         char nul = '\0';
  71.         int len;
  72.  
  73.         //Do we need a line break?
  74.         while (len = strlen(lbp)) && (len * list.font_w + draw_x >= draw_w) {
  75.                 //Yes, we do. Lets calculate where...
  76.                 br = strrchr(lbp, ' ');
  77.  
  78.                 //Is a new line fits in the current line?
  79.                 if (br * list.font_w + draw_x >= draw_w) {
  80.                         br = draw_w - draw_x /list.font_w;
  81.                         while(br) {
  82.                                 if (ESBYTE[lbp + br]==' ') {
  83.                                         br++;
  84.                                         break;
  85.                                 }
  86.                                 br--;
  87.                         }
  88.                 }
  89.                 //Maybe a new line is too big for the whole new line? Then we have to split it
  90.                 if (!br) && (len * list.font_w >= draw_w) {
  91.                         br = draw_w - draw_x / list.font_w;
  92.                 }
  93.  
  94.                 if (br) {
  95.                         ESBYTE[lbp + br] >< nul;
  96.                         RenderLine(lbp);
  97.                         ESBYTE[lbp + br] >< nul;
  98.                         lbp += br;
  99.                         while (ESBYTE[lbp]==' ') && (ESBYTE[lbp]) lbp++;
  100.                         if (ESBYTE[lbp]) NewLine();
  101.                 } else {
  102.                         NewLine();
  103.                         RenderLine(lbp);
  104.                 }
  105.         }
  106.         RenderLine(lbp);
  107. }
  108.  
  109. void TWebBrowser::NewLine()
  110. {
  111.         static bool empty_line = true;
  112.  
  113.         if (draw_x==left_gap) && (draw_y==BODY_MARGIN) return;
  114.         if (t_html) && (!t_body) return;
  115.        
  116.         if (draw_x == style.tag_list.level * 5 * list.font_w + left_gap) {
  117.                 if (!empty_line) empty_line=true; else return;
  118.         } else {
  119.                 empty_line = false;
  120.         }
  121.  
  122.         draw_y += style.cur_line_h;
  123.         style.cur_line_h = list.item_h;
  124.         if (style.blq) draw_x = 6 * list.font_w; else draw_x = 0; //left_gap += style.tag_list.level * 5 * list.font_w ???
  125.         draw_x += style.tag_list.level * 5 * list.font_w + left_gap;
  126. }
  127.  
  128. bool TWebBrowser::RenderImage(dword cur_img)
  129. {
  130.         int img_x, img_y, img_w, img_h;
  131.         dword imgbuf[44];
  132.  
  133.         if (!cur_img) return false;
  134.  
  135.         img_h = ESDWORD[cur_img+8];
  136.         img_w = ESDWORD[cur_img+4];
  137.  
  138.         if (img_w + draw_x >= draw_w) NewLine();
  139.         img_y = draw_y;
  140.         if (img_h < list.item_h) img_y += list.item_h - img_h / 2 - 1; else img_y -= 2;
  141.         style.cur_line_h = math.max(style.cur_line_h, img_h);
  142.  
  143.         img_w = math.min(img_w, canvas.bufw - draw_x);
  144.  
  145.         if (link) links.add_text(draw_x + list.x, img_y + list.y, img_w, img_h, 0);
  146.  
  147.         if (img_y + img_h >= canvas.bufh) canvas.IncreaseBufSize();
  148.  
  149.         if (ESDWORD[cur_img+20] != IMAGE_BPP32) {
  150.                 img_convert stdcall(cur_img, 0, IMAGE_BPP32, 0, 0);
  151.                 $push eax
  152.                 img_destroy stdcall(cur_img);
  153.                 $pop eax
  154.                 cur_img = EAX;
  155.                 if (!EAX) return false;
  156.         }
  157.         imgbuf[04] = canvas.bufw;
  158.         imgbuf[08] = canvas.bufh;
  159.         imgbuf[20] = IMAGE_BPP32;
  160.         imgbuf[24] = buf_data+8;
  161.         img_blend stdcall(#imgbuf, cur_img, draw_x, img_y, 0, 0, img_w, img_h);
  162.         img_destroy stdcall(cur_img);
  163.  
  164.         draw_x += img_w;
  165.         if (draw_x >= draw_w) NewLine();
  166.         return true;
  167. }