TextReader 1.1: split two functions into one

git-svn-id: svn://kolibrios.org@6003 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-12-24 17:04:29 +00:00
parent 97f02885ef
commit 87133f20b1
2 changed files with 49 additions and 47 deletions

View File

@ -1,20 +1,21 @@
void PreparePage() char char_width[255];
{
char line[4096]=0; enum {
char char_width[255]; COUNT_BUF_HEIGHT,
dword line_start; DRAW_BUF
byte ch; };
dword bufoff, buflen;
dword line_length=30; void Parcer(byte mode)
dword stroka_y = 5; {
dword stroka=0; dword bufoff, buflen;
int i, srch_pos; byte ch;
char line[4096]=0;
int srch_pos;
dword stroka=0;
dword stroka_y=5;
dword line_length=30;
dword line_start=io.buffer_data;
label.changeSIZE();
list.w = Form.cwidth-scroll.size_x-1;
//get font chars width, need to increase performance
for (i=0; i<256; i++) char_width[i] = label.symbol_size(i);
//get font buffer height
buflen = strlen(io.buffer_data) + io.buffer_data; buflen = strlen(io.buffer_data) + io.buffer_data;
for (bufoff=io.buffer_data; bufoff<buflen; bufoff++) for (bufoff=io.buffer_data; bufoff<buflen; bufoff++)
{ {
@ -28,44 +29,45 @@ void PreparePage()
if (srch_pos == line_start) break; //no white space found in whole line if (srch_pos == line_start) break; //no white space found in whole line
srch_pos--; srch_pos--;
} }
line_start = bufoff; if (mode==COUNT_BUF_HEIGHT) {
line_length = 30; line_start = bufoff;
stroka++; line_length = 30;
list.count++;
}
if (mode==DRAW_BUF) {
EBX = bufoff-line_start;
strlcpy(#line, line_start, EBX);
label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, #line);
stroka_y += list.item_h;
line_start = bufoff;
line_length = 30;
}
} }
} }
if (mode==COUNT_BUF_HEIGHT) list.count++;
if (mode==DRAW_BUF) label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start);
}
void PreparePage()
{
//get font chars width, need to increase performance
int i;
label.changeSIZE();
for (i=0; i<256; i++) char_width[i] = label.symbol_size(i);
//get font buffer height
list.w = Form.cwidth-scroll.size_x-1;
list.count=0;
Parcer(COUNT_BUF_HEIGHT);
//draw text in buffer //draw text in buffer
list.count = stroka+2;
list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, label.size.pt+1); list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, label.size.pt+1);
if (list.count < list.visible) list.count = list.visible; if (list.count < list.visible) list.count = list.visible;
label.size.height = list.count+1*list.item_h; label.size.height = list.count+1*list.item_h;
label.raw_size = 0; label.raw_size = 0;
Parcer(DRAW_BUF);
line_length = 30; //draw result
line_start = io.buffer_data;
for (bufoff=io.buffer_data; bufoff<buflen; bufoff++)
{
ch = ESBYTE[bufoff];
line_length += char_width[ch];
if (line_length>=list.w) || (ch==10)
{
//set word break
srch_pos = bufoff;
loop()
{
if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
if (srch_pos == line_start) break; //no white space found in whole line
srch_pos--;
}
i = bufoff-line_start;
strlcpy(#line, line_start, i);
label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, #line);
stroka_y += list.item_h;
line_start = bufoff;
line_length = 30;
}
}
label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start);
label.apply_smooth(); label.apply_smooth();
DrawPage(); DrawPage();
} }

View File

@ -18,7 +18,7 @@
#define DEFAULT_EDITOR "/sys/tinypad" #define DEFAULT_EDITOR "/sys/tinypad"
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file." #define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file."
#define VERSION "Text Reader v1.06" #define VERSION "Text Reader v1.1"
#define ABOUT "Idea: Leency, punk_joker #define ABOUT "Idea: Leency, punk_joker
Code: Leency, Veliant, KolibriOS Team Code: Leency, Veliant, KolibriOS Team