Subversion Repositories Kolibri OS

Rev

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