Subversion Repositories Kolibri OS

Rev

Rev 8381 | Rev 8425 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8381 Rev 8396
1
#ifndef INCLUDE_DRAW_BUF_H
1
#ifndef INCLUDE_DRAW_BUF_H
2
#define INCLUDE_DRAW_BUF_H
2
#define INCLUDE_DRAW_BUF_H
3
#print "[include ]\n"
3
#print "[include ]\n"
4
 
4
 
5
#ifndef INCLUDE_KOLIBRI_H
5
#ifndef INCLUDE_KOLIBRI_H
6
#include "../lib/kolibri.h"
6
#include "../lib/kolibri.h"
7
#endif
7
#endif
8
 
8
 
9
dword buf_data=0;
9
dword buf_data=0;
10
 
10
 
11
 
11
 
12
struct DrawBufer {
12
struct DrawBufer {
13
	dword bufx, bufy, bufw, bufh;
13
	dword bufx, bufy, bufw, bufh;
14
	dword fill_color;
14
	dword fill_color;
15
 
15
 
16
	bool Init();
16
	bool Init();
17
	void Show();
17
	void Show();
18
	void Fill();
18
	void Fill();
19
	void DrawBar();
19
	void DrawBar();
20
	void WriteText();
20
	void WriteText();
21
	void PutPixel();
21
	void PutPixel();
22
	void AlignCenter();
22
	void AlignCenter();
23
	void AlignRight();
23
	void AlignRight();
24
	void IncreaseBufSize();
24
	void IncreaseBufSize();
25
};
25
};
26
 
26
 
27
char draw_buf_not_enaught_ram[] = 
27
char draw_buf_not_enaught_ram[] = 
28
"'DrawBufer requested %i MB more memory than the system has.
28
"'DrawBufer requested %i MB more memory than the system has.
29
Application could be unstable.' -E";
29
Application could be unstable.' -E";
30
 
30
 
31
bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh)
31
bool DrawBufer::Init(dword i_bufx, i_bufy, i_bufw, i_bufh)
32
{
32
{
33
	bufx = i_bufx;
33
	bufx = i_bufx;
34
	bufy = i_bufy;
34
	bufy = i_bufy;
35
	bufw = i_bufw; 
35
	bufw = i_bufw; 
36
	bufh = i_bufh;
36
	bufh = i_bufh;
37
	if (buf_data) buf_data = free(buf_data);
37
	if (buf_data) buf_data = free(buf_data);
38
	IncreaseBufSize();
38
	IncreaseBufSize();
39
	if (!buf_data) return false;
39
	if (!buf_data) return false;
40
	ESDWORD[buf_data] = bufw;
40
	ESDWORD[buf_data] = bufw;
41
	ESDWORD[buf_data+4] = bufh;
41
	ESDWORD[buf_data+4] = bufh;
42
	return true;
42
	return true;
43
}
43
}
44
 
44
 
45
void DrawBufer::Fill(dword start_pointer, i_fill_color)
45
void DrawBufer::Fill(dword start_pointer, i_fill_color)
46
{
46
{
47
	dword i;
-
 
48
	dword max_i = bufw * bufh * 4 + buf_data + 8;
47
	dword max_i = bufw * bufh * 4 - start_pointer/4;
49
	fill_color = i_fill_color;
48
	fill_color = i_fill_color;
50
	@MEMSETD(buf_data+start_pointer+8, max_i-buf_data-start_pointer-8/4, fill_color);
49
	@MEMSETD(buf_data+start_pointer+8, max_i, fill_color);
51
}
50
}
52
 
51
 
53
void DrawBufer::DrawBar(dword x, y, w, h, color)
52
void DrawBufer::DrawBar(dword x, y, w, h, color)
54
{
53
{
55
	dword i, j;
54
	dword i, j;
56
	if (y + h >= bufh) IncreaseBufSize();
55
	if (y + h >= bufh) IncreaseBufSize();
57
	for (j=0; j
56
	for (j=0; j
58
		for (i = y+j*bufw+x<<2+8+buf_data; i
57
		for (i = y+j*bufw+x<<2+8+buf_data; i
59
			ESDWORD[i] = color;
58
			ESDWORD[i] = color;
60
		}
59
		}
61
	}
60
	}
62
}
61
}
63
 
62
 
