Subversion Repositories Kolibri OS

Rev

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

  1. :struct more_less_box
  2. {
  3.         unsigned value, min, max;
  4.         dword text;
  5.         int click_delta;
  6.         int x,y;
  7.         unsigned id_inc, id_dec;
  8.         bool disabled;
  9.         void check_values();
  10.         bool click();
  11.         bool inc();
  12.         bool dec();
  13.         void draw();
  14.         void redraw();
  15. };
  16.  
  17. :void more_less_box::check_values()
  18. {
  19.         if (!id_inc) id_inc = GetFreeButtonId();
  20.         if (!id_dec) id_dec = GetFreeButtonId();
  21.         if (!click_delta) click_delta = 1;
  22. }
  23.  
  24. :bool more_less_box::click(unsigned id)
  25. {
  26.         if (disabled) return 0;
  27.         if (id==id_dec) { value = math.max(value-click_delta, min); redraw(); return 1; }
  28.         if (id==id_inc) { value = math.min(value+click_delta, max); redraw(); return 1; }
  29.         return 0;
  30. }
  31.  
  32. :bool more_less_box::inc()
  33. {
  34.         click(id_inc);
  35. }
  36.  
  37. :bool more_less_box::dec()
  38. {
  39.         click(id_dec);
  40. }
  41.  
  42. :void more_less_box::draw(dword _x,_y)
  43. {
  44.         #define VALUE_FIELD_W 34
  45.         #define SIZE 18
  46.         dword text_col;
  47.         dword value_text = itoa(value);
  48.  
  49.         check_values();
  50.         x=_x; y=_y;
  51.  
  52.         DrawRectangle(x, y, VALUE_FIELD_W+1, SIZE, sc.work_graph);
  53.         DrawRectangle3D(x+1, y+1, VALUE_FIELD_W-2, SIZE-2, 0xDDDddd, 0xffffff);
  54.  
  55.         if (disabled)
  56.         {
  57.                 DrawRectangle(x+1, y+1, VALUE_FIELD_W-2, SIZE-2, 0xffffff);
  58.                 DrawBar(x+2, y+2, VALUE_FIELD_W-3, SIZE-3, 0xCCCccc);
  59.                 text_col = sc.work_graph;
  60.         }
  61.         else
  62.         {
  63.                 DrawBar(x+2, y+2, VALUE_FIELD_W-3, SIZE-3, 0xffffff);
  64.                 text_col = sc.work_text;
  65.         }
  66.  
  67.         WriteText( -strlen(value_text)+3*8 + x+6, SIZE / 2 + y -6, 0x90, 0x333333, value_text);
  68.  
  69.         DrawCaptButton(VALUE_FIELD_W + x + 1,    y, SIZE, SIZE, id_inc, sc.button, sc.button_text, "+");
  70.         DrawCaptButton(VALUE_FIELD_W + x + SIZE, y, SIZE, SIZE, id_dec, sc.button, sc.button_text, "-");
  71.         WriteTextWithBg(x+VALUE_FIELD_W+SIZE+SIZE+10, SIZE / 2 + y -7, 0xD0, text_col, text, sc.work);
  72.         DrawRectangle3D(x-1,y-1,VALUE_FIELD_W+SIZE+SIZE+2,SIZE+2,sc.work_dark,sc.work_light);
  73. }
  74.  
  75. :void more_less_box::redraw()
  76. {
  77.         draw(x,y);
  78. }
  79.  
  80.