Subversion Repositories Kolibri OS

Rev

Rev 7924 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef INCLUDE_LIST_BOX_H
  2. #define INCLUDE_LIST_BOX_H
  3.  
  4. #ifndef INCLUDE_KOLIBRI_H
  5. #include "../lib/kolibri.h"
  6. #endif
  7.  
  8. struct llist
  9. {
  10.         int x, y, w, h, item_h, item_w;
  11.         int count, visible, first, column_max; //visible = row_max
  12.         int cur_x, cur_y;
  13.         int text_y;
  14.         byte font_w, font_h, font_type;
  15.         byte wheel_size;
  16.         byte active;
  17.         byte no_selection;
  18.         byte horisontal_selelection;
  19.         void ClearList();
  20.         void SetSizes(int xx, yy, ww, hh, item_hh);
  21.         void SetFont(dword font_ww, font_hh, font_tt);
  22.         int ProcessKey(dword key);
  23.         int ProcessMouse(int xx, yy);
  24.         int MouseOver(int xx, yy);
  25.         int MouseScroll(dword scroll_state);
  26.         int KeyDown();
  27.         int KeyUp();
  28.         int KeyHome();
  29.         int KeyHomeHor();
  30.         int KeyEnd();
  31.         int KeyEndHor();
  32.         int KeyPgDown();
  33.         int KeyPgUp();
  34.         int KeyLeft();
  35.         int KeyRight();
  36.         void CheckDoesValuesOkey();
  37.         void debug();
  38. };
  39.  
  40. :void llist::debug()
  41. {
  42.         char yi[128];
  43.         sprintf(#yi, "%s %d %s %d %s %d %s %d %s %d %s %d", "first:", first, "visible:", visible, "count:", count, "col_max:", column_max, "cur_y:", cur_y, "cur_x:", cur_x);
  44.         debugln(#yi);
  45. }
  46.  
  47.  
  48. :void llist::ClearList()
  49. {
  50.         count = visible = first = cur_y = cur_x = 0;
  51. }
  52.  
  53.  
  54. :void llist::SetSizes(int xx, yy, ww, hh, item_hh)
  55. {
  56.         x = xx;
  57.         y = yy;
  58.         w = ww;
  59.         h = hh;
  60.         item_h = item_hh;
  61.         text_y = item_h - font_h / 2;
  62.         visible = h / item_h;
  63.         wheel_size = 3;
  64.         CheckDoesValuesOkey();
  65. }
  66.  
  67.  
  68. :void llist::SetFont(dword font_ww, font_hh, font_tt)
  69. {
  70.         font_w = font_ww;
  71.         font_h = font_hh;
  72.         font_type = font_tt;
  73. }
  74.  
  75.  
  76. :int llist::MouseScroll(dword scroll_state)
  77. {
  78.         if (count<=visible) return 0;
  79.         if (scroll_state == 65535)
  80.         {
  81.                 if (first == 0) return 0;
  82.                 if (first > wheel_size+1) first -= wheel_size; else first=0;
  83.                 CheckDoesValuesOkey();
  84.                 return 1;
  85.         }
  86.         if (scroll_state == 1)
  87.         {
  88.                 if (visible + first == count) return 0;
  89.                 if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size;
  90.                 CheckDoesValuesOkey();
  91.                 return 1;
  92.         }
  93.         return 0;
  94. }
  95.  
  96.  
  97. :int llist::MouseOver(int xx, yy)
  98. {
  99.         if (xx>x) && (xx<x+w) && (yy>y) && (yy<y+h) return 1;
  100.         return 0;
  101. }
  102.  
  103. :int llist::ProcessMouse(int xx, yy)
  104. {
  105.         int new_cur_y, new_cur_x, ret=0;
  106.         if (MouseOver(xx, yy))
  107.         {
  108.                 new_cur_y = yy - y / item_h + first;
  109.                 if (new_cur_y != cur_y) && (new_cur_y<count)
  110.                 {
  111.                         cur_y = new_cur_y;
  112.                         ret = 1;
  113.                 }
  114.                 if (horisontal_selelection)
  115.                 {              
  116.                         new_cur_x = xx - x / item_w;
  117.                         if (new_cur_x != cur_x) && (new_cur_x<column_max)
  118.                         {
  119.                                 cur_x = new_cur_x;
  120.                                 ret = 1;
  121.                         }
  122.                 }
  123.         }
  124.         return ret;
  125. }
  126.  
  127. :int llist::ProcessKey(dword key)
  128. {
  129.         if (horisontal_selelection) {
  130.                 if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL)     switch(key)     {
  131.                         case SCAN_CODE_HOME:  KeyHome(); break;
  132.                         case SCAN_CODE_END:   KeyEnd();
  133.                 }
  134.                 switch(key) {
  135.                         case SCAN_CODE_LEFT:  return KeyLeft();
  136.                         case SCAN_CODE_RIGHT: return KeyRight();
  137.                         case SCAN_CODE_HOME:  return KeyHomeHor();
  138.                         case SCAN_CODE_END:   return KeyEndHor();
  139.                 }
  140.         }
  141.         switch(key)
  142.         {
  143.                 case SCAN_CODE_DOWN: return KeyDown();
  144.                 case SCAN_CODE_UP:   return KeyUp();
  145.                 case SCAN_CODE_HOME: return KeyHome();
  146.                 case SCAN_CODE_END:  return KeyEnd();
  147.                 case SCAN_CODE_PGUP: return KeyPgUp();
  148.                 case SCAN_CODE_PGDN: return KeyPgDown();
  149.         }
  150.         return 0;
  151. }
  152.  
  153. :int llist::KeyDown()
  154. {
  155.         if (no_selection)
  156.         {
  157.                 if (visible + first >= count) return 0;
  158.                 first++;
  159.                 return 1;              
  160.         }
  161.  
  162.         if (cur_y-first+1<visible)
  163.         {
  164.                 if (cur_y + 1 >= count) return 0;
  165.                 cur_y++;
  166.         }
  167.         else
  168.         {
  169.                 if (visible + first >= count) return 0;
  170.                 first++;
  171.                 cur_y++;
  172.         }
  173.         if (cur_y < first) || (cur_y >= first + visible)
  174.         {
  175.                 first = cur_y;
  176.         }
  177.         CheckDoesValuesOkey();
  178.         return 1;
  179. }
  180.  
  181. :int llist::KeyUp()
  182. {
  183.         if (no_selection)
  184.         {
  185.                 if (first == 0) return 0;
  186.                 first--;
  187.                 return 1;
  188.         }
  189.  
  190.         if (cur_y > first)
  191.         {
  192.                 cur_y--;
  193.         }
  194.         else
  195.         {
  196.                 if (first == 0) return 0;
  197.                 first--;
  198.                 cur_y--;
  199.         }
  200.         if (cur_y < first) || (cur_y > first + visible)
  201.         {
  202.                 first = cur_y;
  203.                 CheckDoesValuesOkey();
  204.         }
  205.         return 1;
  206. }
  207.  
  208. :int llist::KeyHomeHor()
  209. {
  210.         if (cur_x==0) return 0;
  211.         cur_x = 0;
  212.         return 1;
  213. }
  214.  
  215. :int llist::KeyEndHor()
  216. {
  217.         if (cur_x==column_max) return 0;
  218.         cur_x = column_max;
  219.         CheckDoesValuesOkey();
  220.         return 1;
  221. }
  222.  
  223. :int llist::KeyHome()
  224. {
  225.         if (cur_y==0) && (first==0) return 0;
  226.         cur_y = first = 0;
  227.         return 1;
  228. }
  229.  
  230. :int llist::KeyEnd()
  231. {
  232.         if (cur_y==count-1) && (first==count-visible) return 0;
  233.         cur_y = count-1;
  234.         first = count - visible;
  235.         CheckDoesValuesOkey();
  236.         return 1;
  237. }
  238.  
  239. :int llist::KeyPgUp()
  240. {
  241.         if (count <= visible) return KeyHome();
  242.         if (first == 0) return 0;
  243.         first -= visible;
  244.         cur_y = first;
  245.         CheckDoesValuesOkey();
  246.         return 1;
  247. }
  248.  
  249. :int llist::KeyPgDown()
  250. {
  251.         if (count <= visible) return KeyEnd();
  252.         if (first == count - visible) return 0;
  253.         first += visible;
  254.         cur_y = first + visible - 1;
  255.         CheckDoesValuesOkey();
  256.         return 1;
  257. }
  258.  
  259. :void llist::CheckDoesValuesOkey()
  260. {
  261.         if (visible + first > count) first = count - visible;
  262.         if (first < 0) first = 0;
  263.         if (cur_y >= count) cur_y = count - 1;
  264.         if (cur_x >= column_max) cur_x = column_max;
  265.         if (cur_y < 0) cur_y = 0;
  266.         if (cur_x < 0) cur_x = 0;
  267. }
  268.  
  269. :int llist::KeyRight()
  270. {
  271.         if (cur_x < column_max)
  272.         {
  273.                 cur_x++;
  274.         }
  275.         else
  276.         {
  277.                 if (!KeyDown()) return 0;
  278.                 cur_x = 0;
  279.         }
  280.         return 1;
  281. }
  282.  
  283. :int llist::KeyLeft()
  284. {
  285.         if (cur_x > 0)
  286.         {
  287.                 cur_x--;
  288.         }
  289.         else
  290.         {
  291.                 if (!KeyUp()) return 0;
  292.                 cur_x = column_max;
  293.         }
  294.         return 1;
  295. }
  296.  
  297.  
  298. :void llist_copy(dword dest, src)
  299. {
  300.         memmov(dest, src, sizeof(llist));
  301.         /*
  302.         EDI = dest;
  303.         ESI = src;
  304.         EDI.llist.x = ESI.llist.x;
  305.         EDI.llist.y = ESI.llist.y;
  306.         EDI.llist.w = ESI.llist.w;
  307.         EDI.llist.h = ESI.llist.h;
  308.         EDI.llist.item_h = ESI.llist.item_h;
  309.         EDI.llist.text_y = ESI.llist.text_y;
  310.         EDI.llist.font_w = ESI.llist.font_w;
  311.         EDI.llist.font_h = ESI.llist.font_h;
  312.         EDI.llist.font_type = ESI.llist.font_type;
  313.         EDI.llist.count = ESI.llist.count;
  314.         EDI.llist.visible = ESI.llist.visible;
  315.         EDI.llist.first = ESI.llist.first;
  316.         EDI.llist.cur_y = ESI.llist.cur_y;
  317.         EDI.llist.column_max = ESI.llist.column_max;
  318.         EDI.llist.active = ESI.llist.active;
  319.         */
  320. }
  321.  
  322. #endif