Subversion Repositories Kolibri OS

Rev

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

  1. //list_box
  2. #ifndef INCLUDE_LIST_BOX_H
  3. #define INCLUDE_LIST_BOX_H
  4. #print "[include <list_box.h>]\n"
  5.  
  6. #ifndef INCLUDE_KOLIBRI_H
  7. #include "../lib/kolibri.h"
  8. #endif
  9.  
  10. struct llist
  11. {
  12.         int x, y, w, h, line_h, text_y;
  13.         dword font_w, font_h, font_type;
  14.         int count, visible, first, current, column_max; //visible = row_max
  15.         int wheel_size;
  16.         int active;
  17.         void ClearList();
  18.         int MouseOver(int xx, yy);
  19.         int ProcessMouse(int xx, yy);
  20.         int ProcessKey(dword key);
  21.         int KeyDown();
  22.         int KeyUp();
  23.         int KeyHome();
  24.         int KeyEnd();
  25.         int KeyPgDown();
  26.         int KeyPgUp();
  27.         void CheckDoesValuesOkey();
  28.         void SetSizes(int xx, yy, ww, hh, line_hh);
  29.         void SetFont(dword font_ww, font_hh, font_tt);
  30.         int MouseScroll(dword scroll_state);
  31.         void debug_values();
  32. };
  33.  
  34.  
  35. void llist::debug_values()
  36. {
  37.         char yi[128];
  38.         sprintf(#yi, "%s %d %s %d %s %d %s %d", "current:", current, "first:", first,
  39.         "visible:", visible, "count:", count);
  40.         debugln(#yi);
  41. }
  42.  
  43.  
  44.  
  45. void llist::ClearList()
  46. {
  47.         count = visible = first = current = 0;
  48. }
  49.  
  50.  
  51. void llist::SetSizes(int xx, yy, ww, hh, line_hh)
  52. {
  53.         x = xx;
  54.         y = yy;
  55.         w = ww;
  56.         h = hh;
  57.         line_h = line_hh;
  58.         text_y = line_h - font_h / 2;
  59.         visible = h / line_h;
  60.         wheel_size = 3;
  61.         //if (visible > count) visible=count;
  62. }
  63.  
  64. void llist::SetFont(dword font_ww, font_hh, font_tt)
  65. {
  66.         font_w = font_ww;
  67.         font_h = font_hh;
  68.         font_type = font_tt;
  69. }
  70.  
  71.  
  72. int llist::MouseScroll(dword scroll_state)
  73. {
  74.         if (count<=visible) return 0;
  75.         if (scroll_state == 65535)
  76.         {
  77.                 if (first == 0) return 0;
  78.                 if (first > wheel_size+1) first -= wheel_size; else first=0;
  79.                 return 1;
  80.         }
  81.         if (scroll_state == 1)
  82.         {
  83.                 if (visible + first == count) return 0;
  84.                 if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size;
  85.                 return 1;
  86.         }
  87.         return 0;
  88. }
  89.  
  90.  
  91. int llist::MouseOver(int xx, yy)
  92. {
  93.         if (xx>x) && (xx<x+w) && (yy>y) && (yy<y+h) return 1;
  94.         return 0;
  95. }
  96.  
  97. int llist::ProcessMouse(int xx, yy)
  98. {
  99.         int current_temp;
  100.         if (MouseOver(xx, yy))
  101.         {
  102.                 current_temp = yy - y / line_h + first;
  103.                 if (current_temp != current) && (current_temp<count)
  104.                 {
  105.                         current = current_temp;
  106.                         return 1;
  107.                 }
  108.         }
  109.         return 0;
  110. }
  111.  
  112. int llist::ProcessKey(dword key)
  113. {
  114.         switch(key)
  115.         {
  116.                 case SCAN_CODE_DOWN: return KeyDown();
  117.                 case SCAN_CODE_UP:   return KeyUp();
  118.                 case SCAN_CODE_HOME: return KeyHome();
  119.                 case SCAN_CODE_END:  return KeyEnd();
  120.                 case SCAN_CODE_PGUP: return KeyPgUp();
  121.                 case SCAN_CODE_PGDN: return KeyPgDown();
  122.         }
  123.         return 0;
  124. }
  125.  
  126. int llist::KeyDown()
  127. {
  128.         if (current-first+1<visible)
  129.         {
  130.                 if (current + 1 >= count) return 0;
  131.                 current++;
  132.         }
  133.         else
  134.         {
  135.                 if (visible + first >= count) return 0;
  136.                 first++;
  137.                 current++;
  138.         }
  139.         if (current < first) || (current > first + visible)
  140.         {
  141.                 first = current;
  142.                 CheckDoesValuesOkey();
  143.         }
  144.         return 1;
  145. }
  146.  
  147. int llist::KeyUp()
  148. {
  149.         if (current > first)
  150.         {
  151.                 current--;
  152.         }
  153.         else
  154.         {
  155.                 if (first == 0) return 0;
  156.                 first--;
  157.                 current--;
  158.         }
  159.         if (current < first) || (current > first + visible)
  160.         {
  161.                 first = current;
  162.                 CheckDoesValuesOkey();
  163.         }
  164.         return 1;
  165. }
  166.  
  167. int llist::KeyHome()
  168. {
  169.         if (current==0) && (first==0) return 0;
  170.         current = first = 0;
  171.         return 1;
  172. }
  173.  
  174. int llist::KeyEnd()
  175. {
  176.         if (current==count-1) && (first==count-visible) return 0;
  177.         current = count-1;
  178.         first = count - visible;
  179.         return 1;
  180. }
  181.  
  182. int llist::KeyPgUp()
  183. {
  184.         if (count <= visible) return KeyHome();
  185.         if (first == 0) return 0;
  186.         first -= visible;
  187.         CheckDoesValuesOkey();
  188.         return 1;
  189. }
  190.  
  191. int llist::KeyPgDown()
  192. {
  193.         if (count <= visible) return KeyEnd();
  194.         if (first == count - visible) return 0;
  195.         first += visible;
  196.         CheckDoesValuesOkey();
  197.         return 1;
  198. }
  199.  
  200. void llist::CheckDoesValuesOkey()
  201. {
  202.         if (first < 0) first = 0;
  203.         if (visible + first > count) first = count - visible;
  204.         if (current >= count) current = count - 1;
  205.         if (current < 0) current = 0;
  206. }
  207.  
  208. void llist_copy(dword dest, src)
  209. {
  210.         EDI = dest;
  211.         ESI = src;
  212.         EDI.llist.x = ESI.llist.x;
  213.         EDI.llist.y = ESI.llist.y;
  214.         EDI.llist.w = ESI.llist.w;
  215.         EDI.llist.h = ESI.llist.h;
  216.         EDI.llist.line_h = ESI.llist.line_h;
  217.         EDI.llist.text_y = ESI.llist.text_y;
  218.         EDI.llist.font_w = ESI.llist.font_w;
  219.         EDI.llist.font_h = ESI.llist.font_h;
  220.         EDI.llist.font_type = ESI.llist.font_type;
  221.         EDI.llist.count = ESI.llist.count;
  222.         EDI.llist.visible = ESI.llist.visible;
  223.         EDI.llist.first = ESI.llist.first;
  224.         EDI.llist.current = ESI.llist.current;
  225.         EDI.llist.column_max = ESI.llist.column_max;
  226.         EDI.llist.active = ESI.llist.active;
  227. }
  228.  
  229. #endif