void acopt_redraw(ACONTROLP ctl) {
  ACOPTDP d = (ACOPTDP) ctl->d;
  
  if (d->acheck_signature != 136) {
    return;  //-- Not Valid Signature
  }
  
  if ((d->itemn > 0) && (d->draweditemn < d->itemn)) {
    ag_ccanvas(&d->client);
    ag_canvas(&d->client, d->clientWidth, d->nextY);
    ag_rect(&d->client, 0, 0, d->clientWidth, agdp()*max(acfg()->roundsz, 4), acfg()->textbg);
    //-- Set Values
    d->scrollY     = 0;
    d->maxScrollY  = d->nextY - (ctl->h - (agdp() * max(acfg()->roundsz, 4)));
    
    if (d->maxScrollY < 0) {
      d->maxScrollY = 0;
    }
    
    //-- Draw Items
    int i;
    
    for (i = 0; i < d->itemn; i++) {
      acopt_redrawitem(ctl, i);
    }
    
    d->draweditemn = d->itemn;
  }
}
void acopt_ondraw(void * x){
  ACONTROLP   ctl= (ACONTROLP) x;
  ACOPTDP   d  = (ACOPTDP) ctl->d;
  CANVAS *    pc = &ctl->win->c;
  acopt_redraw(ctl);
  if (d->invalidDrawItem!=-1){
    d->touchedItem = d->invalidDrawItem;
    acopt_redrawitem(ctl,d->invalidDrawItem);
    d->invalidDrawItem=-1;
  }
  
  //-- Init Device Pixel Size
  int minpadding = 2;
  int agdp3 = (agdp()*minpadding);
  int agdp6 = (agdp()*(minpadding*2));
  int agdpX = agdp6;
  
  ag_draw(pc,&d->control,ctl->x,ctl->y);
  // ag_draw_ex(pc,&d->client,ctl->x+agdp3,ctl->y+1,0,d->scrollY+1,ctl->w-agdp6,ctl->h-2);
  ag_draw_ex(pc,&d->client,ctl->x+agdp(),ctl->y+1,0,d->scrollY+1,ctl->w-(agdp()*2),ctl->h-2);
  
  if (d->maxScrollY>0){
    //-- Glow
    int i;
    byte isST=(d->scrollY>0)?1:0;
    byte isSB=(d->scrollY<d->maxScrollY)?1:0;
    int add_t_y = 1;
    
    for (i=0;i<agdpX;i++){
      byte alph = 255-round((((float) (i+1))/ ((float) agdpX))*230);
      if (isST)
        ag_rectopa(pc,ctl->x,ctl->y+i+add_t_y,ctl->w,1,acfg()->textbg,alph);
      if (isSB)
        ag_rectopa(pc,ctl->x,((ctl->y+ctl->h)-(add_t_y))-(i+1),ctl->w,1,acfg()->textbg,alph);
    }
    
    //-- Scrollbar
    int newh = ctl->h - agdp6;
    float scrdif    = ((float) newh) / ((float) d->client.h);
    int  scrollbarH = round(scrdif * newh);
    int  scrollbarY = round(scrdif * d->scrollY) + agdp3;
    if (d->scrollY<0){
      scrollbarY = agdp3;
      int alp = (1.0 - (((float) abs(d->scrollY)) / (((float) ctl->h)/4))) * 255;
      if (alp<0) alp = 0;
      ag_rectopa(pc,(ctl->w-agdp()-2)+ctl->x,scrollbarY+ctl->y,agdp(),scrollbarH,acfg()->scrollbar, alp);
    }
    else if (d->scrollY>d->maxScrollY){
      scrollbarY = round(scrdif * d->maxScrollY) + agdp3;
      int alp = (1.0 - (((float) abs(d->scrollY-d->maxScrollY)) / (((float) ctl->h)/4))) * 255;
      if (alp<0) alp = 0;
      ag_rectopa(pc,(ctl->w-agdp()-2)+ctl->x,scrollbarY+ctl->y,agdp(),scrollbarH,acfg()->scrollbar, alp);
    }
    else{
      ag_rect(pc,(ctl->w-agdp()-2)+ctl->x,scrollbarY+ctl->y,agdp(),scrollbarH,acfg()->scrollbar);
    }
  }
}
//-- Add Item Into Control
byte afbox_add(ACONTROLP ctl,char * title, char * desc, byte checked, PNGCANVAS * img,
  byte d_type, char * d_perm, dword d_data, byte selDef){
  
  AFBOXDP d = (AFBOXDP) ctl->d;
  if (d->acheck_signature != 177) return 0; //-- Not Valid Signature
  
  //-- Allocating Memory For Item Data
  AFBOXIP newip = (AFBOXIP) malloc(sizeof(AFBOXI));
  
  newip->d_type   = d_type;
  newip->d_data   = d_data;
  
  snprintf(newip->d_perm,10,"%s",d_perm);
  snprintf(newip->title,256,"%s",title);
  snprintf(newip->desc,256,"%s",desc);
  newip->img      = img;
  
  int imgS        = agdp()*24;
  newip->drawed   = 0;
  newip->th       = ag_txtheight(d->clientTextW,newip->title,1);
  newip->dh       = ag_fontheight(0); // ag_txtheight(d->clientTextW,newip->desc,0);
  newip->ty       = agdp()*4;
  newip->dy       = newip->ty+newip->th;
  newip->h        = (agdp()*8) + newip->dh + newip->th;
  if (newip->h<(agdp()*26)) newip->h = (agdp()*26);
  newip->checked  = checked;
  newip->id       = d->itemn;
  newip->group    = d->groupCounts;
  newip->groupid  = ++d->groupCurrId;
  newip->isTitle  = 0;
  newip->y        = d->nextY;
  d->nextY       += newip->h;
  
  if (selDef){
    d->focusedItem = d->itemn;
    d->selectedId  = d->itemn;
  }
  
  if (checked) d->check_n++;
  
  if (d->itemn>0){
    int i;
    AFBOXIP * tmpitms   = d->items;
    d->items              = malloc( sizeof(AFBOXIP)*(d->itemn+1) );
    for (i=0;i<d->itemn;i++)
      d->items[i]=tmpitms[i];
    d->items[d->itemn] = newip;
    free(tmpitms);
  }
  else{
    d->items    = malloc(sizeof(AFBOXIP));
    d->items[0] = newip;
  }
  d->itemn++;
  return 1;
}
//-- Add Item Into Control
byte acopt_add(ACONTROLP ctl,char * title, char * desc, byte selected){
  ACOPTDP d = (ACOPTDP) ctl->d;
  if (d->acheck_signature != 136) return 0; //-- Not Valid Signature
  
  //-- Allocating Memory For Item Data
  ACOPTIP newip = (ACOPTIP) malloc(sizeof(ACOPTI));
  snprintf(newip->title,64,"%s",title);
  snprintf(newip->desc,128,"%s",desc);
  newip->th       = ag_txtheight(d->clientTextW,newip->title,1);
  if (strlen(newip->desc)==0)
    newip->dh       = 0;
  else
    newip->dh       = ag_txtheight(d->clientTextW,newip->desc,0);
  
  newip->h        = (agdp()*10) + newip->dh + newip->th;
  
  //newip->ty       = agdp()*5;
  //newip->dy       = (agdp()*5)+newip->th;
  
  if (newip->h<(agdp()*22)) newip->h = (agdp()*22);
    
  int hp2   = newip->h/2;
  int tth   = (newip->dh + newip->th) / 2;
  newip->ty = hp2-tth;
  newip->dy = newip->ty+newip->th;
    
  newip->id       = d->itemn;
  newip->group    = d->groupCounts;
  newip->groupid  = ++d->groupCurrId;
  newip->isTitle  = 0;
  newip->y        = d->nextY;
  d->nextY       += newip->h;
  if (selected){
    d->selectedIndexs[newip->group] = newip->id;
  }
  
  if (d->itemn>0){
    int i;
    ACOPTIP * tmpitms   = d->items;
    d->items              = malloc( sizeof(ACOPTIP)*(d->itemn+1) );
    for (i=0;i<d->itemn;i++)
      d->items[i]=tmpitms[i];
    d->items[d->itemn] = newip;
    free(tmpitms);
  }
  else{
    d->items    = malloc(sizeof(ACOPTIP));
    d->items[0] = newip;
  }
  d->itemn++;
  return 1;
}
ACONTROLP accb(
  AWINDOWP win,
  int x,
  int y,
  int w,
  int h,
  char * textv,
  byte checked
){
  //-- Validate Minimum Size
  if (h<agdp()*16) h=agdp()*16;
  if (w<agdp()*16) w=agdp()*16;
  
  //-- Limit Title Length  
  char title[128];
  snprintf(title,128,"%s",textv);
  
  //-- Initializing Button Data
  ACCBDP d = (ACCBDP) malloc(sizeof(ACCBD));
  memset(d,0,sizeof(ACCBD));
  
  //-- Save Touch Message & Set Stats
  d->checked   = checked;
  d->focused   = 0;
  d->pushed    = 0;
  
  //-- Initializing Canvas
  ag_canvas(&d->control,w,h);
  
  //-- Draw Control Background
  ag_draw_ex(&d->control,&win->c,0,0,x,y,w,h);
  
  //-- Calculate Position & Size
  int minpad    = 5*agdp();
  d->chkS       = (agdp()*10);
  int txtW      = w - ((d->chkS+6)+(agdp()*4));
  int txtX      = (d->chkS+(agdp()*4));
  int txtH      = ag_txtheight(txtW,title,0);
  int txtY      = ((h-txtH) / 2);
  if (txtY<1) txtY = 1;
  ag_textf(&d->control,txtW,minpad+txtX,txtY,title,acfg()->textbg,0);
  ag_text(&d->control,txtW,minpad+txtX-1,txtY-1,title,acfg()->textfg,0);
  
  //-- Initializing Control
  ACONTROLP ctl  = malloc(sizeof(ACONTROL));
  ctl->ondestroy= &accb_ondestroy;
  ctl->oninput  = &accb_oninput;
  ctl->ondraw   = &accb_ondraw;
  ctl->onblur   = &accb_onblur;
  ctl->onfocus  = &accb_onfocus;
  ctl->win      = win;
  ctl->x        = x;
  ctl->y        = y;
  ctl->w        = w;
  ctl->h        = h;
  ctl->forceNS  = 0;
  ctl->d        = (void *) d;
  aw_add(win,ctl);
  return ctl;
}
//-- Add Item Into Control
byte acopt_addgroup(ACONTROLP ctl, char * title, char * desc) {
  ACOPTDP d = (ACOPTDP) ctl->d;
  
  if (d->acheck_signature != 136) {
    return 0;  //-- Not Valid Signature
  }
  
  if (d->groupCounts + 1 >= ACOPT_MAX_GROUP) {
    return 0;
  }
  
  //-- Allocating Memory For Item Data
  ACOPTIP newip = (ACOPTIP) malloc(sizeof(ACOPTI));
  snprintf(newip->title, 64, "%s", title);
  snprintf(newip->desc, 128, "%s", desc);
  newip->th       = ag_txtheight(d->clientTextW + (agdp() * 14), newip->title, 0);
  newip->dh       = 0;// ag_txtheight(d->clientTextW+(agdp()*14),newip->desc,0);
  newip->ty       = agdp() * 4;
  newip->dy       = (agdp() * 4) + newip->th;
  newip->h        = (agdp() * 8) + newip->th;
  newip->id       = d->itemn;
  newip->group    = ++d->groupCounts;
  d->groupCurrId  = -1;
  newip->groupid  = -1;
  newip->isTitle  = 1;
  newip->y        = d->nextY;
  d->nextY       += newip->h;
  
  if (d->itemn > 0) {
    int i;
    ACOPTIP * tmpitms   = d->items;
    d->items              = malloc( sizeof(ACOPTIP) * (d->itemn + 1) );
    
    for (i = 0; i < d->itemn; i++) {
      d->items[i] = tmpitms[i];
    }
    
    d->items[d->itemn] = newip;
    free(tmpitms);
  }
  else {
    d->items    = malloc(sizeof(ACOPTIP));
    d->items[0] = newip;
  }
  
  d->itemn++;
  return 1;
}
ACONTROLP aclabel(
  AWINDOWP win,
  int x,
  int y,
  int w,
  int h,
  char * text,
  byte isbig,
  byte vpos,
  byte sigleAligment,
  color cl
){
  //-- Validate Minimum Size
  if (h<agdp()*2) h=agdp()*2;
  if (w<agdp()*10) w=agdp()*10;
  
  //-- Initializing Button Data
  ACLABELDP d = (ACLABELDP) malloc(sizeof(ACLABELD));
  memset(d,0,sizeof(ACLABELD));
  
  //-- Save Touch Message & Set Stats
  d->text      = strdup(text);
  d->isbig     = isbig;
  d->vpos      = vpos;
  d->drawed    = 0;
  d->cl        = cl;
  d->sigleAligment = sigleAligment;
  
  //-- Initializing Canvas
  ag_canvas(&d->control,w,h);
  
  //-- Initializing Control
  ACONTROLP ctl  = malloc(sizeof(ACONTROL));
  ctl->ondestroy= &aclabel_ondestroy;
  ctl->oninput  = &aclabel_oninput;
  ctl->ondraw   = &aclabel_ondraw;
  ctl->onblur   = &aclabel_onblur;
  ctl->onfocus  = NULL;
  ctl->win      = win;
  ctl->x        = x;
  ctl->y        = y;
  ctl->w        = w;
  ctl->h        = h;
  ctl->forceNS  = 0;
  ctl->d        = (void *) d;
  aw_add(win,ctl);
  return ctl;
}
byte auifav_fetch(ACONTROLP FB)
{
	char *o = aarray_get(aui_cfg_array, "favorites");
	if (o == NULL)
		return 0;
	int n = 0;
	char *buf = strdup(o);
	char *tok = strtok(buf, ";");
	while (tok) {
		char *dname = NULL;
		char *desc = NULL;
		if (strcmp(tok, "/") == 0) {
			dname = strdup(alang_get("dir.root"));
			desc = strdup("/");
		} else {
			dname = basename(tok);
			desc = aui_strip(tok, agw() - (agdp() * 46), 0);
		}
		afbox_add(FB, dname, desc, 0, &UI_ICONS[36], 0, "", n++, 0);
		free(desc);
		tok = strtok(NULL, ";");
	}
	free(buf);
	return 1;
}
void accb_ondraw(void * x){
  ACONTROLP   ctl= (ACONTROLP) x;
  ACCBDP      d  = (ACCBDP) ctl->d;
  CANVAS *    pc = &ctl->win->c;
  
  ag_draw(pc,&d->control,ctl->x,ctl->y);
  
  int halfdp   = ceil(((float) agdp())/2);
  int halfdp2  = halfdp*2;
  int chkY = ((ctl->h-d->chkS) / 2);
  
  byte drawed = 0;
  
  //-- Draw Check UI
  int minpad = 3*agdp();
  int addpad = 6*agdp();
  if (!d->checked){
    if (d->pushed)
      drawed=atheme_draw("img.checkbox.push", pc,ctl->x+halfdp,ctl->y+chkY-minpad,d->chkS+addpad,d->chkS+addpad);
    else if (d->focused)
      drawed=atheme_draw("img.checkbox.focus", pc,ctl->x+halfdp,ctl->y+chkY-minpad,d->chkS+addpad,d->chkS+addpad);
    else
      drawed=atheme_draw("img.checkbox", pc,ctl->x+halfdp,ctl->y+chkY-minpad,d->chkS+addpad,d->chkS+addpad);
  }
  else{
    if (d->pushed)
      drawed=atheme_draw("img.checkbox.on.push", pc,ctl->x+halfdp,ctl->y+chkY-minpad,d->chkS+addpad,d->chkS+addpad);
    else if (d->focused)
      drawed=atheme_draw("img.checkbox.on.focus", pc,ctl->x+halfdp,ctl->y+chkY-minpad,d->chkS+addpad,d->chkS+addpad);
    else
      drawed=atheme_draw("img.checkbox.on", pc,ctl->x+halfdp,ctl->y+chkY-minpad,d->chkS+addpad,d->chkS+addpad);
  }
  
  //-- Generic Draw
  if (!drawed){
    if (d->pushed)
      ag_roundgrad(pc, minpad+ctl->x+halfdp,  ctl->y+chkY,         d->chkS,          d->chkS,          acfg()->selectbg_g,  acfg()->selectbg, 0);
    else if(d->focused)
      ag_roundgrad(pc, minpad+ctl->x+halfdp,  ctl->y+chkY,         d->chkS,          d->chkS,          acfg()->selectbg,  acfg()->selectbg_g, 0);
    else
      ag_roundgrad(pc, minpad+ctl->x+halfdp,  ctl->y+chkY,         d->chkS,          d->chkS,          acfg()->controlbg_g,  acfg()->controlbg, 0);
    ag_roundgrad(pc, minpad+ctl->x+halfdp2, ctl->y+chkY+halfdp,  d->chkS-halfdp2,  d->chkS-halfdp2,  acfg()->textbg,       acfg()->textbg,    0);
    if (d->checked){
      ag_roundgrad(pc, minpad+ctl->x+halfdp+halfdp2, ctl->y+chkY+halfdp2,  d->chkS-(halfdp2*2),  d->chkS-(halfdp2*2),  acfg()->selectbg,   acfg()->selectbg_g,0);
    }
  }
}
void aw_textdialog(AWINDOWP parent,char * title,char * text,char * ok_text){
  CANVAS * tmpc = aw_muteparent(parent);
  on_dialog_window = 1;
  ag_rectopa(agc(),0,0,agw(),agh(),0x0000,180);
  ag_sync();
  int elmP  = agdp()*4;
  int winP  = agdp()*4;
  int winW  = agw() - (winP*2);
  int winH  = (agh() / 2) + (winP*4);
  int winX  = winP;
  int winY  = (agh() / 2) - (winH/2);
  int titW  = ag_txtwidth(title,1);
  int capH  = ag_fontheight(1) + (elmP*2);
  int btnH  = agdp()*20;
  int txtH  = winH - (btnH + capH + (elmP*3));
  int txtY  = winY + capH + elmP;
  int btnY  = txtY + txtH + elmP;
  int btnW  = (winW/2) - elmP;
  int btnX  = winX + ((winW/2) - (btnW/2));
  int txtX  = winX + elmP;
  int txtW  = winW - (elmP*2);
  CANVAS alertbg;
  ag_canvas(&alertbg,agw(),agh());
  ag_draw(&alertbg,agc(),0,0);
  ag_roundgrad(&alertbg,winX,winY,winW,winH,acfg_var.border,acfg_var.border_g,acfg_var.roundsz*agdp());
  ag_roundgrad(&alertbg,winX+1,winY+1,winW-2,winH-2,acfg_var.winbg,acfg_var.winbg_g,(acfg_var.roundsz*agdp())-1);
  ag_roundgrad_ex(&alertbg,winX+1,winY+1,winW-2,capH-1,acfg_var.titlebg,acfg_var.titlebg_g,(acfg_var.roundsz*agdp())-1,1,1,0,0);
  ag_textf(&alertbg,titW,((agw()/2)-(titW/2))+1,winY+elmP+1,title,acfg_var.titlebg_g,1);
  ag_text(&alertbg,titW,(agw()/2)-(titW/2),winY+elmP,title,acfg_var.titlefg,1);
  AWINDOWP hWin   = aw(&alertbg);
  actext(hWin,txtX,txtY,txtW,txtH,text,0);
  acbutton(hWin,btnX,btnY,btnW,btnH,(ok_text==NULL?acfg_var.text_ok:ok_text),0,5);
  aw_show(hWin);
  byte ondispatch = 1;
  while(ondispatch){
    dword msg=aw_dispatch(hWin);
    switch (aw_gm(msg)){
      case 5: ondispatch = 0; break;
    }
  }
  aw_destroy(hWin);
  ag_ccanvas(&alertbg);
  on_dialog_window = 0;
  aw_unmuteparent(parent,tmpc);
}
void afbox_redraw(ACONTROLP ctl){
  AFBOXDP d = (AFBOXDP) ctl->d;
  if (d->acheck_signature != 177) return; //-- Not Valid Signature
  if ((d->itemn>0)&&(d->draweditemn<d->itemn)) {
    ag_ccanvas(&d->client);
    ag_canvas(&d->client,d->clientWidth,d->nextY);
    ag_rect(&d->client,0,0,d->clientWidth,agdp()*2,acfg()->textbg);
    
    //-- Set Values
    d->scrollY     = 0;
    d->maxScrollY  = d->nextY-(ctl->h-(agdp()*2));
    if (d->maxScrollY<0) d->maxScrollY=0;
    
    //-- Draw Items
    int i;
    for (i=0;i<d->itemn;i++){
      ag_rect(&d->client,0,d->items[i]->y,d->clientWidth,d->items[i]->h,acfg()->textbg);
      afbox_redrawitem(ctl,i);
    }
    d->draweditemn=d->itemn;
  }
}
//-- Add Item Into Control
byte accheck_add(ACONTROLP ctl,char * title, char * desc, byte checked){
  ACCHECKDP d = (ACCHECKDP) ctl->d;
  if (d->acheck_signature != 133) return 0; //-- Not Valid Signature
  
  //-- Allocating Memory For Item Data
  ACCHECKIP newip = (ACCHECKIP) malloc(sizeof(ACCHECKI));
  snprintf(newip->title,31,"%s",title);
  snprintf(newip->desc,127,"%s",desc);
  newip->th       = ag_txtheight(d->clientTextW,newip->title,0);
  newip->dh       = ag_txtheight(d->clientTextW,newip->desc,0);
  newip->ty       = agdp()*5;
  newip->dy       = (agdp()*5)+newip->th;
  newip->h        = (agdp()*10) + newip->dh + newip->th;
  if (newip->h<(agdp()*22)) newip->h = (agdp()*22);
  newip->checked  = checked;
  newip->id       = d->itemn;
  newip->group    = d->groupCounts;
  newip->groupid  = ++d->groupCurrId;
  newip->isTitle  = 0;
  newip->y        = d->nextY;
  d->nextY       += newip->h;
  
  if (d->itemn>0){
    int i;
    ACCHECKIP * tmpitms   = d->items;
    d->items              = malloc( sizeof(ACCHECKIP)*(d->itemn+1) );
    for (i=0;i<d->itemn;i++)
      d->items[i]=tmpitms[i];
    d->items[d->itemn] = newip;
    free(tmpitms);
  }
  else{
    d->items    = malloc(sizeof(ACCHECKIP));
    d->items[0] = newip;
  }
  d->itemn++;
  return 1;
}
char *auifav(AWINDOWP parent, char *path)
{
	//-- Mute Parent
	CANVAS *tmpc = aw_muteparent(parent);
	aw_set_on_dialog(2);
	ag_rectopa(agc(), 0, 0, agw(), agh(), 0x0000, 180);
	ag_sync();

	//-- Initializing Canvas
	CANVAS favbg;
	ag_canvas(&favbg, agw(), agh());
	ag_draw(&favbg, agc(), 0, 0);

	//-- Init Sizes
	int winY = agh() - round(agh() / 1.618);
	int winH = agh() - winY;
	int titH = agdp() * 24;	// (agdp()*6) + ag_fontheight(1);
	int boxY = winY + titH;
	int boxH = winH - titH;

	//-- Draw Title
	ag_roundgrad_ex(&favbg, 0, winY, agw(), titH, acfg()->navbg,
			acfg()->navbg_g, 0, 0, 0, 0, 0);

	//-- Draw Main Window
	ag_roundgrad_ex(&favbg, 0, boxY, agw(), boxH, acfg()->navbg,
			acfg()->navbg_g, 0, 0, 0, 0, 0);

	byte first = 1;
	char *out_char = NULL;
	while (auifav_win
	       (&favbg, path, &out_char, winY, titH, boxY, boxH, first)) {
		first = 0;
	}

	//-- Cleanup Canvas
	ag_ccanvas(&favbg);

	//-- Unmute Parent
	aw_set_on_dialog(0);
	aw_unmuteparent(parent, tmpc);
	return out_char;
}
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);
      }
    }
  }
}
Example #15
0
void aw_calibtools(AWINDOWP parent){
  int USE_HACK = aw_confirm(
      parent,
      "Use alternative touch",
      "Do you want to use alternative touch?\n  Only use if the default method does not work.\n\nPress the volume keys to select Yes or No.",
      "@alert",
      acfg_var.text_no,
      acfg_var.text_yes
    );
  byte current_hack = atouch_gethack();
  if (!USE_HACK){
    atouch_sethack(1);
  }
  else{
    atouch_sethack(0);
  }
  
  //-- Set Mask
  CANVAS * tmpc = aw_muteparent(parent);
  on_dialog_window = 1;
  ag_rectopa(agc(),0,0,agw(),agh(),0x0000,220);
  ag_sync();
  byte isvalid = 0;
  
  //-- Initializing Canvas
  CANVAS ccv;
  ag_canvas(&ccv,agw(),agh());
  ag_blur(&ccv,agc(),agdp()*2);
  
  int xpos[5] = { agdp()*10, agw()-(agdp()*10), agdp()*10, agw()-(agdp()*10), agw()/2 };
  int ypos[5] = { agdp()*10, agdp()*10, agh() - (agdp()*10), agh()-(agdp()*10), agh()/2 };
  int xtch[5] = { 0,0,0,0,0 };
  int ytch[5] = { 0,0,0,0,0 };
  
  atouch_plaincalibrate();
  char datx[256];
  
  if (!aw_calibdraw(&ccv,0,xpos,ypos,xtch,ytch))
    goto doneit;
  if (!aw_calibdraw(&ccv,1,xpos,ypos,xtch,ytch))
    goto doneit;
  if (!aw_calibdraw(&ccv,2,xpos,ypos,xtch,ytch))
    goto doneit;
  if (!aw_calibdraw(&ccv,3,xpos,ypos,xtch,ytch))
    goto doneit;
  if (!aw_calibdraw(&ccv,4,xpos,ypos,xtch,ytch))
    goto doneit;
  
  float padsz     = agdp()*5;
  float leftx     = ((xtch[0]+xtch[2])/2);
  float rightx    = ((xtch[1]+xtch[3])/2);
  float topy      = ((ytch[0]+ytch[1])/2);
  float bottomy   = ((ytch[2]+ytch[3])/2);
  float centerx   = xtch[4];
  float centery   = ytch[4];
  float halfx     = (agw()/2)-padsz;
  float halfy     = (agh()/2)-padsz;
  float fullx     = agw()-padsz;
  float fully     = agh()-padsz;
  
  byte data_is_valid = 0;
  float cal_x = 0;
  float cal_y = 0;
  int   add_x = 0;
  int   add_y = 0;
  if ((halfx>0)&&(fullx>0)&&(halfy>0)&&(fully>0)){
    cal_x     = ((((centerx-leftx)/halfx) + ((rightx-leftx)/fullx))/2);
    cal_y     = ((((centery-topy)/halfy) + ((bottomy-topy)/fully))/2);
    if ((cal_x>0)&&(cal_y>0)){
      add_x     = round((leftx / cal_x) - padsz);
      add_y     = round((topy / cal_y) - padsz);
      data_is_valid = 1;
    }
  }
  
  if (data_is_valid){
    atouch_set_calibrate(cal_x,add_x,cal_y,add_y);    
    if (!USE_HACK){
      snprintf(datx,255,
        "Use/Replace this command in <#009>aroma-config</#>:\n\n"
        "<#060>calibrate(\n  \"%01.4f\",\"%i\",\"%01.4f\",\"%i\",\"yes\"\n);</#>\n\n",
      cal_x,add_x,cal_y,add_y);
    }
    else{
      snprintf(datx,255,
        "Use/Replace this command in <#009>aroma-config</#>:\n\n"
        "<#060>calibrate(\n  \"%01.4f\",\"%i\",\"%01.4f\",\"%i\"\n);</#>\n\n",
      cal_x,add_x,cal_y,add_y);
    }
    
    aw_calibdraw(&ccv,-1,xpos,ypos,xtch,ytch);
    isvalid       = 1;
  }
  else{
    aw_alert(parent,
      "Calibrated Data",
      "Calibrated data not valid, please try again...",
      "@info",
      NULL);
  }
doneit:
  
  ag_ccanvas(&ccv);
  on_dialog_window = 0;
  aw_unmuteparent(parent,tmpc);
  byte dont_restore_caldata = 0;
  if (isvalid){
    aw_alert(parent,
      "Calibrated Data",
      datx,
      "@info",
      NULL);
    dont_restore_caldata = aw_confirm(
      parent,
      "Set Calibrated Data",
      "Do you want to use the current calibrated data in the current process?\n\n<#080>NOTE:</#> It will revert back when you restart the AROMA Installer...",
      "@alert",
      NULL,
      NULL
    );    
  }
  if (!dont_restore_caldata){
    atouch_sethack(current_hack);
    atouch_restorecalibrate();
  }
}
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 acime2_drawbtn(ACONTROLP ctl, int keyID, int y) {
  ACIMEDP  d      = (ACIMEDP) ctl->d;
  
  if (((keyID < 27) && (keyID != 19)) || (keyID == 30) || (keyID == 31) || (keyID == 29) || (keyID == 34)) {
    char c[8];
    char c2 = 0;
    c[1] = 0;
    
    if (keyID == 30) {
      c[0] = ' ';
    }
    else if (keyID == 34) {
      snprintf(c, 8, "ctrl");
      
      if (d->onCTRL) {
        c2 = '*';
      }
    }
    else if (keyID == 29) {
      c[0] = ',';
    }
    else if (keyID == 31) {
      c[0] = '.';
    }
    else {
      int n = keyID;
      
      if (n > 19) {
        n--;
      }
      
      int np = 3;
      
      if (d->on123) {
        np = (d->onShift) ? 0 : 1;
      }
      else {
        if (d->onShift) {
          np = 2;
        }
        
        int np2 = (d->onShift) ? 0 : 1;
        c2 = acime2_charlist[np2][n];
      }
      
      c[0] = acime2_charlist[np][n];
    }
    
    color cl = (d->pushedId == keyID) ? acfg()->selectfg : acfg()->controlfg;
    int y1 = y;
    y     += (d->btnH / 2) - (ag_fontheight(1) / 2);
    int x  = (d->keyW[keyID] / 2) - (ag_txtwidth(c, 1) / 2);
    ag_textf(
      &d->control,
      d->keyW[keyID],
      d->keyX[keyID] + x,
      y,
      c,
      cl,
      1
    );
    
    if (c2) {
      cl = (d->pushedId == keyID) ? acfg()->selectfg : acfg()->textfg_gray;
      char c2s[2];
      c2s[0] = c2;
      c2s[1] = 0;
      ag_textf(
        &d->control,
        d->keyW[keyID],
        d->keyX[keyID] + d->keyW[keyID] - ag_txtwidth(c2s, 0) - agdp(),
        y1 + agdp(),
        c2s,
        cl,
        0
      );
    }
  }
  else {
    int icoid = 0;
    
    if (keyID == 19) {
      icoid = (!d->onShift ? 27 : (d->onShift == 2 ? 29 : 28));
    }
    else if (keyID == 28) {
      icoid = d->on123 ? 31 : 30;
    }
    else if (keyID == 27) {
      icoid = 32;  // bkspace;
    }
    else if (keyID == 33) {
      icoid = 42;  // tab;
    }
    else if (keyID == 35) {
      icoid = 34;  // left;
    }
    else if (keyID == 36) {
      icoid = 43;  // up;
    }
    else if (keyID == 37) {
      icoid = 44;  // down;
    }
    else if (keyID == 38) {
      icoid = 35;  // right;
    }
    else if (keyID == 32) {
      icoid = 41;  // enter;
    }
    
    PNGCANVAS * ap = aui_icons(icoid);
    
    if (ap != NULL) {
      int isz = agdp() * 16;
      y     += (d->btnH / 2) - (isz / 2);
      int x  = (d->keyW[keyID] / 2) - (isz / 2);
      apng_stretch(
        &d->control, ap, d->keyX[keyID] + x, y, isz, isz, 0, 0, ap->w, ap->h);
    }
  }
}
Example #18
0
byte aw_showmenu(AWINDOWP parent){
  CANVAS * tmpc = aw_muteparent(parent);
  //-- Set Mask
  on_dialog_window = 2;
  ag_rectopa(agc(),0,0,agw(),agh(),0x0000,180);
  ag_sync();
  
  int btnH  = agdp()*20;
  int pad   = agdp()*4;
  int vpad  = agdp()*2;
  int winH  = ((btnH+vpad) * 3) + pad;
  int winW  = agw()-(pad*2);
  int winX  = pad;
  int winY  = agh()-winH;
  int btnY  = winY + pad;
  int btnX  = winX + pad;
  int btnW  = winW - (pad*2);
  
  //-- Initializing Canvas
  CANVAS alertbg;
  ag_canvas(&alertbg,agw(),agh());
  ag_draw(&alertbg,agc(),0,0);
  
  //-- Draw Window Background
  ag_roundgrad_ex(&alertbg,winX-1,winY-1,winW+2,winH+2,acfg_var.border,acfg_var.border_g,(acfg_var.roundsz*agdp())+1,1,1,0,0);
  ag_roundgrad_ex(&alertbg,winX,winY,winW,winH,acfg_var.navbg,acfg_var.navbg_g,acfg_var.roundsz*agdp(),1,1,0,0);
  
  //-- Create Window
  AWINDOWP hWin   = aw(&alertbg);
  acbutton(hWin,btnX,btnY,btnW,btnH,acfg_var.text_about,0,11);
  //acbutton(hWin,btnX,btnY+((btnH+vpad)*1),btnW,btnH,"Help",0,12);
  acbutton(hWin,btnX,btnY+((btnH+vpad)*1),btnW,btnH,acfg_var.text_calibrating,0,13);
  acbutton(hWin,btnX,btnY+((btnH+vpad)*2),btnW,btnH,acfg_var.text_quit,0,14);
  
  aw_show(hWin);
  byte ondispatch = 1;
  byte res        = 0;
  while(ondispatch){
    dword msg=aw_dispatch(hWin);
    switch (aw_gm(msg)){
      case 5: ondispatch = 0; break;
      case 11: res=1; ondispatch = 0; break;
      case 12: res=2; ondispatch = 0; break;
      case 13: res=3; ondispatch = 0; break;
      case 14: res=4; ondispatch = 0; break;
    }
  }
  aw_destroy(hWin);
  ag_ccanvas(&alertbg);
  on_dialog_window = 0;
  aw_unmuteparent(parent,tmpc);
  
  if (res==1){
    aw_about_dialog(parent);
  }
  else if (res==2){
    aw_help_dialog(parent);
  }
  else if (res==3){
    aw_calibtools(parent);
  }
  else if (res==4){
    byte res = aw_confirm(parent, AROMA_NAME " " AROMA_VERSION, acfg_var.text_quit_msg,"@alert",NULL,NULL);
    if (res) return 2;
  }
  return 0;
}
ACONTROLP acopt(
  AWINDOWP win,
  int x,
  int y,
  int w,
  int h
) {
  //-- Validate Minimum Size
  if (h < agdp() * 16) {
    h = agdp() * 16;
  }
  
  if (w < agdp() * 20) {
    w = agdp() * 20;
  }
  
  //-- Initializing Text Data
  ACOPTDP d        = (ACOPTDP) malloc(sizeof(ACOPTD));
  memset(d, 0, sizeof(ACOPTD));
  //-- Set Signature
  d->acheck_signature = 136;
  //-- Initializing Canvas
  ag_canvas(&d->control, w, h);
  int minpadding = 2;
  //-- Initializing Client Size
  d->clientWidth  = w - (agdp() * minpadding);
  d->clientTextW  = d->clientWidth - (agdp() * 18); // d->clientWidth - (agdp()*18) - (agdp()*acfg()->btnroundsz*2);
  d->clientTextX  = (agdp() * 18); // + (agdp()*acfg()->btnroundsz*2);
  d->client.data = NULL;
  //-- Draw Control
  ag_draw_ex(&d->control, &win->c, 0, 0, x, y, w, h);
  ag_rect(&d->control, 0, 0, w, h, acfg()->textbg);
  //-- Set Scroll Value
  d->scrollY     = 0;
  d->maxScrollY  = 0;
  d->prevTouchY  = -50;
  d->invalidDrawItem = -1;
  //-- Set Data Values
  d->items       = NULL;
  d->itemn       = 0;
  d->touchedItem = -1;
  d->focusedItem = -1;
  d->nextY       = agdp() * minpadding;
  d->draweditemn = 0;
  int i;
  
  for (i = 0; i < ACOPT_MAX_GROUP; i++) {
    d->selectedIndexs[i] = -1;
  }
  
  d->groupCounts   = 0;
  d->groupCurrId   = -1;
  ACONTROLP ctl  = malloc(sizeof(ACONTROL));
  ctl->ondestroy = &acopt_ondestroy;
  ctl->oninput  = &acopt_oninput;
  ctl->ondraw   = &acopt_ondraw;
  ctl->onblur   = &acopt_onblur;
  ctl->onfocus  = &acopt_onfocus;
  ctl->win      = win;
  ctl->x        = x;
  ctl->y        = y;
  ctl->w        = w;
  ctl->h        = h;
  ctl->forceNS  = 0;
  ctl->d        = (void *) d;
  aw_add(win, ctl);
  return ctl;
}
Example #20
0
byte aw_confirm(AWINDOWP parent, char * titlev,char * textv,char * img,char * yes_text,char * no_text){
  CANVAS * tmpc = aw_muteparent(parent);
  //-- Set Mask
  on_dialog_window = 1;
  ag_rectopa(agc(),0,0,agw(),agh(),0x0000,180);
  ag_sync();
  
  char title[64];
  char text[512];
  snprintf(title,64,"%s",titlev);
  snprintf(text,512,"%s",textv);
  
  int pad   = agdp()*4;
  int winW  = agw()-(pad*2);
  int txtW  = winW-(pad*2);
  int txtX  = pad*2;
  int btnH  = agdp()*20;
  int titW  = ag_txtwidth(title,1);
  int titH  = ag_fontheight(1) + (pad*2);
  
  PNGCANVASP winp = atheme("img.dialog");
  PNGCANVASP titp = atheme("img.dialog.titlebar");
  APNG9      winv;
  APNG9      titv;
  int vtitY = -1;
  int vpadB = -1;
  int vimgX = pad*2;
  if (titp!=NULL){
    if (apng9_calc(titp,&titv,1)){
      int tmptitH = titH - (pad*2);
      titH        = tmptitH + (titv.t+titv.b);
      vtitY       = titv.t;
    }
  }
  if (winp!=NULL){
    if (apng9_calc(winp,&winv,1)){
      txtW = winW - (winv.l+winv.r);
      txtX = pad  + (winv.l);
      vimgX= pad  + (winv.l);
      vpadB= winv.b;
    }
  }
  
  //-- Load Icon
  PNGCANVAS ap;
  byte imgE = 0; int imgW = 0; int imgH = 0;
  if (apng_load(&ap,img)){
    imgE      = 1;
    imgW      = min(ap.w,agdp()*30);
    imgH      = min(ap.h,agdp()*30);
    int imgA  = pad + imgW;
    txtX     += imgA;
    txtW     -= imgA;
  }
  
  int txtH    = ag_txtheight(txtW,text,0);
  int infH    = ((imgE)&&(txtH<imgH))?imgH:txtH;
    
  //-- Calculate Window Size & Position
  int winH    = titH + infH + btnH + (pad*3);
  if (vpadB!=-1){
    winH    = titH + infH + btnH + (pad*2) + vpadB;
  }
  int winX    = pad;
  int winY    = (agh()/2) - (winH/2);
  
  //-- Calculate Title Size & Position
  int titX    = (agw()/2) - (titW/2);
  int titY    = winY + pad;
  if (vtitY!=-1) titY = winY+vtitY;

  //-- Calculate Text Size & Position
  int infY    = winY + titH + pad;
  int txtY    = infY + ((infH - txtH) / 2);
  int imgY    = infY;
  
  //-- Calculate Button Size & Position
  int btnW    = (txtW / 2) - (pad/2);
  int btnY    = infY+infH+pad;
  int btnX    = txtX;
  int btnX2   = txtX+(txtW/2)+(pad/2);
  
  //-- Initializing Canvas
  CANVAS alertbg;
  ag_canvas(&alertbg,agw(),agh());
  ag_draw(&alertbg,agc(),0,0);
  
  //-- Draw Window
  if (!atheme_draw("img.dialog", &alertbg, winX-1,winY-1,winW+2,winH+2)){
    ag_roundgrad(&alertbg,winX-1,winY-1,winW+2,winH+2,acfg_var.border,acfg_var.border_g,(acfg_var.roundsz*agdp())+1);
    ag_roundgrad(&alertbg,winX,winY,winW,winH,acfg_var.dialogbg,acfg_var.dialogbg_g,acfg_var.roundsz*agdp());
  }
  
  //-- Draw Title
  if (!atheme_draw("img.dialog.titlebar", &alertbg, winX,winY,winW,titH)){
    ag_roundgrad_ex(&alertbg,winX,winY,winW,titH,acfg_var.dlgtitlebg,acfg_var.dlgtitlebg_g,acfg_var.roundsz*agdp(),1,1,0,0);
  }
  ag_textf(&alertbg,titW,titX+1,titY+1,title,acfg_var.dlgtitlebg_g,1);
  ag_text(&alertbg,titW,titX,titY,title,acfg_var.dlgtitlefg,1);
  
  //-- Draw Image
  if (imgE){
    apng_draw_ex(&alertbg,&ap,vimgX,imgY,0,0,imgW,imgH);
    apng_close(&ap);
  }
  
  //-- Draw Text
  ag_textf(&alertbg,txtW,txtX+1,txtY+1,text,acfg_var.dialogbg,0);
  ag_text(&alertbg,txtW,txtX,txtY,text,acfg_var.dialogfg,0);
  
  AWINDOWP hWin   = aw(&alertbg);
  
  acbutton(hWin,btnX,btnY,btnW,btnH,(yes_text==NULL?acfg_var.text_yes:yes_text),0,6);
  acbutton(hWin,btnX2,btnY,btnW,btnH,(no_text==NULL?acfg_var.text_no:no_text),0,5);
      
  aw_show(hWin);
  byte ondispatch = 1;
  byte res = 0;
  while(ondispatch){
    dword msg=aw_dispatch(hWin);
    switch (aw_gm(msg)){
      case 6: res=1; ondispatch = 0; break;
      case 5: ondispatch = 0; break;
    }
  }
  aw_destroy(hWin);
  ag_ccanvas(&alertbg);
  on_dialog_window = 0;
  aw_unmuteparent(parent,tmpc);
  return res;
}
byte
auifav_win(CANVAS * bg, char *path, char **out_char, int titY, int titH,
	   int boxY, int boxH, byte first)
{
	int btnS = agdp() * 20;
	int btnP = agdp() * 2;

	AWINDOWP hWin = aw(bg);
	ACONTROLP title =
	    aclabel(hWin, btnS + btnP, titY, agw() - ((btnS + btnP) * 2), titH,
		    alang_get("tools.favorite"), 1, 1, 2, acfg()->winfg);
	ACONTROLP addthis =
	    imgbtn(hWin, btnP, titY + btnP, btnS, btnS, aui_icons(6), NULL, 1,
		   55);
	ACONTROLP cancel =
	    imgbtn(hWin, agw() - (btnS + btnP), titY + btnP, btnS, btnS,
		   aui_icons(0), NULL, 1, 5);
	ACONTROLP hFile = afbox(hWin, 0, boxY, agw(), boxH, 7, 8, 2, 6);
	auifav_fetch(hFile);

	aw_show_ex(hWin, first ? 1 : 100, titY, hFile);
	byte ondispatch = 1;
	byte reshow = 0;
	do {
		dword msg = aw_dispatch_ex(hWin, titY);
		switch (aw_gm(msg)) {
		case 5:
			{
				//-- DONE
				ondispatch = 0;
			}
			break;
		case 55:
			{
				//-- REFRESH
				ondispatch = 0;
				reshow = 1;
			}
			break;

			//-- ITEM CLICK
		case 7:
			{
				dword fl = afbox_ddata(hFile);
				char *fpath = auifav_getpath(fl);
				if (fpath != NULL) {
					aui_setpath(out_char, fpath, "", 0);
					free(fpath);
					ondispatch = 0;
				}
			}
			break;

			//-- ITEM TAP & HOLD
		case 8:
			{
				dword fl = afbox_ddata(hFile);
				char *fpath = auifav_getpath(fl);
				if (fpath != NULL) {
					int cp = 0;
					AWMENUITEM mi[2];
					aw_menuset(mi, cp++, "select", 33);
					aw_menuset(mi, cp++,
						   "tools.favorite.del", 8);
					byte ret = aw_menu(hWin, NULL, mi, cp);
					if (ret == 2) {
						auifav_del(fpath);
						reshow = 1;
						free(fpath);
						ondispatch = 0;
					} else if (ret == 1) {
						aui_setpath(out_char, fpath, "",
							    0);
						ondispatch = 0;
					}
					free(fpath);
				}
			}
			break;
		}
	}
	while (ondispatch);
	aw_destroy(hWin);
	return reshow;
}
ACONTROLP actext(
  AWINDOWP win,
  int x,
  int y,
  int w,
  int h,
  char * text,
  byte isbig
){
  //-- Validate Minimum Size
  if (h<agdp()*16) h=agdp()*16;
  if (w<agdp()*16) w=agdp()*16;
    
  //-- Initializing Client Area
  int minpadding = max(acfg()->roundsz,4);
  int cw            = w-(agdp()*(minpadding*2));
  int ch            = 0;
  if (text!=NULL)
    ch = ag_txtheight(cw,text,isbig)+(agdp()*(minpadding*2));
  else
    ch = h-(agdp()*2);
  
  //-- Initializing Text Data
  ACTEXTDP d        = (ACTEXTDP) malloc(sizeof(ACTEXTD));
  memset(d,0,sizeof(ACTEXTD));
  
  //-- Initializing Canvas
  ag_canvas(&d->control,w,h);
  ag_canvas(&d->control_focused,w,h);
  ag_canvas(&d->client,cw,ch);
  
  //-- Draw Control
  ag_draw_ex(&d->control,&win->c,0,0,x,y,w,h);
  ag_roundgrad(&d->control,0,0,w,h,acfg()->border,acfg()->border_g,(agdp()*acfg()->roundsz));
  ag_roundgrad(&d->control,1,1,w-2,h-2,acfg()->textbg,acfg()->textbg,(agdp()*acfg()->roundsz)-1);
  
  //-- Draw Focused Control
  ag_draw_ex(&d->control_focused,&win->c,0,0,x,y,w,h);
  ag_roundgrad(&d->control_focused,0,0,w,h,acfg()->selectbg,acfg()->selectbg_g,(agdp()*acfg()->roundsz));
  ag_roundgrad(&d->control_focused,agdp(),agdp(),w-(agdp()*2),h-(agdp()*2),acfg()->textbg,acfg()->textbg,(agdp()*(acfg()->roundsz-1)));
  
  
  //-- Draw Client
  ag_rect(&d->client,0,0,cw,ch,acfg()->textbg);
  if (text!=NULL)
    ag_text(&d->client,cw,0,agdp()*minpadding,text,acfg()->textfg,isbig);
  
  d->isbigtxt    = isbig;
  d->targetY     = 0;
  d->focused     = 0;
  d->scrollY     = 0;
  d->appendPos   = agdp()*minpadding;
  d->forceGlowTop= 0;
  d->isFixedText = 0;
  if (text!=NULL)
    d->maxScrollY  = ch-(h-(agdp()*minpadding));
  else{
    d->maxScrollY  = 0;
    d->isFixedText = 1;
  }
  if (d->maxScrollY<0) d->maxScrollY=0;
  
  ACONTROLP ctl  = malloc(sizeof(ACONTROL));
  ctl->ondestroy= &actext_ondestroy;
  ctl->oninput  = &actext_oninput;
  ctl->ondraw   = &actext_ondraw;
  ctl->onblur   = actext_onblur;
  ctl->onfocus  = actext_onfocus;
  ctl->win      = win;
  ctl->x        = x;
  ctl->y        = y;
  ctl->w        = w;
  ctl->h        = h;
  ctl->forceNS  = 0;
  ctl->d        = (void *) d;
  aw_add(win,ctl);
  return ctl;
}
Example #23
0
void aw_textdialog(AWINDOWP parent,char * titlev,char * text,char * ok_text){
  
  // actext(hWin,txtX,txtY,txtW,txtH,text,0);
  CANVAS * tmpc = aw_muteparent(parent);
  //-- Set Mask
  on_dialog_window = 1;
  ag_rectopa(agc(),0,0,agw(),agh(),0x0000,180);
  ag_sync();
  
  char title[64];
  snprintf(title,64,"%s",titlev);
  
  int pad   = agdp()*4;
  int winW  = agw()-(pad*2);
  int txtW  = winW-(pad*2);
  int txtX  = pad*2;
  int btnH  = agdp()*20;
  int titW  = ag_txtwidth(title,1);
  int titH  = ag_fontheight(1) + (pad*2);
  
  PNGCANVASP winp = atheme("img.dialog");
  PNGCANVASP titp = atheme("img.dialog.titlebar");
  APNG9      winv;
  APNG9      titv;
  int vtitY = -1;
  int vpadB = pad;
  int vimgX = pad*2;
  if (titp!=NULL){
    if (apng9_calc(titp,&titv,1)){
      int tmptitH = titH - (pad*2);
      titH        = tmptitH + (titv.t+titv.b);
      vtitY       = titv.t;
    }
  }
  if (winp!=NULL){
    if (apng9_calc(winp,&winv,1)){
      txtW = winW - (winv.l+winv.r);
      txtX = pad  + (winv.l);
      vimgX= pad  + (winv.l);
      vpadB= winv.b;
    }
  }
  
  byte imgE = 0; int imgW = 0; int imgH = 0;
  int txtH    = agh()/2;
  int infH    = txtH;
  
  //-- Calculate Window Size & Position
  int winH    = titH + infH + btnH + (pad*2) + vpadB;
  
  int winX    = pad;
  int winY    = (agh()/2) - (winH/2);
  
  //-- Calculate Title Size & Position
  int titX    = (agw()/2) - (titW/2);
  int titY    = winY + pad;
  if (vtitY!=-1) titY = winY+vtitY;
  
  //-- Calculate Text Size & Position
  int infY    = winY + titH + pad;
  int txtY    = infY;
  
  //-- Calculate Button Size & Position
  int btnW    = winW / 2;
  int btnY    = infY+infH+pad;
  int btnX    = (agw()/2) - (btnW/2);
  
  //-- Initializing Canvas
  CANVAS alertbg;
  ag_canvas(&alertbg,agw(),agh());
  ag_draw(&alertbg,agc(),0,0);
  
  //-- Draw Window
  if (!atheme_draw("img.dialog", &alertbg, winX,winY,winW,winH)){
    ag_roundgrad(&alertbg,winX-1,winY-1,winW+2,winH+2,acfg_var.border,acfg_var.border_g,(acfg_var.roundsz*agdp())+1);
    ag_roundgrad(&alertbg,winX,winY,winW,winH,acfg_var.dialogbg,acfg_var.dialogbg_g,acfg_var.roundsz*agdp());
  }
  
  //-- Draw Title
  if (!atheme_draw("img.dialog.titlebar", &alertbg, winX,winY,winW,titH)){
    ag_roundgrad_ex(&alertbg,winX,winY,winW,titH,acfg_var.dlgtitlebg,acfg_var.dlgtitlebg_g,acfg_var.roundsz*agdp(),1,1,0,0);
  }
  
  ag_textf(&alertbg,titW,titX+1,titY+1,title,acfg_var.dlgtitlebg_g,1);
  ag_text(&alertbg,titW,titX,titY,title,acfg_var.dlgtitlefg,1);
  
  AWINDOWP hWin   = aw(&alertbg);
  actext(hWin,txtX,txtY,txtW,txtH,text,0);
  ACONTROLP okbtn=acbutton(hWin,btnX,btnY,btnW,btnH,(ok_text==NULL?acfg_var.text_ok:ok_text),0,5);
    
  aw_show(hWin);
  aw_setfocus(hWin,okbtn);
  byte ondispatch = 1;
  while(ondispatch){
    dword msg=aw_dispatch(hWin);
    switch (aw_gm(msg)){
      case 5: ondispatch = 0; break;
    }
  }
  aw_destroy(hWin);
  ag_ccanvas(&alertbg);
  on_dialog_window = 0;
  aw_unmuteparent(parent,tmpc);
}
void actext_rebuild(
  ACONTROLP ctl,
  int x,
  int y,
  int w,
  int h,
  char * text,
  byte isbig,
  byte toBottom
){
  ACTEXTDP  d  = (ACTEXTDP) ctl->d;
  int minpadding = max(acfg()->roundsz,4);
  //-- Cleanup
  ag_ccanvas(&d->control);
  ag_ccanvas(&d->control_focused);
  ag_ccanvas(&d->client);
  memset(d,0,sizeof(ACTEXTD));
  
  //-- Rebuild
  //-- Validate Minimum Size
  if (h<agdp()*16) h=agdp()*16;
  if (w<agdp()*16) w=agdp()*16;
    
  //-- Initializing Client Area
  int cw            = w-(agdp()*(minpadding*2));
  int ch            = 0;
  if (text!=NULL)
    ch = ag_txtheight(cw,text,isbig)+(agdp()*(minpadding*2));
  else
    ch = h-(agdp()*2);

  //-- Initializing Canvas
  ag_canvas(&d->control,w,h);
  ag_canvas(&d->control_focused,w,h);
  ag_canvas(&d->client,cw,ch);
  
  //-- Draw Control
  ag_draw_ex(&d->control,ctl->win->bg,0,0,x,y,w,h);
  ag_roundgrad(&d->control,0,0,w,h,acfg()->border,acfg()->border_g,(agdp()*acfg()->roundsz));
  ag_roundgrad(&d->control,1,1,w-2,h-2,acfg()->textbg,acfg()->textbg,(agdp()*acfg()->roundsz)-1);
  
  //-- Draw Focused Control
  ag_draw_ex(&d->control_focused,ctl->win->bg,0,0,x,y,w,h);
  ag_roundgrad(&d->control_focused,0,0,w,h,acfg()->selectbg,acfg()->selectbg_g,(agdp()*acfg()->roundsz));
  ag_roundgrad(&d->control_focused,agdp(),agdp(),w-(agdp()*2),h-(agdp()*2),acfg()->textbg,acfg()->textbg,(agdp()*(acfg()->roundsz-1)));
  
  //-- Draw Client
  ag_rect(&d->client,0,0,cw,ch,acfg()->textbg);
  if (text!=NULL)
    ag_text(&d->client,cw,0,agdp()*minpadding,text,acfg()->textfg,isbig);
  
  d->isbigtxt    = isbig;
  d->targetY     = 0;
  d->focused     = 0;
  d->scrollY     = 0;
  d->appendPos   = agdp()*minpadding;
  d->forceGlowTop= 0;
  d->isFixedText = 0;
  if (text!=NULL)
    d->maxScrollY  = ch-(h-(agdp()*minpadding));
  else{
    d->maxScrollY  = 0;
    d->isFixedText = 1;
  }
  if (d->maxScrollY<0) d->maxScrollY=0;
  ctl->x        = x;
  ctl->y        = y;
  ctl->w        = w;
  ctl->h        = h;
  ctl->forceNS  = 0;
  
  if (toBottom){
    d->scrollY = d->maxScrollY;
  }
  
  ctl->ondraw(ctl);
  aw_draw(ctl->win);
}
void actext_ondraw(void * x){
  ACONTROLP ctl= (ACONTROLP) x;
  ACTEXTDP  d  = (ACTEXTDP) ctl->d;
  CANVAS *  pc = &ctl->win->c;
  
  //-- Init Device Pixel Size
  int minpadding = max(acfg()->roundsz,4);
  int agdp3 = (agdp()*minpadding);
  int agdp6 = (agdp()*(minpadding*2));
  int agdpX = agdp6;
  
  if ((d->focused)&&(!d->isFixedText)){
    ag_draw(pc,&d->control_focused,ctl->x,ctl->y);
    ag_draw_ex(pc,&d->client,ctl->x+agdp3,ctl->y+agdp(),0,d->scrollY+agdp(),ctl->w-agdp6,ctl->h-(agdp()*2));
  }
  else{
    ag_draw(pc,&d->control,ctl->x,ctl->y);
    ag_draw_ex(pc,&d->client,ctl->x+agdp3,ctl->y+1,0,d->scrollY+1,ctl->w-agdp6,ctl->h-2);
  }
  
  
  if ((d->maxScrollY>0)||(d->forceGlowTop)){
    //-- Glow
    int i;
    byte isST=(d->scrollY>=agdp3)?1:0;
    byte isSB=(d->scrollY<=d->maxScrollY-agdp3)?1:0;
    if (d->forceGlowTop) isST=1;

    int add_t_y = 1;
    if (d->focused)
      add_t_y = agdp();
    for (i=0;i<agdpX;i++){
      byte alph = 255-round((((float) (i+1))/ ((float) agdpX))*230);
      if (isST)
        ag_rectopa(pc,ctl->x+agdp3,ctl->y+i+add_t_y,ctl->w-agdpX,1,acfg()->textbg,alph);
      if (isSB)
        ag_rectopa(pc,ctl->x+agdp3,(ctl->y+ctl->h)-(i+1)-add_t_y,ctl->w-agdpX,1,acfg()->textbg,alph);
    }
    
    if (d->maxScrollY>0){
      //-- Scrollbar
      int newh = ctl->h - agdp6;
      float scrdif    = ((float) newh) / ((float) d->client.h);
      int  scrollbarH = round(scrdif * newh);
      int  scrollbarY = round(scrdif * d->scrollY) + agdp3;
      if (d->scrollY<0){
        scrollbarY = agdp3;
        int alp = (1.0 - (((float) abs(d->scrollY)) / (((float) ctl->h)/4))) * 255;
        if (alp<0) alp = 0;
        ag_rectopa(pc,(ctl->w-agdp()-2)+ctl->x,scrollbarY+ctl->y,agdp(),scrollbarH,acfg()->scrollbar, alp);
      }
      else if (d->scrollY>d->maxScrollY){
        scrollbarY = round(scrdif * d->maxScrollY) + agdp3;
        int alp = (1.0 - (((float) abs(d->scrollY-d->maxScrollY)) / (((float) ctl->h)/4))) * 255;
        if (alp<0) alp = 0;
        ag_rectopa(pc,(ctl->w-agdp()-2)+ctl->x,scrollbarY+ctl->y,agdp(),scrollbarH,acfg()->scrollbar, alp);
      }
      else{
        ag_rect(pc,(ctl->w-agdp()-2)+ctl->x,scrollbarY+ctl->y,agdp(),scrollbarH,acfg()->scrollbar);
      }
    }
  }
}
//*
//* SHOW MAIN DIRECTORY LIST UI
//*
void aui_show_setting() {
  printf("SHOW SETTINGS\n");
  //-- REDRAW BG
  aui_setbg(NULL);
  //-- Main Variable
  AUI_VARS v;
  //-- Return Value
  v.reshow = 0;
  //-- Init Drawing Data
  v.selfile = "";
  v.path = "";
  v.state = 0;
  v.pad = agdp() * 2;
  v.btnH = agdp() * 20;
  v.boxH = agh() - (aui_minY + (v.btnH) + (v.pad * 2));
  v.boxY = aui_minY;
  v.btnY = v.boxY + v.boxH + v.pad;
  v.navW = agw() - (v.pad * 2);
  v.pthW = v.navW;
  v.navY = aui_minY + v.pad;
  v.btnW = floor(v.navW / 3);
  int btnHlv = v.navW - (v.pad / 2);
  v.hFileType = 0;
  v.btnFH = aui_cfg_btnFH();
  //-- Draw Navigation Bar
  // aui_drawtopbar(&aui_win_bg, 0, aui_minY, agw(), v.btnH + (v.pad * 2));
  aui_drawnav(&aui_win_bg, 0, v.btnY - (v.pad + v.btnFH), agw(),
              v.btnH + (v.pad * 2) + v.btnFH);
  //-- Create Main Window
  v.hWin = aw(&aui_win_bg);
  //****************************[ INIT WINDOW CONTROLS ]****************************/
  // imgbtn(v.hWin, v.pad, v.navY, btnHlv, v.btnH, &UI_ICONS[20], alang_get("settings.mount"), 3, 22);
  /*imgbtn(v.hWin, v.pad, v.navY, btnHlv, v.btnH, &UI_ICONS[17],
         alang_get("settings.calib"), 3, 21);
  */
  v.hFile = acopt(v.hWin, 0, v.boxY, agw(), (v.boxH - v.btnFH));
  //-- Toolbar style : 1
  acopt_addgroup(v.hFile, alang_get("settings.toolbar"), "");
  acopt_add(v.hFile, alang_get("settings.toolbar.icontext"), "",
            auic()->tooltext ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.toolbar.icononly"), "",
            auic()->tooltext ? 0 : 1);
  //-- Font size : 2
  acopt_addgroup(v.hFile, alang_get("settings.fontsize"), "");
  acopt_add(v.hFile, alang_get("settings.fontsize.small"), "",
            (auic()->fontsize == 1) ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.fontsize.medium"), "",
            (auic()->fontsize == 2) ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.fontsize.big"), "",
            (auic()->fontsize == 3) ? 1 : 0);
  //-- Font Family : 3
  acopt_addgroup(v.hFile, alang_get("settings.fontfamily"), "");
  
  if (1) {
    AZREADDIRP rz_fonts = az_readdir(AROMA_DIR "/fonts/");
    
    if (rz_fonts != NULL) {
      int i = 0;
      
      for (i = 0; i < rz_fonts->n; i++) {
        if (rz_fonts->t[i] == 1) {
          char desc[256];
          auis_readinfo(desc, AROMA_DIR "/fonts/",
                        rz_fonts->f[i]);
          acopt_add(v.hFile, rz_fonts->f[i], desc,
                    (strcmp
                     (auic()->fontfamily,
                      rz_fonts->f[i]) ==
                     0) ? 1 : 0);
        }
      }
      
      az_readdir_free(rz_fonts);
    }
  }
  
  //-- Icon set : 4
  acopt_addgroup(v.hFile, alang_get("settings.iconset"), "");
  
  if (1) {
    AZREADDIRP rz_icons = az_readdir(AROMA_DIR "/icons/");
    
    if (rz_icons != NULL) {
      int i = 0;
      
      for (i = 0; i < rz_icons->n; i++) {
        if (rz_icons->t[i] == 1) {
          char desc[256];
          auis_readinfo(desc, AROMA_DIR "/icons/",
                        rz_icons->f[i]);
          acopt_add(v.hFile, rz_icons->f[i], desc,
                    (strcmp
                     (auic()->iconset,
                      rz_icons->f[i]) ==
                     0) ? 1 : 0);
        }
      }
      
      az_readdir_free(rz_icons);
    }
  }
  
  //-- Theme : 5
  acopt_addgroup(v.hFile, alang_get("settings.themes"), "");
  acopt_add(v.hFile, "Generic", "Unskinned AROMA File Manager",
            (strcmp(auic()->theme, "") == 0) ? 1 : 0);
            
  if (1) {
    AZREADDIRP rz_theme = az_readdir(AROMA_DIR "/themes/");
    
    if (rz_theme != NULL) {
      int i = 0;
      
      for (i = 0; i < rz_theme->n; i++) {
        if (rz_theme->t[i] == 1) {
          char desc[256];
          auis_readinfo(desc,
                        AROMA_DIR "/themes/",
                        rz_theme->f[i]);
          acopt_add(v.hFile, rz_theme->f[i], desc,
                    (strcmp
                     (auic()->theme,
                      rz_theme->f[i]) ==
                     0) ? 1 : 0);
        }
      }
      
      az_readdir_free(rz_theme);
    }
  }
  
  //-- Languages : 6
  acopt_addgroup(v.hFile, alang_get("settings.lang"), "");
  
  if (1) {
    AZREADDIRP rz_langs = az_readdir(AROMA_DIR "/langs/");
    
    if (rz_langs != NULL) {
      int i = 0;
      
      for (i = 0; i < rz_langs->n; i++) {
        if (rz_langs->t[i] == 1) {
          char desc[256];
          auis_readinfo(desc, AROMA_DIR "/langs/",
                        rz_langs->f[i]);
          acopt_add(v.hFile, rz_langs->f[i], desc,
                    (strcmp
                     (auic()->language,
                      rz_langs->f[i]) ==
                     0) ? 1 : 0);
        }
      }
      
      az_readdir_free(rz_langs);
    }
  }
  
  //-- Font size : 7
  acopt_addgroup(v.hFile, alang_get("settings.trans"), "");
  acopt_add(v.hFile, alang_get("settings.trans.0"), "",
            (acfg()->fadeframes == 0) ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.trans.1"), "",
            (acfg()->fadeframes == 2) ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.trans.2"), "",
            (acfg()->fadeframes == 4) ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.trans.3"), "",
            (acfg()->fadeframes == 6) ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.trans.4"), "",
            (acfg()->fadeframes == 8) ? 1 : 0);
  //-- Automount : 8
  acopt_addgroup(v.hFile, alang_get("settings.mount"), "");
  acopt_add(v.hFile, alang_get("settings.mount.all"), "",
            auic()->automount ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.mount.none"), "",
            auic()->automount ? 0 : 1);
            
   
  //-- colorspace : 9
  acopt_addgroup(v.hFile, alang_get("settings.colorspace"), "");
  acopt_add(v.hFile, alang_get("settings.colorspace.rgba"), "",
            (auic()->colorspace == 1) ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.colorspace.abgr"), "",
            (auic()->colorspace == 2) ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.colorspace.argb"), "",
            (auic()->colorspace == 3) ? 1 : 0);
  acopt_add(v.hFile, alang_get("settings.colorspace.bgra"), "",
            (auic()->colorspace == 4) ? 1 : 0);           
            
            
  //-- Font size : 8
  /*
     acopt_addgroup(v.hFile,"Automount Partitions","");
     acopt_add(v.hFile,"All partitions","",0);
     acopt_add(v.hFile,"None","",1);
   */
  //-- TOOLS
  v.b1 = imgbtn(v.hWin, v.pad, v.btnY - v.btnFH, v.btnW, v.btnH + v.btnFH, &UI_ICONS[33], aui_tbtitle(9), 1, 12);	//-- Done
  v.b2 = imgbtn(v.hWin, v.pad + v.btnW, v.btnY - v.btnFH, v.btnW, v.btnH + v.btnFH, &UI_ICONS[14], aui_tbtitle(10), 1, 22);	//-- Reset
  v.b3 = imgbtn(v.hWin, v.pad + v.btnW * 2, v.btnY - v.btnFH, v.btnW, v.btnH + v.btnFH, &UI_ICONS[0], aui_tbtitle(8), 1, 20);	//-- Cancel
  //-- Show Window
  aw_show_ex(v.hWin, 2, 0, v.hFile);
  // aw_setfocus(v.hWin,v.hFile);
  aui_changetitle(&v, alang_get("settings"));
  byte ondispatch = 1;
  byte saveconfig = 1;
  byte save_to_file = 0;
  
  do {
    dword msg = aw_dispatch(v.hWin);
    
    switch (aw_gm(msg)) {
      case 12: {
          //-- DONE
          ondispatch = 0;
        }
        break;
        
      case 20: {
          //-- CANCEL
          ondispatch = 0;
          saveconfig = 0;
        }
        break;
        
      case 22: {
          //-- RESET
          if (aw_confirm(v.hWin,
                         alang_get("settings.reset"),
                         alang_get("settings.reset.msg"),
                         aui_icons(39), NULL, NULL)) {
            ondispatch = 0;
            saveconfig = 0;
            aui_cfg_init();
            aui_load_icons();
            aui_cfg_reloadfonts();
            aui_langreload();
            aui_themereload();
            save_to_file = 1;
          }
        }
        break;
        
      case 21: {
          //-- CALIB
          if (aw_calibtools(NULL)) {
            aui_cfg_save();
          }
        }
        break;
    }
  }
  while (ondispatch);
  
  if (saveconfig) {
    byte font_reloaded = 0;
    byte colorspace_refreshed = 0;
    //-- Text on toolbar
    auic()->tooltext = (acopt_getvalue(v.hFile, 1) == 1) ? 1 : 0;
    auic()->automount = (acopt_getvalue(v.hFile, 8) == 1) ? 1 : 0;
    //-- Font Size
    byte newfontsz = (byte) acopt_getvalue(v.hFile, 2);
    
    if (newfontsz != auic()->fontsize) {
      auic()->fontsize = newfontsz;
      font_reloaded = 1;
    }
    
    byte newcolorspace = (byte) acopt_getvalue(v.hFile, 9);
    
    if (newcolorspace != auic()->colorspace) {
      auic()->colorspace = newcolorspace;
      colorspace_refreshed = 1;
    }
    
    //-- Font Family
    char * fontsel = acopt_getseltitle(v.hFile, 3);
    
    if ((fontsel != NULL)
        && (strcmp(fontsel, auic()->fontfamily) != 0)) {
      snprintf(auic()->fontfamily, 256, "%s", fontsel);
      font_reloaded = 1;
    }
    
    //-- Iconset
    fontsel = acopt_getseltitle(v.hFile, 4);
    
    if ((fontsel != NULL)
        && (strcmp(fontsel, auic()->iconset) != 0)) {
      snprintf(auic()->iconset, 256, "%s", fontsel);
      aui_unload_icons();
      aui_load_icons();
    }
    
    //-- Theme
    fontsel = acopt_getseltitle(v.hFile, 5);
    
    if ((fontsel != NULL) && (strcmp(fontsel, auic()->theme) != 0)) {
      int newtheme = acopt_getvalue(v.hFile, 5);
      
      if (newtheme == 1) {
        if (strcmp(auic()->theme, "") != 0) {
          snprintf(auic()->theme, 256, "");
          aui_themereload();
        }
      }
      else {
        snprintf(auic()->theme, 256, "%s", fontsel);
        aui_themereload();
      }
    }
    
    //-- Language
    fontsel = acopt_getseltitle(v.hFile, 6);
    
    if ((fontsel != NULL)
        && (strcmp(fontsel, auic()->language) != 0)) {
      snprintf(auic()->language, 256, "%s", fontsel);
      aui_langreload();
    }
    
    //-- Transition
    int transition = acopt_getvalue(v.hFile, 7);
    acfg()->fadeframes = (transition - 1) * 2;
    
    //-- Reload Font
    if (font_reloaded) {
      aui_cfg_reloadfonts();
    }
    
    // set new color space
    if (colorspace_refreshed) {
      aui_cfg_setcolorspace();
    }
    
    save_to_file = 1;
  }
  
  //-- Window
  aw_destroy(v.hWin);
  
  //-- Save
  if (save_to_file) {
    aui_cfg_save();
  }
}
dword accheck_oninput(void * x,int action,ATEV * atev){
  ACONTROLP ctl= (ACONTROLP) x;
  ACCHECKDP d  = (ACCHECKDP) ctl->d;
  dword msg = 0;
  switch (action){
    case ATEV_MOUSEDN:
      {
        d->prevTouchY  = atev->y;
        akinetic_downhandler(&d->akin,atev->y);
        
        int touchpos = atev->y - ctl->y + d->scrollY;
        int i;
        for (i=0;i<d->itemn;i++){
          if ((touchpos>=d->items[i]->y)&&(touchpos<d->items[i]->y+d->items[i]->h)){
            ac_regpushwait(
              ctl,&d->prevTouchY,&d->invalidDrawItem,i
            );
            break;
          }
        }
      }
      break;
    case ATEV_MOUSEUP:
      {
        if ((d->prevTouchY!=-50)&&(abs(d->prevTouchY-atev->y)<agdp()*5)){
          d->prevTouchY=-50;
          int touchpos = atev->y - ctl->y + d->scrollY;
          
          int i;
          for (i=0;i<d->itemn;i++){
            if ((!d->items[i]->isTitle)&&(touchpos>=d->items[i]->y)&&(touchpos<d->items[i]->y+d->items[i]->h)){
              d->items[i]->checked = (d->items[i]->checked)?0:1;
              if ((d->touchedItem != -1)&&(d->touchedItem!=i)){
                int tmptouch=d->touchedItem;
                d->touchedItem = -1;
                accheck_redrawitem(ctl,tmptouch);
              }
              
              int prevfocus = d->focusedItem;
              d->focusedItem= i;
              d->touchedItem= i;
              if ((prevfocus!=-1)&&(prevfocus!=i)){
                accheck_redrawitem(ctl,prevfocus);
              }
              
              
              accheck_redrawitem(ctl,i);
              ctl->ondraw(ctl);
              aw_draw(ctl->win);
              vibrate(30);              
              break;
            }
          }
          
          if ((d->scrollY<0)||(d->scrollY>d->maxScrollY)){
            ac_regbounce(ctl,&d->scrollY,d->maxScrollY);
          }
        }
        else{
          if (akinetic_uphandler(&d->akin,atev->y)){
            ac_regfling(ctl,&d->akin,&d->scrollY,d->maxScrollY);
          }
          else if ((d->scrollY<0)||(d->scrollY>d->maxScrollY)){
            ac_regbounce(ctl,&d->scrollY,d->maxScrollY);
          }
        }
        if (d->touchedItem != -1){
          usleep(30);
          int tmptouch=d->touchedItem;
          d->touchedItem = -1;
          accheck_redrawitem(ctl,tmptouch);
          ctl->ondraw(ctl);
          msg=aw_msg(0,1,0,0);
        }
      }
      break;
    case ATEV_MOUSEMV:
      {
        byte allowscroll=1;
        if (atev->y!=0){
          if (d->prevTouchY!=-50){
            if (abs(d->prevTouchY-atev->y)>=agdp()*5){
              d->prevTouchY=-50;
              if (d->touchedItem != -1){
                int tmptouch=d->touchedItem;
                d->touchedItem = -1;
                accheck_redrawitem(ctl,tmptouch);
                ctl->ondraw(ctl);
                aw_draw(ctl->win);
              }
            }
            else
              allowscroll=0;
          }
          if (allowscroll){
            int mv = akinetic_movehandler(&d->akin,atev->y);
            if (mv!=0){
              if ((d->scrollY<0)&&(mv<0)){
                float dumpsz = 0.6-(0.6*(((float) abs(d->scrollY))/(ctl->h/4)));
                d->scrollY+=floor(mv*dumpsz);
              }
              else if ((d->scrollY>d->maxScrollY)&&(mv>0)){
                float dumpsz = 0.6-(0.6*(((float) abs(d->scrollY-d->maxScrollY))/(ctl->h/4)));
                d->scrollY+=floor(mv*dumpsz);
              }
              else
                d->scrollY+=mv;
  
              if (d->scrollY<0-(ctl->h/4)) d->scrollY=0-(ctl->h/4);
              if (d->scrollY>d->maxScrollY+(ctl->h/4)) d->scrollY=d->maxScrollY+(ctl->h/4);
              msg=aw_msg(0,1,0,0);
              ctl->ondraw(ctl);
            }
          }
        }
      }
      break;
      case ATEV_SELECT:
      {
        if ((d->focusedItem>-1)&&(d->draweditemn>0)){
          if (atev->d){
            if ((d->touchedItem != -1)&&(d->touchedItem!=d->focusedItem)){
              int tmptouch=d->touchedItem;
              d->touchedItem = -1;
              accheck_redrawitem(ctl,tmptouch);
            }
            vibrate(30);
            d->touchedItem=d->focusedItem;
            accheck_redrawitem(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,0,0);
          }
          else{
            if ((d->touchedItem != -1)&&(d->touchedItem!=d->focusedItem)){
              int tmptouch=d->touchedItem;
              d->touchedItem = -1;
              accheck_redrawitem(ctl,tmptouch);
            }
            d->items[d->focusedItem]->checked = (d->items[d->focusedItem]->checked)?0:1;
            d->touchedItem=-1;
            accheck_redrawitem(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,0,0);
          }
        }
      }
      break;
      case ATEV_DOWN:
        {
          if ((d->focusedItem<d->itemn-1)&&(d->draweditemn>0)){
            int prevfocus = d->focusedItem;
            d->focusedItem++;
            while(d->items[d->focusedItem]->isTitle){
              d->focusedItem++;
              if (d->focusedItem>d->itemn-1){
                d->focusedItem = prevfocus;
                return 0;
              }
            }
            accheck_redrawitem(ctl,prevfocus);
            accheck_redrawitem(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,1,0);
            
            int reqY = d->items[d->focusedItem]->y - round((ctl->h/2) - (d->items[d->focusedItem]->h/2));
            ac_regscrollto(
              ctl,
              &d->scrollY,
              d->maxScrollY,
              reqY,
              &d->focusedItem,
              d->focusedItem
            );
          }
        }
      break;
      case ATEV_UP:
        {
          if ((d->focusedItem>0)&&(d->draweditemn>0)){
            int prevfocus = d->focusedItem;
            d->focusedItem--;
            while(d->items[d->focusedItem]->isTitle){
              d->focusedItem--;
              if (d->focusedItem<0){
                d->focusedItem = prevfocus;
                return 0;
              }
            }
            accheck_redrawitem(ctl,prevfocus);
            accheck_redrawitem(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,1,0);
            
            int reqY = d->items[d->focusedItem]->y - round((ctl->h/2) - (d->items[d->focusedItem]->h/2));
            ac_regscrollto(
              ctl,
              &d->scrollY,
              d->maxScrollY,
              reqY,
              &d->focusedItem,
              d->focusedItem
            );
          }
        }
      break;
  }
  return msg;
}
Example #28
0
byte aw_calibdraw(CANVAS * c,
  int id,int * xpos,int * ypos,int * xtch,int * ytch){
  ag_draw(agc(),c,0,0);
  
  usleep(500000);
  
  int sz = agdp()*10;
  if (id!=-1){
    int x  = xpos[id];
    int y  = ypos[id];
    int rx = x-(sz/2);
    int ry = y-(sz/2);
    ag_roundgrad(
      agc(),rx,ry,sz,sz,
      0xffff,
      ag_rgb(200,200,200),
      sz/2);
  }

  if (id!=-1){
    char txt[128];
    snprintf(txt,127,"Step %i: Tap The Circle To Calibrate",id+1);
    char * txt2 = "Press Back Key or Other Keys To Cancel";
    int tw = ag_txtwidth(txt,0);
    int tw2 = ag_txtwidth(txt2,0);
    int tx = (agw()/2) - (tw/2);
    int tx2= (agw()/2) - (tw2/2);
    int ty = (agh()/2) + (sz*2);
    int ty2= (ty +ag_fontheight(0)+agdp());
    ag_text(agc(),tw,tx+1,ty+1,txt,0x0000,0);
    ag_text(agc(),tw,tx,ty,txt,0xffff,0);
    ag_text(agc(),tw2,tx2+1,ty2+1,txt2,0x0000,0);
    ag_text(agc(),tw2,tx2,ty2,txt2,0xffff,0);
  }
  else{
    char * txt  = "Tap The Screen to Test Calibrated Data";
    char * txt2 = "Press Back or Other Keys To Continue";
    int tw = ag_txtwidth(txt,0);
    int tw2 = ag_txtwidth(txt2,0);
    int tx = (agw()/2) - (tw/2);
    int tx2= (agw()/2) - (tw2/2);
    int ty = (agh()/2) + (sz*2);
    int ty2= (ty +ag_fontheight(0)+agdp());
    ag_text(agc(),tw,tx+1,ty+1,txt,0x0000,0);
    ag_text(agc(),tw,tx,ty,txt,0xffff,0);
    ag_text(agc(),tw2,tx2+1,ty2+1,txt2,0x0000,0);
    ag_text(agc(),tw2,tx2,ty2,txt2,0xffff,0);
  }
  
  CANVAS bg;
  ag_canvas(&bg,agw(),agh());
  ag_draw(&bg,agc(),0,0);
  ag_sync();
  
  byte res=1;
  byte ond=1;
  byte onp=0;
  ui_clear_key_queue();
  while (ond){
    ATEV atev;
    ui_clear_key_queue();
    int action=atouch_wait_ex(&atev,1);
    switch (action){
      case ATEV_MOUSEDN:{
        onp=1;
        if (id==-1){
          ag_draw(agc(),&bg,0,0);
          int vz = agdp()*40;
          int vx = atev.x-(vz/2);
          int vy = atev.y-(vz/2);
          ag_roundgrad(agc(),vx,vy,vz,vz,0xffff,ag_rgb(180,180,180),(vz/2));
          ag_sync();
        }
      }
      break;
      case ATEV_MOUSEMV:{
        if (onp){
          if (id!=-1){
            xtch[id]=atev.x;
            ytch[id]=atev.y;
          }
          else{
            ag_draw(agc(),&bg,0,0);
            int vz = agdp()*40;
            int vx = atev.x-(vz/2);
            int vy = atev.y-(vz/2);
            ag_roundgrad(agc(),vx,vy,vz,vz,0xffff,ag_rgb(180,180,180),(vz/2));
            ag_sync();
          }
        }
      }
      break;
      case ATEV_MOUSEUP:{
        if (id!=-1){
          if (onp){
            if ((xtch[id]>0)&&(ytch[id]>0)){
              ond=0;
            }
            onp=0;
          }
        }
      }
      break;
      case ATEV_SELECT:
      case ATEV_BACK:
      case ATEV_MENU:{
        if (atev.d==0){
          ond=0;
          res=0;
        }
      }
      break;
    }
  }
  
  ag_ccanvas(&bg);
  return res;
}
ACONTROLP accheck(
  AWINDOWP win,
  int x,
  int y,
  int w,
  int h
){
  //-- Validate Minimum Size
  if (h<agdp()*16) h=agdp()*16;
  if (w<agdp()*20) w=agdp()*20;

  //-- Initializing Text Data
  ACCHECKDP d        = (ACCHECKDP) malloc(sizeof(ACCHECKD));
  memset(d,0,sizeof(ACCHECKD));
  
  //-- Set Signature
  d->acheck_signature = 133;
  
  //-- Initializing Canvas
  ag_canvas(&d->control,w,h);
  ag_canvas(&d->control_focused,w,h);
  
  int minpadding = max(acfg()->roundsz,4);
  
  //-- Initializing Client Size
  d->clientWidth  = w - (agdp()*minpadding*2);
  d->clientTextW  = d->clientWidth - (agdp()*18) - (agdp()*acfg()->btnroundsz*2);
  d->clientTextX  = (agdp()*18) + (agdp()*acfg()->btnroundsz*2);
  
  d->client.data=NULL;
  
  //-- Draw Control
  ag_draw_ex(&d->control,&win->c,0,0,x,y,w,h);
  ag_roundgrad(&d->control,0,0,w,h,acfg()->border,acfg()->border_g,(agdp()*acfg()->roundsz));
  ag_roundgrad(&d->control,1,1,w-2,h-2,acfg()->textbg,acfg()->textbg,(agdp()*acfg()->roundsz)-1);
  
  //-- Draw Focused Control
  ag_draw_ex(&d->control_focused,&win->c,0,0,x,y,w,h);
  ag_roundgrad(&d->control_focused,0,0,w,h,acfg()->selectbg,acfg()->selectbg_g,(agdp()*acfg()->roundsz));
  ag_roundgrad(&d->control_focused,agdp(),agdp(),w-(agdp()*2),h-(agdp()*2),acfg()->textbg,acfg()->textbg,(agdp()*(acfg()->roundsz-1)));
  
  //-- Set Scroll Value
  d->scrollY     = 0;
  d->maxScrollY  = 0;
  d->prevTouchY  =-50;
  d->invalidDrawItem = -1;
  //-- Set Data Values
  d->items       = NULL;
  d->itemn       = 0;
  d->touchedItem = -1;
  d->focusedItem = -1;
  d->nextY       = agdp()*minpadding;
  d->draweditemn = 0;
  
  d->groupCounts   = 0;
  d->groupCurrId   = -1;
  
  ACONTROLP ctl  = malloc(sizeof(ACONTROL));
  ctl->ondestroy= &accheck_ondestroy;
  ctl->oninput  = &accheck_oninput;
  ctl->ondraw   = &accheck_ondraw;
  ctl->onblur   = &accheck_onblur;
  ctl->onfocus  = &accheck_onfocus;
  ctl->win      = win;
  ctl->x        = x;
  ctl->y        = y;
  ctl->w        = w;
  ctl->h        = h;
  ctl->forceNS  = 0;
  ctl->d        = (void *) d;
  aw_add(win,ctl);
  return ctl;
}
/*
 * Descriptions:
 * -------------
 * AROMA File Manager : Permission File
 *
 */
