Subversion Repositories Kolibri OS

Rev

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