2020-04-11 13:00:31 +02:00
|
|
|
#define MEMSIZE 4096*40
|
|
|
|
|
|
|
|
#include "../lib/gui.h"
|
2020-04-11 23:17:55 +02:00
|
|
|
#include "../lib/io.h"
|
2020-04-11 13:00:31 +02:00
|
|
|
#include "../lib/collection.h"
|
|
|
|
#include "../lib/list_box.h"
|
|
|
|
#include "../lib/fs.h"
|
|
|
|
|
|
|
|
#define ITEM_H 19
|
2020-04-15 19:00:34 +02:00
|
|
|
#define SEP_H 4
|
2020-04-11 13:00:31 +02:00
|
|
|
|
|
|
|
llist menu1;
|
|
|
|
collection names;
|
|
|
|
collection hotkeys;
|
|
|
|
|
2020-04-13 13:51:56 +02:00
|
|
|
int selected, win_x, win_y;
|
2020-04-11 13:00:31 +02:00
|
|
|
|
|
|
|
int max_name_len;
|
|
|
|
int max_hotkey_len;
|
2020-04-15 19:00:34 +02:00
|
|
|
int menu_w, menu_h;
|
2020-04-11 13:00:31 +02:00
|
|
|
|
|
|
|
void GetWindowPosition()
|
|
|
|
{
|
2020-04-13 13:51:56 +02:00
|
|
|
int position;
|
|
|
|
shared_mem = memopen(#shared_name, 16, SHM_OPEN + SHM_WRITE);
|
|
|
|
selected = ESDWORD[shared_mem ];
|
2020-04-12 11:14:17 +02:00
|
|
|
win_x = ESDWORD[shared_mem + 4];
|
|
|
|
win_y = ESDWORD[shared_mem + 8];
|
2020-04-11 23:17:55 +02:00
|
|
|
position = ESDWORD[shared_mem + 12];
|
2020-04-13 13:51:56 +02:00
|
|
|
if (position == MENU_ALIGN_TOP_RIGHT) win_x -= menu1.w;
|
|
|
|
if (position == MENU_ALIGN_BOT_LEFT) win_y -= menu1.h;
|
|
|
|
if (position == MENU_ALIGN_BOT_RIGHT) {
|
2020-04-11 13:00:31 +02:00
|
|
|
win_x -= menu1.w;
|
|
|
|
win_y -= menu1.h;
|
|
|
|
}
|
2020-04-13 13:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetMenuWidths()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<names.count; i++) {
|
|
|
|
max_name_len = math.max(max_name_len, strlen(names.get(i)));
|
|
|
|
}
|
|
|
|
for (i=0; i<hotkeys.count; i++) {
|
|
|
|
max_hotkey_len = math.max(max_hotkey_len, strlen(hotkeys.get(i)));
|
|
|
|
}
|
|
|
|
max_name_len = max_name_len * 6;
|
|
|
|
max_hotkey_len *= 6;
|
|
|
|
if (max_hotkey_len) max_name_len += 12;
|
2020-04-11 13:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetMenuItems(dword current_name)
|
|
|
|
{
|
|
|
|
dword next_name = strchr(current_name, '\n');
|
|
|
|
dword hotkey = strchr(current_name, '|');
|
|
|
|
|
|
|
|
ESBYTE[next_name] = '\0';
|
|
|
|
|
|
|
|
if (hotkey) && (hotkey < next_name) {
|
|
|
|
ESBYTE[hotkey] = '\0';
|
|
|
|
} else {
|
|
|
|
if (hotkey) && (!next_name) {
|
|
|
|
ESBYTE[hotkey] = '\0';
|
|
|
|
} else {
|
2020-04-13 13:51:56 +02:00
|
|
|
hotkey = " ";
|
2020-04-11 13:00:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hotkeys.add(hotkey+1);
|
|
|
|
names.add(current_name);
|
|
|
|
|
|
|
|
if (next_name) GetMenuItems(next_name+2);
|
|
|
|
}
|
|
|
|
|
2020-04-15 19:00:34 +02:00
|
|
|
int GetSeparatorsCount()
|
|
|
|
{
|
|
|
|
int i, count=0;
|
|
|
|
for (i=0; i<names.count; i++) {
|
|
|
|
if (streq(names.get(i), "-")) count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MoveMouseToHandleSeparators(int _mouse_y)
|
|
|
|
{
|
|
|
|
int i, item_y=menu1.y;
|
|
|
|
int item_i=0;
|
|
|
|
for (i=0; i<menu1.count; i++;)
|
|
|
|
{
|
|
|
|
if (streq(names.get(i), "-")) {
|
|
|
|
item_y += SEP_H;
|
|
|
|
} else {
|
|
|
|
item_y += ITEM_H;
|
|
|
|
item_i++;
|
|
|
|
}
|
|
|
|
if (_mouse_y >= item_y) && (_mouse_y < item_y + ITEM_H) {
|
|
|
|
return item_i * ITEM_H + menu1.y;
|
|
|
|
}
|
|
|
|
}
|
2020-04-15 21:22:26 +02:00
|
|
|
return _mouse_y;
|
2020-04-15 19:00:34 +02:00
|
|
|
}
|
|
|
|
|
2020-04-11 13:00:31 +02:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
proc_info Form;
|
|
|
|
|
2020-04-12 11:14:17 +02:00
|
|
|
if (!param) die("'Menu component is for developers only' -I");
|
2020-04-11 23:17:55 +02:00
|
|
|
|
|
|
|
GetMenuItems(#param);
|
2020-04-13 13:51:56 +02:00
|
|
|
GetMenuWidths();
|
2020-04-11 13:00:31 +02:00
|
|
|
|
2020-04-15 19:00:34 +02:00
|
|
|
menu_w = max_name_len + max_hotkey_len + 23;
|
|
|
|
menu_h = GetSeparatorsCount() * SEP_H
|
|
|
|
+ calc(names.count - GetSeparatorsCount() * ITEM_H);
|
|
|
|
|
2020-04-11 13:00:31 +02:00
|
|
|
menu1.count = names.count;
|
|
|
|
menu1.SetFont(6, 9, 0x80);
|
2020-04-15 19:00:34 +02:00
|
|
|
menu1.SetSizes(2,2, menu_w, menu_h, ITEM_H);
|
2020-04-11 13:00:31 +02:00
|
|
|
menu1.cur_y = -1;
|
|
|
|
|
|
|
|
GetWindowPosition();
|
|
|
|
|
|
|
|
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE);
|
|
|
|
loop() switch(WaitEvent())
|
|
|
|
{
|
|
|
|
case evMouse:
|
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
|
|
|
if (!CheckActiveProcess(Form.ID)) exit();
|
|
|
|
mouse.get();
|
2020-04-15 19:00:34 +02:00
|
|
|
if (menu1.MouseOver(mouse.x, mouse.y)) {
|
|
|
|
mouse.y = MoveMouseToHandleSeparators(mouse.y);
|
|
|
|
if (menu1.ProcessMouse(mouse.x, mouse.y)) draw_list();
|
|
|
|
if (mouse.lkm)&&(mouse.up) click();
|
|
|
|
}
|
2020-04-11 13:00:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case evKey:
|
|
|
|
GetKeys();
|
|
|
|
ProcessKeys();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case evReDraw:
|
2020-04-13 23:08:28 +02:00
|
|
|
DefineAndDrawWindow(win_x, win_y, menu1.w+4, menu1.h+4, 0x01, 0, 0, 0x01fffFFF);
|
2020-04-11 13:00:31 +02:00
|
|
|
system.color.get();
|
|
|
|
Draw3DPopup(0,0,menu1.w+2,menu1.h+2);
|
|
|
|
draw_list();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessKeys()
|
|
|
|
{
|
|
|
|
switch(key_scancode)
|
|
|
|
{
|
|
|
|
case SCAN_CODE_ESC:
|
|
|
|
exit();
|
|
|
|
|
|
|
|
case SCAN_CODE_ENTER:
|
|
|
|
click();
|
|
|
|
|
|
|
|
case SCAN_CODE_DOWN:
|
2020-04-15 19:00:34 +02:00
|
|
|
if (!menu1.KeyDown())
|
|
|
|
|| (menu1.count - menu1.cur_y - GetSeparatorsCount() -1 < 0) menu1.KeyHome();
|
2020-04-11 13:00:31 +02:00
|
|
|
draw_list();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCAN_CODE_UP:
|
|
|
|
if (!menu1.KeyUp()) menu1.KeyEnd();
|
|
|
|
draw_list();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (menu1.ProcessKey(key_scancode)) draw_list();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_list()
|
|
|
|
{
|
2020-04-15 19:00:34 +02:00
|
|
|
int i, item_y=menu1.y, item_i=0;
|
2020-04-14 01:11:07 +02:00
|
|
|
dword name_color;
|
|
|
|
dword hotkey_color;
|
|
|
|
|
|
|
|
static dword inactive_background_color;
|
|
|
|
static dword active_background_color;
|
|
|
|
static dword active_top_border_color;
|
|
|
|
static dword inactive_text_shadow_color;
|
|
|
|
static bool skin_dark;
|
|
|
|
|
|
|
|
static bool colors_set;
|
|
|
|
if (!colors_set) {
|
|
|
|
colors_set = true;
|
|
|
|
inactive_background_color = MixColors(system.color.work, 0xFFFfff,230);
|
|
|
|
active_background_color = MixColors(system.color.work_button, system.color.work,230);
|
|
|
|
active_top_border_color = MixColors(system.color.work_graph, system.color.work_button,240);
|
|
|
|
inactive_text_shadow_color = MixColors(system.color.work,0xFFFfff,120);
|
|
|
|
skin_dark = skin_is_dark();
|
|
|
|
}
|
2020-04-11 13:00:31 +02:00
|
|
|
|
|
|
|
for (i=0; i<menu1.count; i++;)
|
|
|
|
{
|
2020-04-15 19:00:34 +02:00
|
|
|
if (streq(names.get(i), "-")) {
|
|
|
|
DrawBar(menu1.x, item_y+0, menu1.w, 1, inactive_background_color);
|
|
|
|
DrawBar(menu1.x, item_y+1, menu1.w, 1, system.color.work_dark);
|
|
|
|
DrawBar(menu1.x, item_y+2, menu1.w, 1, system.color.work_light);
|
|
|
|
DrawBar(menu1.x, item_y+3, menu1.w, 1, inactive_background_color);
|
|
|
|
item_y += SEP_H;
|
2020-04-11 13:00:31 +02:00
|
|
|
} else {
|
2020-04-15 19:00:34 +02:00
|
|
|
if (item_i==menu1.cur_y) {
|
|
|
|
hotkey_color = name_color = system.color.work_button_text;
|
|
|
|
DrawBar(menu1.x, item_y+1, menu1.w, ITEM_H-2, active_background_color);
|
|
|
|
DrawBar(menu1.x, item_y, menu1.w, 1, active_top_border_color);
|
|
|
|
DrawBar(menu1.x, item_y+ITEM_H-1, menu1.w, 1, system.color.work_light);
|
|
|
|
} else {
|
|
|
|
name_color = system.color.work_text;
|
|
|
|
hotkey_color = system.color.work_graph;
|
|
|
|
DrawBar(menu1.x, item_y, menu1.w, ITEM_H, inactive_background_color);
|
|
|
|
if (!skin_dark) WriteText(13+1, item_y + menu1.text_y +1, 0x80,
|
|
|
|
inactive_text_shadow_color, names.get(i));
|
|
|
|
}
|
|
|
|
WriteText(-strlen(hotkeys.get(i))*6 + 13 + max_name_len + max_hotkey_len,
|
|
|
|
item_y + menu1.text_y, 0x80, hotkey_color, hotkeys.get(i));
|
|
|
|
WriteText(13, item_y + menu1.text_y, 0x80, name_color, names.get(i));
|
|
|
|
item_y += ITEM_H;
|
|
|
|
item_i++;
|
2020-04-11 13:00:31 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-13 13:51:56 +02:00
|
|
|
if (selected) WriteText(5, selected-1*ITEM_H + menu1.y + menu1.text_y, 0x80, 0xEE0000, "\x10");
|
2020-04-11 13:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void click()
|
|
|
|
{
|
2020-04-13 13:51:56 +02:00
|
|
|
ESDWORD[shared_mem] = menu1.cur_y + 1;
|
2020-04-11 13:00:31 +02:00
|
|
|
ExitProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
void exit()
|
|
|
|
{
|
2020-04-13 13:51:56 +02:00
|
|
|
ESDWORD[shared_mem] = 0;
|
2020-04-11 13:00:31 +02:00
|
|
|
ExitProcess();
|
|
|
|
}
|