// ========================================================================= // 函数功能:计算目的菜单项相对源菜单项的位置 // 输入参数:DestMenuitem:目的菜单项,SrcMenuitem,源菜单项 // 输出参数:Relative,目的菜单项相对于源菜单项的位置,负数表示前面,正表示后面, // 返回值 : // 说明 :-128表示出错了,顺序是从嫡长子到最小子的方向 // ========================================================================= bool_t CalPosRelative2SrcMenuitem(struct menu_item * DestMenuitem, struct menu_item *SrcMenuitem, s8 *RelaPos) { bool_t result=false; u8 num1=0,num2=0;//用来计算菜单的序号 s8 num=0; if((NULL==DestMenuitem)||(NULL==SrcMenuitem))//参数检查 { printf("Invalid parameter---CalPosRelative2SrcMenuitem\n"); return result; } if(GetParMenuitem(DestMenuitem)!=GetParMenuitem(SrcMenuitem))//不是同一层菜单 { printf("Not same layers----CalPosRelative2SrcMenuitem\n"); return result; } //计算他们的序号 num1=CalMenuitemNumber(DestMenuitem); num2=CalMenuitemNumber(SrcMenuitem); if((num1==0)||(num2==0)) { return result; } else { num=num1-num2; *RelaPos=num; result=true; return result; } }
// ============================================================================================== // 函数功能:针对九格显示的显示参数 // 输入参数:operatingDispara,当前正在操作的显示参数,myCoordinatePoint,鼠标或者触摸的坐标 // 输出参数: // 返回值 :经过更新的当前正在操作的菜单项 // 说明 :切换到相应的坐标的菜单项。(目前只支持在菜单之间的切换,不包括菜单项的展开和返回) // ============================================================================================== struct menu_displaypara *touchlcdaction3by3(struct menu_displaypara *operatingDispara,\ struct coordinate_point myCoordinatePoint) { struct tagRectangle temp_rec={0,0,0,0}; s8 menuNum=0,menuitemNumber=0; s8 step=0;//跳转的步长 s8 FNumber=0; s8 ONumber=0; s8 Line=0; s8 Row=0; //内部使用,不用做参数检查 temp_rec.left=operatingDispara->CurWin->absx0; temp_rec.right=operatingDispara->CurWin->absx0+operatingDispara->CurWin->right-operatingDispara->CurWin->left; temp_rec.top=operatingDispara->CurWin->absy0; temp_rec.bottom=operatingDispara->CurWin->absy0+operatingDispara->CurWin->bottom-operatingDispara->CurWin->top; if(JudgeCoordinatePointInRec(temp_rec,myCoordinatePoint))//先看是否在窗口内,不是的话什么也不做 { menuNum=CalDisBettween2Menuitem(operatingDispara->FVisualMenuitem,operatingDispara->LVisualMenuitem)+1; temp_rec.left+=(operatingDispara->CurWin->right-operatingDispara->CurWin->left-cn_space_margin)/2-(operatingDispara->MenuitemSpace.width*3)/2;; temp_rec.top+=(operatingDispara->CurWin->bottom-operatingDispara->CurWin->top-cn_space_margin)/2-(operatingDispara->MenuitemSpace.height*3)/2; temp_rec.right=temp_rec.left+operatingDispara->MenuitemSpace.width*3+cn_space_margin; temp_rec.bottom=temp_rec.top+operatingDispara->MenuitemSpace.height*3+cn_space_margin; if(JudgeCoordinatePointInRec(temp_rec,myCoordinatePoint))//看是否在窗口的可视区域内,否则什么都不用做 { //看看落在第几个菜单项,从第一个可视菜单项算起 if((operatingDispara->MenuitemSpace.height!=0)&&(0!=operatingDispara->MenuitemSpace.width)) { //之所以-1,是因为我们算的是距离第一个可视菜单项的位置 Line=((myCoordinatePoint.y-temp_rec.top)-cn_space_margin/2)/(operatingDispara->MenuitemSpace.height); Row=((myCoordinatePoint.x-temp_rec.left)-cn_space_margin/2)/(operatingDispara->MenuitemSpace.width); menuitemNumber=CalDisBettween2Menuitem(operatingDispara->FVisualMenuitem,operatingDispara->LVisualMenuitem); if((Line*3+Row)<=menuitemNumber)//在可视菜单项中 { FNumber=CalMenuitemNumber(operatingDispara->FVisualMenuitem); ONumber=CalMenuitemNumber(operatingDispara->OperatingMenuitem); step=FNumber+Line*3+Row-ONumber; // printf("Fnumber=%d,Onumber=%d, L=%d R=%d menuitemnumber=%d step=%d\n",FNumber,ONumber,Line,Row,\ // menuitemNumber,step); goto_menuitem_inslayers(operatingDispara,step); } } else { // return operatingDispara; } } else { // return operatingDispara; } } else { // return operatingDispara; } return operatingDispara; }
// ============================================================================================== // 函数功能:针对水平显示的显示参数进行触摸的反应 // 输入参数:operatingDispara,当前正在操作的显示参数,myCoordinatePoint,鼠标或者触摸的坐标 // 输出参数: // 返回值 :经过更新的当前正在操作的菜单项 // 说明 :切换到相应的坐标的菜单项。(目前只支持在菜单之间的切换,不包括菜单项的展开和返回) // ============================================================================================== struct menu_displaypara *touchlcdactionhorizontal(struct menu_displaypara *operatingDispara,\ struct coordinate_point myCoordinatePoint) { u8 menuNum=0,menuitemNumber=0; s8 step=0;//跳转的步长 u8 FNumber=0; u8 ONumber=0; struct tagRectangle temp_rec={0,0,0,0}; //内部使用,不用做参数检查 temp_rec.left=operatingDispara->CurWin->absx0; temp_rec.right=operatingDispara->CurWin->absx0+operatingDispara->CurWin->right-operatingDispara->CurWin->left; temp_rec.top=operatingDispara->CurWin->absy0; temp_rec.bottom=operatingDispara->CurWin->absy0+operatingDispara->CurWin->bottom-operatingDispara->CurWin->top; if(JudgeCoordinatePointInRec(temp_rec,myCoordinatePoint))//先看是否在窗口内,不是的话什么也不做 { menuNum=CalDisBettween2Menuitem(operatingDispara->FVisualMenuitem,operatingDispara->LVisualMenuitem)+1; temp_rec.left+=cn_space_margin/4; temp_rec.top+=cn_space_margin/4; temp_rec.right=temp_rec.left+menuNum*(operatingDispara->MenuitemSpace.width); temp_rec.bottom=temp_rec.top+operatingDispara->MenuitemSpace.height; if(JudgeCoordinatePointInRec(temp_rec,myCoordinatePoint))//看是否在窗口的可视区域内,否则什么都不用做 { //看看落在第几个菜单项,从第一个可视菜单项算起 if(operatingDispara->MenuitemSpace.width!=0) { //之所以-1,是因为我们算的是距离第一个可视菜单项的位置 menuitemNumber=((myCoordinatePoint.x-temp_rec.left)-1)/(operatingDispara->MenuitemSpace.width); // FNumber=CalMenuitemNumber(operatingDispara->FVisualMenuitem); ONumber=CalMenuitemNumber(operatingDispara->OperatingMenuitem); step=FNumber+menuitemNumber-ONumber; // printf("Fnumber=%d,Onumber=%d,menuitemnumber=%d step=%d\n",FNumber,ONumber,menuitemNumber,step); goto_menuitem_inslayers(operatingDispara,step); } else { // return operatingDispara; } } else { // return operatingDispara; } } else { // return operatingDispara; } return operatingDispara; }
// ========================================================================= // 函数功能:画状态条(最右边) // 输入参数:dispara:代表的显示参数 // 输出参数: // 返回值 : // 说明 :一般而言dispara的所有菜单项因为屏幕的原因不可能同时显示出来,此状态条 // 代表当前操作的菜单项在同层所有菜单中的位置 // ========================================================================= void drawstatecontent_9cell_rightside(struct menu_displaypara *dispara) { u8 numOp=0; u8 numTotal=0; s32 lengthT=0; s32 LengthE=0; struct tagRectangle state_area={0,0,0,0}; numOp=CalMenuitemNumber(dispara->OperatingMenuitem); numTotal=CalMenuitemNum(dispara->FVisualMenuitem); //复原颜色 state_area.left=dispara->CurWin->right-dispara->CurWin->left-cn_column_space; state_area.right=dispara->CurWin->right-dispara->CurWin->left; state_area.top=0; state_area.bottom=dispara->CurWin->bottom-dispara->CurWin->top; GK_ApiFillRect(dispara->CurWin, &state_area, color_back, 0,CN_FILLRECT_MODE_N,0); //标志当前的可视区 lengthT=state_area.bottom-state_area.top; //提高精度; lengthT=lengthT*1000; LengthE=(lengthT+numTotal-1)/numTotal; state_area.top=(numOp-1)*LengthE; state_area.top=(state_area.top)/1000; state_area.bottom=(numOp)*LengthE; state_area.bottom=(state_area.bottom)/1000; GK_ApiFillRect(dispara->CurWin, &state_area, color_light, 0,CN_FILLRECT_MODE_N,0); GK_ApiSyncShow(CN_TIMEOUT_FOREVER); return; }
// ========================================================================= // 函数功能:计算同层两个菜单项之间的距离(间隔几个菜单项), // 输入参数:menuitem1,第一个菜单项,menuitem2,第二个菜单项 // 输出参数: // 返回值 :当前菜单项是同层菜单项的第几个 // 说明 :0xFF表示出错了,顺序是从嫡长子到最小子的方向 // ========================================================================= u8 CalDisBettween2Menuitem(struct menu_item * menuitem1, struct menu_item *menuitem2 ) { u8 result;//计算结果 u8 num1=0,num2=0;//用来计算菜单的序号 if((NULL==menuitem1)||(NULL==menuitem2))//参数检查 { printf("Invalid parameter--CalDisBetween2Menuitem!\n"); return 0xFF; } if(GetParMenuitem(menuitem1)!=GetParMenuitem(menuitem2))//不是同一层菜单 { printf("They are not the same slayers!\n"); return 0xFF; } //计算他们的序号 //计算他们的序号 num1=CalMenuitemNumber(menuitem1); num2=CalMenuitemNumber(menuitem2); if((num1==0)||(num2==0)) { return 0xFF; } else { if(num1>num2) { result=num1-num2; } else { result=num2-num1; } return result; } }
// ========================================================================= // 函数功能:根据九格的形式进行显示项的调整 // 输入参数:待调整的显示参数dispara // 输出参数: // 返回值 : // 说明 :将修改显示参数的FVisualMenuitem和LVisualMenuitem,对于主菜单则不会修改, // 考虑了需要滚屏的情况,尽最大可能的显示更多的菜单项 // ========================================================================= void adjustvisualmenuitem_9cell(struct menu_displaypara *dispara) { u8 dis_num;//窗口可以显示的菜单项条目 u8 OperaNumber=0; u8 FVisualNumber=0; u8 LVisualNumber=0; s32 dis_height;//可视域的宽度 s32 deep_limit; s32 deep_cal; struct menu_item *BBmenuitem=NULL,*LBmenuitem=NULL,*tempmenuitem=NULL; //参数检查 if((NULL==dispara)||(NULL==dispara->OperatingMenuitem)) { printf("Invalid parameter----adjustvisualmenuitem_9cell\n"); return; } if(NULL==dispara->pre) { // printf("No need to adjsutVisualMenuitem for main menuitem!\n"); dis_num=9; } else { deep_cal=dispara->CurWin->absy0+dispara->CurWin->bottom-dispara->CurWin->top; deep_limit=dispara->AppWin->absy0+dispara->AppWin->bottom-dispara->AppWin->top; if(deep_cal>deep_limit)//有超出的部分 { dis_height=deep_limit-dispara->CurWin->absy0; } else { dis_height=deep_cal-dispara->CurWin->absy0; } if(dis_height==0) { printf("Menu space is NULL, so do nothing!\n"); return; } dis_num=dis_height/(dispara->MenuitemSpace.height); } BBmenuitem=GetBBmenuitem(dispara->OperatingMenuitem); LBmenuitem=GetLBmenuitem(dispara->OperatingMenuitem); tempmenuitem=dispara->OperatingMenuitem; if(dis_num>=CalMenuitemNum(dispara->OperatingMenuitem))//能够容纳全部; { dispara->FVisualMenuitem=BBmenuitem; dispara->LVisualMenuitem=LBmenuitem; } else//容纳不了 { //考虑翻页的情况 FVisualNumber=CalMenuitemNumber(dispara->FVisualMenuitem); LVisualNumber=CalMenuitemNumber(dispara->LVisualMenuitem); OperaNumber=CalMenuitemNumber(dispara->OperatingMenuitem); if(OperaNumber<FVisualNumber)//当前操作项已经转到第一显示项前面,向前翻一页 { if(dispara->OperatingMenuitem==BBmenuitem)//从最未位到达最前面,因为是循环的 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将LastVisual指针后调 { if(tempmenuitem==LBmenuitem) { break; } tempmenuitem=GetNextMenuitem(tempmenuitem); dis_num--; } dispara->LVisualMenuitem=tempmenuitem; dispara->FVisualMenuitem=dispara->OperatingMenuitem; } else//顺序到达的 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将SlayerFrist指针前调 { if(tempmenuitem==BBmenuitem) { break; } tempmenuitem=GetPreMenuitem(tempmenuitem); dis_num--; } dispara->FVisualMenuitem=tempmenuitem; dispara->LVisualMenuitem=dispara->OperatingMenuitem; } } else if(OperaNumber>LVisualNumber)//当前操作项已经转到最后显示项后面,向后翻一页 { if(dispara->OperatingMenuitem==LBmenuitem)//从最前位到达最后面,因为是循环的 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将FirstVisual指针后调 { if(tempmenuitem==BBmenuitem) { break; } tempmenuitem=GetPreMenuitem(tempmenuitem); dis_num--; } dispara->FVisualMenuitem=tempmenuitem; dispara->LVisualMenuitem=dispara->OperatingMenuitem; } else//顺序到达的 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将SlayerFrist指针前调 { if(tempmenuitem==LBmenuitem) { break; } tempmenuitem=GetNextMenuitem(tempmenuitem); dis_num--; } dispara->LVisualMenuitem=tempmenuitem; dispara->FVisualMenuitem=dispara->OperatingMenuitem; } } else//没有超出显示页,尽可能的显示多 { if(dis_num<=CalDisBettween2Menuitem(dispara->FVisualMenuitem, dispara->LVisualMenuitem))//在最初始分配的时候会出现 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将SlayerFrist指针前调 { if(tempmenuitem==BBmenuitem) { break; } tempmenuitem=GetPreMenuitem(tempmenuitem); dis_num--; } dispara->FVisualMenuitem=tempmenuitem; tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将SlayerLast指针后调 { if(tempmenuitem==LBmenuitem) { break; } tempmenuitem=GetNextMenuitem(tempmenuitem); dis_num--; } dispara->LVisualMenuitem=tempmenuitem; } else { //不予改变可视的第一项和最后一项 } } } //进行调试的信息,看看到底对否 // printf("BB_menuitem=%s\n",BBmenuitem->node.name); // printf("Fv_menuitem=%s\n",dispara->FVisualMenuitem->node.name); // printf("Op_menuitem=%s\n",dispara->OperatingMenuitem->node.name); // printf("Lv_menuitem=%s\n",dispara->LVisualMenuitem->node.name); // printf("LB_menuitem=%s\n\n",LBmenuitem->node.name); return; }
// ========================================================================= // 函数功能:根据下拉模进行显示项的调整 // 输入参数:待调整的显示参数dispara // 输出参数: // 返回值 : // 说明 :将修改显示参数的FVisualMenuitem和LVisualMenuitem,对于主菜单则不会修改, // 考虑了需要滚屏的情况,尽最大可能的显示更多的菜单项 // ========================================================================= void adjustvisualmenuitem_pull(struct menu_displaypara *dispara) { u8 dis_num;//窗口可以显示的菜单项条目 u8 OperaNumber=0; u8 FVisualNumber=0; u8 LVisualNumber=0; s32 length_Visual;//可视域的宽度 s32 length_E;//每条菜单项占用的长度,水平指的是width,垂直指的是height struct menu_item *BBmenuitem=NULL,*LBmenuitem=NULL,*tempmenuitem=NULL; //参数检查 if((NULL==dispara)||(NULL==dispara->OperatingMenuitem)) { printf("Invalid para for Adjust!\n"); return; } if(NULL==dispara->pre)//主菜单,横向 { length_Visual=dispara->CurWin->right-dispara->CurWin->left; // deep_limit=dispara->AppWin->absx0+dispara->AppWin->right-dispara->AppWin->left; length_E=dispara->MenuitemSpace.width; } else//子菜单,纵向 { length_Visual=dispara->CurWin->bottom-dispara->CurWin->top; // deep_limit=dispara->AppWin->absy0+dispara->AppWin->bottom-dispara->AppWin->top; length_E=dispara->MenuitemSpace.height; } if(length_E==0) { printf("Menu space is NULL, so do nothing!\n"); return; } dis_num=length_Visual/(length_E); BBmenuitem=GetBBmenuitem(dispara->OperatingMenuitem); LBmenuitem=GetLBmenuitem(dispara->OperatingMenuitem); tempmenuitem=dispara->OperatingMenuitem; if(dis_num>=CalMenuitemNum(dispara->OperatingMenuitem))//能够容纳全部; { dispara->FVisualMenuitem=BBmenuitem; dispara->LVisualMenuitem=LBmenuitem; } else//容纳不了 { //考虑翻页的情况 FVisualNumber=CalMenuitemNumber(dispara->FVisualMenuitem); LVisualNumber=CalMenuitemNumber(dispara->LVisualMenuitem); OperaNumber=CalMenuitemNumber(dispara->OperatingMenuitem); if(OperaNumber<FVisualNumber)//当前操作项已经转到第一显示项前面,向前翻一页 { if(dispara->OperatingMenuitem==BBmenuitem)//从最未位到达最前面,因为是循环的 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将LastVisual指针后调 { if(tempmenuitem==LBmenuitem) { break; } tempmenuitem=GetNextMenuitem(tempmenuitem); dis_num--; } dispara->LVisualMenuitem=tempmenuitem; dispara->FVisualMenuitem=dispara->OperatingMenuitem; } else//顺序到达的 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将SlayerFrist指针前调 { if(tempmenuitem==BBmenuitem) { break; } tempmenuitem=GetPreMenuitem(tempmenuitem); dis_num--; } dispara->FVisualMenuitem=tempmenuitem; dispara->LVisualMenuitem=dispara->OperatingMenuitem; } } else if(OperaNumber>LVisualNumber)//当前操作项已经转到最后显示项后面,向后翻一页 { if(dispara->OperatingMenuitem==LBmenuitem)//从最前位到达最后面,因为是循环的 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将FirstVisual指针后调 { if(tempmenuitem==BBmenuitem) { break; } tempmenuitem=GetPreMenuitem(tempmenuitem); dis_num--; } dispara->FVisualMenuitem=tempmenuitem; dispara->LVisualMenuitem=dispara->OperatingMenuitem; } else//顺序到达的 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将SlayerFrist指针前调 { if(tempmenuitem==LBmenuitem) { break; } tempmenuitem=GetNextMenuitem(tempmenuitem); dis_num--; } dispara->LVisualMenuitem=tempmenuitem; dispara->FVisualMenuitem=dispara->OperatingMenuitem; } } else//没有超出显示页,尽可能的显示多 { if(dis_num<=CalDisBettween2Menuitem(dispara->FVisualMenuitem, dispara->LVisualMenuitem))//在最初始分配的时候会出现 { tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将SlayerFrist指针前调 { if(tempmenuitem==BBmenuitem) { break; } tempmenuitem=GetPreMenuitem(tempmenuitem); dis_num--; } dispara->FVisualMenuitem=tempmenuitem; tempmenuitem=dispara->OperatingMenuitem; while(dis_num>1) //将SlayerLast指针后调 { if(tempmenuitem==LBmenuitem) { break; } tempmenuitem=GetNextMenuitem(tempmenuitem); dis_num--; } dispara->LVisualMenuitem=tempmenuitem; } else { //不予改变可视的第一项和最后一项 } } } //进行调试的信息,进行显示校对,看是否正确。 // printf("BB_menuitem=%s\n",BBmenuitem->node.name); // printf("Fv_menuitem=%s\n",dispara->FVisualMenuitem->node.name); // printf("Op_menuitem=%s\n",dispara->OperatingMenuitem->node.name); // printf("Lv_menuitem=%s\n",dispara->LVisualMenuitem->node.name); // printf("LB_menuitem=%s\n\n",LBmenuitem->node.name); return; }