diff --git a/programs/cmm/browser/HTMLv.c b/programs/cmm/browser/HTMLv.c index 89ba22880e..463dd9d19e 100644 --- a/programs/cmm/browser/HTMLv.c +++ b/programs/cmm/browser/HTMLv.c @@ -35,7 +35,7 @@ struct lines{ }; int mouse_dd; -edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19}; +edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19}; scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; @@ -69,9 +69,7 @@ void main() Form.width=WIN_W; Form.height=WIN_H; - SetElementSizes(); - WB1.OpenPage(); SetEventMask(0x27); @@ -92,7 +90,7 @@ void main() btn=GetProcessSlot(Form.ID); IF (btn<>GetActiveProcess()) break; //если окно не активно на события мыши не реагируем - edit_box_mouse stdcall (#edit1); + edit_box_mouse stdcall (#address_box); m.get(); @@ -150,13 +148,13 @@ void main() case evKey: key = GetKey(); - if (edit1.flags & 0b10) SWITCH(key) //если активна строка адреса игнорируем некоторые кнопки + if (address_box.flags & 0b10) SWITCH(key) //если активна строка адреса игнорируем некоторые кнопки { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } WB1.Scan(key); _EDIT_MARK: - if (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#edit1);} //адресная строка + if (key<>0x0d) && (key<>183) && (key<>184) && (key<>173) {EAX=key<<8; edit_box_key stdcall(#address_box);} //адресная строка break; case evReDraw: Draw_Window(); @@ -176,10 +174,10 @@ void main() void SetElementSizes() { - edit1.width = Form.width-266; + address_box.width = Form.width-266; WB1.top = 44; - WB1.width = Form.cwidth - 4; - WB1.height = Form.cheight - WB1.top; + 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; @@ -189,7 +187,7 @@ void SetElementSizes() void Draw_Window() { int j; - DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0x00E4DFE1,0,0); + DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0); GetProcessInfo(#Form, SelfInfo); if (Form.status_window>2) diff --git a/programs/cmm/browser/History.txt b/programs/cmm/browser/History.txt index 9ff3167149..30b231c5f1 100644 --- a/programs/cmm/browser/History.txt +++ b/programs/cmm/browser/History.txt @@ -1,3 +1,7 @@ +12.04.13 - 0.99 +- отрисовка в буфер; +- исправление ошибок и обновление кода. + 20.11.12 - 0.98 - интелектуальная система кеширования изображений. diff --git a/programs/cmm/browser/TWB.h b/programs/cmm/browser/TWB.h index 0daf209c85..51ccf2af34 100644 --- a/programs/cmm/browser/TWB.h +++ b/programs/cmm/browser/TWB.h @@ -8,7 +8,7 @@ dword char download_path[]="/rd/1/.download"; char search_path[]="http://nigma.ru/index.php?s="; -char version[]=" Text-based Browser 0.98.2"; +char version[]=" Text-based Browser 0.99"; struct TWebBrowser { @@ -22,13 +22,11 @@ struct TWebBrowser { void WhatTextStyle(int left1, top1, width1); void DrawPage(); void DrawScroller(); -}; - -byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, -link, ignor_text, li_tab, first_line_drawed, cur_encoding; - +}; TWebBrowser WB1; +byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, + link, ignor_text, li_tab, cur_encoding; dword text_colors[300], text_color_index, @@ -37,23 +35,112 @@ dword text_colors[300], int stroka, stolbec, - tab_len; - -char anchor[256]; -int anchor_line_num; + tab_len, + anchor_line_num; char line[500], tag[100], tagparam[10000], parametr[1200], - options[4096]; + options[4096], + anchor[256]; #include "include\history.h" #include "include\colors.h" #include "include\unicode_tags.h" +#include "include\img_cache.h" #include "include\some_code.h" #include "include\parce_tag.h" +//======================================================================= +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; + DrawBufFill(); +} +void DrawBufFill() +{ + int i; + for (i=0; iy+j*WB1.width+x+h-12*4 ; i-=4) + ESDWORD[drawbuf+i+8] = ESDWORD[-shift[j]+drawbuf+i+8]; + } +} + +void TextGoDown(int left1, top1, width1) +{ + if (!stroka) DrawBar(WB1.left, WB1.top, WB1.width, 5, bg_color); //закрашиваем фон над первой строкой + stroka++; + if (blq_text) stolbec = 8; else stolbec = 0; + if (li_text) stolbec = li_tab * 5; + if (top1>=WB1.top) && ( top1 < WB1.height+WB1.top-10) && (!anchor) + { + PutPaletteImage(drawbuf+8, WB1.width, WB1.line_h, left1-5, top1, 32,0); + DrawBufFill(); + } +} + +void TWebBrowser::DrawPage() +{ + int start_x, start_y, line_length, magrin_left=5; + + if (!header) + { + strcpy(#header, #line); + strcat(#header, " -"); + strcat(#header, #version); + line = 0; + return; + } + + if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor) + { + start_x = stolbec * 6 + left + magrin_left; + start_y = stroka * 10 + top + magrin_left; + line_length = strlen(#line) * 6; + + if (use_truetype == 1) + { + //line_length = get_length stdcall (#line,-1,16,line_length); + text_out stdcall (#line, #fontlol, 17, text_colors[text_color_index], start_x, start_y-3); + } + else + { + 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 (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) { + UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9); + DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]); + } + stolbec += strlen(#line); + } +} +//======================================================================= void TWebBrowser::Scan(int id) { @@ -138,11 +225,14 @@ void TWebBrowser::Scan(int id) if (!BrowserHistory.GoForward()) return; OpenPage(); return; - case 052: //Нажата F3 + //case 255: //F12 + // RunProgram("/rd/1/HTMLv_old", #URL); + // return; + case 052: //F3 if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #download_path); return; case 054: //F5 - IF(edit1.flags & 0b10) break; + IF(address_box.flags & 0b10) break; case REFRESH: if (GetProcessSlot(downloader_id)<>0) { @@ -210,7 +300,6 @@ void TWebBrowser::Scan(int id) char *ABSOLUTE_LINKS[]={ "http:", "mailto:", "ftp:", "/sys/", "/rd/", "/fd/", "/bd/", "/hd/", "/cd/", "/tmp/", 0}; - //dword TWebBrowser::GetNewUrl(dword CUR_URL, NEW_URL){ void TWebBrowser::GetNewUrl(){ int i, len; @@ -307,13 +396,13 @@ void TWebBrowser::OpenPage() void TWebBrowser::ShowPage() { - edit1.size = edit1.pos = strlen(#editURL); - edit1.offset=0; - edit_box_draw stdcall(#edit1); //рисуем строку адреса + address_box.size = address_box.pos = strlen(#editURL); + address_box.offset=0; + edit_box_draw stdcall(#address_box); if (!filesize) { - DrawBar(left, top, width+4, height, 0xFFFFFF); //закрашиваем всё донизу + 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..."); else { @@ -343,13 +432,14 @@ void TWebBrowser::ParseHTML(dword bword){ for (j = 400; j < blink + 1; j++;) DeleteButton(j); blink = 400; - b_text = i_text = u_text = s_text = blq_text = first_line_drawed = + b_text = i_text = u_text = s_text = blq_text = li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //обнуляем теги link_color = 0x0000FF; bg_color = 0xFFFFFF; line = NULL; strcpy(#page_links,"|"); strcpy(#header, #version); + DrawBufInit(); if (pre_text<>2) { @@ -449,16 +539,15 @@ void TWebBrowser::ParseHTML(dword bword){ if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/ if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam(); - if (stolbec + strlen(#line) > lines.column_max) + if (stolbec + strlen(#line) > lines.column_max) //============the same as NEXT_MARK { perenos_num = strrchr(#line, ' '); if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max; strcpy(#temp, #line + perenos_num); //перенос по словам line[perenos_num] = 0x00; - if (stroka >= lines.visible) && (lines.first <>0) break 1; //уходим... + if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //уходим... DrawPage(); - strcpy(#line, #temp); - + strcpy(#line, #temp); TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //закрашиваем следущую строку } DrawPage(); @@ -484,20 +573,21 @@ void TWebBrowser::ParseHTML(dword bword){ if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max; strcpy(#temp, #line + perenos_num); //перенос по словам line[perenos_num] = 0x00; - if (stroka >= lines.visible) && (lines.first <>0) break 1; //уходим... + if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //уходим... DrawPage(); - strcpy(#line, #temp); - + strcpy(#line, #temp); TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //закрашиваем следущую строку } } } DrawPage(); //рисует последнюю строку, потом это надо убрать, оптимизировав код + TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //закрашиваем следущую строку + if (lines.visible * 10 + 25 <= height) - DrawBar(left, lines.visible * 10 + top + 25, width - 15, -lines.visible * 10 + height - 25, bg_color); - if (stroka * 10 + 15 <= height) - DrawBar(left, stroka * 10 + top + 15, width - 15, -stroka * 10 + height - 15, bg_color); //закрашиваем всё до конца + 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.first == 0) lines.all = stroka; if (anchor) //если посреди текста появится новый якорь - будет бесконечный цикл { @@ -510,53 +600,6 @@ void TWebBrowser::ParseHTML(dword bword){ -void TWebBrowser::DrawPage() -{ - int start_x, start_y, line_length; - - if (!header) - { - strcpy(#header, #line); - strcat(#header, " -"); - strcat(#header, #version); - line = 0; - return; - } - - if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor) - { - if (!stroka) && (!stolbec) - { - DrawBar(left, top, width-15, 15, bg_color); //first line - first_line_drawed=1; - } - - start_x = stolbec * 6 + left + 5; - start_y = stroka * 10 + top + 5; - line_length = strlen(#line) * 6; - - if (use_truetype == 1) - { - //line_length = get_length stdcall (#line,-1,16,line_length); - text_out stdcall (#line, #fontlol, 17, text_colors[text_color_index], start_x, start_y-3); - } - else - { - WriteText(start_x, start_y, 0x80, text_colors[text_color_index], #line); - IF (b_text) { $add ebx, 1<<16 $int 0x40 } - } - IF (i_text) Skew(start_x, start_y, line_length+6, 10); - IF (s_text) DrawBar(start_x, start_y + 4, line_length, 1, text_colors[text_color_index]); - IF (u_text) DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]); - IF (link) { - UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9); - DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]); - } - stolbec += strlen(#line); - } -} - - char oldtag[100]; void TWebBrowser::WhatTextStyle(int left1, top1, width1) { dword hr_color; @@ -600,7 +643,11 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) { do{ if (!strcmp(#parametr, "link=")) link_color = GetColor(#options); if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options); - if (!strcmp(#parametr, "bgcolor=")) bg_color=GetColor(#options); + if (!strcmp(#parametr, "bgcolor=")) + { + bg_color=GetColor(#options); + DrawBufFill(); + } } while(GetNextParam()); return; } @@ -701,9 +748,11 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) { if(!chTag("li")) || (!chTag("dt")) //надо сделать вложенные списки { li_text = rez; - IF(rez == 0) return; - TextGoDown(left1, top1, width1); - IF(stroka > -1) && (stroka - 2 < lines.visible) DrawBar(li_tab * 5 * 6 + left1 - 5, top1 + 12, 2, 2, 0); + 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); + } return; } if (!chTag("u")) || (!chTag("ins")) u_text = rez; @@ -719,33 +768,41 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) { if (!chTag("pre")) pre_text = rez; if (!chTag("hr")) { + if (anchor) || (stroka < -1) + { + stroka+=2; + return; + } + if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999; TextGoDown(left1, top1, width1); - TextGoDown(left1, top1 + 10, width1); - if (anchor) return; - IF(strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); - ELSE hr_color = 0x999999; - IF(stroka > 0) DrawBar(left1, top1 + 14, width1 - 8, 1, hr_color); + DrawBufBar(5, WB1.line_h/2, WB1.width-10, 1, hr_color); + TextGoDown(left1, top1+WB1.line_h, width1); } + /* if (!chTag("input")) { do{ - if (!strcmp(#parametr, "type=")) if ((!strcmp(#options, "radio")) || (!strcmp(#options, "checkbox"))) + if (!strcmp(#parametr, "type=")) { - if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,10,10, 0, "\0", 0x888888, text_colors[text_color_index], 0); - stolbec+=2; - } - if (!strcmp(#parametr, "type=")) if ((!strcmp(#options, "text")) || (!strcmp(#options, "password"))) - { - if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,90,10, 0, "\0", 0x555555, 0, 0); - stolbec+=16; - } - if (!strcmp(#parametr, "type=")) if ((!strcmp(#options, "button")) || (!strcmp(#options, "file")) || (!strcmp(#options, "submit"))) - { - if (!anchor) && (stroka > 0) DrawCaptButton(stolbec*6 + left1,top1-2,60,10, 0, 0xCCCccc, 0, "Button"); - stolbec+=21; + if ((!strcmp(#options, "radio")) || (!strcmp(#options, "checkbox"))) + { + if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,10,10, 0, "\0", 0x888888, text_colors[text_color_index], 0); + stolbec+=2; + } + if ((!strcmp(#options, "text")) || (!strcmp(#options, "password"))) + { + if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,90,10, 0, "\0", 0x555555, 0, 0); + stolbec+=16; + } + if ((!strcmp(#options, "button")) || (!strcmp(#options, "file")) || (!strcmp(#options, "submit"))) + { + if (!anchor) && (stroka > 0) DrawCaptButton(stolbec*6 + left1,top1-2,60,10, 0, 0xCCCccc, 0, "Button"); + stolbec+=21; + } } } while(GetNextParam()); } + */ if (!chTag("img")) { Images( left1, top1, width1); @@ -767,120 +824,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) { } -void TextGoDown(int left1, top1, width1) -{ - if (!stroka) && (!stolbec) && (!first_line_drawed) - { - DrawBar(WB1.left, WB1.top, WB1.width-15, 15, bg_color); //закрашиваем первую строку - first_line_drawed=1; - } - stroka++; - if (blq_text) stolbec = 8; - ELSE stolbec = 0; - if (li_text) stolbec = li_tab * 5; - IF(stroka >= 0) && (stroka - 2 < lines.visible) && (!anchor) DrawBar(left1 - 5, top1 + 10, width1 + 5, 10, bg_color); -} - -struct s_image -{ - dword *image; - char path[4096]; -}; -s_image pics[100]; //pics = mem_Alloc( 100*sizeof(s_image) ); -int num_of_pics; - -int GetOrSetPicNum(dword i_path) -{ - int i; - for (i=0; iwidth1) w=width1; - - if (stroka==0) DrawBar(WB1.left, WB1.top, WB1.width-15, 15, bg_color); //закрашиваем первую строку - stroka+=h/10; - if (top1+hWB1.top+WB1.height-10) return; //если ВСЁ изображение ушло ВЕРХ или ВНИЗ - if (top1WB1.top+WB1.height-h-15) //если часть изображения снизу - { - h=WB1.top+WB1.height-top1-15; - } - if (h<=0) return; - if (anchor) return; - - img_draw stdcall (pics[cur_pic].image,left1-5,top1+10,w, h,0,img_lines_first); - DrawBar(left1+w - 5, top1 + 10, width1-w + 5, h, bg_color); - IF (link) UnsafeDefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9); -} - - -//скролл void TWebBrowser::DrawScroller() //не оптимальная отрисовка, но зато в одном месте { scroll1.max_area = lines.all; @@ -888,8 +832,9 @@ void TWebBrowser::DrawScroller() // scroll1.position = lines.first; scroll1.all_redraw=1; - scroll1.start_x=Form.width-28; //left + width - 15 + scroll1.start_x = WB1.left + WB1.width; scroll1.size_y=WB1.height; scrollbar_v_draw(#scroll1); } + diff --git a/programs/cmm/browser/include/img_cache.h b/programs/cmm/browser/include/img_cache.h new file mode 100644 index 0000000000..86163ddce7 --- /dev/null +++ b/programs/cmm/browser/include/img_cache.h @@ -0,0 +1,95 @@ +struct s_image +{ + dword *image; + char path[4096]; +}; +s_image pics[100]; //pics = mem_Alloc( 100*sizeof(s_image) ); +int num_of_pics; + +int GetOrSetPicNum(dword i_path) +{ + int i; + for (i=0; i width1) w = width1; + + if (stroka==0) DrawBar(WB1.left, WB1.top, WB1.width-15, 5, bg_color); //закрашиваем первую строку + stroka+=h/10; + if (top1+hWB1.top+WB1.height-10) return; //если ВСЁ изображение ушло ВЕРХ или ВНИЗ + if (top1WB1.top+WB1.height-h-5) //если часть изображения снизу + { + h=WB1.top+WB1.height-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); + 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/include/menu_rmb.h b/programs/cmm/browser/include/menu_rmb.h index 5b64d22856..35bd86dd75 100644 --- a/programs/cmm/browser/include/menu_rmb.h +++ b/programs/cmm/browser/include/menu_rmb.h @@ -4,6 +4,7 @@ #define ITEM_WIDTH 138 char *ITEMS_LIST[]={ +//"Old HTMLv F12",255, "View in Tinypad F3",52, "WIN F5",54, "DOS Ctrl+D",04, diff --git a/programs/cmm/browser/include/some_code.h b/programs/cmm/browser/include/some_code.h index a6f2140938..aa252583b3 100644 --- a/programs/cmm/browser/include/some_code.h +++ b/programs/cmm/browser/include/some_code.h @@ -31,28 +31,4 @@ void GetURLfromPageLinks(int id) } page_links[j] = 0x00; strcpy(#URL, #page_links+strrchr(#page_links, '|')); -} - - -//У нас нет наклонных шрифтов, поэтому делаем костыль из -//палочек для мороженого и жевательной резинки: -//Снимаем область экрана и выводим её обратно полосками со смещением, -//что даёт перекос картинки -//При наличии фона и т.п. проявится вся костыльность решения :) - -inline void Skew(dword x,y,w,h) -{ - dword italic_buf; - int tile_height=2, - shift=-2, - i, skin_height; - - italic_buf = mem_Alloc(w*h*3); - skin_height = GetSkinHeight(); - CopyScreen(italic_buf, x+Form.left+2, y+Form.top+skin_height, w, h); - - FOR (i=0;i*tile_height