Subversion Repositories Kolibri OS

Rev

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

Rev 7422 Rev 7444
1
#ifndef INCLUDE_GUI_H
1
#ifndef INCLUDE_GUI_H
2
#define INCLUDE_GUI_H
2
#define INCLUDE_GUI_H
3
 
3
 
4
#ifndef INCLUDE_KOLIBRI_H
4
#ifndef INCLUDE_KOLIBRI_H
5
#include "../lib/kolibri.h"
5
#include "../lib/kolibri.h"
6
#endif
6
#endif
7
 
7
 
8
#ifndef INCLUDE_STRING_H
8
#ifndef INCLUDE_STRING_H
9
#include "../lib/strings.h"
9
#include "../lib/strings.h"
10
#endif
10
#endif
11
 
11
 
12
#ifndef INCLUDE_RGB_H
12
#ifndef INCLUDE_RGB_H
13
#include "../lib/patterns/rgb.h"
13
#include "../lib/patterns/rgb.h"
14
#endif
14
#endif
15
 
15
 
16
#ifndef INCLUDE_MATH_H
16
#ifndef INCLUDE_MATH_H
17
#include "../lib/math.h"
17
#include "../lib/math.h"
18
#endif
18
#endif
19
 
19
 
20
#include "../lib/gui/tabs.h"
20
#include "../lib/gui/tabs.h"
21
#include "../lib/gui/more_less_box.h"
21
#include "../lib/gui/more_less_box.h"
22
#include "../lib/gui/checkbox.h"
22
#include "../lib/gui/checkbox.h"
23
#include "../lib/gui/child_window.h"
23
#include "../lib/gui/child_window.h"
24
#include "../lib/gui/text_view_area.h"
24
#include "../lib/gui/text_view_area.h"
25
 
25
 
26
:int last_free_button_id = 1000;
26
:int last_free_button_id = 1000;
27
:int GetFreeButtonId()
27
:int GetFreeButtonId()
28
{
28
{
29
	last_free_button_id++;
29
	last_free_button_id++;
30
	return last_free_button_id;
30
	return last_free_button_id;
31
}
31
}
32
 
32
 
33
:void DrawRectangle(dword x,y,w,h,color1)
33
:void DrawRectangle(dword x,y,w,h,color1)
34
{
34
{
35
	DrawBar(x,y,w,1,color1);
35
	DrawBar(x,y,w,1,color1);
36
	DrawBar(x,y+h,w,1,color1);
36
	DrawBar(x,y+h,w,1,color1);
37
	DrawBar(x,y,1,h,color1);
37
	DrawBar(x,y,1,h,color1);
38
	DrawBar(x+w,y,1,h+1,color1);
38
	DrawBar(x+w,y,1,h+1,color1);
39
}
39
}
40
 
40
 
41
:void DrawWideRectangle(dword x,y,w,h,boder,color1)
41
:void DrawWideRectangle(dword x,y,w,h,boder,color1)
42
{
42
{
43
	DrawBar(x, y, w, boder, color1);
43
	DrawBar(x, y, w, boder, color1);
44
	DrawBar(x, y+h-boder, w, boder, color1);
44
	DrawBar(x, y+h-boder, w, boder, color1);
45
	DrawBar(x, y+boder, boder, h-boder-boder, color1);
45
	DrawBar(x, y+boder, boder, h-boder-boder, color1);
46
	DrawBar(x+w-boder, y+boder, boder, h-boder-boder, color1);
46
	DrawBar(x+w-boder, y+boder, boder, h-boder-boder, color1);
47
}
47
}
48
 
48
 
49
:void DrawRectangle3D(dword x,y,w,h,color1,color2)
49
:void DrawRectangle3D(dword x,y,w,h,color1,color2)
50
{
50
{
51
	DrawBar(x,y,w+1,1,color1);
51
	DrawBar(x,y,w+1,1,color1);
52
	DrawBar(x,y+1,1,h-1,color1);
52
	DrawBar(x,y+1,1,h-1,color1);
53
	DrawBar(x+w,y+1,1,h,color2);
53
	DrawBar(x+w,y+1,1,h,color2);
54
	DrawBar(x,y+h,w,1,color2);
54
	DrawBar(x,y+h,w,1,color2);
55
}
55
}
56
 
