Rev 7274 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7274 | leency | 1 | /* |
2 | We have a long text and need to show it in block. |
||
3 | Normal line break '\n' must be applied. |
||
4 | Long lines should be breaked by word. |
||
5 | TODO: scroll |
||
6 | */ |
||
7 | :int DrawTextViewArea(int x,y,w,h, dword buf_start, bg_col, text_col) |
||
8 | { |
||
9 | dword write_start; |
||
10 | dword buf_end; |
||
8996 | leency | 11 | #define LINE_H 17 |
7274 | leency | 12 | int label_length_max; |
13 | int write_length; |
||
14 | bool end_found; |
||
15 | |||
16 | write_start = buf_start; |
||
17 | buf_end = strlen(buf_start) + buf_start; |
||
18 | label_length_max = w / 8; // 8 big font char width |
||
19 | |||
20 | loop() |
||
21 | { |
||
8996 | leency | 22 | if (bg_col!=-1) DrawBar(x, y, w+1, LINE_H, bg_col); |
7274 | leency | 23 | end_found = false; |
8996 | leency | 24 | write_length = strchr(write_start, '\n') - write_start +1; //search normal line break |
7274 | leency | 25 | if (write_length > label_length_max) || (write_length<=0) //check its position: exceeds maximum line length or not found |
26 | { |
||
27 | if (buf_end - write_start < label_length_max) //check does current line the last |
||
28 | { |
||
29 | write_length = buf_end - write_start; |
||
30 | end_found = true; |
||
31 | } |
||
32 | else |
||
33 | { |
||
34 | for (write_length=label_length_max; write_length>0; write_length--) { //search for white space to make the line break |
||
35 | if (ESBYTE[write_start+write_length] == ' ') { |
||
36 | end_found = true; |
||
37 | break; |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | if (end_found != true) write_length = label_length_max; //no white space, so we write label_length_max |
||
42 | } |
||
43 | ESI = write_length; //set text length attribute for WriteText() |
||
44 | WriteText(x, y, 0x10, text_col, write_start); |
||
45 | // if (editpos >= write_start-buf_start) && (editpos <= write_start-buf_start + write_length) { |
||
46 | // WriteTextB(-write_start+buf_start+editpos * 8 + x - 5 +1, y, 0x90, 0xFF0000, "|"); |
||
47 | // } |
||
48 | write_start += write_length + 1; |
||
8996 | leency | 49 | y += LINE_H; |
7274 | leency | 50 | if (write_start >= buf_end) break; |
51 | } |
||
8996 | leency | 52 | if (bg_col!=-1) DrawBar(x,y,w+1,h-y+LINE_H-4,bg_col); |
53 | return y+LINE_H; |
||
7274 | leency | 54 | }=>>=0)> |