menuGUI.h
上传用户:wealth48
上传日期:2022-06-24
资源大小:1701k
文件大小:7k
- #include "../src/gui/gui.h"
- #include "drv/klcd.h"
- //--------------------菜单控件位置------------------------------------
- structRECT staticRect[4]; //静态
- structRECT movingRect[30];//动态
- structRECT menuRect;//菜单框
- //-------------------------Gobal变量-------------------------------------
- int GuiState = 0;//界面状态:0代表启动界面,1代表菜单1界面,2代表菜单2界面
- int menu1Pos = 0;//菜单1位置
- int menu2Pos = 0;//菜单2位置
- extern U16* pbuf;
- U16 *LcdTempBuf;
- U16 *mainMenuBMP;
- U16 *menuList1BMP;
- U16 *numBMP[10];
- U16 *markBMP;
- U16 *cancalMarkBMP;
- U16 *startBMP;
- U16 *start1BMP;
- U16 *bootBMP[4];
- U16 *thanksBMP;
- U16 *endBMP;
- int bootFlag = 1;
- //------------------------------------------------------------------------
- void InitRect(){
- int i;
- GuiState = 1;//测试
-
- menuRect.left=80;//菜单框
- menuRect.top=80;
- menuRect.right=559;
- menuRect.bottom=409;
- staticRect[0].left=8;//上一页
- staticRect[0].top=216;
- staticRect[0].right=50;
- staticRect[0].bottom=260;
- staticRect[1].left=588;//下一页
- staticRect[1].top=218;
- staticRect[1].right=632;
- staticRect[1].bottom=263;
- staticRect[2].left=116;// 确认
- staticRect[2].top=435;
- staticRect[2].right=268;
- staticRect[2].bottom=471;
- staticRect[3].left=605;// 关闭
- staticRect[3].top=0;
- staticRect[3].right=639;
- staticRect[3].bottom=33;
-
- for(i = 0;i < 25;i++){
- movingRect[i].left=100;
- movingRect[i].top=91 + 70*i;
- movingRect[i].right=200;
- movingRect[i].bottom=91 + 70*i + 67;
- }
-
- }
- //--------------------------------ChoiceWhat---------------------------------------
-
-
-
- int ChoiceWhat(int x,int y){
-
- structRECT tempRect;
- int i;
- switch(GuiState){
- case 0:return 100;
- case 1:for(i = 0;i < 4;i++)
- if(IsInRect(&staticRect[i],x,y)) return 30+i;
- for(i = 0;i < 25;i++){
- if(!IsInRect(&menuRect,x,y))return 100;
- tempRect.left = 100;
- tempRect.top = movingRect[i].top -menu1Pos;
- tempRect.right = 200;
- tempRect.bottom = movingRect[i].bottom -menu1Pos;
- if(IsInRect(&tempRect,x,y))return i;
- }
- case 2:return 100;
-
- }
- }
- //---------------------------------滚动菜单----------------------------------
- void ScrollMenu(int distance){
-
- if(menu1Pos + distance <= 0&&distance < 0)distance = -menu1Pos;
- if(menu1Pos + distance >= 1500&& distance > 0)distance = 1500 - menu1Pos;
-
- pbuf = menuList1BMP + menu1Pos*kLCDWIDTH;
- pbuf += kLCDWIDTH * distance;
- menu1Pos += distance;
- kLCD_Part_Refresh(81,82,559,409);
-
- }
- //-----------------------------------初始化菜单------------------------------
- void InitMenuGUI(){
-
- int i;
-
- LcdTempBuf = malloc(2 * 640 * 480);
- mainMenuBMP = malloc(2 * 640 * 480);
- menuList1BMP = malloc(2 * 640*2000);
- numBMP[0] = malloc(2 * 72 * 67);
- numBMP[1] = malloc(2 * 72 * 67);
- numBMP[2] = malloc(2 * 72 * 67);
- numBMP[3] = malloc(2 * 72 * 67);
- numBMP[4] = malloc(2 * 72 * 67);
- numBMP[5] = malloc(2 * 72 * 67);
- numBMP[6] = malloc(2 * 72 * 67);
- numBMP[7] = malloc(2 * 72 * 67);
- numBMP[8] = malloc(2 * 72 * 67);
- numBMP[9] = malloc(2 * 72 * 67);
- markBMP = malloc(2 * 72 * 67);
- cancalMarkBMP = malloc(2 * 72 * 67);
- thanksBMP = malloc(2 * 328 * 86);
- endBMP = malloc(2 * 640 * 480);
-
- InitRect();
-
-
- LoadBMP(mainMenuBMP,"/sys/ucos/e-menu/mainMenu.bmp",640,480);
- LoadBMP(menuList1BMP,"/sys/ucos/e-menu/menuList.bmp",640,2000);
- LoadBMP(markBMP,"/sys/ucos/e-menu/mark.bmp",72,67);
- LoadBMP(cancalMarkBMP,"/sys/ucos/e-menu/cancalMark.bmp",72,67);
- LoadBMP(endBMP,"/sys/ucos/e-menu/end.bmp",640,480);
-
- //---------------------------------------------------
- LoadBMP(numBMP[0],"/sys/ucos/e-menu/0.bmp",72,67);
- LoadBMP(numBMP[1],"/sys/ucos/e-menu/1.bmp",72,67);
- LoadBMP(numBMP[2],"/sys/ucos/e-menu/2.bmp",72,67);
- LoadBMP(numBMP[3],"/sys/ucos/e-menu/3.bmp",72,67);
- LoadBMP(numBMP[4],"/sys/ucos/e-menu/4.bmp",72,67);
- LoadBMP(numBMP[5],"/sys/ucos/e-menu/5.bmp",72,67);
- LoadBMP(numBMP[6],"/sys/ucos/e-menu/6.bmp",72,67);
- LoadBMP(numBMP[7],"/sys/ucos/e-menu/7.bmp",72,67);
- LoadBMP(numBMP[8],"/sys/ucos/e-menu/8.bmp",72,67);
- LoadBMP(numBMP[9],"/sys/ucos/e-menu/9.bmp",72,67);
- //------------------------------------------------------
-
- LoadBMP(thanksBMP,"/sys/ucos/e-menu/thanks.bmp",328,86);
-
-
- bootFlag = 0;
- OSTimeDly(100);
-
- pbuf = LcdTempBuf;
- ClreaLCD();
- kLCD_Refresh();
- pbuf = mainMenuBMP;
-
- for(i = 320;i >= 0;i -= 5){
- kLCD_Part_Refresh(i,i*3/4,640 - i,480 - i*3/4);
- }
- kLCD_Refresh();
- ScrollMenu(0);
-
-
-
- }
- //-----------------------------------标志已选菜----------------------------------
- void Mark(int index){
- PaintBMP(pbuf,markBMP,192,movingRect[index].top - menu1Pos,72,67);
- kLCD_Part_Refresh(81,82,559,409);
-
- }
- //-----------------------------------取消标志------------------------------------
- void CancalMark(int index){
-
- PaintBMP(pbuf,cancalMarkBMP,192,movingRect[index].top - menu1Pos,72,67);
- kLCD_Part_Refresh(81,82,559,409);
- }
- //-----------------------------------显示数字------------------------------------
- void ShowNum(int x,int y,int num){
-
-
-
-
- int first_Nzero_flag = 0;
- int i = 0;
- pbuf = mainMenuBMP;
- kLCD_Part_Refresh(420,400,640,480);
- pbuf = LcdTempBuf;
- if(first_Nzero_flag|(num/10000)){
- first_Nzero_flag = 1;
- Uart_Printf(0,"%d",num/10000);
-
- PaintBMP(pbuf,numBMP[num/10000],x+i*31,y,72,67);
- kLCD_Part_Refresh(x+i*31,y,x+(i+1)*31,y+46);
- i++;
- }
- if(first_Nzero_flag|((num%10000)/1000)){
- first_Nzero_flag = 1;
-
- PaintBMP(pbuf,numBMP[(num%10000)/1000],x+i*31,y,72,67);
- kLCD_Part_Refresh(x+i*31,y,x+(i+1)*31,y+46);
- i++;
- Uart_Printf(0,"%d",(num%10000)/1000);
-
- }
- if(first_Nzero_flag|((num%1000)/100)){
- first_Nzero_flag = 1;
- PaintBMP(pbuf,numBMP[(num%1000)/100],x+i*31,y,72,67);
- kLCD_Part_Refresh(x+i*31,y,x+(i+1)*31,y+46);
- Uart_Printf(0,"%d",(num%1000)/100);
- i++;
- }
- if(first_Nzero_flag|((num%100)/10)){
- first_Nzero_flag = 1;
- PaintBMP(pbuf,numBMP[(num%100)/10],x+i*31,y,72,67);
- kLCD_Part_Refresh(x+i*31,y,x+(i+1)*31,y+46);
- Uart_Printf(0,"%d",(num%100)/10);
- i++;
- }
-
- PaintBMP(pbuf,numBMP[num%10],x+i*31,y,72,67);
- kLCD_Part_Refresh(x+i*31,y,x+(i+1)*31,y+46);
- Uart_Printf(0,"%d",num%10);
-
- Uart_Printf(0,"I:%d",i);
- pbuf = menuList1BMP + menu1Pos*kLCDWIDTH;
-
- }
- //-----------------------------------------点菜结束--------------------------------------------
- void EndSelect(){
-
- pbuf = LcdTempBuf;
- PaintBMP(pbuf,mainMenuBMP,0,0,640,480);
- PaintBMP(pbuf,thanksBMP,160,208,328,86);
- kLCD_Part_Refresh(81,82,559,409);
- pbuf = menuList1BMP;
- menu1Pos = 0;
- OSTimeDly(2000);
-
- }
- void CloseImage(){
-
- int i;
- pbuf = endBMP;
- for(i = 0;i <= 320;i += 8)
- {
- kLCD_Part_Refresh(0,0,640 - i,i*3/4);
- kLCD_Part_Refresh(640 - i,0,640,480-i*3/4);
- kLCD_Part_Refresh(i,480 - i*3/4,640,480);
- kLCD_Part_Refresh(0,i*3/4,i,480);
- }
- OSTimeDly(2000);
- pbuf = LcdTempBuf;
- ClreaLCD();
- kLCD_Refresh();
- }