Subversion Repositories Kolibri OS

Rev

Rev 7823 | Rev 7924 | Go to most recent revision | 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 cur_y_temp, cur_x_temp, ret=0;
  106.         if (MouseOver(xx, yy))
  107.         {
  108.                 cur_y_temp = yy - y / item_h + first;
  109.                 if (cur_y_temp != cur_y) && (cur_y_temp<count)
  110.                 {
  111.                         cur_y = cur_y_temp;
  112.                         ret = 1;
  113.                 }
  114.                 if (horisontal_selelection)
  115.                 {              
  116.                         cur_x_temp = xx - x / item_w;
  117.                         if (cur_x_temp != cur_x) && (cur_x_temp<column_max)
  118.                         {
  119.                                 cur_x = cur_x_temp;
  120.                                 ret = 1;
  121.                         }
  122.                 }
  123.         }
  124.         return ret;
  125. }
  126.  
  127. :int llist::ProcessKey(dword key)
  128. {
  129.         if (horisontal_selelection) switch(key)
  130.         {
  131.                 case SCAN_CODE_LEFT:  return KeyLeft();
  132.                 case SCAN_CODE_RIGHT: return KeyRight();
  133.                 case SCAN_CODE_HOME:  return KeyHomeHor();
  134.                 case SCAN_CODE_END:   return KeyEndHor();
  135.         }
  136.         switch(key)
  137.         {
  138.                 case SCAN_CODE_DOWN: return KeyDown();
  139.                 case SCAN_CODE_UP:   return KeyUp();
  140.                 case SCAN_CODE_HOME: return KeyHome();
  141.                 case SCAN_CODE_END:  return KeyEnd();
  142.                 case SCAN_CODE_PGUP: return KeyPgUp();
  143.                 case SCAN_CODE_PGDN: return KeyPgDown();
  144.         }
  145.         return 0;
  146. }
  147.  
  148. :int llist::KeyDown()
  149. {
  150.         if (no_selection)
  151.         {
  152.                 if (visible + first >= count) return 0;
  153.                 first++;
  154.                 return 1;              
  155.         }
  156.  
  157.         if (cur_y-first+1<visible)
  158.         {
  159.                 if (cur_y + 1 >= count) return 0;
  160.                 cur_y++;
  161.         }
  162.         else
  163.         {
  164.                 if (visible + first >= count) return 0;
  165.                 first++;
  166.                 cur_y++;
  167.         }
  168.         if (cur_y < first) || (cur_y >= first + visible)
  169.         {
  170.                 first = cur_y;
  171.         }
  172.         CheckDoesValuesOkey();
  173.         return 1;
  174. }
  175.  
  176. :int llist::KeyUp()
  177. {
  178.         if (no_selection)
  179.         {
  180.                 if (first == 0) return 0;
  181.                 first--;
  182.                 return 1;
  183.         }
  184.  
  185.         if (cur_y > first)
  186.         {
  187.                 cur_y--;
  188.         }
  189.         else
  190.         {
  191.                 if (first == 0) return 0;
  192.                 first--;
  193.                 cur_y--;
  194.         }
  195.         if (cur_y < first) || (cur_y > first + visible)
  196.         {
  197.                 first = cur_y;
  198.                 CheckDoesValuesOkey();
  199.         }
  200.         return 1;
  201. }
  202.  
  203. :int llist::KeyHomeHor()
  204. {
  205.         if (cur_x==0) return 0;
  206.         cur_x = 0;
  207.         return 1;
  208. }
  209.  
  210. :int llist::KeyEndHor()
  211. {
  212.         if (cur_x==column_max) return 0;
  213.         cur_x = column_max;
  214.         CheckDoesValuesOkey();
  215.         return 1;
  216. }
  217.  
  218. :int llist::KeyHome()
  219. {
  220.         if (cur_y==0) && (first==0) return 0;
  221.         cur_y = first = 0;
  222.         return 1;
  223. }
  224.  
  225. :int llist::KeyEnd()
  226. {
  227.         if (cur_y==count-1) && (first==count-visible) return 0;
  228.         cur_y = count-1;
  229.         first = count - visible;
  230.         CheckDoesValuesOkey();
  231.         return 1;
  232. }
  233.  
  234. :int llist::KeyPgUp()
  235. {
  236.         if (count <= visible) return KeyHome();
  237.         if (first == 0) return 0;
  238.         first -= visible;
  239.         cur_y = first;
  240.         CheckDoesValuesOkey();
  241.         return 1;
  242. }
  243.  
  244. :int llist::KeyPgDown()
  245. {
  246.         if (count <= visible) return KeyEnd();
  247.         if (first == count - visible) return 0;
  248.         first += visible;
  249.         cur_y = first + visible - 1;
  250.         CheckDoesValuesOkey();
  251.         return 1;
  252. }
  253.  
  254. :void llist::CheckDoesValuesOkey()
  255. {
  256.         if (visible + first > count) first = count - visible;
  257.         if (first < 0) first = 0;
  258.         if (cur_y >= count) cur_y = count - 1;
  259.         if (cur_x >= column_max) cur_x = column_max;
  260.         if (cur_y < 0) cur_y = 0;
  261.         if (cur_x < 0) cur_x = 0;
  262. }
  263.  
  264. :int llist::KeyRight()
  265. {
  266.         if (cur_x < column_max)
  267.         {
  268.                 cur_x++;
  269.         }
  270.         else
  271.         {
  272.                 if (!KeyDown()) return 0;
  273.                 cur_x = 0;
  274.         }
  275.         return 1;
  276. }
  277.  
  278. :int llist::KeyLeft()
  279. {
  280.         if (cur_x > 0)
  281.         {
  282.                 cur_x--;
  283.         }
  284.         else
  285.         {
  286.                 if (!KeyUp()) return 0;
  287.                 cur_x = column_max;
  288.         }
  289.         return 1;
  290. }
  291.  
  292.  
  293. :void llist_copy(dword dest, src)
  294. {
  295.         memmov(dest, src, sizeof(llist));
  296.         /*
  297.         EDI = dest;
  298.         ESI = src;
  299.         EDI.llist.x = ESI.llist.x;
  300.         EDI.llist.y = ESI.llist.y;
  301.         EDI.llist.w = ESI.llist.w;
  302.         EDI.llist.h = ESI.llist.h;
  303.         EDI.llist.item_h = ESI.llist.item_h;
  304.         EDI.llist.text_y = ESI.llist.text_y;
  305.         EDI.llist.font_w = ESI.llist.font_w;
  306.         EDI.llist.font_h = ESI.llist.font_h;
  307.         EDI.llist.font_type = ESI.llist.font_type;
  308.         EDI.llist.count = ESI.llist.count;
  309.         EDI.llist.visible = ESI.llist.visible;
  310.         EDI.llist.first = ESI.llist.first;
  311.         EDI.llist.cur_y = ESI.llist.cur_y;
  312.         EDI.llist.column_max = ESI.llist.column_max;
  313.         EDI.llist.active = ESI.llist.active;
  314.         */
  315. }
  316.  
  317. #endif