Subversion Repositories Kolibri OS

Rev

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

Rev 5542 Rev 5598
-
 
1
#ifndef INCLUDE_GUI_H
-
 
2
#define INCLUDE_GUI_H
-
 
3
 
-
 
4
#ifndef INCLUDE_KOLIBRI_H
-
 
5
#include "../lib/kolibri.h"
-
 
6
#endif
-
 
7
 
-
 
8
#ifndef INCLUDE_STRING_H
1
//#include "strings.h"
9
#include "../lib/strings.h"
-
 
10
#endif
2
 
11
 
3
:void DrawRectangle(dword x,y,w,h,color1)
12
:void DrawRectangle(dword x,y,w,h,color1)
4
{
13
{
5
	if (w<=0) || (h<=0) return;
14
	if (w<=0) || (h<=0) return;
6
	DrawBar(x,y,w,1,color1);
15
	DrawBar(x,y,w,1,color1);
7
	DrawBar(x,y+h,w,1,color1);
16
	DrawBar(x,y+h,w,1,color1);
8
	DrawBar(x,y,1,h,color1);
17
	DrawBar(x,y,1,h,color1);
9
	DrawBar(x+w,y,1,h+1,color1);
18
	DrawBar(x+w,y,1,h+1,color1);
10
}
19
}
11
 
20
 
12
:void DrawRectangle3D(dword x,y,w,h,color1,color2)
21
:void DrawRectangle3D(dword x,y,w,h,color1,color2)
13
{
22
{
14
	if (w<=0) || (h<=0) return;
23
	if (w<=0) || (h<=0) return;
15
	DrawBar(x,y,w+1,1,color1);
24
	DrawBar(x,y,w+1,1,color1);
16
	DrawBar(x,y+1,1,h-1,color1);
25
	DrawBar(x,y+1,1,h-1,color1);
17
	DrawBar(x+w,y+1,1,h,color2);
26
	DrawBar(x+w,y+1,1,h,color2);
18
	DrawBar(x,y+h,w,1,color2);
27
	DrawBar(x,y+h,w,1,color2);
19
}
28
}
20
 
29
 
21
:void DrawCaptButton(dword x,y,w,h,id,color_b, color_t,text)
30
:void DrawCaptButton(dword x,y,w,h,id,color_b, color_t,text)
22
{
31
{
23
	if (id>0) DefineButton(x,y,w,h,id,color_b);
32
	if (id>0) DefineButton(x,y,w,h,id,color_b);
24
	WriteText(-strlen(text)*6+w/2+x+1,h/2-3+y,0x80,color_t,text);
33
	WriteText(-strlen(text)*6+w/2+x+1,h/2-3+y,0x80,color_t,text);
25
}
34
}
26
 
35
 
27
:void WriteTextCenter(dword x,y,w,color_t,text)
36
:void WriteTextCenter(dword x,y,w,color_t,text)
28
{
37
{
29
	WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text);
38
	WriteText(-strlen(text)*6+w/2+x+1,y,0x80,color_t,text);
30
}
39
}
31
 
40
 
32
:void DrawCircle(int x, y, r, color)
41
:void DrawCircle(int x, y, r, color)
33
{
42
{
34
	int i;
43
	int i;
35
	float px=0, py=r, ii = r * 3.1415926 * 2;
44
	float px=0, py=r, ii = r * 3.1415926 * 2;
36
	FOR (i = 0; i < ii; i++)
45
	FOR (i = 0; i < ii; i++)
37
	{
46
	{
38
        PutPixel(px + x, y - py, color);
47
        PutPixel(px + x, y - py, color);
39
        px = py / r + px;
48
        px = py / r + px;
40
        py = -px / r + py;
49
        py = -px / r + py;
41
	}
50
	}
42
}
51
}
43
 
52
 
