Subversion Repositories Kolibri OS

Rev

Rev 7924 | Go to most recent revision | 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. } selection;
  15.  
  16. bool SELECTION::is_active()
  17. {
  18.         if (start_offset) && (end_offset) && (start_offset != end_offset) {
  19.                 return true;
  20.         } else {
  21.                 return false;
  22.         }
  23. }
  24.  
  25. void SELECTION::draw_line(dword x,y,w)
  26. {
  27.         DrawBuf.DrawBar(x, y, w, list.item_h, color);
  28. }
  29.  
  30. void SELECTION::draw(int i)
  31. {
  32.         if (is_active()) {
  33.                 if (start_y == i) && (end_y == i) draw_line(start_x * list.font_w+2, start_y * list.item_h, end_x - start_x * list.font_w);
  34.                 else if (start_y == i) draw_line(start_x * list.font_w+2, start_y * list.item_h, list.w -2- calc(start_x * list.font_w));
  35.                 else if (end_y == i) draw_line(0, end_y * list.item_h, end_x * list.font_w+2);
  36.                 //DrawBuf.DrawBar(start_x * list.font_w + 2,  start_y * list.item_h, 2, list.item_h, 0x00FF00);
  37.                 //DrawBuf.DrawBar(end_x * list.font_w + 0,  end_y * list.item_h, 2, list.item_h, 0xFF00FF);
  38.         }
  39.         DrawBuf.DrawBar(list.cur_x * list.font_w + 2,  list.cur_y * list.item_h, 2, list.item_h, theme.cursor); //DrawCursor
  40. }
  41.  
  42. void SELECTION::cancel()
  43. {
  44.         start_offset = end_offset = lines.get(list.cur_y) + list.cur_x;
  45.         start_x = end_x = list.cur_x;
  46.         start_y = end_y = list.cur_y;
  47.         normalize();
  48. }
  49.  
  50. void SELECTION::set_start()
  51. {
  52.         start_x = list.cur_x;
  53.         start_y = list.cur_y;
  54.         normalize();
  55.         start_offset = lines.get(start_y) + start_x;
  56. }
  57.  
  58. void SELECTION::set_end()
  59. {
  60.         end_x = list.cur_x;
  61.         end_y = list.cur_y;
  62.         normalize();
  63.         end_offset = lines.get(end_y) + end_x;
  64.         debugval("end_x", end_x);
  65.         debugval("end_y", end_y);
  66. }
  67.  
  68.  
  69. void SELECTION::normalize()
  70. {
  71.         start_x = math.min(start_x, lines.get(start_y+1) - lines.get(start_y));
  72.         end_x   = math.min(end_x,   lines.get(end_y+1) - lines.get(end_y));
  73. }
  74.  
  75. void SELECTION::select_all()
  76. {
  77.         start_y = 0;
  78.         start_x = 0;
  79.         end_y = lines.count-2;
  80.         end_x = lines.get(end_y+1) - lines.get(end_y);
  81.         //normalize();
  82.         start_offset = lines.get(start_y) + start_x;
  83.         end_offset = lines.get(end_y) + end_x;
  84.         debugval("end_x__", end_x);
  85.         debugval("end_y__", end_y);
  86. }
  87.  
  88. bool SELECTION::swap_start_end()
  89. {
  90.         start_offset >< end_offset;
  91.         start_x >< end_x;
  92.         start_y >< end_y;
  93.         return true;
  94. }
  95.