Subversion Repositories Kolibri OS

Rev

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

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