byte imgbtn_onfocus(void * x) {
  ACONTROLP   ctl = (ACONTROLP) x;
  IMGBTNDP  d  = (IMGBTNDP) ctl->d;
  d->focused = 1;
  ctl->ondraw(ctl);
  return 1;
}
dword imgbtn_oninput(void * x, int action, ATEV * atev) {
  ACONTROLP ctl  = (ACONTROLP) x;
  IMGBTNDP  d  = (IMGBTNDP) ctl->d;
  dword msg = 0;
  
  switch (action) {
    case ATEV_MOUSEDN: {
        vibrate(30);
        d->pushed = 1;
        msg = aw_msg(0, 1, 0, 0);
        ctl->ondraw(ctl);
      }
      break;
      
    case ATEV_MOUSEUP: {
        d->pushed = 0;
        
        if (aw_touchoncontrol(ctl, atev->x, atev->y)) {
          msg = aw_msg(d->touchmsg, 1, 0, 0);
        }
        else {
          msg = aw_msg(0, 1, 0, 0);
        }
        
        ctl->ondraw(ctl);
      }
      break;
      
    case ATEV_SELECT: {
        if (atev->d) {
          vibrate(30);
          d->pushed = 1;
          msg = aw_msg(0, 1, 0, 0);
          ctl->ondraw(ctl);
        }
        else {
          d->pushed = 0;
          msg = aw_msg(d->touchmsg, 1, 0, 0);
          ctl->ondraw(ctl);
        }
      }
      break;
  }
  
  return msg;
}
void acopt_onblur(void * x) {
  ACONTROLP   ctl = (ACONTROLP) x;
  ACOPTDP   d  = (ACOPTDP) ctl->d;
  d->focused = 0;
  
  if ((d->focusedItem != -1) && (d->draweditemn > 0)) {
    acopt_redrawitem(ctl, d->focusedItem);
  }
  
  ctl->ondraw(ctl);
}
void afbox_scrolltoitem(ACONTROLP ctl){
  AFBOXDP d = (AFBOXDP) ctl->d;
  if (d->focusedItem>-1){
    afbox_redraw(ctl);
    d->scrollY = d->items[d->focusedItem]->y - round((ctl->h/2) - (d->items[d->focusedItem]->h/2));
    if (d->scrollY<0) d->scrollY=0;
    if (d->scrollY>d->maxScrollY) d->scrollY=d->maxScrollY;
  }
  ctl->ondraw(ctl);
  aw_redraw(ctl->win);
}
Ejemplo n.º 5
0
//-- Redraw Window & Controls
void aw_redraw(AWINDOWP win){
  if (!win->isActived) return;
  if (win->controln>0){
    int i;
    for (i=0;i<win->controln;i++){
      ACONTROLP ctl = (ACONTROLP) win->controls[i];
      if (ctl->ondraw!=NULL)
        ctl->ondraw(ctl);
    }
  }
  ag_draw(NULL,&win->c,0,0);
}
dword accb_oninput(void * x,int action,ATEV * atev){
  ACONTROLP ctl  = (ACONTROLP) x;
  ACCBDP  d  = (ACCBDP) ctl->d;
  dword msg = 0;
  switch (action){
    case ATEV_MOUSEDN:
      {
        vibrate(30);
        d->pushed=1;
        msg=aw_msg(0,1,0,0);
        ctl->ondraw(ctl);
      }
      break;
    case ATEV_MOUSEUP:
      {
        d->pushed=0;
        if (aw_touchoncontrol(ctl,atev->x,atev->y))
          d->checked = !d->checked;
        msg=aw_msg(0,1,0,0);
        ctl->ondraw(ctl);
      }
      break;
    case ATEV_SELECT:
      {
        if (atev->d){
          vibrate(30);
          d->pushed=1;
        }
        else{
          d->pushed=0;
          d->checked = !d->checked;
        }
        msg=aw_msg(0,1,0,0);
        ctl->ondraw(ctl);
      }
      break;
  }
  return msg;
}
void afbox_changeboxtype(ACONTROLP ctl, byte t){
  ag_setbusy();
  AFBOXDP d = (AFBOXDP) ctl->d;
  if (d->acheck_signature != 177) return; //-- Not Valid Signature
  d->boxtype      = t;
  int i;
  for (i=0;i<d->itemn;i++){
    afbox_redrawitem(ctl,i);
  }
  ctl->ondraw(ctl);
  aw_redraw(ctl->win);
  ag_sync();
}
byte acopt_onfocus(void * x) {
  ACONTROLP   ctl = (ACONTROLP) x;
  ACOPTDP   d  = (ACOPTDP) ctl->d;
  d->focused = 1;
  
  if ((d->focusedItem == -1) && (d->itemn > 0)) {
    d->focusedItem = 0;
  }
  
  if ((d->focusedItem != -1) && (d->draweditemn > 0)) {
    acopt_redrawitem(ctl, d->focusedItem);
  }
  
  ctl->ondraw(ctl);
  return 1;
}
void afbox_setcheckall(ACONTROLP ctl, byte checked){
  AFBOXDP d = (AFBOXDP) ctl->d;
  if (d->acheck_signature != 177) return;
  int i;
  for (i=0;i<d->itemn;i++){
    AFBOXIP p = d->items[i];
    if (p->checked!=checked){
      p->checked=checked;
      afbox_redrawitem(ctl,i);
      d->check_n+=(checked)?1:-1;
    }
  }
  ctl->ondraw(ctl);
  aw_redraw(ctl->win);
  ag_sync();
  
  dword msg=aw_msg(d->changemsg,1,0,0);
  atouch_send_message(msg);
}
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;
}
dword acime2_oninput(void * x, int action, ATEV * atev) {
  ACONTROLP ctl   = (ACONTROLP) x;
  ACIMEDP  d      = (ACIMEDP) ctl->d;
  dword msg = 0;
  
  switch (action) {
    case ATEV_MOUSEUP: {
        if (d->pushedId < ACIME2_BTNCNT) {
          int keyID = d->pushedId;
          d->keyD[keyID]  = 0;
          d->pushedId     = 255;
          acime2_action(ctl, keyID, 1);
          
          if (((keyID < 27) && (keyID != 19)) || (keyID == 30) || (keyID == 29) || (keyID == 31)) {
            if (d->onShift == 1) {
              d->onShift = 0;
              int i;
              
              for (i = 0; i < ACIME2_BTNCNT; i++) {
                d->keyD[i] = 0;
              }
            }
          }
          
          ctl->ondraw(ctl);
          msg = aw_msg(0, 1, 0, 0);
        }
        else {
          d->pushedId = 255;
        }
      }
      break;
      
    case ATEV_MOUSEDN:
    case ATEV_MOUSEMV: {
        if ((d->pushedId != 200) && (d->pushedId != 254)) {
          int clientX = atev->x - ctl->x;
          int clientY = atev->y - ctl->y;
          
          if (clientY >= 0) {
            int i;
            
            for (i = 1; i < 5; i++) {
              if (clientY < (i * d->btnH)) {
                break;
              }
            }
            
            int r = i;
            byte idpos[5][2] = {
              {0,  9},
              {10, 18},
              {19, 27},
              {28, 32},
              {33, 38}
            };
            
            for (i = idpos[r - 1][0]; i < idpos[r - 1][1]; i++) {
              if (clientX < (d->keyX[i] + d->keyW[i])) {
                break;
              }
            }
            
            if (d->pushedId != i) {
              msg = aw_msg(0, 1, 0, 0);
              
              if (d->pushedId < ACIME2_BTNCNT) {
                d->keyD[d->pushedId]  = 0;
              }
              
              d->pushedId = i;
              acime2_action(ctl, i, 0);
              d->keyD[i]  = 0;
              ctl->ondraw(ctl);
              
              if (action == ATEV_MOUSEDN) {
                vibrate(30);
              }
            }
          }
        }
      }
      break;
  }
  
  return msg;
}
dword acopt_oninput(void * x, int action, ATEV * atev) {
  ACONTROLP ctl = (ACONTROLP) x;
  ACOPTDP d  = (ACOPTDP) 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)) {
              if ((d->touchedItem != -1) && (d->touchedItem != i)) {
                int tmptouch = d->touchedItem;
                d->touchedItem = -1;
                acopt_redrawitem(ctl, tmptouch);
              }
              
              int grp = d->items[i]->group;
              
              if ((d->selectedIndexs[grp] != -1) && (d->selectedIndexs[grp] != i)) {
                int tmpsidx = d->selectedIndexs[grp];
                d->selectedIndexs[grp] = -1;
                acopt_redrawitem(ctl, tmpsidx);
              }
              
              int prevfocus               = d->focusedItem;
              d->focusedItem              = i;
              d->touchedItem              = i;
              d->selectedIndexs[grp]  = i;
              
              if ((prevfocus != -1) && (prevfocus != i)) {
                acopt_redrawitem(ctl, prevfocus);
              }
              
              acopt_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;
          acopt_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;
                acopt_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;
              acopt_redrawitem(ctl, tmptouch);
            }
            
            vibrate(30);
            d->touchedItem = d->focusedItem;
            acopt_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;
              acopt_redrawitem(ctl, tmptouch);
            }
            
            int grp = d->items[d->focusedItem]->group;
            
            if ((d->selectedIndexs[grp] != -1) && (d->selectedIndexs[grp] != d->focusedItem)) {
              int tmpsidx = d->selectedIndexs[grp];
              d->selectedIndexs[grp] = -1;
              acopt_redrawitem(ctl, tmpsidx);
            }
            
            d->selectedIndexs[grp] = d->focusedItem;
            d->touchedItem = -1;
            acopt_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;
            }
          }
          
          acopt_redrawitem(ctl, prevfocus);
          acopt_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;
            }
          }
          
          acopt_redrawitem(ctl, prevfocus);
          acopt_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;
}
Ejemplo n.º 13
0
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);
}
Ejemplo n.º 14
0
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 imgbtn_onblur(void * x) {
  ACONTROLP   ctl = (ACONTROLP) x;
  IMGBTNDP  d  = (IMGBTNDP) ctl->d;
  d->focused = 0;
  ctl->ondraw(ctl);
}