44
:void CheckBox(dword x,y,w,h, bt_id, text, graph_color, text_color, is_checked)
53
:void CheckBox(dword x,y,w,h, bt_id, text, graph_color, text_color, is_checked)
45
{
54
{
46
	DefineButton(x-1, y-1, strlen(text)*6 + w + 17, h+2, bt_id+BT_HIDE+BT_NOFRAME, graph_color);
55
	DefineButton(x-1, y-1, strlen(text)*6 + w + 17, h+2, bt_id+BT_HIDE+BT_NOFRAME, graph_color);
47
	WriteText(x+w+8, h / 2 + y -3, 0x80, text_color, text);
56
	WriteText(x+w+8, h / 2 + y -3, 0x80, text_color, text);
48
	DrawRectangle(x, y, w, h, graph_color);
57
	DrawRectangle(x, y, w, h, graph_color);
49
	if (is_checked == 0)
58
	if (is_checked == 0)
50
	{
59
	{
51
		DrawRectangle3D(x+1, y+1, w-2, h-2, 0xDDDddd, 0xffffff);
60
		DrawRectangle3D(x+1, y+1, w-2, h-2, 0xDDDddd, 0xffffff);
52
		DrawBar(x+2, y+2, w-3, h-3, 0xffffff);
61
		DrawBar(x+2, y+2, w-3, h-3, 0xffffff);
53
	} 
62
	} 
54
	else if (is_checked == 1)
63
	else if (is_checked == 1)
55
	{
64
	{
56
		DrawRectangle(x+1, y+1, w-2, h-2, 0xffffff);
65
		DrawRectangle(x+1, y+1, w-2, h-2, 0xffffff);
57
		DrawRectangle(x+2, y+2, w-4, h-4, 0xffffff);
66
		DrawRectangle(x+2, y+2, w-4, h-4, 0xffffff);
58
		DrawBar(x+3, y+3, w-5, h-5, graph_color);
67
		DrawBar(x+3, y+3, w-5, h-5, graph_color);
59
	}
68
	}
60
	else if (is_checked == 2) //not active
69
	else if (is_checked == 2) //not active
61
	{
70
	{
62
		DrawRectangle(x+1, y+1, w-2, h-2, 0xffffff);
71
		DrawRectangle(x+1, y+1, w-2, h-2, 0xffffff);
63
		DrawRectangle(x+2, y+2, w-4, h-4, 0xffffff);
72
		DrawRectangle(x+2, y+2, w-4, h-4, 0xffffff);
64
		DrawBar(x+3, y+3, w-5, h-5, 0x888888);
73
		DrawBar(x+3, y+3, w-5, h-5, 0x888888);
65
	}
74
	}
66
}
75
}
67
 
76
 
68
:void MoreLessBox(dword x,y,s, bt_id_more, bt_id_less, colors_pointer, value, text)
77
:void MoreLessBox(dword x,y,s, bt_id_more, bt_id_less, colors_pointer, value, text)
69
{
78
{
70
	#define VALUE_FIELD_W 26;
79
	#define VALUE_FIELD_W 26;
71
	system_colors colors;
80
	system_colors colors;
72
	ESI = colors_pointer;
81
	ESI = colors_pointer;
73
	colors.work_graph = ESI.system_colors.work_graph;
82
	colors.work_graph = ESI.system_colors.work_graph;
74
	colors.work_text = ESI.system_colors.work_text;
83
	colors.work_text = ESI.system_colors.work_text;
75
	colors.work_button = ESI.system_colors.work_button;
84
	colors.work_button = ESI.system_colors.work_button;
76
	colors.work_button_text = ESI.system_colors.work_button_text;
85
	colors.work_button_text = ESI.system_colors.work_button_text;
77
 
86
 
78
	DrawRectangle(x, y, VALUE_FIELD_W, s, colors.work_graph);
87
	DrawRectangle(x, y, VALUE_FIELD_W, s, colors.work_graph);
79
	DrawRectangle3D(x+1, y+1, VALUE_FIELD_W-2, s-2, 0xDDDddd, 0xffffff);
88
	DrawRectangle3D(x+1, y+1, VALUE_FIELD_W-2, s-2, 0xDDDddd, 0xffffff);
80
	DrawBar(x+2, y+2, VALUE_FIELD_W-3, s-3, 0xffffff);
89
	DrawBar(x+2, y+2, VALUE_FIELD_W-3, s-3, 0xffffff);
81
	WriteText(x+6, s / 2 + y -3, 0x80, 0x000000, itoa(value));
90
	WriteText(x+6, s / 2 + y -3, 0x80, 0x000000, itoa(value));
82
 
91
 
83
	DrawCaptButton(VALUE_FIELD_W + x + 1,     y, s, s, bt_id_more, colors.work_button, colors.work_button_text, "+");
92
	DrawCaptButton(VALUE_FIELD_W + x + 1,     y, s, s, bt_id_more, colors.work_button, colors.work_button_text, "+");
84
	DrawCaptButton(VALUE_FIELD_W + x + s + 2, y, s, s, bt_id_less, colors.work_button, colors.work_button_text, "-");
93
	DrawCaptButton(VALUE_FIELD_W + x + s + 2, y, s, s, bt_id_less, colors.work_button, colors.work_button_text, "-");
85
	WriteText(x+VALUE_FIELD_W+s+s+10, s / 2 + y -3, 0x80, colors.work_text, text);
94
	WriteText(x+VALUE_FIELD_W+s+s+10, s / 2 + y -3, 0x80, colors.work_text, text);
86
}
95
}
87
 
