⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu.c

📁 这是模仿zlg_GUI写的一个嵌入式GUI,采用3510手机屏.
💻 C
字号:
#include"MYGUIConfig.h"

/****************************************************************************
                显示主菜单,加上边框。
****************************************************************************/
uint8  GUI_MMenuDraw(MMENU *men)
{  WINDOWS  *mwin;
   uint8  i;
   uint8  xx;

   /* 参数过滤 */
   if( (men->no)==0 ) return(0);
   
   mwin = men->win;						// 取得窗口句柄
   /* 判断是否可以显示主菜单 */
   if( (mwin->hight)<50 ) return(0);
   if( (mwin->with)<50 ) return(0);
   
   /* 画菜单条,并显示菜主单 */
   GUI_HLine(mwin->x, mwin->y + 22, mwin->x + mwin->with - 1);
   
   xx = mwin->x;
   for(i=0; i<(men->no); i++)
   {  if( (xx+MMENU_WIDTH) > (mwin->x + mwin->with) ) return(0);
      
      GUI_PutNoStr(xx+2, mwin->y + 14, men->str[i], 4);// 书写主菜单文字
      xx += MMENU_WIDTH;
      GUI_RLine(xx, mwin->y + 12, mwin->y + 22);	// 显示主菜单分界线     
   }
   
   return(1);
}


/****************************************************************************
当前主菜单,加下划线,颜色取反
no:0~2
****************************************************************************/
void  GUI_MMenuSelect(MMENU *men, uint8 no)
{  WINDOWS  *mwin;
   uint8  xx,color;

   //参数过滤 
   if( (men->no)==0 ) return;
   if( no>(men->no) ) return;
  
   mwin = men->win;						// 取得窗口句柄
   // 判断是否可以显示主菜单 
   if( (mwin->hight)<50 ) return;
   if( (mwin->with)<50 ) return;
   
   // 颜色取反
   xx = mwin->x + no*MMENU_WIDTH;
   
   color=LCD_BGColor;
   LCD_BGColor=LCD_ZiColor;
   LCD_ZiColor=color;
   
   GUI_PutNoStr(xx+2, mwin->y + 14, men->str[no], 4);// 书写主菜单文字
   
   color=LCD_BGColor;
   LCD_BGColor=LCD_ZiColor;
   LCD_ZiColor=color;
  }

/****************************************************************************
         取消当前主菜单,恢复原来状态
****************************************************************************/
void  GUI_MMenuNSelect(MMENU *men, uint8 no)
{  
   WINDOWS  *mwin;
   uint8  xx;

   //参数过滤 
   if( (men->no)==0 ) return;
   if( no>(men->no) ) return;
  
   mwin = men->win;						// 取得窗口句柄
   //判断是否可以显示主菜单 
   if( (mwin->hight)<50 ) return;
   if( (mwin->with)<50 ) return;
   
   xx = mwin->x + no*MMENU_WIDTH;
   GUI_PutNoStr(xx+2, mwin->y + 14, men->str[no], 4);// 书写主菜单文字
}

/****************************************************************************
       显示子菜单,加上边框。
****************************************************************************/
uint8  GUI_SMenuDraw(SMENU *men)
{  
   WINDOWS  *mwin;
   uint32   xx, yy;
   uint8    i,color;

   mwin = men->win;
   //判断是否可以显示主菜单 
   if( (mwin->hight)<50 ) return(0);
   if( (mwin->with)<50 ) return(0);
    
   //画菜子单项。下拉子菜单,以向左下拉为原则,若右边溢出则以右下拉显示 
   xx = mwin->x;
   xx += (men->mmenu_no)*MMENU_WIDTH;
   yy = mwin->y + 22;
   yy +=  (men->no) * 11 + 2;
   if( (xx+SMENU_WIDTH) <= (mwin->x + mwin->with - 1) ) 
   {  
      //以左下拉为原则显示子菜单 
      if( (men->mmenu_no) == 0 )
      {  GUI_RLine(xx+SMENU_WIDTH, mwin->y + 22, yy);
         GUI_HLine(xx, yy, xx+SMENU_WIDTH);
      }
      else
      {  GUI_Rectangle(xx, mwin->y + 22, xx+SMENU_WIDTH, yy);
      }
      GUI_HLine(xx+1, mwin->y + 22, xx+MMENU_WIDTH-1);
      
   }
   else
   {  
      //以右下拉为原则 
      if( (xx+MMENU_WIDTH) == (mwin->x + mwin->with - 1) )
      {  
        GUI_RLine(xx-(SMENU_WIDTH-MMENU_WIDTH), mwin->y + 22, yy);
        GUI_HLine(xx-(SMENU_WIDTH-MMENU_WIDTH), yy, xx+MMENU_WIDTH);
         
      }
      else
      {  
        GUI_Rectangle(xx-(SMENU_WIDTH-MMENU_WIDTH), mwin->y + 22, xx+MMENU_WIDTH, yy);
      }
      GUI_HLine(xx+1, mwin->y + 22, xx+MMENU_WIDTH-1);
      
      xx = xx-(SMENU_WIDTH-MMENU_WIDTH);
   }
   
   // 显示菜单文字 
   xx++;
   yy = mwin->y + 22 + 2;
   for(i=0; i<(men->no); i++)
   {  if( i == (men->state) )	// 判断所选择的菜单项
      {  
         
         color=LCD_PenColor;
         LCD_PenColor=LCD_BGColor;
         GUI_RectangleFill(xx, yy, xx+SMENU_WIDTH-2, yy+10);
         LCD_PenColor=color;
         
         color=LCD_BGColor;
         LCD_BGColor=LCD_ZiColor;
         LCD_ZiColor=color;
         
         GUI_PutNoStr(xx+1, yy+1, men->str[i], 6);			// 书写子菜单文字
         
         color=LCD_BGColor;
         LCD_BGColor=LCD_ZiColor;
         LCD_ZiColor=color;
      }
      else
      {  
         color=LCD_PenColor;
         LCD_PenColor=LCD_BGColor;
         GUI_RectangleFill(xx, yy, xx+SMENU_WIDTH-2, yy+10);
         LCD_PenColor=color;
         // 显示菜单字符 
         GUI_PutNoStr(xx+1, yy+1, men->str[i], 6);			// 书写子菜单文字
        
      
      }   
      
      yy += 11;
   }
    
   return(1);
}

