📄 gui.c
字号:
}
}
}
return PPSM_OK;
}
STATUS Change_KeyBoard(P_U32 AreaID, U16 xSrc, U16 ySrc, U16 width, U16 height, U8 CapsLock, U8 Flag3D, U8 KeyFlag,U8 OldKeyFlag)
{
U8 i;
//Clear_Rec(WHITE,xSrc-1,ySrc-1,width,height+2);
Clear_Rec(WHITE,xSrc-1,ySrc-1,width,height+3);
ActiveAreaDisable(*(AreaID+36)); //退格
ActiveAreaDisable(*(AreaID+37)); //英数
if (KeyFlag==1) //要显示英文键盘
{
for (i=0;i<10;i++) ActiveAreaDisable(*(AreaID+i));
for (i=0;i<36;i++) *(AreaID+i)=0;
Draw_KeyBoard(AreaID,xSrc,ySrc,(width-6)/7,(height-3)/4,CapsLock,Flag3D,KeyFlag);
}
else if (KeyFlag==2) //要显示数字键盘1
{
if(OldKeyFlag==1)
{
for (i=10;i<36;i++) ActiveAreaDisable(*(AreaID+i));
for (i=0;i<36;i++) *(AreaID+i)=0;
Draw_KeyBoard(AreaID,xSrc,ySrc,(width-3)/4,(height-2)/3,CapsLock,Flag3D,KeyFlag);
}
else if(OldKeyFlag==3)
{
for (i=0;i<10;i++) ActiveAreaDisable(*(AreaID+i));
for (i=0;i<36;i++) *(AreaID+i)=0;
Draw_KeyBoard(AreaID,xSrc,ySrc,(width-3)/4,(height-2)/3,CapsLock,Flag3D,KeyFlag);
}
}
else if(KeyFlag==3)//要显示数字键盘2
{
if(OldKeyFlag==1)
{
for (i=10;i<36;i++) ActiveAreaDisable(*(AreaID+i));
for (i=0;i<36;i++) *(AreaID+i)=0;
Draw_KeyBoard(AreaID,xSrc,ySrc,(width-3)/4,(height-2)/3,CapsLock,Flag3D,KeyFlag);
}
else if(OldKeyFlag==2)
{
for (i=0;i<10;i++) ActiveAreaDisable(*(AreaID+i));
for (i=0;i<36;i++) *(AreaID+i)=0;
Draw_KeyBoard(AreaID,xSrc,ySrc,(width-3)/4,(height-2)/3,CapsLock,Flag3D,KeyFlag);
}
}
return PPSM_OK;
}
U8 RecvKeyBoard(U8 Flag,int KeyIndex,TEXT *OutStr)
{
U8 Hight=1;
U8 Low=1;
U8 Num=0;
if (Flag==1)
{
while (Hight!=0 && Low!=32 && Num<20)
{
Hight=(U8)((*(OutStr)&0xFF00)>>8);
Low=*(OutStr)&0x00FF;
OutStr++;
Num++;
}
if (Num>=20) return FALSE;
else OutStr--;
}
if (KeyIndex==36) //退格
{
if (Flag==1) //退字符
{
if (Num==1)
{
if (Hight==0) return FALSE;
else *OutStr=0;
}
else if (Num>1)
{
if (Hight==0)
{
OutStr--;
Hight=(U8)((*(OutStr)&0xFF00)>>8);
*OutStr=Hight;
*(OutStr)=*(OutStr)<<8;
*(OutStr)=*(OutStr)|32;
}
else if (Low==32) *(OutStr)=0;
}
}
else if (Flag==2) return 11;
}
else if ((KeyIndex<36)) //其他
{
if( ((KeyIndex>9))||(KeyIndex==-9)) //字母
{
if (Flag==1) //字符串
{
if (Hight==0)
{
*(OutStr)=(65+KeyIndex-10);
*(OutStr)=*(OutStr)<<8;
*(OutStr)=*(OutStr)|32;
*(OutStr+1)=0;
}
else if (Low==32)
{
*(OutStr)=Hight;
*(OutStr)=*(OutStr)<<8;
*(OutStr)=*(OutStr)|(65+KeyIndex-10);
*(OutStr+1)=0;
}
}
else if (Flag==2) //数字
{
return 10;
}
}
else //数字
{
if (Flag==1) //字符串
{
if (Hight==0)
{
*(OutStr)=(48+KeyIndex);
*(OutStr)=*(OutStr)<<8;
*(OutStr)=*(OutStr)|32;
*(OutStr+1)=0;
}
else if (Low==32)
{
*(OutStr)=Hight;
*(OutStr)=*(OutStr)<<8;
*(OutStr)=*(OutStr)|(48+KeyIndex);
*(OutStr+1)=0;
}
}
else if (Flag==2) //数字
{
return KeyIndex;
}
}
}
return TRUE;
}
STATUS PutAssic(U16 str, U16 xSrc, U16 ySrc)
{
U32 tmp , i,j;
U32 Cobit;
U8 dsPtr[64],buffer[5];
U8 upbit,downbit;
tmp=xSrc;
xSrc=ySrc;
ySrc=240-tmp;
tmp=UTL_Word2Deci(str, buffer );
for ( i = 0; i < tmp ; i++){
Cobit = ASCIIADDR+((buffer[i])<<4);
Convert1bitTo2bit( (P_U8)Cobit,0, dsPtr);
if ( ySrc>(i+1)*8 ){
if(PutRec((P_U8)dsPtr, xSrc, ySrc-(i+1)*8, 16, 8,OR_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
}
else
break;
}
return (PPSM_OK);
}
STATUS PutString(P_TEXT str, U16 xSrc, U16 ySrc)
{
U16 tmp;
tmp=xSrc;
xSrc=ySrc;
ySrc=240-tmp;
if (PutStr(str,xSrc,ySrc,16,16)!=PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS PutStr(P_TEXT str, U16 xSrc, U16 ySrc, U16 sizex, U16 sizey)
{
U32 tmp , i,j;
U32 Cobit;
U8 dsPtr[64];
U8 upbit,downbit;
tmp=Strlen(str);
for ( i = 0 ,j=0; i < tmp ; i++,j++){
if (*(str) > 0xa1a1){
downbit = *(str)&0x00ff;
upbit = *(str)>>8;
Cobit = GBADDR+((upbit-0xa1)*94 + (downbit-0xa1))*32;
Convert1bitTo2bit( (P_U8)Cobit,1, dsPtr);
if ( ySrc > (i+1)*sizey ){
if(PutRec((P_U8)dsPtr, xSrc, ySrc-(i+1)*sizey, sizex, sizey,OR_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
}
else
break;
j++;
}
else{
downbit = *(str)&0x00ff;
upbit = *(str)>>8;
Cobit = ASCIIADDR+((upbit)<<4);
Convert1bitTo2bit( (P_U8)Cobit,0, dsPtr);
if ( ySrc > (j+1)*8 ){
if(PutRec((P_U8)dsPtr, xSrc, ySrc-(j+1)*8, 16, 8,OR_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
}
Cobit = ASCIIADDR+((downbit)<<4);
Convert1bitTo2bit( (P_U8)Cobit,0, dsPtr);
j=j+1;
if ( ySrc > (j+1)*8 ){
if(PutRec((P_U8)dsPtr, xSrc, ySrc-(j+1)*8, 16, 8,OR_STYLE, 0) != PPSM_OK) rv = PPSM_ERROR;
}
else
break;
}
str++;
}
return (PPSM_OK);
}
#define GB_FONT_STYLE 1
#define ASSIC_FONT_STYLE 0
/*
unsigned char AscNumLen( unsigned short word )
{
unsigned char temp, i;
unsigned char *buff;
i = 0;
temp = word / 10000;
word = word % 10000;
if ( temp ) *(buff+i++) = temp + '0';
temp = word / 1000;
word = word % 1000;
if ( i || temp ) *(buff+i++) = temp + '0';
temp = word / 100;
word = word % 100;
if ( i || temp ) *(buff+i++) = temp + '0';
temp = word / 10;
if ( i || temp ) *(buff+i++) = temp + '0';
temp = word % 10;
*(buff+i++) = temp + '0';
*(buff+i) = '\0';
return i;
} */
U8 AscNumLen(U16 word)
{
if ( word>=10000 && word<65535 ) return 5;
else if ( word>=1000 && word<10000 ) return 4;
else if ( word>=100 && word<1000 ) return 3;
else if ( word>=10 && word<100 ) return 2;
else if ( word>=0 && word<10 ) return 1;
}
unsigned char UTL_Word2Deci( unsigned short word, unsigned char *buff )
{
unsigned char temp, i;
i = 0;
temp = word / 10000;
word = word % 10000;
if ( temp ) *(buff+i++) = temp + '0';
temp = word / 1000;
word = word % 1000;
if ( i || temp ) *(buff+i++) = temp + '0';
temp = word / 100;
word = word % 100;
if ( i || temp ) *(buff+i++) = temp + '0';
temp = word / 10;
if ( i || temp ) *(buff+i++) = temp + '0';
temp = word % 10;
*(buff+i++) = temp + '0';
*(buff+i) = '\0';
return i;
}
static char getbytebit(unsigned char data, int i)
{
if(i > 8 || i < 0)
return -1;
return ((data>>i)&1);
}
void invert2bit(unsigned char *ptrFont, unsigned char *addrFont)
{
int i;
unsigned char ttp = 0;
unsigned char tmp;
while(i++ < 32)
{
tmp = *ptrFont++;
if(getbytebit(tmp, 7))
ttp += (3<<6);
else
ttp += (0<<6);
if(getbytebit(tmp, 6))
ttp += (3<<4);
else
ttp += (0<<4);
if(getbytebit(tmp, 5))
ttp += (3<<2);
else
ttp += (0<<2);
if(getbytebit(tmp, 4))
ttp += 3;
else
ttp += 0;
*addrFont++ = ttp;
ttp = 0;
if(getbytebit(tmp, 3))
ttp += (3<<6);
else
ttp += (0<<6);
if(getbytebit(tmp, 2))
ttp += (3<<4);
else
ttp += (0<<4);
if(getbytebit(tmp, 1))
ttp += (3<<2);
else
ttp += (0<<2);
if(getbytebit(tmp, 0))
ttp += 3;
else
ttp += 0;
*addrFont++ = ttp;
ttp = 0;
}
}
void Convert1bitTo2bit(unsigned char *ptrFont, unsigned char style, unsigned char *addrFont)
{
int ncount = 0;
int i = 0;
unsigned char ttp = 0;
unsigned char tmp;
if(style == GB_FONT_STYLE)
ncount = 32;
else if(style == ASSIC_FONT_STYLE)
ncount = 16;
while(i++ < ncount)
{
tmp = *ptrFont++;
if(getbytebit(tmp, 7))
ttp += (3<<6);
else
ttp += (0<<6);
if(getbytebit(tmp, 6))
ttp += (3<<4);
else
ttp += (0<<4);
if(getbytebit(tmp, 5))
ttp += (3<<2);
else
ttp += (0<<2);
if(getbytebit(tmp, 4))
ttp += 3;
else
ttp += 0;
*addrFont++ = ttp;
ttp = 0;
if(getbytebit(tmp, 3))
ttp += (3<<6);
else
ttp += (0<<6);
if(getbytebit(tmp, 2))
ttp += (3<<4);
else
ttp += (0<<4);
if(getbytebit(tmp, 1))
ttp += (3<<2);
else
ttp += (0<<2);
if(getbytebit(tmp, 0))
ttp += 3;
else
ttp += 0;
*addrFont++ = ttp;
ttp = 0;
}
}
U16 Strlen(P_TEXT str)
{
U16 len=0;
while (str[len]) len++;
return len;
}
void UTL_U8toU16(U8 *buffU8 ,U16 *buffU16 )
{
unsigned char i;
for (i=0;i<((sizeof(buffU16)));i++){
*(buffU16)=*(buffU8);
buffU8++;
*(buffU16)=*(buffU16)<<8;
*(buffU16)=*(buffU16)|*(buffU8);
buffU16++;
buffU8++;
}
}
static unsigned char btoh( unsigned char num )
{
num = num & 0x0F;
return ( num<10 )? num+'0' : num-10+'A';
}
void UTL_Byte2Hex( unsigned char byte, unsigned char *buff )
{
*buff++ = btoh( byte>>4 );
*buff++ = btoh( byte );
*buff = '\0';
}
void UTL_Word2Hex( unsigned short word, unsigned char *buff )
{
*buff++ = btoh( (unsigned char)(word>>12) );
*buff++ = btoh( (unsigned char)(word>>8) );
*buff++ = btoh( ((unsigned char)word)>>4 );
*buff++ = btoh( (unsigned char)(word) );
*buff = '\0';
}
unsigned char UTL_StrLen( unsigned char *str )
{
unsigned char i;
for ( i=0; *str++!='\0' && i!=255; i++ );
return i;
}
U16 TexttoNum(TEXT *str)
{ U8 i,j;
U16 num;
U8 result;
U8 data1,data2;
num=0;
for (i=0;i<=sizeof(str)/2;i++,str++){
data1=(U8)((*(str)&0xFF00)>>8);
data2=*(str)&0x00FF;
if (i==0)
{
if ((data1<'0')||(data1>'9')){
break;
}
else
{
num=(data1-'0');
}
if ((data2<'0')||(data2>'9'))
{
break;
}
else
{
num=num*10+(data2-'0');
}
}
else
{
if ((data1<'0')||(data1>'9'))
{
break;
}
else
{
num=num*10+(data1-'0');
}
if ((data2<'0')||(data2>'9'))
{
break;
}
else
{
num=num*10+(data2-'0');
}
}
}
return num;
}
U8 StrComprisal(P_TEXT Str1,P_TEXT Str2,U8 flag)
{
U8 p,k;
U8 Flag;
U8 Temp1[10];
U8 Temp2[10];
p=0;
Flag=0;
while(p<10)
{
Temp1[p]=0;
Temp2[p]=0;
Temp1[p+1]=0;
Temp2[p+1]=0;
if (*Str1!=0)
{
Temp1[p]=(U8)((*(Str1)&0xFF00)>>8);
Temp1[p+1]=(U8)(*(Str1)&0x00FF);
if (Temp1[p+1]==32) Temp1[p+1]=0;
}
if (*Str2!=0)
{
Temp2[p]=(U8)((*(Str2)&0xFF00)>>8);
Temp2[p+1]=(U8)(*(Str2)&0x00FF);
}
else
{
if (*Str1!=0) return FALSE;
}
if (flag==1) //编号
{
if (Temp1[0]==Temp2[0])
Flag=1;
else return FALSE;
}
Str1++;
Str2++;
p+=2;
}
p=0;
k=0;
while (Temp2[p]!=0 && p<10)
{
if (Temp2[p]==Temp1[k])
{
Flag++;
k++;
if (Temp1[k]==0) return TRUE;
}
else
{
if (Flag>0) return FALSE;
}
p++;
}
return FALSE;
}
/*
* Compare string1 with string2
* Return:
* < 0 if string1 < string2
* 0 if string1 == string2
* > 0 if string1 > string2
*/
S16 Strcmp(P_TEXT string1, P_TEXT string2)
{
for (; *string1 == *string2; string1++, string2++)
if (*string1 == '\0')
return 0;
return (*string1 - *string2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -