static void *ac_pushwaitthread(void *cookie){
  miui_debug("pthread %s start...\n", __FUNCTION__);
  APUSHWAITDATAP dt = (APUSHWAITDATAP) cookie;
  if (dt->ctl->win->isActived)
    dt->ctl->win->threadnum++;
  else{
    free(dt);
    return NULL;
  }
  int  waitsz  = 0;
  byte isvalid = 1;
  while (++waitsz<300){
    if (!dt->ctl->win->isActived){ isvalid=0; break; }
    if (dt->moveY[0]==-50){ isvalid=0; break; }
    usleep(10);
  }
#if 0
  if ((isvalid)&&(dt->moveY[0]!=-50)){
    dt->flagpointer[0]=dt->flagvalue;
    dt->ctl->ondraw(dt->ctl);
    aw_draw(dt->ctl->win);
  }
#endif
  dt->ctl->win->threadnum--;
  free(dt);
  return NULL;
}
static void *ac_scrolltothread(void *cookie){
  miui_debug("pthread %s start...\n", __FUNCTION__);
  ASCROLLTODATAP dt = (ASCROLLTODATAP) cookie;
  if (dt->ctl->win->isActived)
    dt->ctl->win->threadnum++;
  else{
    free(dt);
    return NULL;
  }
  dt->ctl->forceNS = 1;
  while (dt->scrollY[0]!=dt->requestY){
    int diff = floor(((float) (dt->scrollY[0] - dt->requestY)) * 0.5);
    if (abs(diff)<1)
      dt->scrollY[0] = dt->requestY;
    else
      dt->scrollY[0]-= diff;
    
    //-- REDRAW
    dt->ctl->ondraw(dt->ctl);
    aw_draw(dt->ctl->win);
    if (dt->requestHandler[0]!=dt->requestValue) break;
    if (!dt->ctl->win->isActived) break;
    if (ui_key_pressed(atmsg())){
      ACONTROLP nctl = (ACONTROLP) dt->ctl->win->controls[dt->ctl->win->touchIndex];
      if (nctl==dt->ctl)
        break;
    }
  }
  dt->ctl->forceNS = 0;
  dt->ctl->win->threadnum--;
  free(dt);
  return NULL;
}
void acprog_sethidden(ACONTROLP ctl, byte hidden, byte syncnow){
  APROGDP  d      = (APROGDP) ctl->d;
  d->hidden       = hidden;
  
  d->drawed       = 0;
  acprog_ondraw(ctl);
  if (syncnow) aw_draw(ctl->win);
}
static void *ac_flingthread(void *cookie){
  miui_debug("pthread %s start...\n", __FUNCTION__);
  AFLINGDATAP dt = (AFLINGDATAP) cookie;
  if (dt->ctl->win->isActived)
    dt->ctl->win->threadnum++;
  else{
    free(dt);
    return NULL;
  }
  int mz  = akinetic_fling(dt->akin);
  float vz=0.0;
  while ((mz!=0)&&(dt->ctl->win->isActived)){
    if (dt->ctl->forceNS) break;
    

    int zz=ceil(dt->akin->velocity);
    /*vz+=dt->akin->velocity-zz;
    if (abs(vz)>=1){
      if (vz<0){
        vz+=1.0;
        zz--;
      }
      else{
        vz-=1.0;
        zz++;
      }
    }*/
    //if (zz!=0){
      dt->scrollY[0]+=zz;
      dt->ctl->ondraw(dt->ctl);
      aw_draw(dt->ctl->win);
    //}
    
    if (!dt->ctl->win->isActived) break;
    if ((dt->scrollY[0]<0-(dt->ctl->h/4))||(dt->scrollY[0]>dt->maxScrollY+(dt->ctl->h/4))) break;
    if (ui_key_pressed(atmsg())){
      ACONTROLP nctl = (ACONTROLP) dt->ctl->win->controls[dt->ctl->win->touchIndex];
      if (nctl==dt->ctl)
        break;
    }
    //usleep(4000);
    
    if ((dt->scrollY[0]<0)||(dt->scrollY[0]>dt->maxScrollY))
      mz=akinetic_fling_dampered(dt->akin,0.6);
    else
      mz=akinetic_fling(dt->akin);
  }
  if (dt->ctl->win->isActived){
    if ((dt->scrollY[0]<0)||(dt->scrollY[0]>dt->maxScrollY)){
      ac_regbounce(dt->ctl,dt->scrollY,dt->maxScrollY);
    }
  }
  dt->ctl->win->threadnum--;
  free(dt);
  return NULL;
}
void aclabel_settext(ACONTROLP ctl, char * text, byte syncnow){
  ACLABELDP  d    = (ACLABELDP) ctl->d;
  free(d->text);
  d->text=strdup(text);
  d->drawed= 0;
  
  aclabel_ondraw(ctl);
  if (syncnow){
    aw_draw(ctl->win);
  }
}
void acime2_sendmsg(ACONTROLP ctl, byte a2, byte a3, byte a4) {
  ACIMEDP  d      = (ACIMEDP) ctl->d;
  dword msg = aw_msg(d->inputMsg, a2, (d->onCTRL ? 1 : 0), a4);
  
  if (d->onCTRL) {
    d->keyD[34] = 0;
    d->onCTRL = 0;
    aw_draw(ctl->win);
  }
  
  atouch_send_message(msg);
}
void aclabel_setprop(ACONTROLP ctl, byte isbig, byte vpos, byte sigleAligment, color cl, byte syncnow){
  ACLABELDP  d    = (ACLABELDP) ctl->d;
  
  d->isbig = isbig;
  d->vpos  = vpos;
  d->drawed= 0;
  d->cl    = cl;
  d->sigleAligment=sigleAligment;
  aclabel_ondraw(ctl);
  if (syncnow){
    aw_draw(ctl->win);
  }
}
void acprog_setvalue(ACONTROLP ctl, float value, byte syncnow){
  APROGDP  d      = (APROGDP) ctl->d;
  
  if (value>1) value=1.0;
  if (value<0) value=0.0;
  
  d->onwait       = 0;
  d->value        = value;
  d->width_current= ceil(d->value * ctl->w);
  
  d->drawed = 0;
  acprog_ondraw(ctl);
  if (syncnow) aw_draw(ctl->win);
}
static void * ac_scrolltothread(void * cookie) {
  ASCROLLTODATAP dt = (ASCROLLTODATAP) cookie;
  
  if (dt->ctl->win->isActived) {
    dt->ctl->win->threadnum++;
  }
  else {
    free(dt);
    return NULL;
  }
  
  dt->ctl->forceNS = 1;
  
  while (dt->scrollY[0] != dt->requestY) {
    int diff = floor(((float) (dt->scrollY[0] - dt->requestY)) * 0.5);
    
    if (abs(diff) < 1) {
      dt->scrollY[0] = dt->requestY;
    }
    else {
      dt->scrollY[0] -= diff;
    }
    
    //-- REDRAW
    dt->ctl->ondraw(dt->ctl);
    aw_draw(dt->ctl->win);
    
    if (dt->requestHandler[0] != dt->requestValue) {
      break;
    }
    
    if (!dt->ctl->win->isActived) {
      break;
    }
    
    if (ontouch()) {
      ACONTROLP nctl = (ACONTROLP) dt->ctl->win->controls[dt->ctl->win->touchIndex];
      
      if (nctl == dt->ctl) {
        break;
      }
    }
  }
  
  dt->ctl->forceNS = 0;
  dt->ctl->win->threadnum--;
  free(dt);
  return NULL;
}
static void *ac_bouncethread(void *cookie){
  miui_debug("pthread %s start...\n", __FUNCTION__);
  ABOUNCEDATAP dt = (ABOUNCEDATAP) cookie;
  if (dt->ctl->win->isActived)
    dt->ctl->win->threadnum++;
  else{
    free(dt);
    return NULL;
  }
  int bouncesz    = 0;
  byte bouncetype = 0;
  if (dt->scrollY[0]<0)
    bouncesz = abs(dt->scrollY[0]);
  else if (dt->scrollY[0]>dt->maxScrollY){
    bouncetype = 1;
    bouncesz   = dt->scrollY[0] - dt->maxScrollY;
  }
  
  while (bouncesz>0){
    if (dt->ctl->forceNS) break;
    
    bouncesz = floor(bouncesz*0.9);
    if (bouncetype) dt->scrollY[0] = dt->maxScrollY + bouncesz;
    else dt->scrollY[0] = 0 - bouncesz;
    
    //-- REDRAW
    dt->ctl->ondraw(dt->ctl);
    aw_draw(dt->ctl->win);
    
    if (!dt->ctl->win->isActived) break;
    if (ui_key_pressed(atmsg())){
      ACONTROLP nctl = (ACONTROLP) dt->ctl->win->controls[dt->ctl->win->touchIndex];
      if (nctl==dt->ctl)
        break;
    }
    if (dt->scrollY[0]==0) break;
    if (dt->scrollY[0]==dt->maxScrollY) break;
  }
  dt->ctl->win->threadnum--;
  free(dt);
  return NULL;
}
static void *acprog_onwaitthread(void *cookie){
  ACONTROLP ctl= (ACONTROLP) cookie;
  APROGDP   d  = (APROGDP) ctl->d;
  
  if (ctl->win->isActived)
    ctl->win->threadnum++;
  else
    return NULL;
  
  while (ctl->win->isActived&&d->onwait){
    d->waitpos+=0.05;
    if (d->waitpos>=2.0) d->waitpos=0.0;
    acprog_ondraw(ctl);
    aw_draw(ctl->win);
    usleep(8000);
  }
  
  d->wait_thread=0;
  ctl->win->threadnum--;return NULL;
}
Beispiel #12
0
//-- Set Focus
byte aw_setfocus(AWINDOWP win,ACONTROLP ctl){
  if (!win->isActived) return 0;
  int i;
  for (i=0;i<win->controln;i++){
    ACONTROLP fctl = (ACONTROLP) win->controls[i];
    if (fctl==ctl){
      if (fctl->onfocus!=NULL){
        if (fctl->onfocus(fctl)){
          int pf = win->focusIndex;
          win->focusIndex = i;
          if ((pf!=-1)&&(pf!=i)){
            ACONTROLP pctl = (ACONTROLP) win->controls[pf];
            pctl->onblur(pctl);
          }
          aw_draw(win);
          return 1;
        }
      }
    }
  }
  return 0;
}
static void * ac_pushwaitthread(void * cookie) {
  APUSHWAITDATAP dt = (APUSHWAITDATAP) cookie;
  
  if (dt->ctl->win->isActived) {
    dt->ctl->win->threadnum++;
  }
  else {
    free(dt);
    return NULL;
  }
  
  int  waitsz  = 0;
  byte isvalid = 1;
  
  while (++waitsz < 180) {
    if (!dt->ctl->win->isActived) {
      isvalid = 0;
      break;
    }
    
    if (dt->moveY[0] == -50) {
      isvalid = 0;
      break;
    }
    
    usleep(500);
  }
  
  if ((isvalid) && (dt->moveY[0] != -50)) {
    dt->flagpointer[0] = dt->flagvalue;
    dt->ctl->ondraw(dt->ctl);
    aw_draw(dt->ctl->win);
  }
  
  dt->ctl->win->threadnum--;
  free(dt);
  return NULL;
}
static void * acime2_loopthread(void * cookie) {
  ACONTROLP ctl   = (ACONTROLP) cookie;
  ACIMEDP  d      = (ACIMEDP) ctl->d;
  long lt         = d->loopTick;
  byte pd         = d->pushedId;
  byte ft         = 0;
  
  while (1) {
    usleep(40000);
    
    if ((lt == d->loopTick) && (pd == d->pushedId)) {
      if (ft > 15) {
        if (pd == 30) {
          //-- SPACE
          acime2_sendmsg(ctl, 32, 0, 0);
        }
        else if (pd == 27) {
          //-- Backspace
          acime2_sendmsg(ctl, 8, 0, 0);
        }
        else if (pd == 35) {
          acime2_sendmsg(ctl, 37, 1, 1);  /* left */
        }
        else if (pd == 36) {
          acime2_sendmsg(ctl, 38, 1, 1);  /* up */
        }
        else if (pd == 37) {
          acime2_sendmsg(ctl, 40, 1, 1);  /* down */
        }
        else if (pd == 38) {
          acime2_sendmsg(ctl, 39, 1, 1);  /* right */
        }
        else if (!d->on123) {
          byte keyID = d->pushedId;
          char c = 0;
          
          if ((pd < 27) && (pd != 19)) {
            d->pushedId    = 254;
            int n = pd;
            
            if (n > 19) {
              n--;
            }
            
            int np = (d->onShift) ? 0 : 1;
            c = acime2_charlist[np][n];
            d->keyD[keyID] = 0;
            vibrate(30);
            acime2_sendmsg(ctl, (byte) c, 0, 0);
            
            if (d->onShift == 1) {
              d->onShift = 0;
              int i;
              
              for (i = 0; i < ACIME2_BTNCNT; i++) {
                d->keyD[i] = 0;
              }
            }
            
            ctl->ondraw(ctl);
            aw_draw(ctl->win);
          }
          
          break;
        }
      }
      
      if (ft <= 15) {
        ft++;
      }
    }
    else {
      break;
    }
  }
  
  return NULL;
}
Beispiel #15
0
//-- Dispatch Messages
dword aw_dispatch(AWINDOWP win){
  dword msg;
  int i;
  
  ui_clear_key_queue();
  while(1){
    //-- Wait For Event
    ATEV        atev;
    int action  =atouch_wait(&atev);
    
    //-- Reset Message Value
    msg         = aw_msg(0,0,0,0);
    
    //-- Check an Action Value
    switch (action){
      case ATEV_MESSAGE:{
        msg = atev.msg;
      }
      break;
      case ATEV_BACK:{
        if (!atev.d){
          msg = aw_msg(5,0,0,0);
        }
      }
      break;
      case ATEV_DOWN: case ATEV_RIGHT:
        if (!atev.d){
          if (win->focusIndex!=-1){
            ACONTROLP ctl = (ACONTROLP) win->controls[win->focusIndex];
            if (ctl->oninput!=NULL){
              msg = ctl->oninput((void*)ctl,action,&atev);
            }
            if (aw_gl(msg)==0){
              for (i=win->focusIndex+1;i<win->controln;i++){
                ACONTROLP fctl = (ACONTROLP) win->controls[i];
                if (fctl->onfocus!=NULL){
                  if (fctl->onfocus(fctl)){
                    win->focusIndex = i;
                    ctl->onblur(ctl);
                    aw_draw(win);
                    break;
                  }
                }
              }
            }
          }
        }
      break;
      case ATEV_UP: case ATEV_LEFT:
        if (!atev.d){
          if (win->focusIndex!=-1){
            ACONTROLP ctl = (ACONTROLP) win->controls[win->focusIndex];
            if (ctl->oninput!=NULL){
              msg = ctl->oninput((void*)ctl,action,&atev);
            }
            if (aw_gl(msg)==0){
              for (i=win->focusIndex-1;i>=0;i--){
                ACONTROLP fctl = (ACONTROLP) win->controls[i];
                if (fctl->onfocus!=NULL){
                  if (fctl->onfocus(fctl)){
                    win->focusIndex = i;
                    ctl->onblur(ctl);
                    aw_draw(win);
                    break;
                  }
                }
              }
            }
          }
        }
      break;
      case ATEV_MENU:
      case ATEV_SEARCH:
      case ATEV_HOME:
      case ATEV_SELECT:{
        if (win->focusIndex!=-1){
          ACONTROLP ctl = (ACONTROLP) win->controls[win->focusIndex];
          if (ctl->oninput!=NULL){
            msg = ctl->oninput((void*)ctl,action,&atev);
          }
        }
      }
      break;
      case ATEV_MOUSEDN:
      {
        if (win->controln>0){
          int i;
          for (i=win->controln-1;i>=0;i--){
            ACONTROLP ctl = (ACONTROLP) win->controls[i];
            if (aw_touchoncontrol(ctl,atev.x,atev.y)){
              if (ctl->oninput!=NULL){
                msg             = ctl->oninput((void*)ctl,action,&atev);
                win->touchIndex = i;
                break;
              }
            }
          }
        }
      }
      break;
      case ATEV_MOUSEUP:{
        if (win->touchIndex!=-1){
          ACONTROLP ctl = (ACONTROLP) win->controls[win->touchIndex];
          if (ctl->oninput!=NULL)
            msg             = ctl->oninput((void*)ctl,action,&atev);
          win->touchIndex   = -1;
        }
      }
      break;
      case ATEV_MOUSEMV:{
        if (win->touchIndex!=-1){
          ACONTROLP ctl = (ACONTROLP) win->controls[win->touchIndex];
          if (ctl->oninput!=NULL)
            msg             = ctl->oninput((void*)ctl,action,&atev);
        }
      }
      break;
    }
    
    if (aw_gd(msg)==1) aw_draw(win);
    if (aw_gm(msg)!=0) return msg;
  }
  return msg;
}
static void * ac_bouncethread(void * cookie) {
  ABOUNCEDATAP dt = (ABOUNCEDATAP) cookie;
  
  if (dt->ctl->win->isActived) {
    dt->ctl->win->threadnum++;
  }
  else {
    free(dt);
    return NULL;
  }
  
  int bouncesz    = 0;
  byte bouncetype = 0;
  
  if (dt->scrollY[0] < 0) {
    bouncesz = abs(dt->scrollY[0]);
  }
  else if (dt->scrollY[0] > dt->maxScrollY) {
    bouncetype = 1;
    bouncesz   = dt->scrollY[0] - dt->maxScrollY;
  }
  
  while (bouncesz > 0) {
    if (dt->ctl->forceNS) {
      break;
    }
    
    bouncesz = floor(bouncesz * 0.3);
    
    if (bouncetype) {
      dt->scrollY[0] = dt->maxScrollY + bouncesz;
    }
    else {
      dt->scrollY[0] = 0 - bouncesz;
    }
    
    //-- REDRAW
    dt->ctl->ondraw(dt->ctl);
    aw_draw(dt->ctl->win);
    
    if (!dt->ctl->win->isActived) {
      break;
    }
    
    if (ontouch()) {
      ACONTROLP nctl = (ACONTROLP) dt->ctl->win->controls[dt->ctl->win->touchIndex];
      
      if (nctl == dt->ctl) {
        break;
      }
    }
    
    if (dt->scrollY[0] == 0) {
      break;
    }
    
    if (dt->scrollY[0] == dt->maxScrollY) {
      break;
    }
  }
  
  dt->ctl->win->threadnum--;
  free(dt);
  return NULL;
}
void actext_appendtxt(ACONTROLP ctl,char * txt){
  ACTEXTDP   d  = (ACTEXTDP) ctl->d;
  int ch          = ag_txtheight(d->client.w,txt,d->isbigtxt);
  int canvas_h    = d->client.h;
  
  if ((d->appendPos+ch)>=canvas_h){
    int step_up = (d->appendPos+ch) - canvas_h;
    int y; int ynew=0;
    for (y=step_up; y<canvas_h; y++){
      color * rowdest = agxy(&d->client,0,ynew++);
      color * rowsrc  = agxy(&d->client,0,y);
      memcpy(rowdest,rowsrc,sizeof(color)*d->client.w);
    }
    d->appendPos -= step_up;
  }
  
  ag_rect(&d->client,0,d->appendPos,d->client.w,ch,acfg()->textbg);
  ag_text(&d->client,
    d->client.w,
    0,d->appendPos,
    txt,
    acfg()->textfg,
    d->isbigtxt);

  d->appendPos+=ch;
  
  /*
  int minpadding = max(acfg()->roundsz,4);
  int ch        = ag_txtheight(d->client.w,txt,d->isbigtxt);
  int my        = d->client.h-(agdp()*2); // -(agdp()*(minpadding*2));
  if ((d->appendPos+ch)>=my){
    if (d->appendPos<my){
      ch-=(my-d->appendPos);
    }
    int y; int ynew=0;
    for (y=ch;y<d->client.h;y++){
      color * rowdest = agxy(&d->client,0,ynew++);
      color * rowsrc  = agxy(&d->client,0,y);
      memcpy(rowdest,rowsrc,sizeof(color)*d->client.w);
    }
    int ypos = my-ch;
    ag_rect(&d->client,0,ypos,d->client.w,ch,acfg()->textbg);
    ag_text(&d->client,
      d->client.w,
      0,ypos,
      txt,
      acfg()->textfg,
      d->isbigtxt);
    d->forceGlowTop=1;
    d->appendPos=my;
  }
  else{
    ag_text(&d->client,
      d->client.w,
      0,d->appendPos,
      txt,
      acfg()->textfg,
      d->isbigtxt);
    d->appendPos+=ch;
  }
  */
  ctl->ondraw(ctl);
  aw_draw(ctl->win);
}
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);
}
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;
}
dword afbox_oninput(void * x,int action,ATEV * atev){
  ACONTROLP ctl= (ACONTROLP) x;
  AFBOXDP d  = (AFBOXDP) ctl->d;
  dword msg = 0;
  switch (action){
    case 444:
      {
        // printf("HOLDED: %i - %s",d->touchedItem,d->items[d->touchedItem]->title);
        vibrate(30);
        int tmptouch=d->touchedItem;
        int tmpfocus=d->focusedItem;
        d->selectedId  = tmptouch;
        d->focusedItem = tmptouch;
        d->touchedItem = -1;
        if (tmpfocus!=tmptouch) afbox_redrawitem_ex(ctl,tmpfocus);
        afbox_redrawitem_ex(ctl,tmptouch);
        ctl->ondraw(ctl);
        msg=aw_msg(d->holdmsg,1,0,0);
        atouch_send_message(msg);
      }
      break;
    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:
      {
        byte is_holded = 0;
        if (d->lasttouch==-1) is_holded=1;
        d->lasttouch=0;
        byte ag_check_msg = 0;
        if ((d->prevTouchY!=-50)&&(abs(d->prevTouchY-atev->y)<agdp()*5)){
          d->prevTouchY=-50;
          int touchpos = atev->y - ctl->y + d->scrollY;
          
          byte oncheckpush=((d->check_n>0)||(atev->x>((ctl->x+ctl->w)-(agdp()*32))))?1:0;
          
          if (d->boxtype!=0) oncheckpush=0;
          
          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)){
              
              if ((oncheckpush)&&(!is_holded)){
                d->items[i]->checked = (d->items[i]->checked)?0:1;
                if (d->items[i]->checked)
                  d->check_n++;
                else
                  d->check_n--;
                ag_check_msg = d->changemsg;
              }
              
              if ((d->touchedItem != -1)&&(d->touchedItem!=i)){
                int tmptouch=d->touchedItem;
                d->touchedItem = -1;
                afbox_redrawitem_ex(ctl,tmptouch);
              }
              
              int prevfocus = d->focusedItem;
              d->focusedItem= i;
              d->touchedItem= i;
              if ((prevfocus!=-1)&&(prevfocus!=i)){
                afbox_redrawitem_ex(ctl,prevfocus);
              }
              
              
              afbox_redrawitem_ex(ctl,i);
              ctl->ondraw(ctl);
              aw_draw(ctl->win);
              
              if (!is_holded){
                vibrate(30);
                
                if (!oncheckpush){
                  ag_check_msg = d->touchmsg;
                  d->selectedId=i;
                  msg=aw_msg(ag_check_msg,1,0,0);
                }
              }
              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;
          afbox_redrawitem_ex(ctl,tmptouch);
          ctl->ondraw(ctl);
          msg=aw_msg(ag_check_msg,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;
                afbox_redrawitem_ex(ctl,tmptouch);
                ctl->ondraw(ctl);
                aw_draw(ctl->win);
              }
            }
            else
              allowscroll=0;
          }
          if (allowscroll){
            d->lasttouch=0;
            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_SEARCH:
      {
        d->lasttouch=0;
        if (d->boxtype==0){
          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;
                afbox_redrawitem_ex(ctl,tmptouch);
              }
              vibrate(30);
              d->touchedItem=d->focusedItem;
              afbox_redrawitem_ex(ctl,d->focusedItem);
              ctl->ondraw(ctl);
              msg=aw_msg(0,1,0,0);
            }
            else{
              d->items[d->focusedItem]->checked = (d->items[d->focusedItem]->checked)?0:1;
              if (d->items[d->focusedItem]->checked)
                d->check_n++;
              else
                d->check_n--;
              d->touchedItem=-1;
              afbox_redrawitem_ex(ctl,d->focusedItem);
              ctl->ondraw(ctl);
              msg=aw_msg(d->changemsg,1,0,0);
            }
          }
        }
      }
      break;
      case ATEV_SELECT:
        {
          d->lasttouch=0;
          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;
                afbox_redrawitem_ex(ctl,tmptouch);
              }
              vibrate(30);
              d->touchedItem=d->focusedItem;
              afbox_redrawitem_ex(ctl,d->focusedItem);
              ctl->ondraw(ctl);
              msg=aw_msg(0,1,0,0);
            }
            else{
              if ((d->check_n>0)&&(d->boxtype==0)){
                d->items[d->focusedItem]->checked = (d->items[d->focusedItem]->checked)?0:1;
                if (d->items[d->focusedItem]->checked)
                  d->check_n++;
                else
                  d->check_n--;
                d->touchedItem=-1;
                afbox_redrawitem_ex(ctl,d->focusedItem);
                ctl->ondraw(ctl);
                msg=aw_msg(d->changemsg,1,0,0);
              }
              else{
                if ((d->touchedItem != -1)&&(d->touchedItem!=d->focusedItem)){
                  int tmptouch=d->touchedItem;
                  d->touchedItem = -1;
                  afbox_redrawitem_ex(ctl,tmptouch);
                }
                d->selectedId=d->focusedItem;
                d->touchedItem=-1;
                afbox_redrawitem_ex(ctl,d->focusedItem);
                ctl->ondraw(ctl);
                msg=aw_msg(d->touchmsg,1,0,0);
              }
            }
          }
        }
        break;
      case ATEV_DOWN:
        {
          d->lasttouch=0;
          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;
                d->selectedId  = d->focusedItem;
                return 0;
              }
            }
            d->selectedId  = d->focusedItem;
            afbox_redrawitem_ex(ctl,prevfocus);
            afbox_redrawitem_ex(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:
        {
          d->lasttouch=0;
          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;
                d->selectedId  = d->focusedItem;
                return 0;
              }
            }
            d->selectedId  = d->focusedItem;
            afbox_redrawitem_ex(ctl,prevfocus);
            afbox_redrawitem_ex(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;
}