64
void DrawBufer::WriteText(dword x, y, byte fontType, dword color, str_offset, strlen)
63
void DrawBufer::WriteText(dword x, y, byte fontType, dword color, str_offset, strlen)
65
{
64
{
66
	#define BUGFIX_32000 32000
65
	#define BUGFIX_32000 32000
67
	dword ydiv=0;
66
	dword ydiv=0;
68
	dword reserve_data_1, reserve_data_2;
67
	dword reserve_data_1, reserve_data_2;
69
	dword new_buf_offset;
68
	dword new_buf_offset;
70
	if (y + 30 >= bufh) IncreaseBufSize();
69
	if (y + 30 >= bufh) IncreaseBufSize();
71
	if (y < BUGFIX_32000) {
70
	if (y < BUGFIX_32000) {
72
		ESI = strlen;
71
		ESI = strlen;
73
		WriteBufText(x, y, fontType, color, str_offset, buf_data);
72
		WriteBufText(x, y, fontType, color, str_offset, buf_data);
74
	}
73
	}
75
	else {
74
	else {
76
		ydiv = y / BUGFIX_32000 * BUGFIX_32000;
75
		ydiv = y / BUGFIX_32000 * BUGFIX_32000;
77
		y -= ydiv;
76
		y -= ydiv;
78
		new_buf_offset = ydiv * bufw * 4 + buf_data;
77
		new_buf_offset = ydiv * bufw * 4 + buf_data;
79
 
78
 
80
		reserve_data_1 = ESDWORD[new_buf_offset];
79
		reserve_data_1 = ESDWORD[new_buf_offset];
81
		reserve_data_2 = ESDWORD[new_buf_offset+4];
80
		reserve_data_2 = ESDWORD[new_buf_offset+4];
82
 
81
 
83
		ESDWORD[new_buf_offset] = bufw;
82
		ESDWORD[new_buf_offset] = bufw;
84
		ESDWORD[new_buf_offset+4] = bufh - y;
83
		ESDWORD[new_buf_offset+4] = bufh - y;
85
		ESI = strlen;
84
		ESI = strlen;
86
		WriteBufText(x, y, fontType, color, str_offset, new_buf_offset);
85
		WriteBufText(x, y, fontType, color, str_offset, new_buf_offset);
87
 
86
 
88
		ESDWORD[new_buf_offset] = reserve_data_1;
87
		ESDWORD[new_buf_offset] = reserve_data_1;
89
		ESDWORD[new_buf_offset+4] = reserve_data_2;
88
		ESDWORD[new_buf_offset+4] = reserve_data_2;
90
	}
89
	}
91
}
90
}
92
 
91
 
93
void DrawBufer::PutPixel(dword x, y, color)
92
void DrawBufer::PutPixel(dword x, y, color)
94
{
93
{
95
	dword pos = y*bufw+x*4+8+buf_data;
94
	dword pos = y*bufw+x*4+8+buf_data;
96
	ESDWORD[pos] = color;
95
	ESDWORD[pos] = color;
97
}
96
}
98
 
97
 