56
 
57
:void DrawCaptButton(dword x,y,w,h,id,color_b, color_t,text)
57
:void DrawCaptButton(dword x,y,w,h,id,color_b, color_t,text)
58
{
58
{
59
	dword tx = -strlen(text)*8+w/2+x;
59
	dword tx = -strlen(text)*8+w/2+x;
60
	dword ty = h/2-7+y;
60
	dword ty = h/2-7+y;
61
 
61
 
62
	if (id>0) DefineButton(x,y,w,h,id,color_b);
62
	if (id>0) DefineButton(x,y,w,h,id,color_b);
63
	WriteText(tx+1,ty+1,0x90,MixColors(color_b,0,230),text);
63
	WriteText(tx+1,ty+1,0x90,MixColors(color_b,0,230),text);
64
	WriteText(tx,ty,0x90,color_t,text);
64
	WriteText(tx,ty,0x90,color_t,text);
65
}
65
}
66
 
66
 
67
:int active_button_id = 0;
67
:int active_button_id = 0;
68
:int DrawStandartCaptButton(dword x, y, id, text)
68
:int DrawStandartCaptButton(dword x, y, id, text)
69
{
69
{
70
	#define padding_v 5
70
	#define padding_v 5
71
	#define padding_h 15
71
	#define padding_h 15
72
	#define right_margin 12
72
	#define right_margin 12
73
	#define h padding_v + padding_v + 16 //16 font height
73
	#define h padding_v + padding_v + 16 //16 font height
74
	int tx = x + padding_h;
74
	int tx = x + padding_h;
75
	int ty = y + padding_v+1;
75
	int ty = y + padding_v+1;
76
	int tw = strlen(text)*8;
76
	int tw = strlen(text)*8;
77
	int w = tw + padding_h + padding_h;
77
	int w = tw + padding_h + padding_h;
78
 
78
 
79
 
79
 
80
	if (id>0) DefineButton(x,y,w,h,id,system.color.work_button);
80
	if (id>0) DefineButton(x,y,w,h,id,system.color.work_button);
81
 
81
 
82
	WriteText(tx+1,ty+1,0x90,MixColors(system.color.work_button,0,230),text);
82
	WriteText(tx+1,ty+1,0x90,MixColors(system.color.work_button,0,230),text);
83
	WriteText(tx,ty,0x90,system.color.work_button_text,text);
83
	WriteText(tx,ty,0x90,system.color.work_button_text,text);
84
 
84
 
85
	if (active_button_id==id) {
85
	if (active_button_id==id) {
86
		DrawBar(tx,ty+15,tw,1, MixColors(system.color.work_button,0,230));
86
		DrawBar(tx,ty+15,tw,1, MixColors(system.color.work_button,0,230));
87
		DrawBar(tx,ty+14,tw,1, system.color.work_button_text);
87
		DrawBar(tx,ty+14,tw,1, system.color.work_button_text);
88
	}
88
	}
89
 
89
 
90
	return w + right_margin;
90
	return w + right_margin;
91
}
91
}
92
 
92
 
93
:void ActiveButtonSwitch(int min, max)
93
:void ActiveButtonSwitch(int min, max)
94
{
94
{
95
	active_button_id++;
95
	active_button_id++;
96
	if (active_button_id>max) || (active_button_id
96
	if (active_button_id>max) || (active_button_id
97
}
97
}
98
 
98
 
99
:void WriteTextCenter(dword x,y,w,color_t,text)
99
:void WriteTextCenter(dword x,y,w,color_t,text)
100
{
100
{
101
	WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text);
101
	WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text);
102
}
102
}
103
 
103
 