96
 
88
:void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent)
97
:void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent)
89
{
98
{
90
	int progress_w;
99
	int progress_w;
91
	static int fill_old;
100
	static int fill_old;
92
	    
101
	    
93
	//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;}
102
	//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;}
94
	if (progress_percent<=0) || (progress_percent>=100) return;
103
	if (progress_percent<=0) || (progress_percent>=100) return;
95
	
104
	
96
	DrawRectangle(st_x, st_y, st_w,st_h, col_border);
105
	DrawRectangle(st_x, st_y, st_w,st_h, col_border);
97
	DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff);
106
	DrawRectangle3D(st_x+1, st_y+1, st_w-2,st_h-2, 0xFFFfff, 0xFFFfff);
98
 
107
 
99
	if (progress_percent>0) && (progress_percent<=100)
108
	if (progress_percent>0) && (progress_percent<=100)
100
	{
109
	{
101
		progress_w = st_w - 3 * progress_percent / 100;
110
		progress_w = st_w - 3 * progress_percent / 100;
102
		DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill);
111
		DrawBar(st_x+2, st_y+2, progress_w, st_h-3, col_fill);
103
		DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff);
112
		DrawBar(st_x+2+progress_w, st_y+2, st_w-progress_w-3, st_h-3, 0xFFFfff);
104
	}
113
	}
105
}
114
}
106
 
115
 
107
:void DrawLink(dword x,y,font_type,btn_id, inscription)
116
:void DrawLink(dword x,y,font_type,btn_id, inscription)
108
{
117
{
109
	int w;
118
	int w;
110
	WriteText(x,y,font_type,0x4E00E7,inscription);
119
	WriteText(x,y,font_type,0x4E00E7,inscription);
111
	if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*7;
120
	if (font_type==0x80) w = strlen(inscription)*6; else w = strlen(inscription)*7;
112
	DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0);
121
	DefineButton(x-1,y-1,w,10,btn_id+BT_HIDE,0);
113
	DrawBar(x,y+8,w,1,0x4E00E7);
122
	DrawBar(x,y+8,w,1,0x4E00E7);
114
}
123
}
115
 
124
 
