2015-12-24 18:04:29 +01:00
|
|
|
enum {
|
|
|
|
COUNT_BUF_HEIGHT,
|
|
|
|
DRAW_BUF
|
|
|
|
};
|
|
|
|
|
2018-11-04 01:20:00 +01:00
|
|
|
#define DRAW_PADDING 12
|
|
|
|
|
2020-04-10 18:19:52 +02:00
|
|
|
void Parse(byte mode)
|
2015-12-17 16:48:28 +01:00
|
|
|
{
|
2015-12-24 18:04:29 +01:00
|
|
|
dword bufoff, buflen;
|
|
|
|
byte ch;
|
|
|
|
char line[4096]=0;
|
|
|
|
int srch_pos;
|
2018-11-04 01:20:00 +01:00
|
|
|
dword stroka_y=DRAW_PADDING-3;
|
2015-12-24 18:04:29 +01:00
|
|
|
dword line_length=30;
|
|
|
|
dword line_start=io.buffer_data;
|
2015-12-21 13:13:21 +01:00
|
|
|
|
|
|
|
buflen = strlen(io.buffer_data) + io.buffer_data;
|
|
|
|
for (bufoff=io.buffer_data; bufoff<buflen; bufoff++)
|
2015-12-17 16:48:28 +01:00
|
|
|
{
|
|
|
|
ch = ESBYTE[bufoff];
|
2018-05-22 14:04:44 +02:00
|
|
|
line_length += kfont_char_width[ch];
|
2015-12-17 16:48:28 +01:00
|
|
|
if (line_length>=list.w) || (ch==10) {
|
|
|
|
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--;
|
|
|
|
}
|
2015-12-24 18:04:29 +01:00
|
|
|
if (mode==COUNT_BUF_HEIGHT) {
|
|
|
|
line_start = bufoff;
|
|
|
|
line_length = 30;
|
|
|
|
list.count++;
|
|
|
|
}
|
|
|
|
if (mode==DRAW_BUF) {
|
|
|
|
EBX = bufoff-line_start;
|
|
|
|
strlcpy(#line, line_start, EBX);
|
2018-11-04 01:20:00 +01:00
|
|
|
kfont.WriteIntoBuffer(DRAW_PADDING,stroka_y,list.w,kfont.size.height, bg_color, text_color, kfont.size.pt, #line);
|
2015-12-24 18:04:29 +01:00
|
|
|
stroka_y += list.item_h;
|
|
|
|
line_start = bufoff;
|
|
|
|
line_length = 30;
|
|
|
|
}
|
2015-12-17 16:48:28 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-24 00:47:37 +01:00
|
|
|
if (mode==COUNT_BUF_HEIGHT) list.count+=2;
|
2018-11-04 01:20:00 +01:00
|
|
|
if (mode==DRAW_BUF) kfont.WriteIntoBuffer(DRAW_PADDING,stroka_y,list.w,kfont.size.height, bg_color, text_color, kfont.size.pt, line_start);
|
2015-12-24 18:04:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreparePage()
|
|
|
|
{
|
|
|
|
list.w = Form.cwidth-scroll.size_x-1;
|
|
|
|
list.count=0;
|
2020-04-10 18:19:52 +02:00
|
|
|
Parse(COUNT_BUF_HEIGHT);
|
2015-12-24 18:04:29 +01:00
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
//draw text in buffer
|
2018-11-04 01:20:00 +01:00
|
|
|
list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, kfont.size.pt+6);
|
2015-12-17 16:48:28 +01:00
|
|
|
if (list.count < list.visible) list.count = list.visible;
|
2016-12-21 20:50:13 +01:00
|
|
|
kfont.size.height = list.count+1*list.item_h;
|
|
|
|
kfont.raw_size = 0;
|
2020-04-10 18:19:52 +02:00
|
|
|
Parse(DRAW_BUF);
|
2015-12-17 16:48:28 +01:00
|
|
|
|
2016-12-23 01:27:00 +01:00
|
|
|
if (list.count > list.visible * 10) DrawPage();
|
2015-12-24 18:04:29 +01:00
|
|
|
//draw result
|
2016-12-21 20:50:13 +01:00
|
|
|
kfont.ApplySmooth();
|
2015-12-17 16:48:28 +01:00
|
|
|
DrawPage();
|
|
|
|
}
|