Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | 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;
11
	int line_h = 15;
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
	{
22
		if (bg_col!=-1) DrawBar(x, y, w+1, line_h, bg_col);
23
		end_found = false;
24
		write_length = strchr(write_start, '\n') - write_start; //search normal line break
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;
49
		y += line_h;
50
		if (write_start >= buf_end) break;
51
	}
52
	if (bg_col!=-1) DrawBar(x,y,w+1,h-y+line_h-4,bg_col);
53
	return y+line_h;
54
}