116
:void PutShadow(dword x,y,w,h,skinned,strength)
125
:void PutShadow(dword x,y,w,h,skinned,strength)
117
{
126
{
118
	proc_info wForm;
127
	proc_info wForm;
119
	dword shadow_buf, skin_height;
128
	dword shadow_buf, skin_height;
120
	shadow_buf = mem_Alloc(w*h*3);
129
	shadow_buf = mem_Alloc(w*h*3);
121
 	GetProcessInfo(#wForm, SelfInfo);
130
 	GetProcessInfo(#wForm, SelfInfo);
122
	CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h);
131
	CopyScreen(shadow_buf, 5*skinned+x+wForm.left, GetSkinHeight()*skinned+y+wForm.top, w, h);
123
	ShadowImage(shadow_buf, w, h, strength);
132
	ShadowImage(shadow_buf, w, h, strength);
124
	_PutImage(x,y,w,h,shadow_buf);
133
	_PutImage(x,y,w,h,shadow_buf);
125
	mem_Free(shadow_buf);
134
	mem_Free(shadow_buf);
126
}
135
}
127
 
136
 
128
:void DrawPopup(dword x,y,w,h,skinned, col_work,col_border)
137
:void DrawPopup(dword x,y,w,h,skinned, col_work,col_border)
129
{
138
{
130
	DrawRectangle(x,y,w,h,col_border);
139
	DrawRectangle(x,y,w,h,col_border);
131
	DrawBar(x+1,y+1,w-1,1,0xFFFfff);
140
	DrawBar(x+1,y+1,w-1,1,0xFFFfff);
132
	DrawBar(x+1,y+2,1,h-2,0xFFFfff);
141
	DrawBar(x+1,y+2,1,h-2,0xFFFfff);
133
	if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work);
142
	if (col_work!=-1) DrawBar(x+2,y+2,w-2,h-2,col_work);
134
	DrawPopupShadow(x,y,w,h-1,skinned);
143
	DrawPopupShadow(x,y,w,h-1,skinned);
135
}
144
}
136
 
145
 
137
:void DrawPopupShadow(dword x,y,w,h,skinned)
146
:void DrawPopupShadow(dword x,y,w,h,skinned)
138
{
147
{
139
	PutShadow(w+x+1,y,1,h+2,skinned,2);
148
	PutShadow(w+x+1,y,1,h+2,skinned,2);
140
	PutShadow(w+x+2,y+1,1,h+2,skinned,1);
149
	PutShadow(w+x+2,y+1,1,h+2,skinned,1);
141
	PutShadow(x,y+h+2,w+2,1,skinned,2);
150
	PutShadow(x,y+h+2,w+2,1,skinned,2);
142
	PutShadow(x+1,y+h+3,w+1,1,skinned,1);
151
	PutShadow(x+1,y+h+3,w+1,1,skinned,1);
143
}
152
}
144
 
153
 
145
:void GrayScaleImage(dword color_image, w, h)
154
:void GrayScaleImage(dword color_image, w, h)
146
{
155
{
147
	dword i,gray,rr,gg,bb;
156
	dword i,gray,rr,gg,bb;
148
	for (i = 0; i < w*h*3; i+=3)
157
	for (i = 0; i < w*h*3; i+=3)
149
	{
158
	{
150
		rr = DSBYTE[i+color_image];
159
		rr = DSBYTE[i+color_image];
151
		gg = DSBYTE[i+1+color_image];
160
		gg = DSBYTE[i+1+color_image];
152
		bb = DSBYTE[i+2+color_image];
161
		bb = DSBYTE[i+2+color_image];
153
		gray = rr*rr;
162
		gray = rr*rr;
154
		gray += gg*gg;
163
		gray += gg*gg;
155
		gray += bb*bb;
164
		gray += bb*bb;
156
		gray = sqrt(gray) / 3;
165
		gray = sqrt(gray) / 3;
157
		DSBYTE[i  +color_image] = DSBYTE[i+1+color_image] = DSBYTE[i+2+color_image] = gray;
166
		DSBYTE[i  +color_image] = DSBYTE[i+1+color_image] = DSBYTE[i+2+color_image] = gray;
158
	}
167
	}
159
}
168
}
160
 
169
 
161
:void ShadowImage(dword color_image, w, h, strength)
170
:void ShadowImage(dword color_image, w, h, strength)
162
{
171
{
163
	dword col, to;
172
	dword col, to;
164
	strength = 10 - strength;
173
	strength = 10 - strength;
165
	to = w*h*3 + color_image;
174
	to = w*h*3 + color_image;
166
	for ( ; color_image < to; color_image++)
175
	for ( ; color_image < to; color_image++)
167
	{
176
	{
168
		col = strength * DSBYTE[color_image] / 10;
177
		col = strength * DSBYTE[color_image] / 10;
169
		DSBYTE[color_image] = col;
178
		DSBYTE[color_image] = col;
170
	}
179
	}
171
}
180
}
172
>
181
 
-
 
182
#endif
-
 
183
>
173
184