Subversion Repositories Kolibri OS

Rev

Rev 7778 | Rev 7780 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7773 leency 1
#define MEMSIZE 4096*40
2
 
7778 leency 3
#include "../lib/gui.h"
7773 leency 4
#include "../lib/io.h"
5
#include "../lib/collection.h"
6
#include "../lib/list_box.h"
7
#include "../lib/fs.h"
8
 
9
#define ITEM_H 19
10
 
11
llist menu1;
12
collection names;
13
collection hotkeys;
14
 
15
int win_x, win_y;
16
 
17
int max_name_len;
18
int max_hotkey_len;
19
 
20
int selected = 0;
21
 
7778 leency 22
/*
7773 leency 23
dword cur_param = #param;
24
int GetNextParam()
25
{
26
	int result;
27
	dword next_param = strchr(cur_param, ' ');
28
	ESBYTE[next_param] = '\0';
29
	result = atoi(cur_param);
30
	cur_param = next_param+1;
31
	return result;
32
}
7778 leency 33
*/
7773 leency 34
 
35
void GetWindowPosition()
36
{
7774 leency 37
	int position, rez;
7779 leency 38
	shared_mem = memopen(#shared_name, 20, SHM_READ);
39
	win_x    = ESDWORD[shared_mem +  4];
40
	win_y    = ESDWORD[shared_mem +  8];
7778 leency 41
	position = ESDWORD[shared_mem + 12];
42
	selected = ESDWORD[shared_mem + 16];
7773 leency 43
	if (position==2) win_x -= menu1.w;
44
	if (position==3) {
45
		win_x -= menu1.w;
46
		win_y -= menu1.h;
47
	}
48
	if (position==4) win_y -= menu1.h;
49
}
50
 
51
void GetMenuItems(dword current_name)
52
{
53
	dword next_name = strchr(current_name, '\n');
54
	dword hotkey = strchr(current_name, '|');
55
 
56
	ESBYTE[next_name] = '\0';
57
 
58
	if (hotkey) && (hotkey < next_name) {
59
		ESBYTE[hotkey] = '\0';
60
	} else {
61
		if (hotkey) && (!next_name) {
62
			ESBYTE[hotkey] = '\0';
63
		} else {
64
			hotkey = "  ";
65
		}
66
	}
67
 
68
	hotkeys.add(hotkey+1);
69
	names.add(current_name);
70
 
71
	if (next_name) GetMenuItems(next_name+2);
72
}
73
 
74
void main()
75
{
76
	proc_info Form;
77
 
7779 leency 78
	if (!param) die("'Menu component is for developers only' -I");
7778 leency 79
 
80
	GetMenuItems(#param);
7773 leency 81
	max_name_len = strlen(names.get(0)) * 6;
82
	max_hotkey_len = strlen(hotkeys.get(0)) * 6;
83
 
84
	menu1.count = names.count;
85
	menu1.SetFont(6, 9, 0x80);
86
	menu1.SetSizes(2,2, max_name_len + max_hotkey_len + 23, menu1.count*ITEM_H, ITEM_H);
87
	menu1.cur_y = -1;
88
 
89
	GetWindowPosition();
90
 
91
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE);
92
	loop() switch(WaitEvent())
93
	{
94
		case evMouse:
95
			GetProcessInfo(#Form, SelfInfo);
96
			if (!CheckActiveProcess(Form.ID)) exit();
97
			mouse.get();
98
			if (menu1.ProcessMouse(mouse.x, mouse.y)) draw_list();
99
			if (mouse.lkm)&&(mouse.up) click();
100
			break;
101
 
102
		case evKey:
103
			GetKeys();
104
			ProcessKeys();
105
			break;
106
 
107
		case evReDraw:
108
			DefineAndDrawWindow(win_x, win_y, menu1.w+4, menu1.h+3, 0x01, 0, 0, 0x01fffFFF);
109
			system.color.get();
110
			Draw3DPopup(0,0,menu1.w+2,menu1.h+2);
111
			draw_list();
112
	}
113
}
114
 
115
void ProcessKeys()
116
{
117
	switch(key_scancode)
118
	{
119
		case SCAN_CODE_ESC:
120
			exit();
121
 
122
		case SCAN_CODE_ENTER:
123
			click();
124
 
125
		case SCAN_CODE_DOWN:
126
			if (!menu1.KeyDown()) menu1.KeyHome();
127
			draw_list();
128
			break;
129
 
130
		case SCAN_CODE_UP:
131
			if (!menu1.KeyUp()) menu1.KeyEnd();
132
			draw_list();
133
			break;
134
 
135
		default:
136
			if (menu1.ProcessKey(key_scancode)) draw_list();
137
	}
138
}
139
 
140
void draw_list()
141
{
142
	int i, item_y;
143
 
144
	dword active_background_color = MixColors(system.color.work_button, system.color.work,230);
145
	dword active_top_border_color = MixColors(system.color.work_graph, system.color.work_button,240);
146
	dword inactive_text_shadow_color = MixColors(system.color.work,0xFFFfff,150);
147
	dword text_color;
148
	bool skin_dark = is_the_skin_dark();
149
 
150
	for (i=0; i
151
	{
152
		item_y = i*ITEM_H+menu1.y;
153
		if (i==menu1.cur_y) {
154
			text_color = system.color.work_button_text;
155
			DrawBar(menu1.x, item_y+1,        menu1.w, ITEM_H-2, active_background_color);
156
			DrawBar(menu1.x, item_y,          menu1.w, 1, active_top_border_color);
157
			DrawBar(menu1.x, item_y+ITEM_H-1, menu1.w, 1, system.color.work_light);
158
			WriteText(13 + max_name_len, item_y + menu1.text_y, 0x80, text_color, hotkeys.get(i));
159
		} else {
160
			text_color = system.color.work_text;
161
			DrawBar(menu1.x, item_y, menu1.w, ITEM_H, system.color.work);
162
			if (!skin_dark) WriteText(13+1, item_y + menu1.text_y +1, 0x80, inactive_text_shadow_color, names.get(i));
163
			WriteText(13 + max_name_len, item_y + menu1.text_y, 0x80, system.color.work_graph, hotkeys.get(i));
164
		}
165
		WriteText(13, item_y + menu1.text_y, 0x80, text_color, names.get(i));
166
	}
167
	if (selected) WriteText(5, selected*ITEM_H + menu1.y + menu1.text_y, 0x80, 0xEE0000, "\x10");
168
}
169
 
170
void click()
171
{
7779 leency 172
	char res[2];
173
	res[0] = menu1.cur_y + 1;
174
	res[1] = '\0';
175
	//ESDWORD[shared_mem] = menu1.cur_y + 1;
176
	CreateFile(2, #res, "/tmp0/1/menu.tmp");
7773 leency 177
	ExitProcess();
178
}
179
 
180
void exit()
181
{
7779 leency 182
	//ESDWORD[shared_mem] = 0;
183
	CreateFile(2, 0, "/tmp0/1/menu.tmp");
7773 leency 184
	ExitProcess();
185
}