99
void DrawBufer::AlignRight(dword x,y,w,h, content_width)
98
void DrawBufer::AlignRight(dword x,y,w,h, content_width)
100
{
99
{
101
	dword i, j, l;
100
	dword i, j, l;
102
	dword content_left = w - content_width / 2;
101
	dword content_left = w - content_width / 2;
103
	for (j=0; j
102
	for (j=0; j
104
	{
103
	{
105
		for (i=j*w+w-x*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
104
		for (i=j*w+w-x*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
106
		{
105
		{
107
			ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
106
			ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
108
		}
107
		}
109
	}
108
	}
110
}
109
}
111
 
110
 
112
void DrawBufer::AlignCenter(dword x,y,w,h, content_width)
111
void DrawBufer::AlignCenter(dword x,y,w,h, content_width)
113
{
112
{
114
	dword i, j, l;
113
	dword i, j, l;
115
	dword content_left = w - content_width / 2;
114
	dword content_left = w - content_width / 2;
116
	for (j=0; j
115
	for (j=0; j
117
	{
116
	{
118
		for (i=j*w+content_width+content_left*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
117
		for (i=j*w+content_width+content_left*4, l=j*w+content_width+x*4; (i>=j*w+content_left*4) && (l>=j*w*4); i-=4, l-=4)
119
		{
118
		{
120
			ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
119
			ESDWORD[buf_data+8+i] >< ESDWORD[buf_data+8+l];
121
		}
120
		}
122
	}
121
	}
123
}
122
}
124
 
-
 
125
/*
123
 
126
void DrawBufer::Zoom2x(int zoom)
124
void DrawBufer::Show(dword _y_offset, _h)
127
{
-
 
128
	int i, s;
-
 
129
	dword point_x, max_i, zline_w, s_inc;
-
 
130
 
-
 
131
	point_x = 0;
-
 
132
	max_i = bufw * bufh * 4 + buf_data+8;
-
 
133
	s_inc = zoom * 4;
-
 
134
	zline_w = zbufw * 4;
-
 
135
 
-
 
136
	for (i=buf_data+8, s=zbuf_data+8; i
-
 
137
		ESDWORD[s] = ESDWORD[i];
-
 
138
		ESDWORD[s+4] = ESDWORD[i];
-
 
139
		ESDWORD[s+zline_w] = ESDWORD[i];
-
 
140
		ESDWORD[s+zline_w+4] = ESDWORD[i];
-
 
141
		if (zoom==3)
-
 
142
		{
-
 
143
			ESDWORD[s+8] = ESDWORD[i];
-
 
144
			ESDWORD[zline_w+s+8] = ESDWORD[i];
-
 
145
			ESDWORD[zline_w*2+s] = ESDWORD[i];
-
 
146
			ESDWORD[zline_w*2+s+4] = ESDWORD[i];
-
 
147
			ESDWORD[zline_w*2+s+8] = ESDWORD[i];
-
 
148
		}
-
 
149
 
-
 
150
		point_x++;
-
 
151
		if (point_x >= bufw) 
-
 
152
		{
-
 
153
			s += zoom - 1 * zline_w;
-
 
154
			point_x = 0;
-
 
155
		}
-
 
156
	}
-
 
157
}
-
 
158
*/
-
 
159
 
-
 
160
 
-
 
161
void DrawBufer::Show(dword _y_offset)
-
 
162
{
125
{
163
	PutPaletteImage(_y_offset * bufw * 4 + buf_data+8, bufw, bufh, bufx, bufy, 32, 0);	
126
	PutPaletteImage(_y_offset * bufw * 4 + buf_data+8, bufw, _h, bufx, bufy, 32, 0);
164
}
127
}
165
 
128
 
166
void DrawBufer::IncreaseBufSize()
129
void DrawBufer::IncreaseBufSize()
167
{
130
{
168
	static dword alloc_counter;
131
	static dword alloc_counter;
169
	static dword bufh_initial;
132
	static dword bufh_initial;
170
	dword alloc_size;
133
	dword alloc_size;
171
	dword free_ram_size;
134
	dword free_ram_size;
172
	char error_str[256];
135
	char error_str[256];
173
 
136
 
174
	if (!buf_data) {
137
	if (!buf_data) {
175
		alloc_counter = 1;
138
		alloc_counter = 1;
176
		bufh_initial = bufh;
139
		bufh_initial = bufh;
177
		alloc_size = bufw * bufh * 4 + 8;
140
		alloc_size = bufw * bufh * 4 + 8;
178
		buf_data = malloc(alloc_size);
141
		buf_data = malloc(alloc_size);
179
	}
142
	}
180
	else {
143
	else {
181
		alloc_counter++;
144
		alloc_counter++;
182
		bufh = bufh_initial * alloc_counter;
145
		bufh = bufh_initial * alloc_counter;
183
		alloc_size = bufw * bufh * 4 + 8;
146
		alloc_size = bufw * bufh * 4 + 8;
184
		buf_data = realloc(buf_data, alloc_size);
147
		buf_data = realloc(buf_data, alloc_size);
185
		Fill(alloc_counter - 1 * bufw * bufh_initial * 4 + 8, fill_color);
148
		Fill(alloc_counter - 1 * bufw * bufh_initial * 4 + 8, fill_color);
186
	}
149
	}
187
 
150
 
188
	free_ram_size = GetFreeRAM() * 1024;
151
	free_ram_size = GetFreeRAM() * 1024;
189
	if (alloc_size > free_ram_size) {
152
	if (alloc_size > free_ram_size) {
190
		sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size - free_ram_size/1048576);
153
		sprintf(#error_str, #draw_buf_not_enaught_ram, alloc_size - free_ram_size/1048576);
191
		notify(#error_str);
154
		notify(#error_str);
192
	}
155
	}
193
}
156
}
194
 
157
 
195
 
158
 
196
 
159
 
197
#endif
160
#endif