void accheck_redrawitem(ACONTROLP ctl, int index){
  ACCHECKDP d = (ACCHECKDP) ctl->d;
  if (d->acheck_signature != 133) return; //-- Not Valid Signature
  if ((index>=d->itemn)||(index<0)) return; //-- Not Valid Index
  
  ACCHECKIP p = d->items[index];
  CANVAS *  c = &d->client;
  
  //-- Cleanup Background
  ag_rect(c,0,p->y,d->clientWidth,p->h,acfg()->textbg);
  
  if (p->isTitle){
    ag_roundgrad(c,0,p->y,d->clientWidth,p->h,acfg()->titlebg,acfg()->titlebg_g,0);
    ag_textf(c,d->clientTextW+(agdp()*14),(d->clientTextX-(agdp()*14))+1,p->y+p->ty,p->title,acfg()->titlebg_g,0);
    ag_text(c,d->clientTextW+(agdp()*14),d->clientTextX-(agdp()*14),p->y+p->ty-1,p->title,acfg()->titlefg,0);
  }
  else{
    color txtcolor = acfg()->textfg;
    color graycolor= acfg()->textfg_gray;
    byte isselectcolor=0;
    if (index==d->touchedItem){
      if (!atheme_draw("img.selection.push", c,0,p->y+agdp(),d->clientWidth,p->h-(agdp()*2))){
        color pshad = ag_calpushad(acfg()->selectbg_g);
        dword hl1 = ag_calcpushlight(acfg()->selectbg,pshad);
        ag_roundgrad(c,0,p->y+agdp(),d->clientWidth,p->h-(agdp()*2),acfg()->selectbg,pshad,(agdp()*acfg()->roundsz));
        ag_roundgrad(c,0,p->y+agdp(),d->clientWidth,(p->h-(agdp()*2))/2,LOWORD(hl1),HIWORD(hl1),(agdp()*acfg()->roundsz));
      }
      
      graycolor = txtcolor = acfg()->selectfg;
      isselectcolor=1;
    }
    else if ((index==d->focusedItem)&&(d->focused)){
      if (!atheme_draw("img.selection", c,0,p->y+agdp(),d->clientWidth,p->h-(agdp()*2))){
        dword hl1 = ag_calchighlight(acfg()->selectbg,acfg()->selectbg_g);
        ag_roundgrad(c,0,p->y+agdp(),d->clientWidth,p->h-(agdp()*2),acfg()->selectbg,acfg()->selectbg_g,(agdp()*acfg()->roundsz));
        ag_roundgrad(c,0,p->y+agdp(),d->clientWidth,(p->h-(agdp()*2))/2,LOWORD(hl1),HIWORD(hl1),(agdp()*acfg()->roundsz));
      }
      graycolor = txtcolor = acfg()->selectfg;
      isselectcolor=1;
    }
    if (index<d->itemn-1){
      //-- Not Last... Add Separator
      color sepcl = ag_calculatealpha(acfg()->textbg,acfg()->textfg_gray,80);
      ag_rect(c,0,p->y+p->h-1,d->clientWidth,1,sepcl);
    }
    
    //-- Now Draw The Text
    if (isselectcolor){
      ag_textf(c,d->clientTextW,d->clientTextX,p->y+p->ty,p->title,acfg()->selectbg_g,0);
      ag_textf(c,d->clientTextW,d->clientTextX,p->y+p->dy,p->desc,acfg()->selectbg_g,0);
    }
    ag_text(c,d->clientTextW,d->clientTextX-1,p->y+p->ty-1,p->title,txtcolor,0);
    ag_text(c,d->clientTextW,d->clientTextX-1,p->y+p->dy-1,p->desc,graycolor,0);
    
    //-- Now Draw The Checkbox
    int halfdp   = ceil(((float) agdp())/2);
    int halfdp2  = halfdp*2;
    int chkbox_s = (agdp()*10);
    int chkbox_x = round((d->clientTextX/2)- ((chkbox_s+2)/2));
    int chkbox_y = p->y + round((p->h/2) - (chkbox_s/2));
    
    byte drawed = 0;
    int minpad = 3*agdp();
    int addpad = 6*agdp();
    if (p->checked){
      if (index==d->touchedItem)
        drawed=atheme_draw("img.checkbox.on.push", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
      else if ((index==d->focusedItem)&&(d->focused))
        drawed=atheme_draw("img.checkbox.on.focus", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
      else
        drawed=atheme_draw("img.checkbox.on", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
    }
    else{
      if (index==d->touchedItem)
        drawed=atheme_draw("img.checkbox.push", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
      else if ((index==d->focusedItem)&&(d->focused))
        drawed=atheme_draw("img.checkbox.focus", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
      else
        drawed=atheme_draw("img.checkbox", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
    }
    if (!drawed){
      ag_roundgrad(c,
        chkbox_x,
        chkbox_y,
        chkbox_s,
        chkbox_s,
        acfg()->controlbg_g,
        acfg()->controlbg,
        0);
      ag_roundgrad(c,
        chkbox_x+halfdp,
        chkbox_y+halfdp,
        chkbox_s-halfdp2,
        chkbox_s-halfdp2,
        acfg()->textbg,
        acfg()->textbg,
        0);
      if (p->checked){
        ag_roundgrad(c,
          chkbox_x+halfdp2,
          chkbox_y+halfdp2,
          chkbox_s-(halfdp2*2),
          chkbox_s-(halfdp2*2),
          acfg()->selectbg,
          acfg()->selectbg_g,
          0);
      }
    }
  }
}
ACONTROLP imgbtn_reinit(
  AWINDOWP win,
  ACONTROLP ctl,
  int x,
  int y,
  int w,
  int h,
  PNGCANVAS * img,
  char * text,
  byte isflat,
  byte touchmsg
) {
  if ((ctl != NULL) && (x == 0) && (y == 0) && (h == 0) && (w == 0)) {
    x = ctl->x;
    y = ctl->y;
    w = ctl->w;
    h = ctl->h;
  }
  
  int txtw = 0;
  int txth = 0;
  int txtx = 0;
  int txty = 0;
  
  if (w < agdp() * 20) {
    w = agdp() * 20;
  }
  
  if (h < agdp() * 20) {
    h = agdp() * 20;
  }
  
  if (text != NULL) {
    //-- Initializing Text Metrics
    if ((isflat == 3) || (isflat == 4)) {
      txtw = ag_txtwidth(text, 0);
      txth = ag_fontheight(0);
      
      if (w < ((agdp() * 22) + txtw)) {
        w = ((agdp() * 22) + txtw);
      }
      
      txtx = round(w / 2) - round(((agdp() * 20) + txtw) / 2);
      txty = round(h / 2) - round(txth / 2);
    }
    else {
      txtw = ag_txtwidth(text, 0);
      txth = ag_fontheight(0);
      
      if (h < ((agdp() * 20) + txth)) {
        h = ((agdp() * 20) + txth);
      }
      
      txtx = round(w / 2) - round(txtw / 2);
      txty = (agdp() * 16);
    }
  }
  
  int imgS = agdp() * 16;
  int imgX = round(w / 2) - round(imgS / 2);
  int imgY = 0; // agdp()*2;
  int contentH = (agdp() * 16) +  txth;
  int contentY = (h / 2) - (contentH / 2);
  
  if ((isflat == 3) || (isflat == 4)) {
    imgY = round(h / 2) - round(imgS / 2);
    imgX = txtx + (agdp() * 2);
    txtx += agdp() * 20;
  }
  else {
    imgY += contentY;
    txty += contentY;
  }
  
  if (isflat == 3) {
    isflat = 0;
  }
  
  //-- Initializing Button Data
  IMGBTNDP d = NULL;
  
  if (ctl != NULL) {
    d = ctl->d;
    win = ctl->win;
  }
  else {
    d = (IMGBTNDP) malloc(sizeof(IMGBTND));
    memset(d, 0, sizeof(IMGBTND));
    //-- Save Touch Message & Set Stats
    d->focused   = 0;
    d->pushed    = 0;
    //-- Initializing Canvas
    ag_canvas(&d->control, w, h);
    ag_canvas(&d->control_pushed, w, h);
    ag_canvas(&d->control_focused, w, h);
  }
  
  d->touchmsg  = touchmsg;
  //-- Draw Rest Control
  dword hl1 = ag_calchighlight(acfg()->controlbg, acfg()->controlbg_g);
  ag_draw_ex(&d->control, win->bg, 0, 0, x, y, w, h);
  
  if (!isflat) {
    if (!atheme_draw("img.button", &d->control, 0, 0, w, h)) {
      ag_roundgrad(&d->control, 0, 0, w, h, acfg()->border, acfg()->border_g, (agdp()*acfg()->btnroundsz));
      ag_roundgrad(&d->control, 1, 1, w - 2, h - 2,
                   ag_calculatealpha(acfg()->controlbg, acfg()->winbg, 180),
                   ag_calculatealpha(acfg()->controlbg_g, acfg()->winbg, 160),
                   (agdp()*acfg()->btnroundsz) - 1
                  );
      ag_roundgrad(&d->control, 2, 2, w - 4, h - 4, acfg()->controlbg, acfg()->controlbg_g, (agdp()*acfg()->btnroundsz) - 2);
      ag_roundgrad_ex(&d->control, 2, 2, w - 4, (h - 4) / 2, LOWORD(hl1), HIWORD(hl1), (agdp()*acfg()->btnroundsz) - 2, 1, 1, 0, 0);
    }
  }
  
  ag_textf(&d->control, txtw, txtx + 1, txty + 1, text, acfg()->controlbg, 0);
  ag_text(&d->control, txtw, txtx, txty, text, acfg()->controlfg, 0);
  color pshad = ag_calpushad(acfg()->selectbg_g);
  ag_draw_ex(&d->control_pushed, win->bg, 0, 0, x, y, w, h);
  int wadd = (isflat == 2) ? 2 : 0;
  int wdel = wadd * 2;
  
  //-- Draw Pushed Control
  if (!isflat) {
    hl1 = ag_calcpushlight(acfg()->selectbg, pshad);
    
    if (!atheme_draw("img.button.push", &d->control_pushed, 0, 0, w, h)) {
      ag_roundgrad(&d->control_pushed, 0, 0, w, h, acfg()->border, acfg()->border_g, (agdp()*acfg()->btnroundsz));
      //ag_roundgrad(&d->control_pushed,1,1,w-2,h-2,acfg()->controlbg,acfg()->controlbg_g,(agdp()*acfg()->btnroundsz)-1);
      ag_roundgrad(&d->control_pushed, 1, 1, w - 2, h - 2, acfg()->selectbg, pshad, (agdp()*acfg()->btnroundsz) - 1);
      ag_roundgrad_ex(&d->control_pushed, 1, 1, w - 2, (h - 2) / 2, LOWORD(hl1), HIWORD(hl1), (agdp()*acfg()->btnroundsz) - 1, 1, 1, 0, 0);
    }
    
    ag_textf(&d->control_pushed, txtw, txtx + 1, txty + 1, text, acfg()->selectbg_g, 0);
    ag_text(&d->control_pushed, txtw, txtx, txty, text, acfg()->selectfg, 0);
  }
  else {
    hl1 = ag_calchighlight(acfg()->controlbg, acfg()->controlbg_g);
    
    if (!atheme_draw("img.button", &d->control_pushed, 0, 0, w, h)) {
      ag_roundgrad(&d->control_pushed, wadd, wadd, w - wdel, h - wdel, acfg()->border, acfg()->border_g, (agdp()*acfg()->btnroundsz));
      /*ag_roundgrad(&d->control_pushed,wadd+1,wadd+1,w-(2+wdel),h-(2+wdel),
        ag_calculatealpha(acfg()->controlbg,acfg()->winbg,180),
        ag_calculatealpha(acfg()->controlbg_g,acfg()->winbg,160),
        (agdp()*acfg()->btnroundsz)-1
      );*/
      ag_roundgrad(&d->control_pushed, wadd + 1, wadd + 1, w - (2 + wdel), h - (2 + wdel), acfg()->controlbg, acfg()->controlbg_g, (agdp()*acfg()->btnroundsz) - 1);
      ag_roundgrad_ex(&d->control_pushed, wadd + 1, wadd + 1, w - (2 + wdel), (h - (1 + wdel)) / 2, LOWORD(hl1), HIWORD(hl1), (agdp()*acfg()->btnroundsz) - 1, 1, 1, 0, 0);
    }
    
    ag_textf(&d->control_pushed, txtw, txtx + 1, txty + 1, text, acfg()->controlbg, 0);
    ag_text(&d->control_pushed, txtw, txtx, txty, text, acfg()->controlfg, 0);
  }
  
  //-- Draw Focused Control
  hl1 = ag_calchighlight(acfg()->selectbg, acfg()->selectbg_g);
  ag_draw_ex(&d->control_focused, win->bg, 0, 0, x, y, w, h);
  
  if (!atheme_draw("img.button.focus", &d->control_focused, 0, 0, w, h)) {
    ag_roundgrad(&d->control_focused, wadd, wadd, w - wdel, h - wdel, acfg()->border, acfg()->border_g, (agdp()*acfg()->btnroundsz));
    //ag_roundgrad(&d->control_focused,wadd+1,wadd+1,w-(wdel+2),h-(wdel+2),acfg()->controlbg,acfg()->controlbg_g,(agdp()*acfg()->btnroundsz)-1);
    ag_roundgrad(&d->control_focused, wadd + 1, wadd + 1, w - (wdel + 2), h - (wdel + 2), acfg()->selectbg, acfg()->selectbg_g, (agdp()*acfg()->btnroundsz) - 1);
    ag_roundgrad_ex(&d->control_focused, wadd + 1, wadd + 1, w - (wdel + 2), (h - (wdel + 2)) / 2, LOWORD(hl1), HIWORD(hl1), (agdp()*acfg()->btnroundsz) - 1, 1, 1, 0, 0);
  }
  
  ag_textf(&d->control_focused, txtw, txtx + 1, txty + 1, text, acfg()->selectbg_g, 0);
  ag_text(&d->control_focused, txtw, txtx, txty, text, acfg()->selectfg, 0);
  
  if (img != NULL) {
    apng_stretch(&d->control, img, imgX, imgY, imgS, imgS, 0, 0, img->w, img->h);
    apng_stretch(&d->control_pushed, img, imgX, imgY, imgS, imgS, 0, 0, img->w, img->h);
    apng_stretch(&d->control_focused, img, imgX, imgY, imgS, imgS, 0, 0, img->w, img->h);
  }
  
  //-- Initializing Control
  if (ctl == NULL) {
    ctl  = malloc(sizeof(ACONTROL));
    ctl->ondestroy = &imgbtn_ondestroy;
    ctl->oninput  = &imgbtn_oninput;
    ctl->ondraw   = &imgbtn_ondraw;
    ctl->onblur   = &imgbtn_onblur;
    ctl->onfocus  = &imgbtn_onfocus;
    ctl->win      = win;
    ctl->forceNS  = 0;
    ctl->d        = (void *) d;
    ctl->x        = x;
    ctl->y        = y;
    ctl->w        = w;
    ctl->h        = h;
    aw_add(win, ctl);
  }
  else {
    ctl->x        = x;
    ctl->y        = y;
    ctl->w        = w;
    ctl->h        = h;
    imgbtn_ondraw(ctl);
  }
  
  return ctl;
}
void acopt_redrawitem(ACONTROLP ctl, int index) {
  ACOPTDP d = (ACOPTDP) ctl->d;
  
  if (d->acheck_signature != 136) {
    return;  //-- Not Valid Signature
  }
  
  if ((index >= d->itemn) || (index < 0)) {
    return;  //-- Not Valid Index
  }
  
  ACOPTIP p = d->items[index];
  CANVAS  * c = &d->client;
  //-- Cleanup Background
  ag_rect(c, 0, p->y, d->clientWidth, p->h, acfg()->textbg);
  
  if (p->isTitle) {
    ag_roundgrad(c, 0, p->y, d->clientWidth, p->h, acfg()->controlbg,  acfg()->controlbg_g, 0);
    ag_rect(c, 0, p->y + p->h - 1, d->clientWidth, 1, acfg()->border);
    ag_rect(c, 0, p->y + p->h - 2, d->clientWidth, 1, acfg()->controlbg);
    char ntitle[256];
    snprintf(ntitle, 256, "<b>%s</b>", p->title);
    ag_textf(c, d->clientTextW + (agdp() * 14), (d->clientTextX - (agdp() * 14)) + 1, p->y + p->ty, ntitle, acfg()->controlbg, 0);
    ag_text(c, d->clientTextW + (agdp() * 14), d->clientTextX - (agdp() * 14), p->y + p->ty - 1, ntitle, acfg()->controlfg, 0);
  }
  else {
    color txtcolor = acfg()->textfg;
    color graycolor = acfg()->textfg_gray;
    byte isselectcolor = 0;
    
    if (index == d->touchedItem) {
      if (!atheme_draw("img.selection.push", c, 0, p->y + agdp(), d->clientWidth, p->h - (agdp() * 2))) {
        color pshad = ag_calpushad(acfg()->selectbg_g);
        dword hl1 = ag_calcpushlight(acfg()->selectbg, pshad);
        ag_roundgrad(c, 0, p->y + agdp(), d->clientWidth, p->h - (agdp() * 2), acfg()->selectbg, pshad, (agdp()*acfg()->roundsz));
        ag_roundgrad(c, 0, p->y + agdp(), d->clientWidth, (p->h - (agdp() * 2)) / 2, LOWORD(hl1), HIWORD(hl1), (agdp()*acfg()->roundsz));
      }
      
      graycolor = txtcolor = acfg()->selectfg;
      isselectcolor = 1;
    }
    else if ((index == d->focusedItem) && (d->focused)) {
      if (!atheme_draw("img.selection", c, 0, p->y + agdp(), d->clientWidth, p->h - (agdp() * 2))) {
        dword hl1 = ag_calchighlight(acfg()->selectbg, acfg()->selectbg_g);
        ag_roundgrad(c, 0, p->y + agdp(), d->clientWidth, p->h - (agdp() * 2), acfg()->selectbg, acfg()->selectbg_g, (agdp()*acfg()->roundsz));
        ag_roundgrad(c, 0, p->y + agdp(), d->clientWidth, (p->h - (agdp() * 2)) / 2, LOWORD(hl1), HIWORD(hl1), (agdp()*acfg()->roundsz));
      }
      
      graycolor = txtcolor = acfg()->selectfg;
      isselectcolor = 1;
    }
    
    if (index < d->itemn - 1) {
      //-- Not Last... Add Separator
      color sepcl = ag_calculatealpha(acfg()->textbg, acfg()->textfg_gray, 80);
      ag_rect(c, 0, p->y + p->h - 1, d->clientWidth, 1, sepcl);
    }
    
    //-- Now Draw The Text
    if (isselectcolor) {
      ag_textf(c, d->clientTextW, d->clientTextX, p->y + p->ty, p->title, acfg()->selectbg_g, 1);
      ag_textf(c, d->clientTextW, d->clientTextX, p->y + p->dy, p->desc, acfg()->selectbg_g, 0);
    }
    
    ag_text(c, d->clientTextW, d->clientTextX - 1, p->y + p->ty - 1, p->title, txtcolor, 1);
    ag_text(c, d->clientTextW, d->clientTextX - 1, p->y + p->dy - 1, p->desc, graycolor, 0);
    //-- Now Draw The Checkbox
    int halfdp   = ceil(((float) agdp()) / 2);
    int halfdp2  = halfdp * 2;
    int optbox_s = (agdp() * 10);
    int optbox_r = floor(optbox_s / 2);
    int optbox_x = round((d->clientTextX / 2) - (optbox_s / 2));
    int optbox_y = p->y + round((p->h / 2) - (optbox_s / 2));
    byte drawed = 0;
    int minpad = 3 * agdp();
    int addpad = 6 * agdp();
    
    if (p->id == d->selectedIndexs[p->group]) {
      if (index == d->touchedItem) {
        drawed = atheme_draw("img.radio.on.push", c, optbox_x - minpad, optbox_y - minpad, optbox_s + addpad, optbox_s + addpad);
      }
      else if ((index == d->focusedItem) && (d->focused)) {
        drawed = atheme_draw("img.radio.on.focus", c, optbox_x - minpad, optbox_y - minpad, optbox_s + addpad, optbox_s + addpad);
      }
      else {
        drawed = atheme_draw("img.radio.on", c, optbox_x - minpad, optbox_y - minpad, optbox_s + addpad, optbox_s + addpad);
      }
    }
    else {
      if (index == d->touchedItem) {
        drawed = atheme_draw("img.radio.push", c, optbox_x - minpad, optbox_y - minpad, optbox_s + addpad, optbox_s + addpad);
      }
      else if ((index == d->focusedItem) && (d->focused)) {
        drawed = atheme_draw("img.radio.focus", c, optbox_x - minpad, optbox_y - minpad, optbox_s + addpad, optbox_s + addpad);
      }
      else {
        drawed = atheme_draw("img.radio", c, optbox_x - minpad, optbox_y - minpad, optbox_s + addpad, optbox_s + addpad);
      }
    }
    
    if (!drawed) {
      ag_roundgrad(c,
                   optbox_x,
                   optbox_y,
                   optbox_s,
                   optbox_s,
                   acfg()->controlbg_g,
                   acfg()->controlbg,
                   optbox_r
                  );
      ag_roundgrad(c,
                   optbox_x + halfdp,
                   optbox_y + halfdp,
                   optbox_s - halfdp2,
                   optbox_s - halfdp2,
                   acfg()->textbg,
                   acfg()->textbg,
                   optbox_r - halfdp);
                   
      if (p->id == d->selectedIndexs[p->group]) {
        ag_roundgrad(c,
                     optbox_x + halfdp2,
                     optbox_y + halfdp2,
                     optbox_s - (halfdp2 * 2),
                     optbox_s - (halfdp2 * 2),
                     acfg()->selectbg,
                     acfg()->selectbg_g,
                     optbox_r - halfdp2);
      }
    }
  }
}
void afbox_redrawitem_ex(ACONTROLP ctl, int index){
  AFBOXDP d = (AFBOXDP) ctl->d;
  if (d->acheck_signature != 177) return; //-- Not Valid Signature
  if ((index>=d->itemn)||(index<0)) return; //-- Not Valid Index
  
  AFBOXIP p = d->items[index];
  CANVAS *  c = &d->client;
  
  //-- Cleanup Background
  ag_rect(c,0,p->y,d->clientWidth,p->h,acfg()->textbg);
  
  if (p->isTitle){
    ag_roundgrad(c,0,p->y,d->clientWidth,p->h,acfg()->titlebg,acfg()->titlebg_g,0);
    ag_textf(c,d->clientTextW+(agdp()*14),(d->clientTextX-(agdp()*14))+1,p->y+p->ty,p->title,acfg()->titlebg_g,0);
    ag_text(c,d->clientTextW+(agdp()*14),d->clientTextX-(agdp()*14),p->y+p->ty-1,p->title,acfg()->titlefg,0);
  }
  else{
    color txtcolor = acfg()->textfg;
    color graycolor= acfg()->textfg_gray;
    byte isselectcolor=0;
    if (index==d->touchedItem){
      if (!atheme_draw("img.selection.push", c,0,p->y+1,d->clientWidth,p->h-2)){
        color pshad = ag_calpushad(acfg()->selectbg_g);
        dword hl1 = ag_calcpushlight(acfg()->selectbg,pshad);
        ag_roundgrad(c,0,p->y+1,d->clientWidth,p->h-3,acfg()->selectbg,pshad,(agdp()*2));
        ag_roundgrad(c,0,p->y+1,d->clientWidth,(p->h-3)/2,LOWORD(hl1),HIWORD(hl1),(agdp()*2));
      }
      graycolor = txtcolor = acfg()->selectfg;
      isselectcolor=1;
    }
    else if ((index==d->focusedItem)&&(d->focused)){
      if (!atheme_draw("img.selection", c,0,p->y+1,d->clientWidth,p->h-2)){
        dword hl1 = ag_calchighlight(acfg()->selectbg,acfg()->selectbg_g);
        ag_roundgrad(c,0,p->y+1,d->clientWidth,p->h-3,acfg()->selectbg,acfg()->selectbg_g,(agdp()*2));
        ag_roundgrad(c,0,p->y+1,d->clientWidth,(p->h-3)/2,LOWORD(hl1),HIWORD(hl1),(agdp()*2));
      }
      graycolor = txtcolor = acfg()->selectfg;
      isselectcolor=1;
    }
    if (index<d->itemn-1){
      //-- Not Last... Add Separator
      color sepcl = ag_calculatealpha(acfg()->textbg,acfg()->textfg_gray,80);
      ag_rect(c,0,p->y+p->h-1,d->clientWidth,1,sepcl);
    }
    
    //-- Now Draw The Checkbox
    int imgS = agdp()*24;
    if (p->img!=NULL){
      apng_stretch(c,p->img,agdp(),p->y+agdp(),imgS,imgS,0,0,p->img->w,p->img->h);
    }
    
    
    int txt_h = p->th+p->dh;
    int tit_y = (p->h / 2) - (txt_h / 2);
    int des_y = tit_y+p->th;
    int des_add = 0;
    if (d->boxtype!=0){
      des_add = (agdp()*16);
    }
    
    char permstr[64];
    snprintf(permstr,64,"%s",p->d_perm);
    //-- Now Draw The Text
    if (isselectcolor){
      ag_textf(c,d->clientTextW,d->clientTextX,p->y+tit_y,p->title,acfg()->selectbg_g,1);
      ag_textf(c,d->clientTextW+des_add,d->clientTextX,p->y+des_y,p->desc,acfg()->selectbg_g,0);
      ag_textf(c,d->clientTextW+des_add,d->clientTextX-1,p->y+des_y-1,p->desc,graycolor,0);
      
      ag_textf(c,d->clientTextW+des_add,d->clientTextX,p->y+des_y,permstr,acfg()->selectbg_g,0);
      ag_textf(c,d->clientTextW+des_add,d->clientTextX-1,p->y+des_y-1,permstr,graycolor,0);
    }
    else{
      ag_text(c,d->clientTextW+des_add,d->clientTextX-1,p->y+des_y-1,p->desc,graycolor,0);
      ag_text(c,d->clientTextW+des_add,d->clientTextX-1,p->y+des_y-1,permstr,graycolor,0);
    }
    ag_textf(c,d->clientTextW,d->clientTextX-1,p->y+tit_y-1,p->title,txtcolor,1);
    
    
    
    // img
    
    //-- Now Draw The Checkbox
    int halfdp   = ceil(((float) agdp())/2);
    int halfdp2  = halfdp*2;
    int chkbox_s = (agdp()*10);
    int chkbox_x = (d->clientTextX+d->clientTextW+(agdp()*9)) - ((chkbox_s+2)/2);
    int chkbox_y = p->y + round((p->h/2) - (chkbox_s/2));
    
    byte drawed = 0;
    int minpad = 3*agdp();
    int addpad = 6*agdp();
    
    if (d->boxtype==0){
      if (p->checked){
        if (index==d->touchedItem)
          drawed=atheme_draw("img.checkbox.on.push", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
        else if ((index==d->focusedItem)&&(d->focused))
          drawed=atheme_draw("img.checkbox.on.focus", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
        else
          drawed=atheme_draw("img.checkbox.on", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
      }
      else{
        if (index==d->touchedItem)
          drawed=atheme_draw("img.checkbox.push", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
        else if ((index==d->focusedItem)&&(d->focused))
          drawed=atheme_draw("img.checkbox.focus", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
        else
          drawed=atheme_draw("img.checkbox", c,chkbox_x-minpad,chkbox_y-minpad,chkbox_s+addpad,chkbox_s+addpad);
      }
      if (!drawed){
        ag_roundgrad(c,
          chkbox_x,
          chkbox_y,
          chkbox_s,
          chkbox_s,
          acfg()->controlbg_g,
          acfg()->controlbg,
          0);
        ag_roundgrad(c,
          chkbox_x+halfdp,
          chkbox_y+halfdp,
          chkbox_s-halfdp2,
          chkbox_s-halfdp2,
          acfg()->textbg,
          acfg()->textbg,
          0);
        if (p->checked){
          ag_roundgrad(c,
            chkbox_x+halfdp2,
            chkbox_y+halfdp2,
            chkbox_s-(halfdp2*2),
            chkbox_s-(halfdp2*2),
            acfg()->selectbg,
            acfg()->selectbg_g,
            0);
        }
      }
    }
  }
}