104
:void DrawCircle(int x, y, r, color)
104
:void DrawCircle(int x, y, r, color)
105
{
105
{
106
	int i;
106
	int i;
107
	float px=0, py=r, ii = r * 3.1415926 * 2;
107
	float px=0, py=r, ii = r * 3.1415926 * 2;
108
	FOR (i = 0; i < ii; i++)
108
	FOR (i = 0; i < ii; i++)
109
	{
109
	{
110
        PutPixel(px + x, y - py, color);
110
        PutPixel(px + x, y - py, color);
111
        px = py / r + px;
111
        px = py / r + px;
112
        py = -px / r + py;
112
        py = -px / r + py;
113
	}
113
	}
114
}
114
}
115
 
115
 
116
:void DrawEditBox(dword edit_box_pointer)
116
:void DrawEditBox(dword edit_box_pointer)
117
{
117
{
118
	dword x,y,w,h,bg,t;
118
	dword x,y,w,h,bg,t;
119
	ESI = edit_box_pointer;
119
	ESI = edit_box_pointer;
120
	x = ESI.edit_box.left;
120
	x = ESI.edit_box.left;
121
	y = ESI.edit_box.top;
121
	y = ESI.edit_box.top;
122
	w = ESI.edit_box.width+1;
122
	w = ESI.edit_box.width+1;
123
	h = 22;
123
	h = 22;
124
	if (ESI.edit_box.flags & 100000000000b) bg = 0xCACACA; else bg = 0xFFFfff;
124
	if (ESI.edit_box.flags & 100000000000b) bg = 0xCACACA; else bg = 0xFFFfff;
125
	edit_box_draw  stdcall (edit_box_pointer);
125
	edit_box_draw  stdcall (edit_box_pointer);
126
	DrawRectangle3D(x-1, y-1, w+1, h+1, 0xE7E7E7, bg);
126
	DrawRectangle3D(x-1, y-1, w+1, h+1, 0xE7E7E7, bg);
127
	DrawRectangle(x-2, y-2, w+3, h+3, system.color.work_graph);
127
	DrawRectangle(x-2, y-2, w+3, h+3, system.color.work_graph);
128
	DrawRectangle3D(x-3, y-3, w+5, h+5, system.color.work_dark, system.color.work_light);
128
	DrawRectangle3D(x-3, y-3, w+5, h+5, system.color.work_dark, system.color.work_light);
129
}
129
}
130
 
130
 
131
:void DrawEditBoxPos(dword x,y, edit_box_pointer)
131
:void DrawEditBoxPos(dword x,y, edit_box_pointer)
132
{
132
{
133
	ESI = edit_box_pointer;
133
	ESI = edit_box_pointer;
134
	ESI.edit_box.left = x;
134
	ESI.edit_box.left = x;
135
	ESI.edit_box.top = y;
135
	ESI.edit_box.top = y;
136
	DrawEditBox(dword edit_box_pointer);
136
	DrawEditBox(dword edit_box_pointer);
137
}
137
}
138
 
138
 
139
:void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent)
139
:void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent)
140
{
140
{
141
	int progress_w;
141
	int progress_w;
142
	static int fill_old;
142
	static int fill_old;
143
	    
143
	    
144
	//if (progress_percent<=0) {DrawBar(st_x,st_y, st_x + st_w + fill_old + 15,st_h+1, col_fon); fill_old=0; return;}
144
	//if (progress_percent<=0) {DrawBar(st_x,st_y, st_x + st_w + fill_old + 15,st_h+1, col_fon); fill_old=0; return;}
145
	if (progress_percent<=0) || (progress_percent>=100) return;
145
	if (progress_percent<=0) || (progress_percent>=100) return;
146
	
146
	
147
	DrawRectangle(st_x, st_y, st_w,st_h, col_border);
147
	DrawRectangle(st_x, st_y, st_w,st_h, col_border);
148
	DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff);
148
	DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff);
149
 
149
 
150
	if (progress_percent>0) && (progress_percent<=100)
150
	if (progress_percent>0) && (progress_percent<=100)
151
	{
151
	{
152
		progress_w = st_w - 3 * progress_percent / 100;
152
		progress_w = st_w - 3 * progress_percent / 100;
153
		DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill);
153
		DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill);
154
		DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff);
154
		DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff);
155
	}
155
	}
156
}
156
}
157
 
157
 
