From 3953f09968b286d514abdb5b678dfd0761218922 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Fri, 27 Dec 2013 01:08:50 +0000 Subject: [PATCH] HTMLv: code refactoring #2 git-svn-id: svn://kolibrios.org@4414 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/TWB/TWB.c | 44 +++++++++++++++++++----------------- programs/cmm/TWB/draw_buf.h | 22 +++++++++--------- programs/cmm/TWB/img_cache.h | 29 ++++++++++++++---------- programs/cmm/browser/HTMLv.c | 28 ++++++++++------------- 4 files changed, 63 insertions(+), 60 deletions(-) diff --git a/programs/cmm/TWB/TWB.c b/programs/cmm/TWB/TWB.c index 3f7d68c085..a092d436c1 100644 --- a/programs/cmm/TWB/TWB.c +++ b/programs/cmm/TWB/TWB.c @@ -11,9 +11,11 @@ dword char download_path[]="/rd/1/.download"; char search_path[]="http://nigma.ru/index.php?s="; +struct lines{ + int visible, all, first, column_max; +}; struct TWebBrowser { - int left, top, width, height, line_h; llist list; void GetNewUrl(); void OpenPage(); @@ -73,13 +75,13 @@ void TWebBrowser::DrawPage() if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor) { - start_x = stolbec * 6 + left + magrin_left; - start_y = stroka * 10 + top + magrin_left; + start_x = stolbec * 6 + list.x + magrin_left; + start_y = stroka * 10 + list.y + magrin_left; line_length = strlen(#line) * 6; WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, drawbuf); IF (b_text) WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, drawbuf); - IF (i_text) DrawBufSkew(start_x, 0, line_length, line_h); + IF (i_text) DrawBufSkew(start_x, 0, line_length, list.line_h); IF (s_text) DrawBufBar(start_x, 4, line_length, 1, text_colors[text_color_index]); IF (u_text) DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]); IF (link) { @@ -202,12 +204,12 @@ void TWebBrowser::ShowPage() if (!filesize) { - DrawBar(left, top, width+scroll1.size_x+1, height, 0xFFFFFF); //fill all - if (GetProcessSlot(downloader_id)<>0) WriteText(left + 10, top + 18, 0x80, 0, "Loading..."); + DrawBar(list.x, list.y, list.w+scroll1.size_x+1, list.h, 0xFFFFFF); //fill all + if (GetProcessSlot(downloader_id)<>0) WriteText(list.x + 10, list.y + 18, 0x80, 0, "Loading..."); else { - WriteText(left + 10, top + 18, 0x80, 0, "Page not found. May be, URL contains some errors."); - if (!strcmp(get_URL_part(5),"http:"))) WriteText(left + 10, top + 32, 0x80, 0, "Or Internet unavilable for your configuration."); + WriteText(list.x + 10, list.y + 18, 0x80, 0, "Page not found. May be, URL contains some errors."); + if (!strcmp(get_URL_part(5),"http:"))) WriteText(list.x + 10, list.y + 32, 0x80, 0, "Or Internet unavilable for your configuration."); } //return; } @@ -342,12 +344,12 @@ void TWebBrowser::ParseHTML(dword bword){ if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //уходим... DrawPage(); strcpy(#line, #temp); - TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //закрашиваем следущую строку + TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку } DrawPage(); line=NULL; - if (tag) WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //обработка тегов + if (tag) WhatTextStyle(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //обработка тегов tag = parametr = tagparam = ignor_param = NULL; break; @@ -371,18 +373,18 @@ void TWebBrowser::ParseHTML(dword bword){ if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //уходим... DrawPage(); strcpy(#line, #temp); - TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //закрашиваем следущую строку + TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку } } } DrawPage(); //рисует последнюю строку, потом это надо убрать, оптимизировав код - TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //закрашиваем следущую строку + TextGoDown(list.x + 5, stroka * 10 + list.y + 5, list.w - 20); //закрашиваем следущую строку - if (lines.visible * 10 + 25 <= height) - DrawBar(left, lines.visible * 10 + top + 25, width, -lines.visible * 10 + height - 25, bg_color); - if (stroka * 10 + 5 <= height) - DrawBar(left, stroka * 10 + top + 5, width, -stroka * 10 + height - 5, bg_color); //закрашиваем всё до конца + if (lines.visible * 10 + 25 <= list.h) + DrawBar(list.x, lines.visible * 10 + list.y + 25, list.w, -lines.visible * 10 + list.h - 25, bg_color); + if (stroka * 10 + 5 <= list.h) + DrawBar(list.x, stroka * 10 + list.y + 5, list.w, -stroka * 10 + list.h - 5, bg_color); //закрашиваем всё до конца if (lines.first == 0) lines.all = stroka; if (anchor) //если посреди текста появится новый якорь - будет бесконечный цикл { @@ -576,7 +578,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) { if (rez) { TextGoDown(left1, top1, width1); - if (stroka > -1) && (stroka - 2 < lines.visible) DrawBufBar(li_tab * 5 * 6 + left1 - 5, line_h/2-3, 2, 2, 0x555555); + if (stroka > -1) && (stroka - 2 < lines.visible) DrawBufBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555); } return; } @@ -600,8 +602,8 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) { } if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999; TextGoDown(left1, top1, width1); - DrawBufBar(5, WB1.line_h/2, WB1.width-10, 1, hr_color); - TextGoDown(left1, top1+WB1.line_h, width1); + DrawBufBar(5, WB1.list.line_h/2, WB1.list.w-10, 1, hr_color); + TextGoDown(left1, top1+WB1.list.line_h, width1); } if (!chTag("img")) { @@ -632,8 +634,8 @@ void TWebBrowser::DrawScroller() // scroll1.position = lines.first; scroll1.all_redraw=1; - scroll1.start_x = WB1.left + WB1.width; - scroll1.size_y=WB1.height; + scroll1.start_x = WB1.list.x + WB1.list.w; + scroll1.size_y=WB1.list.h; scrollbar_v_draw(#scroll1); } diff --git a/programs/cmm/TWB/draw_buf.h b/programs/cmm/TWB/draw_buf.h index 9c8aaf08f3..24ee191a88 100644 --- a/programs/cmm/TWB/draw_buf.h +++ b/programs/cmm/TWB/draw_buf.h @@ -2,21 +2,21 @@ dword drawbuf; void DrawBufInit() { free(drawbuf); - drawbuf = malloc(WB1.width * WB1.line_h +4 * 4 + 8); //+1 for good luck - ESDWORD[drawbuf] = WB1.width; - ESDWORD[drawbuf+4] = WB1.line_h; + drawbuf = malloc(WB1.list.w * WB1.list.line_h +4 * 4 + 8); //+1 for good luck + ESDWORD[drawbuf] = WB1.list.w; + ESDWORD[drawbuf+4] = WB1.list.line_h; } void DrawBufFill() { int i; - for (i=0; iy+j*WB1.width+x+h-12*4 ; i-=4) + for (i = y+j*WB1.list.w+x+w+h*4; i>y+j*WB1.list.w+x+h-12*4 ; i-=4) ESDWORD[drawbuf+i+8] = ESDWORD[-shift[j]+drawbuf+i+8]; } } @@ -64,12 +64,12 @@ void DrawBufAlignCenter(dword x,y,w,h) void TextGoDown(int left1, top1, width1) { - if (!stroka) DrawBar(WB1.left, WB1.top, WB1.width, 5, bg_color); //çàêðàøèâàåì ôîí Г­Г Г¤ ïåðâîé ñòðîêîé - if (top1>=WB1.top) && ( top1 < WB1.height+WB1.top-10) && (!anchor) + if (!stroka) DrawBar(WB1.list.x, WB1.list.y, WB1.list.w, 5, bg_color); //çàêðàøèâàåì ôîí Г­Г Г¤ ïåðâîé ñòðîêîé + if (top1>=WB1.list.y) && ( top1 < WB1.list.h+WB1.list.y-10) && (!anchor) { - if (text_align == ALIGN_CENTER) DrawBufAlignCenter(left1,top1,WB1.width,WB1.line_h); - if (text_align == ALIGN_RIGHT) DrawBufAlignRight(left1,top1,WB1.width,WB1.line_h); - PutPaletteImage(drawbuf+8, WB1.width, WB1.line_h, left1-5, top1, 32,0); + if (text_align == ALIGN_CENTER) DrawBufAlignCenter(left1,top1,WB1.list.w,WB1.list.line_h); + if (text_align == ALIGN_RIGHT) DrawBufAlignRight(left1,top1,WB1.list.w,WB1.list.line_h); + PutPaletteImage(drawbuf+8, WB1.list.w, WB1.list.line_h, left1-5, top1, 32,0); DrawBufFill(); } stroka++; diff --git a/programs/cmm/TWB/img_cache.h b/programs/cmm/TWB/img_cache.h index 00b455bf40..4f5bceb6f7 100644 --- a/programs/cmm/TWB/img_cache.h +++ b/programs/cmm/TWB/img_cache.h @@ -42,9 +42,14 @@ void Images(int left1, top1, width1) if (strcmpn(#img_path, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0) { - img_path[strrchr(#img_path, '/')] = '\0'; //обрезаем её урл до последнего / - strcat(#img_path, #options); - + //get path: absolute or relative + if (options[0]=='/') + strcpy(#img_path, #options); + else + { + img_path[strrchr(#img_path, '/')] = '\0'; + strcat(#img_path, #options); + } cur_pic=GetOrSetPicNum(#img_path); if (!pics[cur_pic].path) { @@ -53,7 +58,7 @@ void Images(int left1, top1, width1) } } } - if (!strcmp(#parametr,"alt=")) + if (!strcmp(#parametr,"alt=")) { strcpy(#alt, "["); strcat(#alt, #options); @@ -72,23 +77,23 @@ void Images(int left1, top1, width1) h = DSWORD[pics[cur_pic].image+8]; if (w > width1) w = width1; - if (stroka==0) DrawBar(WB1.left, WB1.top, WB1.width-15, 5, bg_color); //закрашиваем первую строку + if (stroka==0) DrawBar(WB1.list.x, WB1.list.y, WB1.list.w-15, 5, bg_color); //закрашиваем первую строку stroka+=h/10; - if (top1+hWB1.top+WB1.height-10) return; //если ВСЁ изображение ушло ВЕРХ или ВНИЗ - if (top1WB1.list.y+WB1.list.h-10) return; //если ВСЁ изображение ушло ВЕРХ или ВНИЗ + if (top1WB1.top+WB1.height-h-5) //если часть изображения снизу + if (top1>WB1.list.y+WB1.list.h-h-5) //если часть изображения снизу { - h=WB1.top+WB1.height-top1-5; + h=WB1.list.y+WB1.list.h-top1-5; } if (h<=0) return; if (anchor) return; img_draw stdcall (pics[cur_pic].image, left1-5, top1, w, h,0,img_lines_first); - DrawBar(left1+w - 5, top1, WB1.width-w, h, bg_color); + DrawBar(left1+w - 5, top1, WB1.list.w-w, h, bg_color); IF (link) UnsafeDefineButton(left1 - 5, top1, w, h-1, blink + BT_HIDE, 0xB5BFC9); } \ No newline at end of file diff --git a/programs/cmm/browser/HTMLv.c b/programs/cmm/browser/HTMLv.c index bc29dfae08..22c71ca440 100644 --- a/programs/cmm/browser/HTMLv.c +++ b/programs/cmm/browser/HTMLv.c @@ -40,9 +40,6 @@ char editURL[sizeof(URL)], page_links[12000], header[2048]; -struct lines{ - int visible, all, first, column_max; -}; int mouse_dd; edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19}; @@ -90,13 +87,15 @@ void main() switch(EAX & 0xFF) { CASE evMouse: - /*scrollbar_v_mouse (#scroll1); //конченый скролл притормажимает, идём "своим путём" + /* + //not work well, so we are use custom way of processing scroll + scrollbar_v_mouse (#scroll1); if (lines.first <> scroll1.position) { lines.first = scroll1.position; WB1.ParseHTML(buf, filesize); - //break; - };*/ + }; + */ if (!CheckActiveProcess(Form.ID)) break; @@ -104,7 +103,7 @@ void main() m.get(); - if (m.y>WB1.top) && (m.yWB1.list.y) && (m.ym.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //если курсор над окном + half_scroll_size = WB1.list.h - 16 * lines.visible / lines.all - 3 /2; + if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; //если курсор над окном btn=lines.first; //сохраняем старое количество - lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height; + lines.first = m.y -half_scroll_size -WB1.list.y * lines.all / WB1.list.h; if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible; if (btn<>lines.first) WB1.ParseHTML(buf); //чтоб лишний раз не перерисовывать } @@ -199,12 +198,9 @@ void main() void SetElementSizes() { address_box.width = Form.width-266; - WB1.top = 44; - WB1.width = Form.width - 10 - scroll1.size_x; - WB1.height = Form.height - WB1.top - GetSkinHeight() - 4; - WB1.line_h = 10; - lines.column_max = WB1.width - 30 / 6; - lines.visible = WB1.height - 3 / WB1.line_h - 2; + WB1.list.SetSizes(0, 44, Form.width - 10 - scroll1.size_x, Form.cheight - 44, 0, 10); + lines.column_max = WB1.list.w - 30 / 6; + lines.visible = WB1.list.h - 3 / WB1.list.line_h - 2; DrawBufInit(); }