Subversion Repositories Kolibri OS

Rev

Rev 7291 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. dword CursorFile = FROM "pointer.cur";
  2.  
  3. struct _link
  4. {
  5.         CustomCursor CursorPointer;
  6.         int count;
  7.         int x[4096], y[4096], w[4096], h[4096];
  8.         collection text;
  9.         collection url;
  10.         void clear();
  11.         void add();
  12.         dword get_active_url();
  13.         void draw_underline();
  14.         int hover();
  15.         int active;
  16. } link;
  17.  
  18. void _link::clear()
  19. {
  20.         text.drop();
  21.         url.drop();
  22.         count = 0;
  23. }
  24.  
  25. void _link::add(int _xx, _yy, _ww, _hh, dword _textt, _urll )
  26. {
  27.         if (count==4095) return;
  28.         x[count] = _xx;
  29.         y[count] = _yy;
  30.         w[count] = _ww;
  31.         h[count] = _hh;
  32.         text.add(_textt);
  33.         url.add(_urll);
  34.         count++;
  35. }
  36.  
  37. dword _link::get_active_url()
  38. {
  39.         return url.get(active);
  40. }
  41.  
  42. void _link::draw_underline(dword i, color)
  43. {
  44.         DrawBar(x[i]+list.x, -list.first*list.item_h+y[i]+list.y+h[i]-2, w[i], 1, color);
  45. }
  46.  
  47. int _link::hover(dword mouse_x, mouse_y)
  48. {
  49.         int i;
  50.         int new_active = -1;
  51.         int link_start_y = list.first*list.item_h;
  52.         mouse_x -= list.x;
  53.         mouse_y -= list.y;
  54.         for (i=0; i<count; i++) {
  55.                 if(y[i] > link_start_y) && (y[i] < link_start_y+list.h) {
  56.                         // debugln( sprintf(#param, "mx:%i my:%i x[i]:%i y[i]:%i", mx, my, x[i], y[i]) );
  57.                         if (mouse_x > x[i])
  58.                         && (mouse_x < x[i]+w[i])
  59.                         && (mouse_y > y[i]-link_start_y)
  60.                         && (mouse_y < h[i]-link_start_y+link.y[i]) {
  61.                                 new_active = i;
  62.                                 break;
  63.                         }
  64.                 }
  65.         }
  66.  
  67.         if (new_active != active)
  68.         {
  69.                 if (-1 == new_active) {
  70.                         draw_underline(active, 0x0000FF);
  71.                         CursorPointer.Restore();               
  72.                 }
  73.                 else {
  74.                         draw_underline(active, 0x0000FF);
  75.                         draw_underline(new_active, 0xFFFfff);
  76.                         CursorPointer.Load(#CursorFile);
  77.                         CursorPointer.Set();
  78.                 }
  79.                 active = new_active;
  80.                 return true;
  81.         }
  82.  
  83.         return false;
  84. }