158
:void DrawLink(dword x,y,font_type,btn_id, inscription)
158
:void DrawLink(dword x,y,font_type,btn_id, inscription)
159
{
159
{
160
	int w;
160
	int w;
161
	WriteText(x,y,font_type,0x4E00E7,inscription);
161
	WriteText(x,y,font_type,0x4E00E7,inscription);
162
	if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*8;
162
	if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*8;
163
	DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0);
163
	DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0);
164
	DrawBar(x,y+8,w,1,0x4E00E7);
164
	DrawBar(x,y+8,w,1,0x4E00E7);
165
}
165
}
166
 
166
 
167
:void PutShadow(dword x,y,w,h,skinned,strength)
167
:void PutShadow(dword x,y,w,h,skinned,strength)
168
{
168
{
169
	proc_info wForm;
169
	proc_info wForm;
170
	dword shadow_buf, skin_height;
170
	dword shadow_buf, skin_height;
171
	shadow_buf = mem_Alloc(w*h*3);
171
	shadow_buf = mem_Alloc(w*h*3);
172
 	GetProcessInfo(#wForm, SelfInfo);
172
 	GetProcessInfo(#wForm, SelfInfo);
173
	CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h);
173
	CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h);
174
	ShadowImage(shadow_buf, w, h, strength);
174
	ShadowImage(shadow_buf, w, h, strength);
175
	_PutImage(x,y,w,h,shadow_buf);
175
	_PutImage(x,y,w,h,shadow_buf);
176
	mem_Free(shadow_buf);
176
	mem_Free(shadow_buf);
177
}
177
}
178
 
178
 
179
:void DrawPopup(dword x,y,w,h,skinned, col_work,col_border)
179
:void DrawPopup(dword x,y,w,h,skinned, col_work,col_border)
180
{
180
{
181
	DrawRectangle(x,y,w,h,col_border);
181
	DrawRectangle(x,y,w,h,col_border);
182
	DrawBar(x+1,y+1,w-1,1,0xFFFfff);
182
	DrawBar(x+1,y+1,w-1,1,0xFFFfff);
183
	DrawBar(x+1,y+2,1,h-2,0xFFFfff);
183
	DrawBar(x+1,y+2,1,h-2,0xFFFfff);
184
	if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work);
184
	if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work);
185
	DrawPopupShadow(x,y,w,h-1,skinned);
185
	DrawPopupShadow(x,y,w,h-1,skinned);
186
}
186
}
187
 
187
 
188
:void DrawPopupShadow(dword x,y,w,h,skinned)
188
:void DrawPopupShadow(dword x,y,w,h,skinned)
189
{
189
{
190
	PutShadow(w+x+1,y,1,h+2,skinned,2);
190
	PutShadow(w+x+1,y,1,h+2,skinned,2);
191
	PutShadow(w+x+2,y+1,1,h+2,skinned,1);
191
	PutShadow(w+x+2,y+1,1,h+2,skinned,1);
192
	PutShadow(x,y+h+2,w+2,1,skinned,2);
192
	PutShadow(x,y+h+2,w+2,1,skinned,2);
193
	PutShadow(x+1,y+h+3,w+1,1,skinned,1);
193
	PutShadow(x+1,y+h+3,w+1,1,skinned,1);
194
}
194
}
195
 
195
 
196
:dword GrayScaleImage(dword color_image, w, h)
196
:dword GrayScaleImage(dword color_image, w, h)
197
{
197
{
198
	dword i,gray,to,rr,gg,bb;
198
	dword i,gray,to,rr,gg,bb;
199
	to = w*h*3 + color_image;
199
	to = w*h*3 + color_image;
200
	for (i = color_image; i < to; i+=3)
200
	for (i = color_image; i < to; i+=3)
201
	{
201
	{
202
		rr = DSBYTE[i];
202
		rr = DSBYTE[i];
203
		gg = DSBYTE[i+1];
203
		gg = DSBYTE[i+1];
204
		bb = DSBYTE[i+2];
204
		bb = DSBYTE[i+2];
205
		gray = rr*rr;
205
		gray = rr*rr;
206
		gray += gg*gg;
206
		gray += gg*gg;
207
		gray += bb*bb;
207
		gray += bb*bb;
208
		gray = sqrt(gray) / 3;
208
		gray = sqrt(gray) / 3;
209
		DSBYTE[i] = DSBYTE[i+1] = DSBYTE[i+2] = gray;
209
		DSBYTE[i] = DSBYTE[i+1] = DSBYTE[i+2] = gray;
210
	}
210
	}
211
	return gray;
211
	return gray;
212
}
212
}
213
 
