From d1ac782f6d1d8ce8ea458563d825310120744474 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Thu, 7 Jan 2016 15:26:59 +0000 Subject: [PATCH] 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 --- programs/cmm/examples/compile.bat | 3 ++ programs/cmm/examples/menu.c | 69 ++++++++++++++++++++++++++++ programs/cmm/lib/kolibri.h | 7 +-- programs/cmm/lib/menu.h | 74 +++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 programs/cmm/examples/menu.c create mode 100644 programs/cmm/lib/menu.h diff --git a/programs/cmm/examples/compile.bat b/programs/cmm/examples/compile.bat index 8912325202..162813961e 100644 --- a/programs/cmm/examples/compile.bat +++ b/programs/cmm/examples/compile.bat @@ -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 \ No newline at end of file diff --git a/programs/cmm/examples/menu.c b/programs/cmm/examples/menu.c new file mode 100644 index 0000000000..a393a3721c --- /dev/null +++ b/programs/cmm/examples/menu.c @@ -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; + } +} diff --git a/programs/cmm/lib/kolibri.h b/programs/cmm/lib/kolibri.h index 98bfc6852a..246727ac46 100644 --- a/programs/cmm/lib/kolibri.h +++ b/programs/cmm/lib/kolibri.h @@ -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(); diff --git a/programs/cmm/lib/menu.h b/programs/cmm/lib/menu.h new file mode 100644 index 0000000000..b1e8f01f0f --- /dev/null +++ b/programs/cmm/lib/menu.h @@ -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