Add standard Menu component lib/menu.h and example how to use it

git-svn-id: svn://kolibrios.org@6041 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2016-01-07 15:26:59 +00:00
parent 11f7490d24
commit d1ac782f6d
4 changed files with 148 additions and 5 deletions

View File

@ -1,11 +1,14 @@
c-- example.c
c-- collections.c
c-- menu.c
@del @@example
@del @@collections
@del @@menu
@rename example.com @@example
@rename collections.com @@collections
@rename menu.com @@menu
@del warning.txt
@pause

View File

@ -0,0 +1,69 @@
#define MEMSIZE 4096*10
#include "../lib/io.h"
#include "../lib/list_box.h"
#include "../lib/gui.h"
#include "../lib/menu.h"
struct _object
{
int x,y,w,h,id;
};
_object butv = { 20, 20, 100, 30, 10};
_object buta = {150, 20, 100, 30, 20};
char vegetables[] =
"Onion
Melon
Tomato
Squash
Salad";
char animals[] =
"Cat
Dog
Pig
Cow
Goat
Rabbit";
byte category;
void main()
{
proc_info Form;
int id;
loop() switch(WaitEvent())
{
case evButton:
id=GetButtonID();
if (id==1) ExitProcess();
if (id==butv.id) {
menu.selected = category+1;
menu.show(Form.left+5 + butv.x, Form.top+skin_height + butv.y + butv.h, 100, #vegetables, butv.id);
}
if (id==buta.id) {
menu.selected = 0;
menu.show(Form.left+5 + buta.x, Form.top+skin_height + buta.y + buta.h, 120, #animals, buta.id);
}
break;
case evKey:
GetKeys();
break;
case evReDraw:
if (menu.list.cur_y) {
if (menu.list.cur_y > butv.id) && (menu.list.cur_y < buta.id) category = menu.list.cur_y - butv.id;
}
DefineAndDrawWindow(215,100,350,300,0x34,0xFFFFFF,"Window header");
GetProcessInfo(#Form, SelfInfo);
WriteText(10,110,0x80,0,#param);
DrawCaptButton(butv.x, butv.y, butv.w, butv.h, butv.id, 0xCCCccc, 0x000000, "Vegetables");
DrawCaptButton(buta.x, buta.y, buta.w, buta.h, buta.id, 0xCCCccc, 0x000000, "Aminal");
break;
}
}

View File

@ -719,10 +719,7 @@ inline fastcall dword GetStartTime()
dword width,height;
} screen;
:struct _skin
{
dword width,height;
} SKIN;
:byte skin_height;
:void DrawDate(dword x, y, color, in_date)
{
@ -795,7 +792,7 @@ void ______INIT______()
self.path = I_Path;
__path_name__(#__BUF_DIR__,I_Path);
SKIN.height = GetSkinHeight();
skin_height = GetSkinHeight();
screen.width = GetScreenWidth();
screen.height = GetScreenHeight();

74
programs/cmm/lib/menu.h Normal file
View File

@ -0,0 +1,74 @@
struct _menu
{
dword appear_x, appear_y, text, identifier, selected;
llist list;
void show();
char stak[4096];
}menu;
void _menu::show(dword _appear_x, _appear_y, _menu_width, _text, _identifier)
{
appear_x = _appear_x;
appear_y = _appear_y;
text = _text;
identifier = _identifier;
list.cur_y = -1;
list.ClearList();
list.count = chrnum(text, '\n')+1;
list.SetSizes(2,2,_menu_width,list.count*19,19);
CreateThread(#_menu_thread,#stak+4092);
}
void _menu_thread()
{
proc_info MenuForm;
SetEventMask(100111b);
loop() switch(WaitEvent())
{
case evMouse:
GetProcessInfo(#MenuForm, SelfInfo);
if (!CheckActiveProcess(MenuForm.ID)) _menu_no_item_click();
mouse.get();
if (menu.list.ProcessMouse(mouse.x, mouse.y)) _menu_draw_list();
if (mouse.lkm)&&(mouse.up) _menu_item_click();
break;
case evKey:
GetKeys();
if (key_scancode==SCAN_CODE_ESC) _menu_no_item_click();
if (key_scancode==SCAN_CODE_ENTER) _menu_item_click();
if (menu.list.ProcessKey(key_scancode)) _menu_draw_list();
break;
case evReDraw:
DefineAndDrawWindow(menu.appear_x,menu.appear_y,menu.list.w+2,menu.list.h+4,0x01, 0, 0, 0x01fffFFF);
DrawPopup(0,0,menu.list.w,menu.list.h+3,0, 0xE4DFE1,0x9098B0);
_menu_draw_list();
}
}
void _menu_draw_list()
{
int N, bgcol;
for (N=0; N<menu.list.count; N++;)
{
if (N==menu.list.cur_y) bgcol=0xFFFfff; else bgcol=0xE4DFE1;
DrawBar(menu.list.x, N*menu.list.item_h+menu.list.y, menu.list.w-3, menu.list.item_h, bgcol);
}
WriteTextLines(13, menu.list.item_h-8/2+menu.list.y, 0x80, 0, menu.text, menu.list.item_h);
if (menu.selected) WriteText(5, menu.selected-1*menu.list.item_h+7, 0x80, 0xEE0000, "\x10");
}
void _menu_item_click()
{
menu.list.cur_y = menu.identifier + menu.list.cur_y;
ExitProcess();
}
void _menu_no_item_click()
{
menu.list.cur_y = 0;
ExitProcess();
}