2018-10-10 16:44:01 +02:00
|
|
|
#ifndef INCLUDE_MENU_H
|
|
|
|
#define INCLUDE_MENU_H
|
2016-01-07 16:26:59 +01:00
|
|
|
|
2018-10-11 16:32:24 +02:00
|
|
|
#ifndef INCLUDE_LIST_BOX
|
2018-10-10 16:44:01 +02:00
|
|
|
#include "../lib/list_box.h"
|
2018-10-11 16:32:24 +02:00
|
|
|
#endif
|
2018-10-10 16:44:01 +02:00
|
|
|
|
|
|
|
:dword menu_process_id;
|
|
|
|
|
2018-10-11 16:32:24 +02:00
|
|
|
:struct _menu : llist
|
2016-01-07 16:26:59 +01:00
|
|
|
{
|
|
|
|
dword appear_x, appear_y, text, identifier, selected;
|
|
|
|
void show();
|
|
|
|
char stak[4096];
|
2018-10-10 16:44:01 +02:00
|
|
|
} menu;
|
2016-01-07 16:26:59 +01:00
|
|
|
|
2018-10-11 16:32:24 +02:00
|
|
|
:void _menu::show(dword _appear_x, _appear_y, _menu_width, _menu_text, _identifier)
|
2016-01-07 16:26:59 +01:00
|
|
|
{
|
2018-10-10 16:44:01 +02:00
|
|
|
#define ITEM_H 21
|
2016-01-07 16:26:59 +01:00
|
|
|
appear_x = _appear_x;
|
|
|
|
appear_y = _appear_y;
|
2018-10-11 16:32:24 +02:00
|
|
|
text = _menu_text;
|
2016-01-07 16:26:59 +01:00
|
|
|
identifier = _identifier;
|
|
|
|
|
2018-10-11 16:32:24 +02:00
|
|
|
cur_y = -1;
|
|
|
|
ClearList();
|
|
|
|
count = chrnum(text, '\n')+1;
|
|
|
|
SetSizes(2,2,_menu_width,count*ITEM_H,ITEM_H);
|
2016-01-07 16:26:59 +01:00
|
|
|
|
2018-04-21 14:28:00 +02:00
|
|
|
menu_process_id = CreateThread(#_menu_thread,#stak+4092);
|
2016-01-07 16:26:59 +01:00
|
|
|
}
|
|
|
|
|
2018-10-10 16:44:01 +02:00
|
|
|
:void _menu_thread()
|
2016-01-07 16:26:59 +01:00
|
|
|
{
|
2020-04-06 21:54:05 +02:00
|
|
|
MOUSE m;
|
|
|
|
DefineAndDrawWindow(menu.appear_x,menu.appear_y,menu.w+2,menu.h+4,0x01, 0, 0, 0x01fffFFF);
|
|
|
|
DrawPopup(0,0,menu.w,menu.h+3,0, 0xE4DFE1,0x9098B0);
|
|
|
|
_menu_draw_list();
|
|
|
|
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_MOUSE + EVM_MOUSE_FILTER);
|
2016-01-07 16:26:59 +01:00
|
|
|
loop() switch(WaitEvent())
|
|
|
|
{
|
|
|
|
case evMouse:
|
2020-04-06 21:54:05 +02:00
|
|
|
m.get();
|
|
|
|
if (menu.ProcessMouse(m.x, m.y)) _menu_draw_list();
|
|
|
|
if (m.lkm)&&(m.up) _menu_item_click();
|
2016-01-07 16:26:59 +01:00
|
|
|
break;
|
|
|
|
case evKey:
|
|
|
|
GetKeys();
|
2020-04-06 21:54:05 +02:00
|
|
|
if (key_scancode==SCAN_CODE_ESC) _menu_exit();
|
2016-01-07 16:26:59 +01:00
|
|
|
if (key_scancode==SCAN_CODE_ENTER) _menu_item_click();
|
2018-10-11 16:32:24 +02:00
|
|
|
if (menu.ProcessKey(key_scancode)) _menu_draw_list();
|
2016-01-07 16:26:59 +01:00
|
|
|
break;
|
|
|
|
case evReDraw:
|
2020-04-06 21:54:05 +02:00
|
|
|
_menu_exit();
|
2016-01-07 16:26:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 16:44:01 +02:00
|
|
|
:void _menu_draw_list()
|
2016-01-07 16:26:59 +01:00
|
|
|
{
|
|
|
|
int N, bgcol;
|
2018-10-11 16:32:24 +02:00
|
|
|
for (N=0; N<menu.count; N++;)
|
2016-01-07 16:26:59 +01:00
|
|
|
{
|
2018-10-11 16:32:24 +02:00
|
|
|
if (N==menu.cur_y) bgcol=0xFFFfff; else bgcol=0xE4DFE1;
|
|
|
|
DrawBar(menu.x, N*menu.item_h+menu.y, menu.w-3, menu.item_h, bgcol);
|
2016-01-07 16:26:59 +01:00
|
|
|
}
|
2018-10-11 16:32:24 +02:00
|
|
|
WriteTextLines(13, menu.item_h-8/2+menu.y, 0x80, 0, menu.text, menu.item_h);
|
|
|
|
if (menu.selected) WriteText(5, menu.selected-1*menu.item_h+8, 0x80, 0xEE0000, "\x10");
|
2016-01-07 16:26:59 +01:00
|
|
|
}
|
|
|
|
|
2018-10-10 16:44:01 +02:00
|
|
|
:void _menu_item_click()
|
2016-01-07 16:26:59 +01:00
|
|
|
{
|
2018-10-11 16:32:24 +02:00
|
|
|
menu.cur_y = menu.identifier + menu.cur_y;
|
2018-04-21 14:28:00 +02:00
|
|
|
KillProcess(menu_process_id);
|
2016-01-07 16:26:59 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 21:54:05 +02:00
|
|
|
:void _menu_exit()
|
2016-01-07 16:26:59 +01:00
|
|
|
{
|
2018-10-11 16:32:24 +02:00
|
|
|
menu.cur_y = 0;
|
2018-04-21 14:28:00 +02:00
|
|
|
KillProcess(menu_process_id);
|
2018-10-10 16:44:01 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 13:51:56 +02:00
|
|
|
#define MENU_ALIGN_TOP_LEFT 0
|
|
|
|
#define MENU_ALIGN_TOP_RIGHT 1
|
|
|
|
#define MENU_ALIGN_BOT_LEFT 2
|
|
|
|
#define MENU_ALIGN_BOT_RIGHT 3
|
2020-04-11 23:17:55 +02:00
|
|
|
|
|
|
|
:dword shared_mem = NULL;
|
|
|
|
:char shared_name[] = "LMENU";
|
|
|
|
:void open_lmenu(dword _x, _y, _position, _selected, _text)
|
|
|
|
{
|
|
|
|
if (!shared_mem) {
|
2020-04-13 13:51:56 +02:00
|
|
|
shared_mem = memopen(#shared_name, 16, SHM_CREATE + SHM_WRITE);
|
|
|
|
if (EDX) shared_mem = memopen(#shared_name, 16, SHM_WRITE);
|
2020-04-11 23:17:55 +02:00
|
|
|
}
|
2020-04-13 13:51:56 +02:00
|
|
|
ESDWORD[shared_mem ] = _selected;
|
2020-04-11 23:17:55 +02:00
|
|
|
ESDWORD[shared_mem + 4] = _x;
|
|
|
|
ESDWORD[shared_mem + 8] = _y;
|
|
|
|
ESDWORD[shared_mem + 12] = _position;
|
2020-04-13 13:51:56 +02:00
|
|
|
menu_process_id = RunProgram("/sys/develop/menu", _text);
|
2020-04-11 23:17:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
:dword get_menu_click()
|
|
|
|
{
|
2020-04-13 13:51:56 +02:00
|
|
|
if (menu_process_id) && (GetProcessSlot(menu_process_id)) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
menu_process_id = NULL;
|
2020-04-13 15:16:55 +02:00
|
|
|
EAX = ESDWORD[shared_mem];
|
|
|
|
ESDWORD[shared_mem] = 0;
|
|
|
|
return EAX;
|
2020-04-13 13:51:56 +02:00
|
|
|
}
|
2020-04-11 23:17:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 16:44:01 +02:00
|
|
|
#endif
|