byte auido_setperm(AWINDOWP parent,char * path, char * fn)
{
  struct stat fst;
  byte buf[12];
  memset(buf,0,12);
	if (!stat(path, &fst)) {		  
		buf[11] = (fst.st_mode & S_IXOTH) ? 1 : 0;
		buf[10] = (fst.st_mode & S_IWOTH) ? 1 : 0;
		buf[9]  = (fst.st_mode & S_IROTH) ? 1 : 0;
		  
		buf[8] = (fst.st_mode & S_IXGRP) ? 1 : 0;
		buf[7] = (fst.st_mode & S_IWGRP) ? 1 : 0;
		buf[6] = (fst.st_mode & S_IRGRP) ? 1 : 0;
		  
		buf[5] = (fst.st_mode & S_IXUSR) ? 1 : 0;
		buf[4] = (fst.st_mode & S_IWUSR) ? 1 : 0;
		buf[3] = (fst.st_mode & S_IRUSR) ? 1 : 0;
		
		buf[2] = (fst.st_mode & S_ISVTX) ? 1 : 0;
		buf[1] = (fst.st_mode & S_ISGID) ? 1 : 0;
		buf[0] = (fst.st_mode & S_ISUID) ? 1 : 0;
	}
	
  //-- Init Dialog Window
	CANVAS *tmpc = aw_muteparent(parent);
	aw_set_on_dialog(2);
	ag_rectopa(agc(), 0, 0, agw(), agh(), 0x0000, 180);
	ag_sync();

	//-- Initializing Canvas
	CANVAS bg;
	ag_canvas(&bg, agw(), agh());
	ag_draw(&bg, agc(), 0, 0);

	//-- Size & Position
	/*
	   MainTitle
	   SubTitle
	   [PAD]
	   user  group others
	   [x] r [x] w [x] x
	   [x] r [x] w [x] x
	   [x] r [x] w [x] x
	   [x] s [x] g [x] t
	   [PAD]
	   [ BUTTONS ]
	 */
	 
	int pad  = agdp() * 4;
	int padB = pad;
	int padT = pad;
	int padL = pad;
	int padR = pad;
	PNGCANVASP winp = atheme("img.dialog");
	APNG9 winv;
	if (winp != NULL) {
		if (apng9_calc(winp, &winv, 1)) {
			padL = winv.l;
			padR = winv.r;
			padB = winv.b;
			padT = winv.t;
		}
	}

	int hpad = agdp() * 2;
	int winW = agw() - (pad * 2);	//-- Window
	int winX = pad;
	int cliW = winW - (padL + padR + (hpad*2));	//-- Window Client
	int cliX = pad + padL + hpad;
	int titH = ag_fontheight(1) + (agdp() * 2);	//-- Title Height
	int chkH = agdp()*20;
	int txtH = ag_fontheight(0) + agdp();	      //-- Text Interface Height
	int btnH = agdp() * 24;
	int cliH = titH + txtH + (chkH * 4) + btnH + (pad);
	int winH = cliH + padT + padB;
	int winY = (agh() / 2) - (winH / 2);
	int cliY = winY + padT;
	int _Y   = cliY;

	//-- Draw Canvas
	if (!atheme_draw("img.dialog", &bg, winX, winY, winW, winH)) {
		ag_roundgrad(&bg, winX - 1, winY - 1, winW + 2, winH + 2,
			     acfg()->border, acfg()->border_g,
			     (acfg()->roundsz * agdp()) + 1);
		ag_roundgrad(&bg, winX, winY, winW, winH, acfg()->dialogbg,
			     acfg()->dialogbg_g, acfg()->roundsz * agdp());
	}

	//-- Init Window & Controls
	AWINDOWP hWin = aw(&bg);

  ACONTROLP txtTitle =
    aclabel(hWin, cliX, _Y, cliW, titH,
	    alang_get("tools.chmod"), 1, 1, 2, acfg()->winfg);
	_Y+=titH;
	
  ACONTROLP txtFilename =
    aclabel(hWin, cliX, _Y, cliW, txtH,
	    fn, 0, 1, 2, acfg()->winfg);
  _Y+=txtH+pad;
  
  int colW = cliW / 4;
  int col1 = cliX;
  int col2 = col1 + colW;
  int col3 = col2 + colW;
  int col4 = col3 + colW;
  
  aclabel(hWin, col1, _Y, colW, chkH,
	    alang_get("tools.chmod.user"), 0, 1, 1, acfg()->winfg);
  ACONTROLP cbR1 = accb(hWin,col2,_Y,colW,chkH,alang_get("tools.chmod.read"),buf[3]);
  ACONTROLP cbW1 = accb(hWin,col3,_Y,colW,chkH,alang_get("tools.chmod.write"),buf[4]);
  ACONTROLP cbX1 = accb(hWin,col4,_Y,colW,chkH,alang_get("tools.chmod.exec"),buf[5]);
  _Y+=chkH;
  
  aclabel(hWin, col1, _Y, colW, chkH,
	    alang_get("tools.chmod.group"), 0, 1, 1, acfg()->winfg);
  ACONTROLP cbR2 = accb(hWin,col2,_Y,colW,chkH,alang_get("tools.chmod.read"),buf[6]);
  ACONTROLP cbW2 = accb(hWin,col3,_Y,colW,chkH,alang_get("tools.chmod.write"),buf[7]);
  ACONTROLP cbX2 = accb(hWin,col4,_Y,colW,chkH,alang_get("tools.chmod.exec"),buf[8]);
  _Y+=chkH;
  
  aclabel(hWin, col1, _Y, colW, chkH,
	    alang_get("tools.chmod.others"), 0, 1, 1, acfg()->winfg);
  ACONTROLP cbR3 = accb(hWin,col2,_Y,colW,chkH,alang_get("tools.chmod.read"),buf[9]);
  ACONTROLP cbW3 = accb(hWin,col3,_Y,colW,chkH,alang_get("tools.chmod.write"),buf[10]);
  ACONTROLP cbX3 = accb(hWin,col4,_Y,colW,chkH,alang_get("tools.chmod.exec"),buf[11]);
  _Y+=chkH;

  ACONTROLP cbZ1 = accb(hWin,col2,_Y,colW,chkH,alang_get("tools.chmod.setuid"),buf[0]);
  ACONTROLP cbZ2 = accb(hWin,col3,_Y,colW,chkH,alang_get("tools.chmod.setgid"),buf[1]);
  ACONTROLP cbZ3 = accb(hWin,col4,_Y,colW,chkH,alang_get("tools.chmod.sticky"),buf[2]);
  
  _Y+=chkH;
  int btnW = cliW / 2;
  int btn1 = cliX;
  int btn2 = btn1 + btnW;
	ACONTROLP okBtn =
	    imgbtn(hWin, btn1, _Y, btnW-(pad/2), btnH, aui_icons(33), alang_get("ok"), 3, 6);

  ACONTROLP cancelBtn =
	    imgbtn(hWin, btn2+(pad/2), _Y, btnW-(pad/2), btnH, aui_icons(0), alang_get("cancel"), 3, 5);
	    
	//-- Show Window
	aw_show_ex(hWin, 0, 0, okBtn);
	byte ondispatch = 1;
  byte retval = 1;
	//-- Dispatch
	do {
		dword msg = aw_dispatch(hWin);
		switch (aw_gm(msg)) {
		case 5:
			{
				ondispatch = 0;
			}
			break;
		case 6:
			{
				// ondispatch = 0;
				buf[0]=accb_ischecked(cbZ1);
        buf[1]=accb_ischecked(cbZ2);
        buf[2]=accb_ischecked(cbZ3);
        buf[3]=accb_ischecked(cbR1);
        buf[4]=accb_ischecked(cbW1);
        buf[5]=accb_ischecked(cbX1);
        buf[6]=accb_ischecked(cbR2);
        buf[7]=accb_ischecked(cbW2);
        buf[8]=accb_ischecked(cbX2);
        buf[9]=accb_ischecked(cbR3);
        buf[10]=accb_ischecked(cbW3);
        buf[11]=accb_ischecked(cbX3);
        
        mode_t newmod = 0;
        if (buf[0]) newmod |= S_ISUID;
        if (buf[1]) newmod |= S_ISGID;
        if (buf[2]) newmod |= S_ISVTX;
        if (buf[3]) newmod |= S_IRUSR;
        if (buf[4]) newmod |= S_IWUSR;
        if (buf[5]) newmod |= S_IXUSR;
        if (buf[6]) newmod |= S_IRGRP;
        if (buf[7]) newmod |= S_IWGRP;
        if (buf[8]) newmod |= S_IXGRP;
        if (buf[9]) newmod |= S_IROTH;
        if (buf[10]) newmod |= S_IWOTH;
        if (buf[11]) newmod |= S_IXOTH;

        printf("CHMOD %o - %s\n",newmod,path);
        chmod(path,newmod);
        
        ondispatch = 0;
        retval = 0;
			}
			break;
		}
	}
	while (ondispatch);

	//-- Release Resources
	aw_destroy(hWin);
	ag_ccanvas(&bg);
	aw_set_on_dialog(0);
	aw_unmuteparent(parent, tmpc);
	
	return retval;
}