Subversion Repositories Kolibri OS

Rev

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