📄 gui.c
字号:
/******************************************************************************
Gui.c by gp 2003.12.11
******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include "ppsm.h"
#include "errors.h"
#include "proto.h"
#include "M68328.h"
#include "Gui.h"
#include "PubVal.h"
extern U8 RightPic[80];
extern U8 LeftPic[75];
extern P_U8 LcallocBit(U16 DIRWIDTH,U16 DIRHEIGHT);
STATUS PutProcessBar( U16 Num,U16 TotalNum,U16 xSrc,U16 ySrc,U16 width,U16 height )
{
U16 tmpwidth;
if (Clear_Rec(WHITE,xSrc+1,ySrc+1,width-2,height-2)!=PPSM_OK) return PPSM_ERROR;
if (TotalNum<=Num)
{
if (Clear_Rec(BLACK,xSrc+1,ySrc+2,width-3,height-3)!=PPSM_OK)
return PPSM_ERROR;
}
else
{
tmpwidth=((width-3)*Num)/TotalNum;
if (Clear_Rec(BLACK,xSrc+1,ySrc+2,tmpwidth,height-3)!=PPSM_OK) return PPSM_ERROR;
}
}
STATUS PutChoseY(U8 Flag,U16 xSrc,U16 ySrc,U16 width,U16 height)
{
if (Clear_Rec(WHITE,xSrc+1,ySrc+1,width-2,height-2)!=PPSM_OK) return PPSM_ERROR;
if (Flag==TRUE)
{
Draw_Line(BLACK,xSrc+2,height/2+ySrc,xSrc+width/3,height-2+ySrc);
Draw_Line(BLACK,xSrc+width/3,height-2+ySrc,xSrc+width-2,height/3+ySrc);
}
}
STATUS Put_RightPic(U16 xSrc, U16 ySrc)
{
if (PutRec((P_U8)RightPic, ySrc, 240-xSrc, 17, 16, OR_STYLE, 0)!=PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS Put_LeftPic(U16 xSrc, U16 ySrc)
{
if (PutRec((P_U8)LeftPic, ySrc, 240-xSrc, 17, 15, OR_STYLE, 0)!=PPSM_OK) rv=PPSM_ERROR;
return PPSM_OK;
}
STATUS Move_RightPic(U16 OldxSrc, U16 OldySrc, U16 NewxSrc, U16 NewySrc)
{
if (Clear_Rec(WHITE,OldxSrc,OldySrc,17,17)!=PPSM_OK) return PPSM_ERROR;
if (Put_RightPic(NewxSrc, NewySrc)!=PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS Move_LeftPic(U16 OldxSrc, U16 OldySrc, U16 NewxSrc, U16 NewySrc)
{
if (Clear_Rec(WHITE,OldxSrc,OldySrc,17,17)!=PPSM_OK) return PPSM_ERROR;
if (Put_LeftPic(NewxSrc, NewySrc)!=PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS Cursor_Init(U8 Blink,U16 width,U16 height)
{
CursorInit(height,width);
//CursorSetStatus(PPSM_CURSOR_REVERSED);
CursorSetStatus(PPSM_CURSOR_ON);
CursorSetBlink(Blink);
return PPSM_OK;
}
STATUS SetCursorPos(U16 xSrc,U16 ySrc)
{
if (CursorSetPos(ySrc,240-xSrc)!=PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS SetTextString(P_TEXT str,U16 xSrc,U16 ySrc,U16 width,U16 height,U8 CursorFlag)
{
U8 i;
if (Clear_Rec(WHITE,xSrc,ySrc,width,height)!=PPSM_OK) return PPSM_ERROR;
if (PutString(str,xSrc+1,(height-16)/2+ySrc)!=PPSM_OK) return PPSM_ERROR;
if (CursorFlag==TRUE)
{
i=0;
while (*(str+i)!=0) i++;
if ( (U8)(*(str+i-1)&0x00FF)==32 )
{
if (SetCursorPos(Strlen(str)*16+xSrc-2,(height-16)/2+ySrc)!=PPSM_OK) return PPSM_ERROR;
}
else
{
if (SetCursorPos(Strlen(str)*16+xSrc+6,(height-16)/2+ySrc)!=PPSM_OK) return PPSM_ERROR;
}
}
return PPSM_OK;
}
STATUS SetTextAsc(U16 num,U16 xSrc,U16 ySrc,U16 width,U16 height,U8 CursorFlag)
{
if (Clear_Rec(WHITE,xSrc,ySrc,width,height)!=PPSM_OK) return PPSM_ERROR;
if (num>0 )
{
if (PutAssic(num,xSrc+1,(height-14)/2+ySrc)!=PPSM_OK) return PPSM_ERROR;
}
if (CursorFlag==TRUE)
{
if (SetCursorPos(AscNumLen(num)*8+xSrc+6,(height-16)/2+ySrc)!=PPSM_OK) return PPSM_ERROR;
}
return PPSM_OK;
}
void NumtoString(P_U8 num,U16 xSrc,U16 ySrc,U16 width,U16 height,U8 CursorFlag,U8 DotFlag)
{
TEXT PDot[11]={'0.','1.','2.','3.','4.','5.','6.','7.','8.','9.',0};
TEXT ADot[11]={'.0','.1','.2','.3','.4','.5','.6','.7','.8','.9',0};
TEXT Dot='. ';
U8 i;
TEXT TmpCh;
TEXT Food[6];
U8 TmpInt=0;
U8 TmpFloat=0;
U8 Tmp=0;
for(i=0;i<6;i++)
*(Food+i)=0; //初始化菜品
//保存整数和小数
TmpInt=num[0];
TmpFloat=num[1];
if(TmpInt==0)
{
if(DotFlag==TRUE)
{
TmpCh=*(PDot);
*Food=TmpCh;
if(TmpFloat==0)
{
*(Food+1)='0 ';
}
else
{
TmpCh=InttoChar(TmpFloat);
*(Food+1)=TmpCh;
}
}
else
{
TmpCh=InttoChar(TmpInt);
*Food=TmpCh;
}
}
else if(TmpInt>0&&TmpInt<10)
{
if(DotFlag==TRUE)
{
TmpCh=*(PDot+TmpInt);
*Food=TmpCh;
if(TmpFloat==0)
{
*(Food+1)='0 ';
}
else
{
TmpCh=InttoChar(TmpFloat);
*(Food+1)=TmpCh;
}
}
else
{
TmpCh=InttoChar(TmpInt);
*Food=TmpCh;
}
}
else if(TmpInt>=10)
{
if(DotFlag==TRUE)
{
TmpCh=InttoChar(TmpInt);
*Food=TmpCh;
*(Food+1)=Dot;
if(TmpFloat==0)
{
*(Food+1)=*ADot;
}
else
{
if(TmpFloat>0&&TmpFloat<10)
{
TmpCh=*(ADot+TmpFloat);
*(Food+1)=TmpCh;
}
else
{
Tmp=TmpFloat/10;
*(Food+1)=*(ADot+Tmp);
Tmp=TmpFloat%10;
TmpCh=InttoChar(Tmp);
*(Food+2)=TmpCh;
}
}
}
else
{
TmpCh=InttoChar(TmpInt);
*Food=TmpCh;
}
}
SetTextString(Food,xSrc,ySrc,width,height,CursorFlag);
}
TEXT InttoChar(U8 num)
{
TEXT String[101]={ '0 ','1 ','2 ','3 ','4 ','5 ','6 ','7 ','8 ','9 ',
'10','11','12','13','14','15','16','17','18','19',
'20','21','22','23','24','25','26','27','28','29',
'30','31','32','33','34','35','36','37','38','39',
'40','41','42','43','44','45','46','47','48','49',
'50','51','52','53','54','55','56','57','58','59',
'60','61','62','63','64','65','66','67','68','69',
'70','71','72','73','74','75','76','77','78','79',
'80','81','82','83','84','85','86','87','88','89',
'90','91','92','93','94','95','96','97','98','99',0};
TEXT Ch;
Ch=*(String+num);
return Ch;
}
STATUS Draw_Line(U8 Color, U16 xSrc1, U16 ySrc1, U16 xSrc2, U16 ySrc2)
{
if (DrawLine(Color,ySrc1,240-xSrc1,ySrc2,240-xSrc2,0,REPLACE_STYLE)!= PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS Draw_Rec(U8 Color, U16 xSrc, U16 ySrc, U16 width, U16 height)
{
if (DrawRec(Color, ySrc,240-width-xSrc,ySrc+height,240-xSrc,0,REPLACE_STYLE)!=PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS Clear_Rec(U8 Color, U16 xSrc, U16 ySrc, U16 width, U16 height)
{
if (ClearRec(Color,ySrc,240-width-xSrc,height,width,REPLACE_STYLE)!=PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS Draw_Text(U16 xSrc, U16 ySrc, U16 width, U16 height, U8 Flag3D)
{
U8 j;
for (j=0;j<Flag3D;j++)
{
Draw_Line(BLACK, xSrc+j, ySrc+j, xSrc+width-j, ySrc+j);
Draw_Line(BLACK, xSrc+j, ySrc+j, xSrc+j, ySrc+height-j);
Draw_Line(WHITE, xSrc+j, ySrc+height-j, xSrc+width-j, ySrc+height-j);
Draw_Line(WHITE, xSrc+width-j, ySrc+j, xSrc+width-j, ySrc+height-j);
}
}
STATUS Ascii_Button3D(P_U32 areaId, P_TEXT str, U16 xSrc, U16 ySrc, U16 width, U16 height, U8 Flag3D)
{
U8 j;
U16 x,y;
for (j=0;j<Flag3D;j++)
{
Draw_Line(WHITE, xSrc+j, ySrc+j, xSrc+width-j, ySrc+j);
Draw_Line(WHITE, xSrc+j, ySrc+j, xSrc+j, ySrc+height-j);
Draw_Line(BLACK, xSrc+j, ySrc+height-j, xSrc+width-j, ySrc+height-j);
Draw_Line(BLACK, xSrc+width-j, ySrc+j, xSrc+width-j, ySrc+height-j);
}
if (ActiveAreaEnable(areaId,ICON_AREA,0, ySrc-1, 239-width-xSrc, ySrc+height+1, 241-xSrc)!=PPSM_OK) return PPSM_ERROR;
y = 240-xSrc - ((width - (Strlen(str)+2)*8) >> 1);
x = ySrc + ((height - 16) >> 1);
if (PutStr(str,x,y,8,8)!=PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS Text_Button3D(P_U32 areaId, P_TEXT str, U16 xSrc, U16 ySrc, U16 width, U16 height, U8 Flag3D)
{
U8 j;
U16 x,y;
for (j=0;j<Flag3D;j++)
{
Draw_Line(WHITE, xSrc+j, ySrc+j, xSrc+width-j, ySrc+j);
Draw_Line(WHITE, xSrc+j, ySrc+j, xSrc+j, ySrc+height-j);
Draw_Line(BLACK, xSrc+j, ySrc+height-j, xSrc+width-j, ySrc+height-j);
Draw_Line(BLACK, xSrc+width-j, ySrc+j, xSrc+width-j, ySrc+height-j);
}
if (ActiveAreaEnable(areaId,ICON_AREA,0, ySrc-1, 239-width-xSrc, ySrc+height+1, 241-xSrc)!=PPSM_OK) return PPSM_ERROR;
y = 240-xSrc - ((width - Strlen(str)*16) >> 1);
x = ySrc + ((height - 16) >> 1);
if(PutStr(str, x, y,16,16)!= PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS ChgButtonTxt(U32 areaId, P_TEXT str)
{
S16 xSrc, ySrc, xDest, yDest;
U16 x1,y1,x2,y2;
U16 x,y;
if (ActiveAreaRead(areaId,&xSrc,&ySrc,&xDest,&yDest)!= PPSM_OK) return PPSM_ERROR;
x1=240-yDest; y1=xSrc;
x2=240-ySrc; y2=xDest;
Clear_Rec(WHITE,x1+2,y1+2,x2-x1-4,y2-y1-4);
y = 240-x1 - ((x2-x1 - Strlen(str)*16) >> 1);
x = y1 + ((y2-y1 - 16) >> 1);
if(PutStr(str, x, y,16,16)!= PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
/*
STATUS Image_Button()
{
}*/
// 起点(xSrc,ySrc)
STATUS Draw_Table(U16 xSrc, U16 ySrc, U16 Cols, U16 Rows ,P_U16 ColWidth, U16 RowHeight)
{
U8 i;
U16 tempwidth;
for (i=0;i<Cols;i++)
{
tempwidth+=*(ColWidth+i);
}
for (i=0;i<Rows+1;i++)
{
if (Draw_Line(BLACK, xSrc, RowHeight*i+ySrc, xSrc+tempwidth, RowHeight*i+ySrc)!=PPSM_OK) return PPSM_ERROR;
}
tempwidth=xSrc;
for (i=0;i<Cols+1;i++)
{
if (Draw_Line(BLACK, tempwidth, ySrc, tempwidth, RowHeight*Rows+ySrc)!=PPSM_OK) return PPSM_ERROR;
tempwidth+=*(ColWidth+i);
}
}
STATUS Draw_Signal(U8 Volume)
{
U8 j;
if (Volume>5) return PPSM_ERROR;
Clear_Rec(WHITE,12,3,30,14);
Draw_Line(BLACK, 12, 3, 18, 3);
Draw_Line(BLACK, 15, 3, 15, 16);
Draw_Line(BLACK, 12, 3, 15, 6);
Draw_Line(BLACK, 18, 3, 15, 6);
for (j=0;j<Volume;j++)
{
Draw_Line(BLACK, j*3+17, 14-(j*2), j*3+17, 16);
Draw_Line(BLACK, j*3+18, 14-(j*2), j*3+18, 16);
}
}
STATUS Draw_Battery(U8 Volume)
{
U8 j;
if (Volume>4) return PPSM_ERROR;
Clear_Rec(WHITE,17,6,17,11);
Draw_Rec(BLACK,17,6,14,10);
Draw_Line(BLACK, 32,9,32,13);
Draw_Line(BLACK, 33,9,33,13);
for (j=0;j<Volume;j++)
{
Draw_Line(BLACK, j*3+19,8,j*3+19,14);
Draw_Line(BLACK, j*3+20,8,j*3+20,14);
}
}
STATUS Draw_Logo(P_TEXT str)
{
TEXT Logo_Txt[]={'康','文','特','点','菜','器',0};
//TEXT Logo_Txt[]={'无','线',' P','DA',0};
TEXT UNReg_Bottom[]={'演','示','试','用','版',0};
TEXT Operators_Txt[]={'操','作','员',':',0};
TEXT AdminUser_Txt[]={'管','理','员',0};
//TEXT Reg_Bottom[]={'西','安','新','博','科','技',0};
TEXT Reg_Bottom[]={'本','机','号',': ',0};
ClearScreen(WHITE);
// Draw_Rec(BLACK, 1,1,238,318);
Clear_Rec(WHITE,10,1,229,318);
Draw_Rec(BLACK,10,1,229,318);
if (PutString((P_TEXT)Logo_Txt,65,1)!=PPSM_OK) return PPSM_ERROR;
str[2]=0;
if (*str!=0) PutString(str,205,1);//工作任务
Draw_Line(BLACK, 10, 18, 238, 18);
Draw_Line(BLACK, 10, 300, 238, 300);
if (PutString((P_TEXT)Operators_Txt,11,302)!=PPSM_OK) return PPSM_ERROR;
//操作员
if (EmployeeIndex==0xFF)
{
if (PutString((P_TEXT)AdminUser_Txt,68,302)!=PPSM_OK) return PPSM_ERROR;
}
else
{
if (PutString((P_TEXT)Employee[EmployeeIndex].EmpName,68,302)!=PPSM_OK) return PPSM_ERROR;
}
//用户是否注册
if (Sys_Reg_Flag==TRUE)
{
if (PutString((P_TEXT)Reg_Bottom,160,302)!=PPSM_OK) return PPSM_ERROR;
if (PutAssic(PDAID,220,304)!=PPSM_OK) return PPSM_ERROR;
}
else
{
if (PutString((P_TEXT)UNReg_Bottom,160,302)!=PPSM_OK) return PPSM_ERROR;
}
}
STATUS MessageBox(P_TEXT strTitle, P_TEXT strMsg, U8 ButtonFlag,P_U32 areaId, P_U8 MsgBoxBmp)
{
U8 j;
TEXT cmdOKTxt[]={'确','定',0};
TEXT cmdQuestionTxt[2][2]={{'是',0},{'否',0}};
if (SaveRec(MsgBoxBmp, 110, 30, 101, 181, 0)!=PPSM_OK) return PPSM_ERROR;
ActiveListPush();
Clear_Rec(WHITE,30,110,180,100);
for (j=0;j<2;j++)
{
Draw_Line(WHITE, 30+j, 110+j, 210-j, 110+j);
Draw_Line(WHITE, 30+j, 110+j, 30+j, 210-j);
Draw_Line(BLACK, 30+j, 210-j, 210-j, 210-j);
Draw_Line(BLACK, 210-j, 110+j, 210-j, 210-j);
}
if (PutString(strTitle,32,112)!=PPSM_OK) return PPSM_ERROR;
InvRec(112, 32, 17, 177);
if (PutString(strMsg,120 - (Strlen(strMsg)*8),138)!=PPSM_OK) return PPSM_ERROR;
switch(ButtonFlag)
{
case 1:
Text_Button3D(areaId,(P_TEXT)cmdOKTxt,90, 166, 60, 26, 2);
break;
case 2:
Text_Button3D(areaId,(P_TEXT)cmdQuestionTxt[0],50, 166, 60, 26, 2);
areaId++;
Text_Button3D(areaId,(P_TEXT)cmdQuestionTxt[1],130, 166, 60, 26, 2);
break;
default:
break;
}
}
STATUS CloseMsgBox(P_U8 MsgBoxBmp, U8 ButtonFlag, P_U32 areaId)
{
ActiveListPop();
if (ExchangeRec(110, 30, 101, 181, MsgBoxBmp)!=PPSM_OK) return PPSM_ERROR;
if (ButtonFlag==1)
{
*areaId=0;
}
else if (ButtonFlag==2)
{
*areaId=0;
areaId++;
*areaId=0;
}
else return PPSM_ERROR;
return PPSM_OK;
}
STATUS Active_AreaEnable(P_U32 AreaID, U16 xSrc, U16 ySrc, U16 width, U16 height)
{
if (ActiveAreaEnable(AreaID,ICON_AREA,0, ySrc-1, 239-width-xSrc, ySrc+height+1, 241-xSrc)!=PPSM_OK) return PPSM_ERROR;
return PPSM_OK;
}
STATUS Draw_KeyBoard(P_U32 AreaID, U16 xSrc, U16 ySrc, U16 width, U16 height, U8 CapsLock, U8 Flag3D, U8 KeyFlag)
{
U8 i,j;
TEXT NumKeyMap[]={'7','8','9','4','5','6','1','2','3','0',' ','.',0};
TEXT EnKeyMap[] ={'A','B','C','D','E',' ',' ','F','G','H','I',
'J','K','L','M','N','O','P','Q','R','S','T',
'U','V','W','X','Y','Z',0};
U8 NumKeyIndex[12]={7,8,9,4,5,6,1,2,3,0,36,37};
U8 EnKeyIndex[28] ={10,11,12,13,14,36,37,15,16,
17,18,19,20,21,22,23,
24,25,26,27,28,29,30,
31,32,33,34,35};
TEXT BackSpaceTxt[]={'<-',0};
TEXT DotTxt[] ={'. ',0};
TEXT ShiftTxt[]={'数',0};
TEXT Shift1TxT[]={'英',0};
TEXT tempkey[]={' ',0};
/*if (KeyFlag==1) //要显示英文键盘
{
for (i=0;i<4;i++)
{
for (j=0;j<7;j++)
{
if (EnKeyIndex[i*7+j]<36)
{
tempkey[0]=EnKeyMap[i*7+j];
if (CapsLock==FALSE) tempkey[0]|=0x20;
Ascii_Button3D(AreaID+EnKeyIndex[i*7+j],(P_TEXT)tempkey,xSrc+(j*(width+1)), ySrc+(i*(height+1)), width, height, Flag3D);
}
else if (EnKeyIndex[i*7+j]==36)
{
Text_Button3D(AreaID+36,(P_TEXT)BackSpaceTxt,xSrc+(j*(width+1)), ySrc+(i*(height+1)), width, height, Flag3D);
}
else if (EnKeyIndex[i*7+j]==37)
{
Text_Button3D(AreaID+37,(P_TEXT)ShiftTxt,xSrc+(j*(width+1)), ySrc+(i*(height+1)), width, height, Flag3D);
}
}
}
}*/
if (KeyFlag==2) //要显示数字键盘1
{
for (i=0;i<4;i++)
{
for (j=0;j<3;j++)
{
if (NumKeyIndex[i*3+j]<36)
{
tempkey[0]=NumKeyMap[i*3+j];
Ascii_Button3D(AreaID+NumKeyIndex[i*3+j],(P_TEXT)tempkey,xSrc+(j*(width+1)), ySrc+(i*(height+1)), width, height, Flag3D);
}
else if (NumKeyIndex[i*3+j]==36)
{
Text_Button3D(AreaID+36,(P_TEXT)BackSpaceTxt,xSrc+(j*(width+1)), ySrc+(i*(height+1)), width, height, Flag3D);
}
else if (NumKeyIndex[i*3+j]==37)
{
Text_Button3D(AreaID+37,(P_TEXT)DotTxt,xSrc+(j*(width+1)), ySrc+(i*(height+1)), width, height, Flag3D);
}
}
}
}
else if (KeyFlag==3) //要显示数字键盘2
{
for(i=0;i<4;i++)
{
for(j=0;j<3;j++)
{
if(NumKeyIndex[i*3+j]<36)
{
tempkey[0]=NumKeyMap[i*3+j];
Ascii_Button3D(AreaID+NumKeyIndex[i*3+j],(P_TEXT)tempkey,xSrc+(j*(width+1)),ySrc+(i*(height+1)),width,height,Flag3D);
}
else if(NumKeyIndex[i*3+j]==36)
Text_Button3D(AreaID+36,(P_TEXT)BackSpaceTxt,xSrc+(j*(width+1)),ySrc+(i*(height+1)),width,height,Flag3D);
else if(NumKeyIndex[i*3+j]==37)
Text_Button3D(AreaID+37,(P_TEXT)DotTxt,xSrc+(j*(width+1)),ySrc+(i*(height+1)),width,height,Flag3D);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -