?? menu.c
字號:
// menu.c
//
#include "includes.h"
// 菜單信息結(jié)構(gòu)
MenuInfor MenuInforFile = {"文件",1,20,10,24,12,1,4};
MenuInfor MenuInforNew = {"新建",1,20,10,24,12,1,2};
MenuInfor MenuInforEmpy = {"空白",1,20,10,24,12,1,0};
MenuInfor MenuInforTemplate = {"模板",1,20,50,24,12,0,0};
MenuInfor MenuInforOpen = {"打開",1,20,40,24,12,0,0};
MenuInfor MenuInforClose = {"關(guān)閉",1,20,70,24,12,0,0};
MenuInfor MenuInforSave = {"保存",1,20,100,24,12,0,0};
MenuInfor MenuInforEdit = {"編輯",1,20,50,24,12,0,4};
MenuInfor MenuInforCut = {"剪切",1,20,10,24,12,1,0};
MenuInfor MenuInforCopy = {"復(fù)制",1,20,40,24,12,0,0};
MenuInfor MenuInforPaste = {"粘貼",1,20,70,24,12,0,0};
MenuInfor MenuInforFind = {"查找",1,20,100,24,12,0,0};
MenuInfor MenuInforRoot = {"歡迎",1,20,40,24,12,0,2};
// 父菜單---文件
struct Menu MenuFile = {&MenuInforFile,&MenuRoot,&MenuNew,&MenuEdit,&MenuEdit};
struct Menu MenuNew = {&MenuInforNew,&MenuFile,&MenuEmpy,&MenuSave,&MenuOpen}; // 新建
struct Menu MenuEmpy = {&MenuInforEmpy,&MenuNew,0,&MenuTemplate,&MenuTemplate}; // 空白文件
struct Menu MenuTemplate = {&MenuInforTemplate,&MenuNew,0,&MenuEmpy,&MenuEmpy}; // 模板
struct Menu MenuOpen = {&MenuInforOpen,&MenuFile,0,&MenuNew,&MenuClose}; // 打開
struct Menu MenuClose= {&MenuInforClose,&MenuFile,0,&MenuOpen,&MenuSave}; // 關(guān)閉
struct Menu MenuSave = {&MenuInforSave,&MenuFile,0,&MenuClose,&MenuNew}; // 保存
// 父菜單
struct Menu MenuEdit ={&MenuInforEdit,&MenuRoot,&MenuCut,&MenuFile,&MenuFile}; // 編輯
struct Menu MenuCut ={&MenuInforCut,&MenuEdit,0,&MenuFind,&MenuCopy}; // 剪切
struct Menu MenuCopy ={&MenuInforCopy,&MenuEdit,0,&MenuCut,&MenuPaste}; // 復(fù)制
struct Menu MenuPaste ={&MenuInforPaste,&MenuEdit,0,&MenuCopy,&MenuFind}; // 粘貼
struct Menu MenuFind ={&MenuInforFind,&MenuEdit,0,&MenuPaste,&MenuCut}; // 查找
struct Menu MenuRoot = {&MenuInforRoot,0,&MenuFile,0,0}; // 開始時候的菜單
void onBeforeKey(struct Menu* pCurMenu)
{
uchar uLeft,uTop,uRight,uBottom;
uLeft = pCurMenu->PMenuInfor->offX;
uTop = pCurMenu->PMenuInfor->offY;
uRight = uLeft + pCurMenu->PMenuInfor->Height;
uBottom = uTop + pCurMenu->PMenuInfor->Width;
pCurMenu->PMenuInfor->bIsFocus = 0; // 當(dāng)前子菜單失去焦點
RectBlock(uLeft - 5,uTop - 5,uRight + 5 ,uBottom + 5,0 ); // 當(dāng)前子菜單失去黑色邊框
pCurMenu->pLeftMenu->PMenuInfor->bIsFocus = 1; // 左邊兄弟菜單項獲得焦點
*pCurMenu = *(pCurMenu->pLeftMenu); // 當(dāng)前菜單項轉(zhuǎn)為左邊兄弟菜單項
}
void onAfterKey(struct Menu* pCurMenu)
{
uchar uLeft,uTop,uRight,uBottom;
uLeft = pCurMenu->PMenuInfor->offX;
uTop = pCurMenu->PMenuInfor->offY;
uRight = uLeft + pCurMenu->PMenuInfor->Height;
uBottom = uTop + pCurMenu->PMenuInfor->Width;
pCurMenu->PMenuInfor->bIsFocus = 0; // 當(dāng)前子菜單失去焦點
RectBlock(uLeft - 5,uTop - 5,uRight + 5 ,uBottom + 5,0 ); // 當(dāng)前子菜單失去黑色邊框
pCurMenu->pRightMenu->PMenuInfor->bIsFocus = 1; // 右邊兄弟菜單項獲得焦點
*pCurMenu = *(pCurMenu->pRightMenu); // 當(dāng)前菜單項轉(zhuǎn)為左邊兄弟菜單項
}
void onOkKey(struct Menu* pCurMenu)
{
if(pCurMenu->pChildMenu != 0)
{
pCurMenu->PMenuInfor->bIsFocus = 0; // 當(dāng)前父菜單項失去焦點
pCurMenu->pChildMenu->PMenuInfor->bIsFocus = 1; // 默認(rèn)第一子菜單項獲得焦點
*pCurMenu = *(pCurMenu->pChildMenu); // 菜單轉(zhuǎn)化為子菜單
}
else
{
return;
}
}
void onCancelKey(struct Menu* pCurMenu)
{
if(pCurMenu->pParentMenu != 0)
{
pCurMenu->PMenuInfor->bIsFocus = 0; // 當(dāng)前菜單項失去焦點
pCurMenu->pParentMenu->PMenuInfor->bIsFocus = 1; // 父菜單項獲得焦點
*pCurMenu = *(pCurMenu->pParentMenu);
}
else
{
return;
}
}
void PutPixel(uchar x, uchar y, uchar mode)
{
fnSetPos(x,y);
if(mode) // mode != 0
fnCW0P(LC_BIT_OP | 0x08 | (7-(y % 8)));
else
fnCW0P(LC_BIT_OP | 0x00 | (7-(y % 8)));
}
uchar ReverPrin(uchar *ptr)
{
uchar c1,c2;
uchar *tmpBuf; // LCD顯示數(shù)據(jù)緩沖區(qū)
uchar i=0,j=0,j1=0,k,uLen=0,uRow,uCol,uVal=0;
const typFNT_GB12 data1 ;
uchar uIndex1,uIndex2; // 存儲漢字的索引
uchar uMask1,uMask2; // 1個字橫向字模信息的2個字節(jié)
uchar k1,k2;
while (ptr[uLen]!=0)
{
uLen++; ////探測字串長度
};
tmpBuf = ptr;
i = 0;
while(i<uLen)
{
c1 = tmpBuf[i];
c2 = tmpBuf[i+1];
uRow = fnGetRow();
uCol = fnGetCol();
if(c1 >= 0x20 && c1 <= 0x7f) // 0x20---0x7f
{ // ASCII 的 12行 * 6列 字符顯示
for( j = 0; j < 12; j++) // 逐行顯示
{
for ( k = 0; k < 6; k++) // 逐列顯示
{
cursor(uRow + j,uCol + k); // 置當(dāng)前顯示地址
k1 = (uCol + k) & 0x07 ; // 當(dāng)前屏幕點屬于的字節(jié)單元的像素點;水平共16字節(jié)單元,
// 每字節(jié)8個像素點,從左到右為01234567點,
// 對應(yīng)數(shù)據(jù)的76543210位
k2 = 7 - k1; // 當(dāng)前屏幕點屬于的字節(jié)單元的位
k1 = BIT(7-k); // 當(dāng)前屏幕點屬于的字節(jié)單元的數(shù)據(jù)的第7-k個數(shù)據(jù)位置1,其余置0
uVal = pgm_read_byte(ASCII_TBL+(c1-0x20)*12 + j);
k1 = ( uVal & k1 ) == k1 ? 1 : 0; // 測試對應(yīng)字庫中字的第j行1字節(jié)數(shù)據(jù)中的7-k個數(shù)據(jù)位是否為1
if(k1 == 0)
fnCW0P(LC_BIT_OP | 0x08 | k2 ); // 反轉(zhuǎn)顯示
else
fnCW0P(LC_BIT_OP | k2 ); // 反轉(zhuǎn)顯示
}
}
cursor(uRow ,uCol + 6); // 下一個字符
i++;
}
else // 0x80 -- 0xff
{ // 中文12行*12列漢字顯示
for(j1 = 0; j1 < sizeof(GB_12)/sizeof(GB_12[0]);j1 ++) // 找字
{
memcpy_P(&data1, &GB_12[j1], sizeof(typFNT_GB12)); // 從程序區(qū)拷貝一個結(jié)構(gòu)體數(shù)據(jù)
uIndex1 = data1.Index[0];
uIndex2 = data1.Index[1];
if(c1 == uIndex1 && c2 == uIndex2)
break;
}
if(j1 >= sizeof(GB_12)/sizeof(GB_12[0]) ) // 找不到,屏幕就是空白
return 0;
for( j=0;j<12;j++) // 逐行顯示
{
for ( k = 0; k < 8; k++) // 逐列顯示
{
cursor(uRow + j,uCol + k); // 置當(dāng)前顯示地址
k1 = (uCol + k) & 0x07 ; // 當(dāng)前屏幕點屬于的字節(jié)單元的像素點;水平共16字節(jié)單元,
// 每字節(jié)8個像素點,從左到右為01234567點,
// 對應(yīng)數(shù)據(jù)的76543210位
k2 = 7 - k1; // 當(dāng)前屏幕點屬于的字節(jié)單元的位
k1 = BIT(7 - (k & 0x07)); // 當(dāng)前屏幕點屬于的字節(jié)單元的數(shù)據(jù)的第7 - k & 0x07個數(shù)據(jù)位置1,其余置0
memcpy_P(&data1, &GB_12[j1], sizeof(typFNT_GB12));
uMask1 = data1.Msk[2*j];
k1 = (uMask1 & k1 ) == k1 ? 1 : 0; // 漢字左邊部分
if(k1 == 0) // 反轉(zhuǎn)顯示
fnCW0P(LC_BIT_OP | 0x08 | k2 );
else
fnCW0P(LC_BIT_OP | k2 ); // 反轉(zhuǎn)顯示
}
for ( k = 0; k < 4; k++) // 逐列顯示
{
cursor(uRow + j,uCol + k +8); // 置當(dāng)前顯示地址
k1 = (uCol + k + 8) & 0x07 ; // 當(dāng)前屏幕點屬于的字節(jié)單元的像素點;水平共16字節(jié)單元,
// 每字節(jié)8個像素點,從左到右為01234567點,
// 對應(yīng)數(shù)據(jù)的76543210位
k2 = 7 - k1; // 當(dāng)前屏幕點屬于的字節(jié)單元的位
k1 = BIT(7 - (k & 0x07)); // 當(dāng)前屏幕點屬于的字節(jié)單元的數(shù)據(jù)的第7 - k & 0x07個數(shù)據(jù)位置1,其余置0
uMask2 = data1.Msk[2*j+1];
k1 = (uMask2 & k1 ) == k1 ? 1 : 0; // 漢字右邊部分
if(k1 == 0) // 反轉(zhuǎn)顯示
fnCW0P(LC_BIT_OP | 0x08 | k2 );
else
fnCW0P(LC_BIT_OP | k2 ); // 反轉(zhuǎn)顯示
}
}
cursor(uRow ,uCol + 13); // 下一個漢字
i +=2; // 在字符串中一個漢字占2個字節(jié)
}
}
return uLen;
}
// chRight 畫矩形
void RectBlock(uchar chLeft,uchar chTop,uchar chRight,uchar chBottom,uchar mode)
{
uchar i,j;
if( chLeft > chRight) // 使 chLeft 不大于 chRight
{
i = chLeft;
chLeft = chRight;
chRight = i;
}
if( chTop > chBottom) // 使 chTop 不大于 chBottom
{
i = chTop;
chTop = chBottom;
chBottom = i;
}
if(chRight > 64 )
{
chRight = 64;
}
// if(chBottom > 127 )
// {
// chBottom = 110;
// }
for( i = chLeft; i <= chRight; i++) // 逐個點畫
for( j = chTop; j <= chBottom;j++)
{
PutPixel(i,j,mode);
}
}
void MenuDis(MenuInfor * pMenuInfor)
{
uchar chX,chY;
if(pMenuInfor == 0)
return;
chX = pMenuInfor->offX;
chY = pMenuInfor->offY;
cursor(chX,chY);
if( pMenuInfor->bIsFocus == 1) // 反轉(zhuǎn)顯示
{
RectBlock(chX - 5,chY -5,chX + pMenuInfor->Height + 5,chY + pMenuInfor->Width + 5,1); // 現(xiàn)將背景填黑
ReverPrin(pMenuInfor->strChinese);
}
else // 不反轉(zhuǎn)顯示
{
dprintf(pMenuInfor->strChinese);
}
}
void DisPaly(struct Menu * pCurMenu)
{
uchar i=0;
if(pCurMenu->pParentMenu == 0) // 如果是根菜單,直接顯示
{
MenuDis(pCurMenu->PMenuInfor); // 根菜單顯示
return;
}
uchar ucNum = pCurMenu->pParentMenu->PMenuInfor->subMenuNum; // 兄弟菜單項的個數(shù)
for(i = 0; i < ucNum; i++ )
{
MenuDis(pCurMenu->PMenuInfor); // 菜單顯示
pCurMenu = pCurMenu->pRightMenu;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -