Subversion Repositories Kolibri OS

Rev

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

  1. struct SELECTION {
  2.         dword start_x, start_y, start_offset;
  3.         dword end_x, end_y, end_offset;
  4.         dword color;
  5.         bool is_active();
  6.         void set_start();
  7.         void set_end();
  8.         void draw();
  9.         void draw_line();
  10.         void cancel();
  11.         bool swap_start_end();
  12.         void normalize();
  13.         void select_all();
  14.         void debug();
  15. } selection;
  16.  
  17. bool SELECTION::is_active()
  18. {
  19.         if (start_offset) && (end_offset) && (start_offset != end_offset) {
  20.                 return true;
  21.         } else {
  22.                 return false;
  23.         }
  24. }
  25.  
  26. void SELECTION::draw_line(dword x,y,w)
  27. {
  28.         canvas.DrawBar(x, y - list.first * list.item_h, w, list.item_h, color);
  29. }
  30.  
  31. void SELECTION::draw(int i)
  32. {
  33.         if (is_active()) {
  34.                 if (start_y == i) && (end_y == i) draw_line(start_x * list.font_w+2, start_y, end_x - start_x * list.font_w);
  35.                 else if (start_y == i) draw_line(start_x * list.font_w+2, start_y, list.w -2- calc(start_x * list.font_w));
  36.                 else if (end_y == i) draw_line(0, end_y, end_x * list.font_w+2);
  37.                 //only for debug:
  38.                 //canvas.DrawBar(start_x * list.font_w + 2,  start_y * list.item_h, 2, list.item_h, 0x00FF00);
  39.                 //canvas.DrawBar(end_x * list.font_w + 0,  end_y * list.item_h, 2, list.item_h, 0xFF00FF);
  40.         }
  41.         //DrawCursor
  42.         if (list.cur_y >= list.first) && (list.cur_y <= list.first+list.visible) {
  43.                 canvas.DrawBar(list.cur_x * list.font_w + 2,  list.cur_y - list.first * list.item_h, 2, list.item_h, theme.cursor);
  44.         }
  45. }
  46.  
  47. void SELECTION::cancel()
  48. {
  49.         start_offset = end_offset = lines.get(list.cur_y) + list.cur_x;
  50.         start_x = end_x = list.cur_x;
  51.         start_y = end_y = list.cur_y;
  52.         normalize();
  53. }
  54.  
  55. void SELECTION::set_start()
  56. {
  57.         if (selection.is_active()) return;
  58.         start_x = list.cur_x;
  59.         start_y = list.cur_y;
  60.         normalize();
  61.         start_offset = lines.get(start_y) + start_x;
  62. }
  63.  
  64. :void SELECTION::debug()
  65. {
  66.         char rez[256];
  67.         sprintf(#rez, "start_x: %d start_y: %d end_x: %d end_y: %d", start_x, start_y, end_x, end_y);
  68.         debugln(#rez);
  69. }
  70.  
  71. void SELECTION::set_end()
  72. {
  73.         end_x = list.cur_x;
  74.         end_y = list.cur_y;
  75.         normalize();
  76.         end_offset = lines.get(end_y) + end_x;
  77. }
  78.  
  79.  
  80. void SELECTION::normalize()
  81. {
  82.         start_x = math.min(start_x, lines.get(start_y+1) - lines.get(start_y));
  83.         end_x   = math.min(end_x,   lines.get(end_y+1) - lines.get(end_y));
  84. }
  85.  
  86. void SELECTION::select_all()
  87. {
  88.         start_y = 0;
  89.         start_x = 0;
  90.         end_y = lines.count-2;
  91.         end_x = lines.get(end_y+1) - lines.get(end_y);
  92.         start_offset = lines.get(start_y) + start_x;
  93.         end_offset = lines.get(end_y) + end_x;
  94. }
  95.  
  96. bool SELECTION::swap_start_end()
  97. {
  98.         start_offset >< end_offset;
  99.         start_x >< end_x;
  100.         start_y >< end_y;
  101.         return true;
  102. }
  103.