/****************************************************************************
                   消隐子菜单项
****************************************************************************/
uint8  GUI_SMenuHide(SMENU *men)
{  
   WINDOWS  *mwin;
   uint8    xx, yy,color;

   mwin = men->win;
   //判断是否可以显示主菜单 
   if( (mwin->hight)<50 ) return(0);
   if( (mwin->with)<50 ) return(0);
    
   //画菜子单项。下拉子菜单,以向左下拉为原则,若右边溢出则以右下拉显示 
   xx = mwin->x;
   xx +=  (men->mmenu_no)*MMENU_WIDTH;
   yy = mwin->y + 22;
   yy +=  (men->no) * 11 + 2;
   
   if( (xx+SMENU_WIDTH) <= (mwin->x + mwin->with - 1) ) 
   {  // 以左下拉为原则显示子菜单 
      if( (men->mmenu_no) == 0 )
      { 
        color=LCD_PenColor;
        LCD_PenColor=LCD_BGColor;
        GUI_RectangleFill(xx+1, mwin->y + 22+1, xx+SMENU_WIDTH, yy);
        LCD_PenColor=color;
      }
      else
      {  
        color=LCD_PenColor;
        LCD_PenColor=LCD_BGColor;
        GUI_RectangleFill(xx, mwin->y + 22+1, xx+SMENU_WIDTH, yy);
        LCD_PenColor=color;
      }
      GUI_HLine(xx+1, mwin->y + 22, xx+MMENU_WIDTH-1);
   }
   else
   {  // 以右下拉为原则 
      if( (xx+MMENU_WIDTH) == (mwin->x + mwin->with - 1) )
      {  
        color=LCD_PenColor;
        LCD_PenColor=LCD_BGColor;
        GUI_RectangleFill(xx-(SMENU_WIDTH-MMENU_WIDTH), mwin->y + 22+1, xx+MMENU_WIDTH-1, yy);
        LCD_PenColor=color;
      }
      else
      {  
        color=LCD_PenColor;
        LCD_PenColor=LCD_BGColor;
        GUI_RectangleFill(xx-(SMENU_WIDTH-MMENU_WIDTH), mwin->y + 22+1, xx+MMENU_WIDTH, yy);
        LCD_PenColor=color;
      }
      GUI_HLine(xx+1, mwin->y + 22, xx+MMENU_WIDTH-1);
   }
    
   return(1);
}


/****************************************************************************
                 显示图标菜单。
****************************************************************************/
uint8  GUI_MenuIcoDraw(MENUICO *ico)
{  
   uint8 color;
   // 参数过滤 
   if( ( (ico->x)<1 ) || ( (ico->x)>(GUI_LCM_XMAX-34 ) ) ) return(0);	// 显示起始地址判断
   if( ( (ico->icodat)==NULL ) || ( (ico->title)==NULL ) ) return(0);	// 显示数据内容判断
   
   GUI_LoadPic(ico->x, ico->y, (uint8 *) ico->icodat, 32, 32);		// 显示ICO图32x32
   
   color=LCD_PenColor;
   LCD_PenColor=LCD_BGColor;
   GUI_HLine(ico->x, ico->y+32, ico->x+32);		                // 显示一空行
   LCD_PenColor=color;
     
   if( (ico->state)==0 )
   {
     GUI_PutNoStr(ico->x, ico->y+33, ico->title, 5);
   }
   else
   { 
    color=LCD_BGColor;
    LCD_BGColor=LCD_ZiColor;
    LCD_ZiColor=color;
    

    GUI_PutNoStr(ico->x, ico->y+33, ico->title, 5);

    color=LCD_BGColor;
    LCD_BGColor=LCD_ZiColor;
    LCD_ZiColor=color;
}
   
   return(1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -