中级会员
 
- 积分
- 239
- 金钱
- 239
- 注册时间
- 2018-6-16
- 在线时间
- 31 小时
|
10金钱
//检查
//listbox:listbox指针
//in_key:输入按键指针
//返回值:未用到
u8 listbox_check(_listbox_obj * listbox,void * in_key)
{
_in_obj *key=(_in_obj*)in_key;
_listbox_list * listx;
u16 endx;//条目显示区的尾端.
u16 tempindex;
u16 i;
u16 lastindex;
static u8 scrollbarflag=0;//scrollbar标记
switch(key->intype)
{
case IN_TYPE_TOUCH: //触摸屏按下了
if(listbox!=NULL)//listbox非空
{
endx=listbox->left+listbox->width-1;
if(listbox->scbv->totalitems>listbox->scbv->itemsperpage)//有滚动条
{
endx-=LBOX_SCB_WIDTH;
if(listbox->top<=key->y&&key->y<=(listbox->top+listbox->height)&&listbox->left<=key->x&&key->x<=(endx+LBOX_SCB_WIDTH))//在有效区域内(SCB+条目区域)
{
//在滚动条范围之内.
if((listbox->top<=key->y&&key->y<=(listbox->top+listbox->height)&&endx<=key->x&&key->x<=(endx+LBOX_SCB_WIDTH))||scrollbarflag==1)
{
if(listbox->sta&(1<<6))break; //是从list区划过来的,直接不执行
scrollbarflag=1; //标记scrollbar模式
tempindex=listbox->scbv->topitem;
key->x=listbox->scbv->left+1; //强制让x坐标在scrollbar里面
scrollbar_check(listbox->scbv,in_key);//滚动条检测
if(tempindex!=listbox->scbv->topitem)listbox_draw_list(listbox);
listbox->sta|=1<<7;
break;
}
}else scrollbarflag=0;
if((listbox->sta&0xc0)==(1<<7))//上次操作仅仅是在滚动条区域内
{
listbox->sta=0;
scrollbar_check(listbox->scbv,in_key);//滚动条检测
}
}
tempindex=listbox->sta&0x3f;//得到当前sta种的位置
if(listbox->top<=key->y&&key->y<=(listbox->top+listbox->height)&&listbox->left<=key->x&&key->x<(endx))//在items区域内
{
//itemperpage最大不能超过64!(按20一个index设计,这样64个list可以支持到64*20=1280垂直像素的屏)
for(i=0;i<listbox->scbv->itemsperpage;i++)//找到当前触屏按下的坐标在listbox种的index
{
if(key->y<=(listbox->top+(i+1)*gui_phy.listheight)&&key->y>=(listbox->top+i*gui_phy.listheight))break;
}
if((listbox->sta&(1<<6))==0)//编号还无效
{
listbox->sta|=1<<6; //标记有效
listbox->sta|=i; //记录编号
}else if((listbox->sta&(1<<7))==0)//还不是滑动
{
if(listbox->scbv->totalitems<=listbox->scbv->itemsperpage)break;//没滚动条,滑动无效
if(gui_disabs(i,(listbox->sta&0x3f))>1) listbox->sta|=1<<7;//滑动距离大于1个条目的间隙 标记滑动
}
if((listbox->sta&0xc0)==0xc0)//是滑动
{
lastindex=listbox->scbv->topitem;
if(tempindex>i)//减少了
{
listbox->sta&=0xc0;//清空上次的
listbox->sta|=i;//记录最近的index号
listbox->scbv->topitem+=tempindex-i;
if(listbox->scbv->topitem>=(listbox->scbv->totalitems-listbox->scbv->itemsperpage))listbox->scbv->topitem=listbox->scbv->totalitems-listbox->scbv->itemsperpage;
}else if(i>tempindex)//增加了
{
listbox->sta&=0xc0;//清空上次的
listbox->sta|=i;//记录最近的index号
i-=tempindex;
if(listbox->scbv->topitem>=i)listbox->scbv->topitem-=i;
else listbox->scbv->topitem=0;
}else break;
if(listbox->scbv->topitem!=lastindex)listbox_draw_listbox(listbox);//重画listbox
}
}else //按键松开了,或者滑出了
{
if(listbox->sta&(1<<7))//滑动
{
listbox->sta=0;
listbox->oldtime=GUI_TIMER_10MS;//记录当前时间
listbox->curnamepos=0;//清零
}else if(listbox->sta&(1<<6))//单点按下
{
listbox->dbclick=0; //双击标记清零
if((listbox->scbv->topitem+tempindex)==listbox->selindex)
{
listbox->dbclick|=1<<7; //标记双击了
listbox_2click_hook(listbox);//执行双击钩子函数
}else if((listbox->scbv->topitem+tempindex)<listbox->scbv->totalitems) //重新选择新的选项
{
if((listbox->selindex<(listbox->scbv->topitem+listbox->scbv->itemsperpage))&&(listbox->selindex>=listbox->scbv->topitem))//老的selindex在屏幕范围内
{
i=listbox->selindex-listbox->scbv->topitem;//老编号
listx=list_search(listbox->list,listbox->selindex);//得到listindex的名字
gui_fill_rectangle(listbox->left,listbox->top+i*gui_phy.listheight,endx-listbox->left+1,gui_phy.listheight,listbox->lbkcolor);//恢复底色
gui_show_ptstr(listbox->left,listbox->top+i*gui_phy.listheight+(gui_phy.listheight-listbox->font)/2,endx,gui_phy.lcdheight,0,listbox->lncolor,listbox->font,listx->name,1);//显示名字
}
listbox->selindex=listbox->scbv->topitem+tempindex;
listx=list_search(listbox->list,listbox->selindex);//得到listindex的名字
gui_fill_rectangle(listbox->left,listbox->top+tempindex*gui_phy.listheight,endx-listbox->left+1,gui_phy.listheight,listbox->lnselbkcolor);//填充选中后的底色
gui_show_ptstr(listbox->left,listbox->top+tempindex*gui_phy.listheight+(gui_phy.listheight-listbox->font)/2,endx,gui_phy.lcdheight,0,listbox->lnselcolor,listbox->font,listx->name,1);//显示名字
listbox->fname=listx->name;//获得当前选中的条目的名字
listbox->namelen=strlen((const char*)listbox->fname)*listbox->font/2;//名字的总长度
}
listbox->sta=0;
listbox->oldtime=GUI_TIMER_10MS;//记录当前时间
listbox->curnamepos=0;
}else
{
if(gui_disabs(listbox->oldtime,GUI_TIMER_10MS)>=5)//超过50ms了.
{
if(listbox->selindex>=listbox->scbv->topitem&&listbox->selindex<(listbox->scbv->topitem+listbox->scbv->itemsperpage))//选中条目在当前的显示范围内
{
i=endx-listbox->left;//得到显示文字区域的长度
if(i<listbox->namelen)//小于文字长度,就是不能够一次显示的
{
tempindex=listbox->selindex-listbox->scbv->topitem;
gui_fill_rectangle(listbox->left,listbox->top+tempindex*gui_phy.listheight,endx-listbox->left+1,gui_phy.listheight,listbox->lnselbkcolor);//填充选中后的底色
gui_show_ptstr(listbox->left,listbox->top+tempindex*gui_phy.listheight+(gui_phy.listheight-listbox->font)/2,endx,gui_phy.lcdheight,listbox->curnamepos,listbox->lnselcolor,listbox->font,listbox->fname,1);//显示名字
listbox->curnamepos++;
if(listbox->curnamepos+i>listbox->namelen+i/4)listbox->curnamepos=0;//循环显示
}
}
listbox->oldtime=GUI_TIMER_10MS;//记录当前时间
}
}
}
}
break;
case IN_TYPE_KEY: //按键数据
break;
case IN_TYPE_JOYPAD://手柄数据
break;
case IN_TYPE_MOUSE: //鼠标数据
break;
default:
break;
}
return 0;
}
如上函数所示,用红标线的语句怎么理解,是不是上面的语句和下面的语句反了?求大神指导~~~~~
|
|