WebView 1.3 unstable: use page buffer

git-svn-id: svn://kolibrios.org@5766 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-08-23 10:12:13 +00:00
parent a97a1f029d
commit 0fc1052214
5 changed files with 46 additions and 50 deletions

View File

@ -19,15 +19,15 @@ struct TWebBrowser {
_style style; _style style;
dword draw_line_width; dword draw_line_width;
DrawBufer DrawBuf; DrawBufer DrawBuf;
void Parse(); void Prepare();
void SetTextStyle(); void SetStyle();
void DrawStyle();
void DrawPage(); void DrawPage();
void DrawScroller(); void DrawScroller();
void LoadInternalPage(); void LoadInternalPage();
void NewLine(); void NewLine();
void Perenos(); void Perenos();
void BufEncode(); void BufEncode();
byte end_parsing;
} WB1; } WB1;
@ -72,9 +72,9 @@ char anchor[256];
//============================================================================================ //============================================================================================
void TWebBrowser::DrawPage() void TWebBrowser::DrawStyle()
{ {
int start_x, start_y, line_length, stolbec_len, magrin_left=5; int start_x, start_y, line_length, stolbec_len, body_magrin=5;
if (!header) if (!header)
{ {
@ -87,21 +87,21 @@ void TWebBrowser::DrawPage()
} }
if (t_html) && (!t_body) return; if (t_html) && (!t_body) return;
if (stroka >= 0) && (stroka - 2 < list.visible) && (line) && (!anchor) if (line) && (!anchor)
{ {
start_x = stolbec * list.font_w + magrin_left * DrawBuf.zoom + list.x; start_x = stolbec * list.font_w + body_magrin * DrawBuf.zoom + list.x;
start_y = stroka * list.line_h + magrin_left + list.y; start_y = stroka * list.line_h + body_magrin;
stolbec_len = utf8_strlen(#line); stolbec_len = utf8_strlen(#line);
line_length = stolbec_len * list.font_w * DrawBuf.zoom; line_length = stolbec_len * list.font_w * DrawBuf.zoom;
WriteBufText(start_x, 0, list.font_type, text_colors[text_color_index], #line, buf_data); WriteBufText(start_x, start_y, list.font_type, text_colors[text_color_index], #line, buf_data);
if (style.b) WriteBufText(start_x+1, 0, list.font_type, text_colors[text_color_index], #line, buf_data); if (style.b) WriteBufText(start_x+1, start_y, list.font_type, text_colors[text_color_index], #line, buf_data);
if (style.i) { stolbec++; DrawBuf.Skew(start_x, 0, line_length, list.line_h); } // bug with zoom>1 if (style.i) { stolbec++; DrawBuf.Skew(start_x, start_y, line_length, list.line_h); } // bug with zoom>1
if (style.s) DrawBuf.DrawBar(start_x, list.line_h / 2 - DrawBuf.zoom, line_length, DrawBuf.zoom, text_colors[text_color_index]); if (style.s) DrawBuf.DrawBar(start_x, list.line_h / 2 - DrawBuf.zoom + start_y, line_length, DrawBuf.zoom, text_colors[text_color_index]);
if (style.u) DrawBuf.DrawBar(start_x, list.line_h - DrawBuf.zoom - DrawBuf.zoom, line_length, DrawBuf.zoom, text_colors[text_color_index]); if (style.u) DrawBuf.DrawBar(start_x, list.line_h - DrawBuf.zoom - DrawBuf.zoom + start_y, line_length, DrawBuf.zoom, text_colors[text_color_index]);
if (link) { if (link) {
DrawBuf.DrawBar(start_x, list.line_h - DrawBuf.zoom - DrawBuf.zoom, line_length, DrawBuf.zoom, text_colors[text_color_index]); DrawBuf.DrawBar(start_x, list.line_h - DrawBuf.zoom - DrawBuf.zoom + start_y, line_length, DrawBuf.zoom, text_colors[text_color_index]);
UnsafeDefineButton(start_x-2, start_y-1, line_length + 3, DrawBuf.zoom * list.font_h, PageLinks.count + 400 + BT_HIDE, 0xB5BFC9); UnsafeDefineButton(start_x-2, start_y-1 + list.y, line_length + 3, DrawBuf.zoom * list.font_h, PageLinks.count + 400 + BT_HIDE, 0xB5BFC9);
PageLinks.AddText(#line, line_length, list.line_h, UNDERLINE); PageLinks.AddText(#line, line_length, list.line_h, UNDERLINE);
} }
stolbec += stolbec_len; stolbec += stolbec_len;
@ -111,10 +111,10 @@ void TWebBrowser::DrawPage()
void TWebBrowser::LoadInternalPage(dword bufpos, in_filesize){ void TWebBrowser::LoadInternalPage(dword bufpos, in_filesize){
bufsize = in_filesize; bufsize = in_filesize;
bufpointer = bufpos; bufpointer = bufpos;
Parse(); Prepare();
} }
//============================================================================================ //============================================================================================
void TWebBrowser::Parse(){ void TWebBrowser::Prepare(){
word bukva[2]; word bukva[2];
int j; int j;
byte ignor_param; byte ignor_param;
@ -124,7 +124,6 @@ void TWebBrowser::Parse(){
style.b = style.i = style.u = style.s = style.blq = t_html = t_body = style.b = style.i = style.u = style.s = style.blq = t_html = t_body =
style.li = link = ignor_text = text_color_index = text_colors[0] = style.li_tab = 0; style.li = link = ignor_text = text_color_index = text_colors[0] = style.li_tab = 0;
end_parsing = false;
style.align = ALIGN_LEFT; style.align = ALIGN_LEFT;
link_color_inactive = 0x0000FF; link_color_inactive = 0x0000FF;
link_color_active = 0xFF0000; link_color_active = 0xFF0000;
@ -156,7 +155,6 @@ void TWebBrowser::Parse(){
for ( ; (bufpointer+bufsize > bufpos) && (ESBYTE[bufpos]!=0); bufpos++;) for ( ; (bufpointer+bufsize > bufpos) && (ESBYTE[bufpos]!=0); bufpos++;)
{ {
if (end_parsing) break;
bukva = ESBYTE[bufpos]; bukva = ESBYTE[bufpos];
if (ignor_text) && (bukva!='<') continue; if (ignor_text) && (bukva!='<') continue;
switch (bukva) switch (bukva)
@ -230,9 +228,9 @@ void TWebBrowser::Parse(){
if (tagparam) GetNextParam(); if (tagparam) GetNextParam();
if (stolbec + utf8_strlen(#line) > list.column_max) Perenos(); if (stolbec + utf8_strlen(#line) > list.column_max) Perenos();
DrawPage(); DrawStyle();
line = NULL; line = NULL;
if (tag) SetTextStyle(WB1.DrawBuf.zoom * 5 + list.x, stroka * list.line_h + list.y + 5); //îáðàáîòêà òåãîâ if (tag) SetStyle(WB1.DrawBuf.zoom * 5 + list.x, stroka * list.line_h + list.y + 5); //îáðàáîòêà òåãîâ
tag = attr = tagparam = ignor_param = NULL; tag = attr = tagparam = ignor_param = NULL;
break; break;
default: default:
@ -248,18 +246,16 @@ void TWebBrowser::Parse(){
if (stolbec + line_len > list.column_max) Perenos(); if (stolbec + line_len > list.column_max) Perenos();
} }
} }
DrawPage(); DrawStyle();
NewLine(); NewLine();
DrawBar(list.x, stroka * list.line_h + list.y + 5, draw_line_width, -stroka * list.line_h + list.h - 5, bg_color); DrawPage();
DrawBar(list.x, list.visible * list.line_h + list.y + 4, draw_line_width, -list.visible * list.line_h + list.h - 4, bg_color);
if (list.first == 0) list.count = stroka; if (list.first == 0) list.count = stroka;
if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
{ {
anchor=NULL; anchor=NULL;
list.first=anchor_line_num; list.first=anchor_line_num;
Parse(); Prepare();
} }
DrawScroller();
} }
//============================================================================================ //============================================================================================
void TWebBrowser::Perenos() void TWebBrowser::Perenos()
@ -270,14 +266,13 @@ void TWebBrowser::Perenos()
if (!perenos_num) && (utf8_strlen(#line)>list.column_max) perenos_num=list.column_max; if (!perenos_num) && (utf8_strlen(#line)>list.column_max) perenos_num=list.column_max;
strcpy(#new_line_text, #line + perenos_num); strcpy(#new_line_text, #line + perenos_num);
line[perenos_num] = 0x00; line[perenos_num] = 0x00;
if (stroka-1 > list.visible) && (list.first <>0) end_parsing=true; DrawStyle();
DrawPage();
strcpy(#line, #new_line_text); strcpy(#line, #new_line_text);
NewLine(); NewLine();
} }
//============================================================================================ //============================================================================================
char oldtag[100]; char oldtag[100];
void TWebBrowser::SetTextStyle(int left1, top1) { void TWebBrowser::SetStyle(int left1, top1) {
dword hr_color; dword hr_color;
byte opened; byte opened;
byte meta_encoding; byte meta_encoding;
@ -527,15 +522,11 @@ void TWebBrowser::NewLine()
onleft = list.x + 5; onleft = list.x + 5;
ontop = stroka * list.line_h + list.y + 5; ontop = stroka * list.line_h + list.y + 5;
if (!stroka) DrawBar(list.x, list.y, draw_line_width, 5, bg_color);
if (t_html) && (!t_body) return; if (t_html) && (!t_body) return;
if (stroka * list.line_h + 5 >= 0) && ( stroka + 1 * list.line_h + 5 < list.h) && (!anchor) if (stroka * list.line_h + 5 >= 0) && ( stroka + 1 * list.line_h + 5 < list.h) && (!anchor)
{ {
if (style.align == ALIGN_CENTER) && (DrawBuf.zoom==1) DrawBuf.AlignCenter(onleft,ontop,list.w,list.line_h,stolbec * list.font_w); if (style.align == ALIGN_CENTER) && (DrawBuf.zoom==1) DrawBuf.AlignCenter(onleft,ontop,list.w,list.line_h,stolbec * list.font_w);
if (style.align == ALIGN_RIGHT) && (DrawBuf.zoom==1) DrawBuf.AlignRight(onleft,ontop,list.w,list.line_h,stolbec * list.font_w); if (style.align == ALIGN_RIGHT) && (DrawBuf.zoom==1) DrawBuf.AlignRight(onleft,ontop,list.w,list.line_h,stolbec * list.font_w);
DrawBuf.bufy = ontop;
DrawBuf.Show();
DrawBuf.Fill(bg_color);
} }
stroka++; stroka++;
if (style.blq) stolbec = 6; else stolbec = 0; if (style.blq) stolbec = 6; else stolbec = 0;
@ -545,4 +536,9 @@ void TWebBrowser::NewLine()
int istag(dword text) { if (!strcmp(#tag,text)) return 1; else return 0; } int istag(dword text) { if (!strcmp(#tag,text)) return 1; else return 0; }
int isattr(dword text) { if (!strcmp(#attr,text)) return 1; else return 0; } int isattr(dword text) { if (!strcmp(#attr,text)) return 1; else return 0; }
int isval(dword text) { if (!strcmp(#val,text)) return 1; else return 0; } int isval(dword text) { if (!strcmp(#val,text)) return 1; else return 0; }
//============================================================================================
void TWebBrowser::DrawPage()
{
PutPaletteImage(list.first * list.line_h * DrawBuf.bufw * 4 + buf_data+8, DrawBuf.bufw, list.h, DrawBuf.bufx, DrawBuf.bufy, 32, 0);
DrawScroller();
}

View File

@ -30,14 +30,14 @@
char homepage[] = FROM "html\\homepage.htm"; char homepage[] = FROM "html\\homepage.htm";
#ifdef LANG_RUS #ifdef LANG_RUS
char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.23"; char version[]=" ’¥ªáâ®¢ë© ¡à ã§¥à 1.3 UNSTABLE";
?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­" ?define IMAGES_CACHE_CLEARED "Šíè ª à⨭®ª ®ç¨é¥­"
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤" ?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤­¨© á« ©¤"
char loading[] = "‡ £à㧪  áâà ­¨æë...<br>"; char loading[] = "‡ £à㧪  áâà ­¨æë...<br>";
char page_not_found[] = FROM "html\page_not_found_ru.htm"; char page_not_found[] = FROM "html\page_not_found_ru.htm";
char accept_language[]= "Accept-Language: ru\n"; char accept_language[]= "Accept-Language: ru\n";
#else #else
char version[]=" Text-based Browser 1.23"; char version[]=" Text-based Browser 1.3 UNSTABLE";
?define IMAGES_CACHE_CLEARED "Images cache cleared" ?define IMAGES_CACHE_CLEARED "Images cache cleared"
?define T_LAST_SLIDE "This slide is the last" ?define T_LAST_SLIDE "This slide is the last"
char loading[] = "Loading...<br>"; char loading[] = "Loading...<br>";
@ -182,7 +182,7 @@ void main()
//Mouse scroll //Mouse scroll
if (mouse.vert) if (mouse.vert)
{ {
if (WB1.list.MouseScroll(mouse.vert)) WB1.Parse(); if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage();
} }
//Drag scroller //Drag scroller
scroll_wv.all_redraw = 0; scroll_wv.all_redraw = 0;
@ -201,7 +201,7 @@ void main()
btn=WB1.list.first; btn=WB1.list.first;
WB1.list.first = mouse.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; WB1.list.first = mouse.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h;
if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible;
if (btn!=WB1.list.first) WB1.Parse(); if (btn!=WB1.list.first) WB1.DrawPage();
} }
break; break;
@ -311,7 +311,7 @@ void SetElementSizes()
WB1.list.wheel_size = 7; WB1.list.wheel_size = 7;
WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w; WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w;
WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h; WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h;
WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h); WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h * 20);
} }
void Draw_Window() void Draw_Window()
@ -382,19 +382,19 @@ void Scan(dword id__)
case SCAN_CODE_END: case SCAN_CODE_END:
case SCAN_CODE_PGUP: case SCAN_CODE_PGUP:
case SCAN_CODE_PGDN: case SCAN_CODE_PGDN:
if (WB1.list.ProcessKey(key_scancode)) WB1.Parse(); if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage();
return; return;
case SCAN_CODE_UP: case SCAN_CODE_UP:
if (WB1.list.first <= 0) return; if (WB1.list.first <= 0) return;
WB1.list.first--; WB1.list.first--;
WB1.Parse(); WB1.DrawPage();
return; return;
case SCAN_CODE_DOWN: case SCAN_CODE_DOWN:
if (WB1.list.visible + WB1.list.first >= WB1.list.count) return; if (WB1.list.visible + WB1.list.first >= WB1.list.count) return;
WB1.list.first++; WB1.list.first++;
WB1.Parse(); WB1.DrawPage();
return; return;
case GOTOURL_BUTTON: case GOTOURL_BUTTON:
@ -441,7 +441,7 @@ void Scan(dword id__)
case VIEW_SOURCE: case VIEW_SOURCE:
WB1.list.first = 0; WB1.list.first = 0;
ShowSource(); ShowSource();
WB1.Parse(); WB1.DrawPage();
break; break;
case EDIT_SOURCE: case EDIT_SOURCE:
@ -456,7 +456,7 @@ void Scan(dword id__)
case FREE_IMG_CACHE: case FREE_IMG_CACHE:
ImgCache.Free(); ImgCache.Free();
notify(IMAGES_CACHE_CLEARED); notify(IMAGES_CACHE_CLEARED);
WB1.Parse(); WB1.DrawPage();
return; return;
case VIEW_HISTORY: case VIEW_HISTORY:
@ -633,7 +633,7 @@ void ShowPage()
WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found)); WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
} }
else else
WB1.Parse(); WB1.Prepare();
if (!header) strcpy(#header, #version); if (!header) strcpy(#header, #version);
if (!strcmp(#version, #header)) DrawTitle(#header); if (!strcmp(#version, #header)) DrawTitle(#header);

View File

@ -361,7 +361,7 @@ void InitTWB() {
void DrawLetter() { void DrawLetter() {
bufsize = strlen(mdata); bufsize = strlen(mdata);
WB1.LoadInternalPage(bufsize, mdata); WB1.LoadInternalPage(bufsize, mdata);
if (bufsize) WB1.Parse(); if (bufsize) WB1.Prepare();
DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, 0xFFFfff); DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, 0xFFFfff);
} }

View File

@ -5,7 +5,7 @@
cls cls
c-- ttf_viewer.c c-- ttf_viewer.c
@rename ttf_viewer.com ttf_viewer @rename ttf_viewer.com ttf_viewer
@kpack ttf_viewer
@del warning.txt @del warning.txt
@del lang.h-- @del lang.h--
@pause @pause
kpack ttf_viewer

View File

@ -5,7 +5,7 @@
cls cls
c-- ttf_viewer.c c-- ttf_viewer.c
@rename ttf_viewer.com ttf_viewer @rename ttf_viewer.com ttf_viewer
@kpack ttf_viewer
@del warning.txt @del warning.txt
@del lang.h-- @del lang.h--
@pause @pause
kpack ttf_viewer