Rev 7770 | Rev 7779 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7770 | Rev 7778 | ||
---|---|---|---|
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 | MOUSE m; |
35 | MOUSE m; |
36 | DefineAndDrawWindow(menu.appear_x,menu.appear_y,menu.w+2,menu.h+4,0x01, 0, 0, 0x01fffFFF); |
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); |
37 | DrawPopup(0,0,menu.w,menu.h+3,0, 0xE4DFE1,0x9098B0); |
38 | _menu_draw_list(); |
38 | _menu_draw_list(); |
39 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_MOUSE + EVM_MOUSE_FILTER); |
39 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_MOUSE + EVM_MOUSE_FILTER); |
40 | loop() switch(WaitEvent()) |
40 | loop() switch(WaitEvent()) |
41 | { |
41 | { |
42 | case evMouse: |
42 | case evMouse: |
43 | m.get(); |
43 | m.get(); |
44 | if (menu.ProcessMouse(m.x, m.y)) _menu_draw_list(); |
44 | if (menu.ProcessMouse(m.x, m.y)) _menu_draw_list(); |
45 | if (m.lkm)&&(m.up) _menu_item_click(); |
45 | if (m.lkm)&&(m.up) _menu_item_click(); |
46 | break; |
46 | break; |
47 | case evKey: |
47 | case evKey: |
48 | GetKeys(); |
48 | GetKeys(); |
49 | if (key_scancode==SCAN_CODE_ESC) _menu_exit(); |
49 | if (key_scancode==SCAN_CODE_ESC) _menu_exit(); |
50 | if (key_scancode==SCAN_CODE_ENTER) _menu_item_click(); |
50 | if (key_scancode==SCAN_CODE_ENTER) _menu_item_click(); |
51 | if (menu.ProcessKey(key_scancode)) _menu_draw_list(); |
51 | if (menu.ProcessKey(key_scancode)) _menu_draw_list(); |
52 | break; |
52 | break; |
53 | case evReDraw: |
53 | case evReDraw: |
54 | _menu_exit(); |
54 | _menu_exit(); |
55 | } |
55 | } |
56 | } |
56 | } |
57 | 57 | ||
58 | :void _menu_draw_list() |
58 | :void _menu_draw_list() |
59 | { |
59 | { |
60 | int N, bgcol; |
60 | int N, bgcol; |
61 | for (N=0; N |
61 | for (N=0; N |
62 | { |
62 | { |
63 | if (N==menu.cur_y) bgcol=0xFFFfff; else bgcol=0xE4DFE1; |
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); |
64 | DrawBar(menu.x, N*menu.item_h+menu.y, menu.w-3, menu.item_h, bgcol); |
65 | } |
65 | } |
66 | 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); |
67 | 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"); |
68 | } |
68 | } |
69 | 69 | ||
70 | :void _menu_item_click() |
70 | :void _menu_item_click() |
71 | { |
71 | { |
72 | menu.cur_y = menu.identifier + menu.cur_y; |
72 | menu.cur_y = menu.identifier + menu.cur_y; |
73 | KillProcess(menu_process_id); |
73 | KillProcess(menu_process_id); |
74 | } |
74 | } |
75 | 75 | ||
76 | :void _menu_exit() |
76 | :void _menu_exit() |
77 | { |
77 | { |
78 | menu.cur_y = 0; |
78 | menu.cur_y = 0; |
79 | KillProcess(menu_process_id); |
79 | KillProcess(menu_process_id); |
80 | } |
80 | } |
- | 81 | ||
- | 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 | { |
|
- | 100 | dword res = ESDWORD[shared_mem]; |
|
- | 101 | ESDWORD[shared_mem] = 0; |
|
- | 102 | return res; |
|
- | 103 | } |
|
81 | 104 | ||
82 | #endif |
105 | #endif |