Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef INCLUDE_CHECKBOX
  2. #define INCLUDE_CHECKBOX
  3.  
  4. struct checkbox
  5. {
  6.         dword text;
  7.         bool checked;
  8.         bool disabled;
  9.         dword x,y, id;
  10.         bool click();
  11.         void draw();
  12.         void redraw();
  13. };
  14.  
  15. :bool checkbox::click(dword _id)
  16. {
  17.         if (disabled) return 0;
  18.         if (_id == id) {
  19.                 checked^=1;
  20.                 redraw();
  21.                 return 1;              
  22.         }
  23.         return 0;
  24. }
  25.  
  26. :void checkbox::draw(dword _x,_y)
  27. {
  28.         #define SIZE 14
  29.         static dword checkbox_flag;
  30.         dword text_col = sc.work_text;
  31.         if (!id) id = GetFreeButtonId();
  32.         x=_x; y=_y;
  33.  
  34.         DefineButton(x-1, y-1, strlen(text)*8 + SIZE + 17, SIZE+2, id+BT_HIDE+BT_NOFRAME, 0);
  35.         DrawRectangle(x, y, SIZE, SIZE, sc.work_graph);
  36.         if (disabled)
  37.         {
  38.                 DrawRectangle(x+1, y+1, SIZE-2, SIZE-2, 0xffffff);
  39.                 DrawBar(x+2, y+2, SIZE-3, SIZE-3, 0xCCCccc);
  40.                 text_col = MixColors(sc.work, sc.work_text, 128);
  41.         }
  42.         else if (checked == false)
  43.         {
  44.                 DrawRectangle3D(x+1, y+1, SIZE-2, SIZE-2, 0xDDDddd, 0xffffff);
  45.                 DrawBar(x+2, y+2, SIZE-3, SIZE-3, 0xffffff);
  46.         }
  47.         else if (checked == true)
  48.         {
  49.                 if (!checkbox_flag) checkbox_flag = memopen("CHECKBOX", NULL, SHM_READ);
  50.                 if (checkbox_flag) _PutImage(x+1, y+1, 13, 13, checkbox_flag);
  51.                 else DrawBar(x+2, y+2, SIZE-3, SIZE-3, 0x58C33C);
  52.         }
  53.         if (text) WriteTextWithBg(x+SIZE+8, SIZE / 2 + y -7, 0xD0, text_col, text, sc.work);
  54.         DrawRectangle3D(x-1,y-1,SIZE+2,SIZE+2,sc.work_dark,sc.work_light);
  55. }
  56.  
  57. :void checkbox::redraw()
  58. {
  59.         draw(x,y);
  60. }
  61.  
  62. #endif