Subversion Repositories Kolibri OS

Rev

Rev 7447 | Rev 7770 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef INCLUDE_MENU_H
  2. #define INCLUDE_MENU_H
  3.  
  4. #ifndef INCLUDE_LIST_BOX
  5. #include "../lib/list_box.h"
  6. #endif
  7.  
  8. :dword menu_process_id;
  9.  
  10. :struct _menu : llist
  11. {
  12.         dword appear_x, appear_y, text, identifier, selected;  
  13.         void show();
  14.         char stak[4096];
  15. } menu;
  16.  
  17. :void _menu::show(dword _appear_x, _appear_y, _menu_width, _menu_text, _identifier)
  18. {
  19.         #define ITEM_H 21
  20.         appear_x = _appear_x;
  21.         appear_y = _appear_y;
  22.         text = _menu_text;
  23.         identifier = _identifier;
  24.  
  25.         cur_y = -1;
  26.         ClearList();
  27.         count = chrnum(text, '\n')+1;
  28.         SetSizes(2,2,_menu_width,count*ITEM_H,ITEM_H);
  29.  
  30.         menu_process_id = CreateThread(#_menu_thread,#stak+4092);
  31. }
  32.  
  33. :void _menu_thread()
  34. {
  35.         proc_info MenuForm;
  36.         SetEventMask(100111b);
  37.         loop() switch(WaitEvent())
  38.         {
  39.                 case evMouse:
  40.                         GetProcessInfo(#MenuForm, SelfInfo);
  41.                         if (!CheckActiveProcess(MenuForm.ID)) _menu_no_item_click();
  42.                         mouse.get();
  43.                         if (menu.ProcessMouse(mouse.x, mouse.y)) _menu_draw_list();
  44.                         if (mouse.lkm)&&(mouse.up) _menu_item_click();
  45.                         break;         
  46.                 case evKey:
  47.                         GetKeys();
  48.                         if (key_scancode==SCAN_CODE_ESC) _menu_no_item_click();
  49.                         if (key_scancode==SCAN_CODE_ENTER) _menu_item_click();
  50.                         if (menu.ProcessKey(key_scancode)) _menu_draw_list();
  51.                         break;
  52.                 case evReDraw:
  53.                         DefineAndDrawWindow(menu.appear_x,menu.appear_y,menu.w+2,menu.h+4,0x01, 0, 0, 0x01fffFFF);
  54.                         DrawPopup(0,0,menu.w,menu.h+3,0, 0xE4DFE1,0x9098B0);
  55.                         _menu_draw_list();                             
  56.         }
  57. }
  58.  
  59. :void _menu_draw_list()
  60. {
  61.         int N, bgcol;
  62.         for (N=0; N<menu.count; N++;)
  63.         {
  64.                 if (N==menu.cur_y) bgcol=0xFFFfff; else bgcol=0xE4DFE1;
  65.                 DrawBar(menu.x, N*menu.item_h+menu.y, menu.w-3, menu.item_h, bgcol);
  66.         }
  67.         WriteTextLines(13, menu.item_h-8/2+menu.y, 0x80, 0, menu.text, menu.item_h);
  68.         if (menu.selected) WriteText(5, menu.selected-1*menu.item_h+8, 0x80, 0xEE0000, "\x10");
  69. }
  70.  
  71. :void _menu_item_click()
  72. {
  73.         menu.cur_y = menu.identifier + menu.cur_y;
  74.         KillProcess(menu_process_id);
  75. }
  76.  
  77. :void _menu_no_item_click()
  78. {
  79.         menu.cur_y = 0;
  80.         KillProcess(menu_process_id);
  81. }
  82.  
  83. #endif