Subversion Repositories Kolibri OS

Rev

Rev 9465 | 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.         DefineHiddenButton(x-1, y-1, strlen(text)*8 + SIZE + 17, SIZE+2, id+BT_NOFRAME);
  35.         UnsafeDefineButton(x, y, SIZE, SIZE, id, 0);
  36.         DrawRectangle(x, y, SIZE, SIZE, sc.line);
  37.         if (disabled)
  38.         {
  39.                 DrawRectangle(x+1, y+1, SIZE-2, SIZE-2, 0xffffff);
  40.                 DrawBar(x+2, y+2, SIZE-3, SIZE-3, 0xCCCccc);
  41.                 text_col = MixColors(sc.work, sc.work_text, 128);
  42.         }
  43.         else if (checked == false)
  44.         {
  45.                 DrawRectangle3D(x+1, y+1, SIZE-2, SIZE-2, 0xDDDddd, 0xffffff);
  46.                 DrawBar(x+2, y+2, SIZE-3, SIZE-3, 0xffffff);
  47.         }
  48.         else if (checked == true)
  49.         {
  50.                 if (!checkbox_flag) checkbox_flag = memopen("CHECKBOX", NULL, SHM_READ);
  51.                 if (checkbox_flag) PutImage(x+1, y+1, 13, 13, checkbox_flag);
  52.                 else DrawBar(x+2, y+2, SIZE-3, SIZE-3, 0x58C33C);
  53.         }
  54.         if (text) WriteTextWithBg(x+SIZE+8, SIZE / 2 + y -7, 0xD0, text_col, text, sc.work);
  55.         DrawRectangle3D(x-1,y-1,SIZE+2,SIZE+2,sc.dark,sc.light);
  56. }
  57.  
  58. :void checkbox::redraw()
  59. {
  60.         draw(x,y);
  61. }
  62.  
  63. #endif