Subversion Repositories Kolibri OS

Rev

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

Rev 7450 Rev 7770
1
#ifndef INCLUDE_MENU_H
1
#ifndef INCLUDE_MENU_H
2
#define INCLUDE_MENU_H
2
#define INCLUDE_MENU_H
3
 
3
 
4
#ifndef INCLUDE_LIST_BOX
4
#ifndef INCLUDE_LIST_BOX
5
#include "../lib/list_box.h"
5
#include "../lib/list_box.h"
6
#endif
6
#endif
7
 
7
 
8
:dword menu_process_id;
8
:dword menu_process_id;
9
 
9
 
10
:struct _menu : llist
10
:struct _menu : llist
11
{
11
{
12
	dword appear_x, appear_y, text, identifier, selected;	
12
	dword appear_x, appear_y, text, identifier, selected;	
13
	void show();
13
	void show();
14
	char stak[4096];
14
	char stak[4096];
15
} menu;
15
} menu;
16
 
16
 
17
:void _menu::show(dword _appear_x, _appear_y, _menu_width, _menu_text, _identifier)
17
:void _menu::show(dword _appear_x, _appear_y, _menu_width, _menu_text, _identifier)
18
{
18
{
19
	#define ITEM_H 21
19
	#define ITEM_H 21
20
	appear_x = _appear_x;
20
	appear_x = _appear_x;
21
	appear_y = _appear_y;
21
	appear_y = _appear_y;
22
	text = _menu_text;
22
	text = _menu_text;
23
	identifier = _identifier;
23
	identifier = _identifier;
24
 
24
 
25
	cur_y = -1;
25
	cur_y = -1;
26
	ClearList();
26
	ClearList();
27
	count = chrnum(text, '\n')+1;
27
	count = chrnum(text, '\n')+1;
28
	SetSizes(2,2,_menu_width,count*ITEM_H,ITEM_H);
28
	SetSizes(2,2,_menu_width,count*ITEM_H,ITEM_H);
29
 
29
 
30
	menu_process_id = CreateThread(#_menu_thread,#stak+4092);
30
	menu_process_id = CreateThread(#_menu_thread,#stak+4092);
31
}
31
}
32
 
32
 
33
:void _menu_thread()
33
:void _menu_thread()
34
{
34
{
35
	proc_info MenuForm;
35
	MOUSE m;
-
 
36
	DefineAndDrawWindow(menu.appear_x,menu.appear_y,menu.w+2,menu.h+4,0x01, 0, 0, 0x01fffFFF);
-
 
37
	DrawPopup(0,0,menu.w,menu.h+3,0, 0xE4DFE1,0x9098B0);
36
	SetEventMask(100111b);
38
	_menu_draw_list();				
-
 
39
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_MOUSE + EVM_MOUSE_FILTER);
37
	loop() switch(WaitEvent())
40
	loop() switch(WaitEvent())
38
	{
41
	{
39
		case evMouse:
42
		case evMouse:
40
			GetProcessInfo(#MenuForm, SelfInfo);
-
 
41
			if (!CheckActiveProcess(MenuForm.ID)) _menu_no_item_click();
-
 
42
			mouse.get();
43
			m.get();
43
			if (menu.ProcessMouse(mouse.x, mouse.y)) _menu_draw_list();
44
			if (menu.ProcessMouse(m.x, m.y)) _menu_draw_list();
44
			if (mouse.lkm)&&(mouse.up) _menu_item_click();
45
			if (m.lkm)&&(m.up) _menu_item_click();
45
			break;		
46
			break;		
46
		case evKey:
47
		case evKey:
47
			GetKeys();
48
			GetKeys();
48
			if (key_scancode==SCAN_CODE_ESC) _menu_no_item_click();
49
			if (key_scancode==SCAN_CODE_ESC) _menu_exit();
49
			if (key_scancode==SCAN_CODE_ENTER) _menu_item_click();
50
			if (key_scancode==SCAN_CODE_ENTER) _menu_item_click();
50
			if (menu.ProcessKey(key_scancode)) _menu_draw_list();
51
			if (menu.ProcessKey(key_scancode)) _menu_draw_list();
51
			break;
52
			break;
52
		case evReDraw:
53
		case evReDraw:
53
			DefineAndDrawWindow(menu.appear_x,menu.appear_y,menu.w+2,menu.h+4,0x01, 0, 0, 0x01fffFFF);
-
 
54
			DrawPopup(0,0,menu.w,menu.h+3,0, 0xE4DFE1,0x9098B0);
-
 
55
			_menu_draw_list();				
54
			_menu_exit();
56
	}
55
	}
57
}
56
}
58
 
57
 
59
:void _menu_draw_list()
58
:void _menu_draw_list()
60
{
59
{
61
	int N, bgcol;
60
	int N, bgcol;
62
	for (N=0; N
61
	for (N=0; N
63
	{
62
	{
64
		if (N==menu.cur_y) bgcol=0xFFFfff; else bgcol=0xE4DFE1;
63
		if (N==menu.cur_y) bgcol=0xFFFfff; else bgcol=0xE4DFE1;
65
		DrawBar(menu.x, N*menu.item_h+menu.y, menu.w-3, menu.item_h, bgcol);
64
		DrawBar(menu.x, N*menu.item_h+menu.y, menu.w-3, menu.item_h, bgcol);
66
	}
65
	}
67
	WriteTextLines(13, menu.item_h-8/2+menu.y, 0x80, 0, menu.text, menu.item_h);
66
	WriteTextLines(13, menu.item_h-8/2+menu.y, 0x80, 0, menu.text, menu.item_h);
68
	if (menu.selected) WriteText(5, menu.selected-1*menu.item_h+8, 0x80, 0xEE0000, "\x10");
67
	if (menu.selected) WriteText(5, menu.selected-1*menu.item_h+8, 0x80, 0xEE0000, "\x10");
69
}
68
}
70
 
69
 
71
:void _menu_item_click()
70
:void _menu_item_click()
72
{
71
{
73
	menu.cur_y = menu.identifier + menu.cur_y;
72
	menu.cur_y = menu.identifier + menu.cur_y;
74
	KillProcess(menu_process_id);
73
	KillProcess(menu_process_id);
75
}
74
}
76
 
75
 
77
:void _menu_no_item_click()
76
:void _menu_exit()
78
{
77
{
79
	menu.cur_y = 0;
78
	menu.cur_y = 0;
80
	KillProcess(menu_process_id);
79
	KillProcess(menu_process_id);
81
}
80
}
82
 
81
 
83
#endif
82
#endif