HTMLv: code refactoring #2

git-svn-id: svn://kolibrios.org@4414 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2013-12-27 01:08:50 +00:00
parent e3a51a20f1
commit 3953f09968
4 changed files with 63 additions and 60 deletions

View File

@ -11,9 +11,11 @@ dword
char download_path[]="/rd/1/.download"; char download_path[]="/rd/1/.download";
char search_path[]="http://nigma.ru/index.php?s="; char search_path[]="http://nigma.ru/index.php?s=";
struct lines{
int visible, all, first, column_max;
};
struct TWebBrowser { struct TWebBrowser {
int left, top, width, height, line_h;
llist list; llist list;
void GetNewUrl(); void GetNewUrl();
void OpenPage(); void OpenPage();
@ -73,13 +75,13 @@ void TWebBrowser::DrawPage()
if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor) if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor)
{ {
start_x = stolbec * 6 + left + magrin_left; start_x = stolbec * 6 + list.x + magrin_left;
start_y = stroka * 10 + top + magrin_left; start_y = stroka * 10 + list.y + magrin_left;
line_length = strlen(#line) * 6; line_length = strlen(#line) * 6;
WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, drawbuf); 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 (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 (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 (u_text) DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
IF (link) { IF (link) {
@ -202,12 +204,12 @@ void TWebBrowser::ShowPage()
if (!filesize) if (!filesize)
{ {
DrawBar(left, top, width+scroll1.size_x+1, height, 0xFFFFFF); //fill all DrawBar(list.x, list.y, list.w+scroll1.size_x+1, list.h, 0xFFFFFF); //fill all
if (GetProcessSlot(downloader_id)<>0) WriteText(left + 10, top + 18, 0x80, 0, "Loading..."); if (GetProcessSlot(downloader_id)<>0) WriteText(list.x + 10, list.y + 18, 0x80, 0, "Loading...");
else else
{ {
WriteText(left + 10, top + 18, 0x80, 0, "Page not found. May be, URL contains some errors."); 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(left + 10, top + 32, 0x80, 0, "Or Internet unavilable for your configuration."); if (!strcmp(get_URL_part(5),"http:"))) WriteText(list.x + 10, list.y + 32, 0x80, 0, "Or Internet unavilable for your configuration.");
} }
//return; //return;
} }
@ -342,12 +344,12 @@ void TWebBrowser::ParseHTML(dword bword){
if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì... if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
DrawPage(); DrawPage();
strcpy(#line, #temp); 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(); DrawPage();
line=NULL; 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; tag = parametr = tagparam = ignor_param = NULL;
break; break;
@ -371,18 +373,18 @@ void TWebBrowser::ParseHTML(dword bword){
if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì... if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
DrawPage(); DrawPage();
strcpy(#line, #temp); 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(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä 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) if (lines.visible * 10 + 25 <= list.h)
DrawBar(left, lines.visible * 10 + top + 25, width, -lines.visible * 10 + height - 25, bg_color); DrawBar(list.x, lines.visible * 10 + list.y + 25, list.w, -lines.visible * 10 + list.h - 25, bg_color);
if (stroka * 10 + 5 <= height) if (stroka * 10 + 5 <= list.h)
DrawBar(left, stroka * 10 + top + 5, width, -stroka * 10 + height - 5, bg_color); //çàêðàøèâàåì âñ¸ äî êîíöà 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 (lines.first == 0) lines.all = stroka;
if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
{ {
@ -576,7 +578,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
if (rez) if (rez)
{ {
TextGoDown(left1, top1, width1); 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; 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; if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
TextGoDown(left1, top1, width1); TextGoDown(left1, top1, width1);
DrawBufBar(5, WB1.line_h/2, WB1.width-10, 1, hr_color); DrawBufBar(5, WB1.list.line_h/2, WB1.list.w-10, 1, hr_color);
TextGoDown(left1, top1+WB1.line_h, width1); TextGoDown(left1, top1+WB1.list.line_h, width1);
} }
if (!chTag("img")) if (!chTag("img"))
{ {
@ -632,8 +634,8 @@ void TWebBrowser::DrawScroller() //
scroll1.position = lines.first; scroll1.position = lines.first;
scroll1.all_redraw=1; scroll1.all_redraw=1;
scroll1.start_x = WB1.left + WB1.width; scroll1.start_x = WB1.list.x + WB1.list.w;
scroll1.size_y=WB1.height; scroll1.size_y=WB1.list.h;
scrollbar_v_draw(#scroll1); scrollbar_v_draw(#scroll1);
} }

View File

@ -2,21 +2,21 @@ dword drawbuf;
void DrawBufInit() void DrawBufInit()
{ {
free(drawbuf); free(drawbuf);
drawbuf = malloc(WB1.width * WB1.line_h +4 * 4 + 8); //+1 for good luck drawbuf = malloc(WB1.list.w * WB1.list.line_h +4 * 4 + 8); //+1 for good luck
ESDWORD[drawbuf] = WB1.width; ESDWORD[drawbuf] = WB1.list.w;
ESDWORD[drawbuf+4] = WB1.line_h; ESDWORD[drawbuf+4] = WB1.list.line_h;
} }
void DrawBufFill() void DrawBufFill()
{ {
int i; int i;
for (i=0; i<WB1.width* WB1.line_h +4 * 4; i+=4) ESDWORD[drawbuf+i+8] = bg_color; for (i=0; i<WB1.list.w* WB1.list.line_h +4 * 4; i+=4) ESDWORD[drawbuf+i+8] = bg_color;
} }
void DrawBufBar(dword x, y, w, h, color) void DrawBufBar(dword x, y, w, h, color)
{ {
int i, j; int i, j;
for (j=0; j<h; j++) for (j=0; j<h; j++)
{ {
for (i = y+j*WB1.width+x*4; i<y+j*WB1.width+x+w*4 ; i+=4) ESDWORD[drawbuf+i+8] = color; for (i = y+j*WB1.list.w+x*4; i<y+j*WB1.list.w+x+w*4 ; i+=4) ESDWORD[drawbuf+i+8] = color;
} }
} }
@ -27,7 +27,7 @@ void DrawBufSkew(dword x, y, w, h)
stolbec++; stolbec++;
for (j=0; j<=3; j++) for (j=0; j<=3; j++)
{ {
for (i = y+j*WB1.width+x+w+h*4; i>y+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]; 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) void TextGoDown(int left1, top1, width1)
{ {
if (!stroka) DrawBar(WB1.left, WB1.top, WB1.width, 5, bg_color); //çàêðàøèâàåì ôîí íàä ïåðâîé ñòðîêîé if (!stroka) DrawBar(WB1.list.x, WB1.list.y, WB1.list.w, 5, bg_color); //çàêðàøèâàåì ôîí íàä ïåðâîé ñòðîêîé
if (top1>=WB1.top) && ( top1 < WB1.height+WB1.top-10) && (!anchor) 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_CENTER) DrawBufAlignCenter(left1,top1,WB1.list.w,WB1.list.line_h);
if (text_align == ALIGN_RIGHT) DrawBufAlignRight(left1,top1,WB1.width,WB1.line_h); if (text_align == ALIGN_RIGHT) DrawBufAlignRight(left1,top1,WB1.list.w,WB1.list.line_h);
PutPaletteImage(drawbuf+8, WB1.width, WB1.line_h, left1-5, top1, 32,0); PutPaletteImage(drawbuf+8, WB1.list.w, WB1.list.line_h, left1-5, top1, 32,0);
DrawBufFill(); DrawBufFill();
} }
stroka++; stroka++;

View File

@ -42,9 +42,14 @@ void Images(int left1, top1, width1)
if (strcmpn(#img_path, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0) if (strcmpn(#img_path, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0)
{ {
img_path[strrchr(#img_path, '/')] = '\0'; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî / //get path: absolute or relative
strcat(#img_path, #options); if (options[0]=='/')
strcpy(#img_path, #options);
else
{
img_path[strrchr(#img_path, '/')] = '\0';
strcat(#img_path, #options);
}
cur_pic=GetOrSetPicNum(#img_path); cur_pic=GetOrSetPicNum(#img_path);
if (!pics[cur_pic].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, "["); strcpy(#alt, "[");
strcat(#alt, #options); strcat(#alt, #options);
@ -72,23 +77,23 @@ void Images(int left1, top1, width1)
h = DSWORD[pics[cur_pic].image+8]; h = DSWORD[pics[cur_pic].image+8];
if (w > width1) w = width1; 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; stroka+=h/10;
if (top1+h<WB1.top) || (top1>WB1.top+WB1.height-10) return; //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ if (top1+h<WB1.list.y) || (top1>WB1.list.y+WB1.list.h-10) return; //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
if (top1<WB1.top) //åñëè ÷àñòü èçîáðàæåíèÿ ñâåðõó if (top1<WB1.list.y) //åñëè ÷àñòü èçîáðàæåíèÿ ñâåðõó
{ {
img_lines_first=WB1.top-top1; img_lines_first=WB1.list.y-top1;
h=h-img_lines_first; h=h-img_lines_first;
top1=WB1.top; top1=WB1.list.y;
} }
if (top1>WB1.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 (h<=0) return;
if (anchor) return; if (anchor) return;
img_draw stdcall (pics[cur_pic].image, left1-5, top1, w, h,0,img_lines_first); 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); IF (link) UnsafeDefineButton(left1 - 5, top1, w, h-1, blink + BT_HIDE, 0xB5BFC9);
} }

View File

@ -40,9 +40,6 @@ char editURL[sizeof(URL)],
page_links[12000], page_links[12000],
header[2048]; header[2048];
struct lines{
int visible, all, first, column_max;
};
int mouse_dd; int mouse_dd;
edit_box address_box= {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};
@ -90,13 +87,15 @@ void main()
switch(EAX & 0xFF) switch(EAX & 0xFF)
{ {
CASE evMouse: 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) if (lines.first <> scroll1.position)
{ {
lines.first = scroll1.position; lines.first = scroll1.position;
WB1.ParseHTML(buf, filesize); WB1.ParseHTML(buf, filesize);
//break; };
};*/ */
if (!CheckActiveProcess(Form.ID)) break; if (!CheckActiveProcess(Form.ID)) break;
@ -104,7 +103,7 @@ void main()
m.get(); m.get();
if (m.y>WB1.top) && (m.y<Form.height) && (filesize) if (m.y>WB1.list.y) && (m.y<Form.height) && (filesize)
{ {
if (m.pkm) if (m.pkm)
{ {
@ -147,10 +146,10 @@ void main()
if (scroll_used) if (scroll_used)
{ {
half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2; half_scroll_size = WB1.list.h - 16 * lines.visible / lines.all - 3 /2;
if (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //åñëè êóðñîð íàä îêíîì 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; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî 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 (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü if (btn<>lines.first) WB1.ParseHTML(buf); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
} }
@ -199,12 +198,9 @@ void main()
void SetElementSizes() void SetElementSizes()
{ {
address_box.width = Form.width-266; address_box.width = Form.width-266;
WB1.top = 44; WB1.list.SetSizes(0, 44, Form.width - 10 - scroll1.size_x, Form.cheight - 44, 0, 10);
WB1.width = Form.width - 10 - scroll1.size_x; lines.column_max = WB1.list.w - 30 / 6;
WB1.height = Form.height - WB1.top - GetSkinHeight() - 4; lines.visible = WB1.list.h - 3 / WB1.list.line_h - 2;
WB1.line_h = 10;
lines.column_max = WB1.width - 30 / 6;
lines.visible = WB1.height - 3 / WB1.line_h - 2;
DrawBufInit(); DrawBufInit();
} }