//画list //listbox:listbox指针 void listbox_draw_list(_listbox_obj *listbox) { u16 i; u16 endx=0; u16 tempcolor; _listbox_list * listx; endx=listbox->left+listbox->width-1; //条目显示结束x坐标 if(listbox->scbv->totalitems>listbox->scbv->itemsperpage)endx-=LBOX_SCB_WIDTH;//需要滚动条了. gui_fill_rectangle(listbox->left,listbox->top,endx-listbox->left+1,listbox->height,listbox->lbkcolor);//清空为底色. listx=list_search(listbox->list,listbox->scbv->topitem);//得到顶部list信息(curitem在listbox中用于记录顶部index) for(i=0;i<listbox->scbv->itemsperpage;i++)//显示条目 { if((listbox->scbv->topitem+i)==listbox->selindex)//此项为选中项目 { gui_fill_rectangle(listbox->left,listbox->top+i*gui_phy.listheight,endx-listbox->left+1,gui_phy.listheight,listbox->lnselbkcolor);//填充底色 listbox->fname=listx->name;//获得当前选中的条目的名字 listbox->namelen=strlen((const char*)listbox->fname)*listbox->font/2;//名字的总长度 listbox->curnamepos=0; tempcolor=listbox->lnselcolor; }else tempcolor=listbox->lncolor; gui_show_ptstr(listbox->left,listbox->top+i*gui_phy.listheight+(gui_phy.listheight-listbox->font)/2,endx,gui_phy.lcdheight,0,tempcolor,listbox->font,listx->name,1); if(listx->nextlist==0)break; listx=listx->nextlist; } }
//画滚动条 //scbx:滚动条指针 void scrollbar_draw_scrollbar(_scrollbar_obj *scbx) { u32 scbactlen = 0; //滚动条可以滚动的空间长度 if(scbx == NULL) { return; //无效,直接退出 } gui_fill_rectangle(scbx->left, scbx->top, scbx->width, scbx->height, scbx->inbkcolor); gui_draw_rectangle(scbx->left, scbx->top, scbx->width, scbx->height, scbx->rimcolor); if((scbx->type & 0X03) == 0) { //标准滚动条 if((scbx->type & 0x80) == 0) { //水平滚动条 scrollbar_draw_btn(scbx->left, scbx->top, SCROLLBAR_PART_LEN, scbx->height, scbx->btncolor, scbx->rimcolor, SCROLLBAR_SIGN_RCOLOR, SCROLLBAR_SIGN_LEFT); scrollbar_draw_btn(scbx->left + scbx->width - SCROLLBAR_PART_LEN, scbx->top, SCROLLBAR_PART_LEN, scbx->height, scbx->btncolor, scbx->rimcolor, SCROLLBAR_SIGN_RCOLOR, SCROLLBAR_SIGN_RIGHT); scbactlen = scbx->width - 2 * SCROLLBAR_PART_LEN; //可供 滚动条滚动的空间范围 } else { //垂直滚动条 scrollbar_draw_btn(scbx->left, scbx->top, scbx->width, SCROLLBAR_PART_LEN, scbx->btncolor, scbx->rimcolor, SCROLLBAR_SIGN_RCOLOR, SCROLLBAR_SIGN_UP); scrollbar_draw_btn(scbx->left, scbx->top + scbx->height - SCROLLBAR_PART_LEN, scbx->width, SCROLLBAR_PART_LEN, scbx->btncolor, scbx->rimcolor, SCROLLBAR_SIGN_RCOLOR, SCROLLBAR_SIGN_DOWN); scbactlen = scbx->height - 2 * SCROLLBAR_PART_LEN; //可供 滚动条滚动的空间范围 } } else { //没有两端按钮的滚动条 if((scbx->type & 0x80) == 0) { scbactlen = scbx->width; //水平滚动条 } else { scbactlen = scbx->height; //垂直滚动条 } } if(scbx->itemsperpage > scbx->totalitems) { scbx->scbbarlen = scbactlen; } else { scbx->scbbarlen = (scbactlen * scbx->itemsperpage) / scbx->totalitems; //得到滚动条的长度 } scrollbar_setpos(scbx); }
//画滚动条的按键 //x,y,width,height:坐标及尺寸 //bkcolor:背景色 //rimcolor:边框颜色 //signcolor:符号的颜色 //signx:符号编号 0,上;1,下;2,左;3,右;4,垂直;5,水平; void scrollbar_draw_btn(u16 x, u16 y, u16 width, u16 height, u16 bkcolor, u16 rimcolor, u16 signcolor, u8 signx) { gui_fill_rectangle(x, y, width, height, bkcolor); //填充内部颜色 gui_draw_rectangle(x, y, width, height, rimcolor); //画外边框 if(width >= 8 && height >= 8) { //足够画图标 scrollbar_draw_sign(x + width / 2 - 4, y + height / 2 - 4, signcolor, signx); } }
static void gui_test_draw_desktop() { if (!gui_fill_picture("/bin/screen.bmp")) { gui_fill_rectangle(0, 0, MAX_X, MAX_Y, VGA_COLOR_BLUE); } }
//画出窗口 //windowx:窗口指针 void window_draw(_window_obj *windowx) { u8 winclosebtnsize = 0; //关闭按钮的尺寸 if(windowx == NULL) { return; //无效,直接退出 } if(windowx->type & (1 << 0)) { //圆角窗,仿android的时候,不支持按钮(放了难看) gui_draw_arcrectangle(windowx->left, windowx->top, windowx->width, windowx->captionheight, windowx->arcwinr, 1, windowx->captionbkcu, windowx->captionbkcd); //画出标题栏 gui_fill_rectangle(windowx->left, windowx->top + windowx->captionheight - windowx->arcwinr, windowx->arcwinr, windowx->arcwinr, windowx->captionbkcd); //把下部分不需要的半圆形的部分填充掉1 gui_fill_rectangle(windowx->left + windowx->width - windowx->arcwinr, windowx->top + windowx->captionheight - windowx->arcwinr, windowx->arcwinr, windowx->arcwinr, windowx->captionbkcd); //把下部分不需要的半圆形的部分填充掉2 gui_draw_arcrectangle(windowx->left, windowx->top + windowx->captionheight, windowx->width, windowx->height - windowx->captionheight, windowx->arcwinr, 1, windowx->windowbkc, windowx->windowbkc); //填充空白部分 gui_fill_rectangle(windowx->left, windowx->top + windowx->captionheight, windowx->arcwinr, windowx->arcwinr, windowx->windowbkc); //把上部分不需要的半圆形的部分填充掉1 gui_fill_rectangle(windowx->left + windowx->width - windowx->arcwinr, windowx->top + windowx->captionheight, windowx->arcwinr, windowx->arcwinr, windowx->windowbkc); //把上部分不需要的半圆形的部分填充掉2 gui_draw_arcrectangle(windowx->left, windowx->top, windowx->width, windowx->height, windowx->arcwinr, 0, ARC_WIN_RIM_COLOR, ARC_WIN_RIM_COLOR); //画边框 //画出标题栏 } else { //方角窗 //填充内部 gui_fill_rectangle(windowx->left, windowx->top, windowx->width, windowx->captionheight / 2, windowx->captionbkcu); //填充上半部分 gui_fill_rectangle(windowx->left, windowx->top + windowx->captionheight / 2, windowx->width, windowx->captionheight / 2, windowx->captionbkcd); //填充下半部分 gui_fill_rectangle(windowx->left, windowx->top + windowx->captionheight - 1, windowx->width, windowx->height - windowx->captionheight, windowx->windowbkc); //填充内部 //画边框 gui_draw_rectangle(windowx->left, windowx->top, windowx->width, windowx->height, STD_WIN_RIM_OUTC); //画外框 gui_draw_rectangle(windowx->left + 1, windowx->top + 1, windowx->width - 2, windowx->height - 2, STD_WIN_RIM_MIDC); //画中间框 gui_draw_rectangle(windowx->left + 2, windowx->top + windowx->captionheight - 1, windowx->width - 4, windowx->height - windowx->captionheight - 1, STD_WIN_RIM_INC); //画内框 if(windowx->type & (1 << 7)) { btn_draw(windowx->closebtn);//有按钮的时候需要画按钮. winclosebtnsize = WIN_BTN_SIZE; } } if(windowx->type & (1 << 5)) { gui_show_strmid(windowx->left, windowx->top, windowx->width, windowx->captionheight, windowx->captioncolor, windowx->font, windowx->caption); //显示标题 } else { gui_show_ptstr(windowx->left + WIN_BTN_OFFSIDE, windowx->top + (windowx->captionheight - windowx->font) / 2, windowx->left + windowx->width - 2 * WIN_BTN_OFFSIDE - winclosebtnsize, windowx->top + windowx->captionheight, 0, windowx->captioncolor, windowx->font, windowx->caption, 1); //靠左显示caption } }
//设置滚动条的位置 //scbx:滚动条指针 void scrollbar_setpos(_scrollbar_obj *scbx) { u16 scbpos; u16 scblen; u16 x, y, xlen, ylen; u8 scbtype; u8 scbplen; if((scbx->type & 0X03) == SCROLLBAR_TYPE_NBT) { scbplen = 0; //两端没有按钮 } else { scbplen = SCROLLBAR_PART_LEN; //两端有按钮 } if((scbx->type & 0x80) == SCROLLBAR_DIR_VER) { //垂直滚动条 scblen = scbx->height - 2 * scbplen - scbx->scbbarlen; //得到滚动条滚动空间的长度 x = scbx->left + 1; y = scbx->top + scbplen + 1; xlen = scbx->width - 2; ylen = scblen + scbx->scbbarlen - 2; } else { //水平滚动条 scblen = scbx->width - 2 * scbplen - scbx->scbbarlen; x = scbx->left + scbplen + 1; y = scbx->top + 1; xlen = scblen + scbx->scbbarlen - 2; ylen = scbx->height - 2; } gui_fill_rectangle(x, y, xlen, ylen, scbx->inbkcolor); //清空上次的位置 if(scbx->totalitems <= scbx->itemsperpage) { //总条目不够一页显示的 scbpos = scblen; } else if(scbx->topitem >= (scbx->totalitems - scbx->itemsperpage)) { //当前选择项大于等于最后一页的第一项 scbx->topitem = scbx->totalitems - scbx->itemsperpage; //范围限定在最后一页第一项 scbpos = scblen; } else { //不是最后一页 scbpos = (scbx->topitem * scblen) / (scbx->totalitems - scbx->itemsperpage); //计算当前滚动条的位置 } if((scbx->type & 0x80) == SCROLLBAR_DIR_VER) { //垂直滚动条 x = scbx->left; y = scbx->top + scbplen + scbpos; xlen = scbx->width; ylen = scbx->scbbarlen; scbtype = SCROLLBAR_SIGN_HOR; } else { //水平滚动条 x = scbx->left + scbplen + scbpos; y = scbx->top; xlen = scbx->scbbarlen; ylen = scbx->height; scbtype = SCROLLBAR_SIGN_VER; } scrollbar_draw_btn(x, y, xlen, ylen, scbx->btncolor, scbx->rimcolor, SCROLLBAR_SIGN_RCOLOR, scbtype); //重画滚动条 scrollbar_hook(scbx);//执行钩子函数 }
//闹铃处理(尺寸:44*20) //x,y:坐标 //返回值,处理结果 u8 calendar_alarm_msg(u16 x,u16 y) { u8 rval=0; u16 *lcdbuf=0; //LCD显存 lcdbuf=(u16*)gui_memin_malloc(44*20*2); //申请内存 if(lcdbuf) //申请成功 { app_read_bkcolor(x,y,44,20,lcdbuf); //读取背景色 gui_fill_rectangle(x,y,44,20,LIGHTBLUE); gui_draw_rectangle(x,y,44,20,BROWN); gui_show_num(x+2,y+2,2,RED,16,alarm.hour,0X81); gui_show_ptchar(x+2+16,y+2,x+2+16+8,y+2+16,0,RED,16,':',1); gui_show_num(x+2+24,y+2,2,RED,16,alarm.min,0X81); OSTaskSuspend(6); //挂起主任务 while(rval==0) { tp_dev.scan(0); if(tp_dev.sta&TP_PRES_DOWN)//触摸屏被按下 { if(app_tp_is_in_area(&tp_dev,x,y,44,20))//判断某个时刻,触摸屏的值是不是在某个区域内 { rval=0XFF;//取消 break; } } delay_ms(5); if(system_task_return)break; //需要返回 } app_recover_bkcolor(x,y,44,20,lcdbuf); //读取背景色 }else rval=1; system_task_return=0; alarm.ringsta&=~(1<<7); //取消闹铃 calendar_alarm_init((_alarm_obj*)&alarm,&calendar); //重新初始化闹钟 gui_memin_free(lcdbuf); OSTaskResume(6); //恢复主任务 system_task_return=0; return rval; }
//检查 //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; }