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
7447 leency 1
#ifndef INCLUDE_MENU_H
2
#define INCLUDE_MENU_H
6041 leency 3
 
7450 leency 4
#ifndef INCLUDE_LIST_BOX
7447 leency 5
#include "../lib/list_box.h"
7450 leency 6
#endif
7447 leency 7
 
8
:dword menu_process_id;
9
 
7450 leency 10
:struct _menu : llist
6041 leency 11
{
12
	dword appear_x, appear_y, text, identifier, selected;
13
	void show();
14
	char stak[4096];
7447 leency 15
} menu;
6041 leency 16
 
7450 leency 17
:void _menu::show(dword _appear_x, _appear_y, _menu_width, _menu_text, _identifier)
6041 leency 18
{
7447 leency 19
	#define ITEM_H 21
6041 leency 20
	appear_x = _appear_x;
21
	appear_y = _appear_y;
7450 leency 22
	text = _menu_text;
6041 leency 23
	identifier = _identifier;
24
 
7450 leency 25
	cur_y = -1;
26
	ClearList();
27
	count = chrnum(text, '\n')+1;
28
	SetSizes(2,2,_menu_width,count*ITEM_H,ITEM_H);
6041 leency 29
 
7252 leency 30
	menu_process_id = CreateThread(#_menu_thread,#stak+4092);
6041 leency 31
}
32
 
7447 leency 33
:void _menu_thread()
6041 leency 34
{
7770 leency 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);
38
	_menu_draw_list();
39
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_MOUSE + EVM_MOUSE_FILTER);
6041 leency 40
	loop() switch(WaitEvent())
41
	{
42
		case evMouse:
7770 leency 43
			m.get();
44
			if (menu.ProcessMouse(m.x, m.y)) _menu_draw_list();
45
			if (m.lkm)&&(m.up) _menu_item_click();
6041 leency 46
			break;
47
		case evKey:
48
			GetKeys();
7770 leency 49
			if (key_scancode==SCAN_CODE_ESC) _menu_exit();
6041 leency 50
			if (key_scancode==SCAN_CODE_ENTER) _menu_item_click();
7450 leency 51
			if (menu.ProcessKey(key_scancode)) _menu_draw_list();
6041 leency 52
			break;
53
		case evReDraw:
7770 leency 54
			_menu_exit();
6041 leency 55
	}
56
}
57
 
7447 leency 58
:void _menu_draw_list()
6041 leency 59
{
60
	int N, bgcol;
7450 leency 61
	for (N=0; N
6041 leency 62
	{
7450 leency 63
		if (N==menu.cur_y) bgcol=0xFFFfff; else bgcol=0xE4DFE1;
64
		DrawBar(menu.x, N*menu.item_h+menu.y, menu.w-3, menu.item_h, bgcol);
6041 leency 65
	}
7450 leency 66
	WriteTextLines(13, menu.item_h-8/2+menu.y, 0x80, 0, menu.text, menu.item_h);
67
	if (menu.selected) WriteText(5, menu.selected-1*menu.item_h+8, 0x80, 0xEE0000, "\x10");
6041 leency 68
}
69
 
7447 leency 70
:void _menu_item_click()
6041 leency 71
{
7450 leency 72
	menu.cur_y = menu.identifier + menu.cur_y;
7252 leency 73
	KillProcess(menu_process_id);
6041 leency 74
}
75
 
7770 leency 76
:void _menu_exit()
6041 leency 77
{
7450 leency 78
	menu.cur_y = 0;
7252 leency 79
	KillProcess(menu_process_id);
7447 leency 80
}
81
 
7778 leency 82
 
83
:dword shared_mem = NULL;
84
:char shared_name[] = "LMENU";
85
:void open_lmenu(dword _x, _y, _position, _selected, _text)
86
{
87
	if (!shared_mem) {
88
		shared_mem = memopen(#shared_name, 20, SHM_CREATE);
89
		if (EDX) shared_mem = memopen(#shared_name, 20, SHM_WRITE);
90
	}
91
	ESDWORD[shared_mem +  4] = _x;
92
	ESDWORD[shared_mem +  8] = _y;
93
	ESDWORD[shared_mem + 12] = _position;
94
	ESDWORD[shared_mem + 16] = _selected;
95
	RunProgram("/sys/develop/menu", _text);
96
}
97
 
98
:dword get_menu_click()
99
{
7779 leency 100
	//dword res = ESDWORD[shared_mem];
101
	char res[2];
102
	ReadFile(0, 2, #res, "/tmp0/1/menu.tmp");
103
	//ESDWORD[shared_mem] = 0;
104
	return res[0];
7778 leency 105
}
106
 
7447 leency 107
#endif