Subversion Repositories Kolibri OS

Rev

Rev 7774 | Rev 7779 | 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;
7778 leency 38
	shared_mem = memopen(#shared_name, 20, SHM_WRITE);
39
	win_x = ESDWORD[shared_mem +  4];
40
	win_y = ESDWORD[shared_mem +  8];
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
 
7778 leency 78
	if (!param)
79
		die(
80
"'This is a menu component used in Eolite, WebView, etc...
81
Please forget it if you are not a developer ;)' -I");
82
 
83
	GetMenuItems(#param);
7773 leency 84
	max_name_len = strlen(names.get(0)) * 6;
85
	max_hotkey_len = strlen(hotkeys.get(0)) * 6;
86
 
87
	//selected = ESDWORD[shared_mem];
88
 
89
	menu1.count = names.count;
90
	menu1.SetFont(6, 9, 0x80);
91
	menu1.SetSizes(2,2, max_name_len + max_hotkey_len + 23, menu1.count*ITEM_H, ITEM_H);
92
	menu1.cur_y = -1;
93
 
94
	GetWindowPosition();
95
 
96
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE);
97
	loop() switch(WaitEvent())
98
	{
99
		case evMouse:
100
			GetProcessInfo(#Form, SelfInfo);
101
			if (!CheckActiveProcess(Form.ID)) exit();
102
			mouse.get();
103
			if (menu1.ProcessMouse(mouse.x, mouse.y)) draw_list();
104
			if (mouse.lkm)&&(mouse.up) click();
105
			break;
106
 
107
		case evKey:
108
			GetKeys();
109
			ProcessKeys();
110
			break;
111
 
112
		case evReDraw:
113
			DefineAndDrawWindow(win_x, win_y, menu1.w+4, menu1.h+3, 0x01, 0, 0, 0x01fffFFF);
114
			system.color.get();
115
			Draw3DPopup(0,0,menu1.w+2,menu1.h+2);
116
			draw_list();
117
	}
118
}
119
 
120
void ProcessKeys()
121
{
122
	switch(key_scancode)
123
	{
124
		case SCAN_CODE_ESC:
125
			exit();
126
 
127
		case SCAN_CODE_ENTER:
128
			click();
129
 
130
		case SCAN_CODE_DOWN:
131
			if (!menu1.KeyDown()) menu1.KeyHome();
132
			draw_list();
133
			break;
134
 
135
		case SCAN_CODE_UP:
136
			if (!menu1.KeyUp()) menu1.KeyEnd();
137
			draw_list();
138
			break;
139
 
140
		default:
141
			if (menu1.ProcessKey(key_scancode)) draw_list();
142
	}
143
}
144
 
145
void draw_list()
146
{
147
	int i, item_y;
148
 
149
	dword active_background_color = MixColors(system.color.work_button, system.color.work,230);
150
	dword active_top_border_color = MixColors(system.color.work_graph, system.color.work_button,240);
151
	dword inactive_text_shadow_color = MixColors(system.color.work,0xFFFfff,150);
152
	dword text_color;
153
	bool skin_dark = is_the_skin_dark();
154
 
155
	for (i=0; i
156
	{
157
		item_y = i*ITEM_H+menu1.y;
158
		if (i==menu1.cur_y) {
159
			text_color = system.color.work_button_text;
160
			DrawBar(menu1.x, item_y+1,        menu1.w, ITEM_H-2, active_background_color);
161
			DrawBar(menu1.x, item_y,          menu1.w, 1, active_top_border_color);
162
			DrawBar(menu1.x, item_y+ITEM_H-1, menu1.w, 1, system.color.work_light);
163
			WriteText(13 + max_name_len, item_y + menu1.text_y, 0x80, text_color, hotkeys.get(i));
164
		} else {
165
			text_color = system.color.work_text;
166
			DrawBar(menu1.x, item_y, menu1.w, ITEM_H, system.color.work);
167
			if (!skin_dark) WriteText(13+1, item_y + menu1.text_y +1, 0x80, inactive_text_shadow_color, names.get(i));
168
			WriteText(13 + max_name_len, item_y + menu1.text_y, 0x80, system.color.work_graph, hotkeys.get(i));
169
		}
170
		WriteText(13, item_y + menu1.text_y, 0x80, text_color, names.get(i));
171
	}
172
	if (selected) WriteText(5, selected*ITEM_H + menu1.y + menu1.text_y, 0x80, 0xEE0000, "\x10");
173
}
174
 
175
void click()
176
{
7778 leency 177
	ESDWORD[shared_mem] = menu1.cur_y + 1;
7773 leency 178
	ExitProcess();
179
}
180
 
181
void exit()
182
{
7778 leency 183
	ESDWORD[shared_mem] = 0;
7773 leency 184
	ExitProcess();
185
}