213
 
214
:void ShadowImage(dword color_image, w, h, strength)
214
:void ShadowImage(dword color_image, w, h, strength)
215
{
215
{
216
	dword col, to;
216
	dword col, to;
217
	strength = 10 - strength;
217
	strength = 10 - strength;
218
	to = w*h*3 + color_image;
218
	to = w*h*3 + color_image;
219
	for ( ; color_image < to; color_image++)
219
	for ( ; color_image < to; color_image++)
220
	{
220
	{
221
		col = strength * DSBYTE[color_image] / 10;
221
		col = strength * DSBYTE[color_image] / 10;
222
		DSBYTE[color_image] = col;
222
		DSBYTE[color_image] = col;
223
	}
223
	}
224
}
224
}
225
 
225
 
226
:void WriteTextLines(dword x,y,byte fontType, dword color, text_pointer, line_h)
226
:void WriteTextLines(dword x,y,byte fontType, dword color, text_pointer, line_h)
227
{
227
{
228
	dword next_word_pointer = strchr(text_pointer, '\n');
228
	dword next_word_pointer = strchr(text_pointer, '\n');
229
	if (next_word_pointer) WriteTextLines(dword x, y+line_h, byte fontType, dword color, next_word_pointer+2, line_h);
229
	if (next_word_pointer) WriteTextLines(dword x, y+line_h, byte fontType, dword color, next_word_pointer+2, line_h);
230
	ESBYTE[next_word_pointer] = NULL;
230
	ESBYTE[next_word_pointer] = NULL;
231
	WriteText(dword x, y, byte fontType, dword color, text_pointer);
231
	WriteText(dword x, y, byte fontType, dword color, text_pointer);
232
	ESBYTE[next_word_pointer] = '\n';
232
	ESBYTE[next_word_pointer] = '\n';
233
}
233
}
234
 
234
 
235
//this function increase falue and return it
235
//this function increase falue and return it
236
//useful for list of controls which goes one after one
236
//useful for list of controls which goes one after one
237
:struct incn
237
:struct incn
238
{
238
{
239
	dword n;
239
	dword n;
240
	dword inc(dword _addition);
240
	dword inc(dword _addition);
241
};
241
};
242
 
242
 
243
:dword incn::inc(dword _addition)
243
:dword incn::inc(dword _addition)
244
{
244
{
245
	n+=_addition;
245
	n+=_addition;
246
	return n;
246
	return n;
247
}
247
}
248
 
248
 
249
//block with hover
249
//block with hover
250
struct block {
250
struct block {
251
	int x,y,w,h;
251
	int x,y,w,h;
252
	bool hovered();
252
	bool hovered();
253
	void set_size();
253
	void set_size();
254
};
254
};
255
 
255
 
256
:bool block::hovered() {
256
:bool block::hovered() {
257
	if ((mouse.x>x) && (mouse.y>y) 
257
	if ((mouse.x>=x) && (mouse.y>=y) 
258
	&& (mouse.y
258
	&& (mouse.y<=y+h) && (mouse.x<=x+w)) 
259
		return true;
259
		return true;
260
	return false;
260
	return false;
261
}
261
}
262
 
262
 
263
:void block::set_size(dword _x, _y, _w, _h)
263
:void block::set_size(dword _x, _y, _w, _h)
264
{
264
{
265
	x=_x; 
265
	x=_x; 
266
	y=_y;
266
	y=_y;
267
	w=_w;
267
	w=_w;
268
	h=_h;
268
	h=_h;
269
}
269
}
270
 
270
 
271
 
271
 
272
 
272
 
273
 
273
 
274
 
274
 
275
#endif
275
#endif
276
>
276
>