📄 pdagui.c
字号:
/***************************************************** **PDA_GUI demo by zhang kaohua 2004,5,20 kaohua@126.com** *****************************************************/#include <stdio.h>#include <stdlib.h>#include <time.h>#include "pthread.h"#if UNIX | DOS_DJGPP#endif#define MWINCLUDECOLORS#include "nano-X.h"#define WIDTH 320#define HEIGHT 215#define bkpic "./res/picture/top18.bmp"/**********************************************************/static GR_WINDOW_ID window;static GR_WINDOW_ID bt1,bt2,bt3;static GR_WINDOW_ID smb[10]; //menustatic GR_WINDOW_ID scb[10]; //shortCutstatic GR_GC_ID gc;static GR_GC_ID gcfn;static GR_FONT_ID fontid;static GR_IMAGE_ID picID; //put background's imagestatic GR_IMAGE_ID icon[10]; //put icon's imagestatic GR_IMAGE_INFO picIF; //image information of backgroundstatic GR_IMAGE_INFO iconIF[10]; //image information of icon struct DATE_TIME { char year[10]; char mon[10]; char day[10]; char hour[10]; char min[10]; char sec[10]; char week[10]; char date[50]; char dateTime[50]; }; char *fileName[10]={"退 出","记事本","名片","通讯录","画板","游戏","闹钟","音乐","file8","file9"}; char *picfile[10]={"./res/picture/book10s.gif","./res/picture/earth6s.gif","./res/picture/note39s.gif","./res/picture/hbs.gif","","","","","",""}; struct DATE_TIME datetime; static int ret;/**********************************************************/void drawMainWin(GR_GC_ID gc);void drawBar(GR_GC_ID gc);void loadImage(GR_IMAGE_ID picID,GR_IMAGE_INFO picIF,char *picfile);void setBackGround();void* doTime(void* data);void doStartMenu(int fileNnum,GR_GC_ID gc);void doShortCut(char *fileName,int fileNum,GR_GC_ID gc,int x,int y,GR_IMAGE_ID icon,GR_IMAGE_INFO iconIF);void doEventButtonDown(GR_EVENT_BUTTON *bevent,GR_GC_ID gc);void doEventButtonUp(GR_EVENT_BUTTON *bevent);void doEventMouseExit(GR_EVENT_MOUSE *mevent,GR_GC_ID gc);void doEventMouseEnter(GR_EVENT_MOUSE *mevent,GR_GC_ID gc);void highLightStartMenu(int i);/**********************************************************/int main(int ac, char **av){ //void * retval; int i; pthread_t th_com; if (GrOpen() < 0) exit(1); gc = GrNewGC(); gcfn=GrNewGC(); GrSetGCBackground(gc, WHITE); GrSetGCForeground(gc, 255); GrSetGCUseBackground(gcfn, GR_FALSE); GrSetGCBackground(gcfn, BLACK); GrSetGCForeground(gcfn, 255); fontid = GrCreateFont("HZKFONT", 0, NULL); GrSetFontSize(fontid, 16); GrSetFontRotation(fontid, 330); // 33 degrees GrSetFontAttr(fontid, GR_TFKERNING | GR_TFANTIALIAS, 0); GrSetGCFont(gcfn, fontid); //loadImage(picID,picIF,bkpic); if(!(picID = GrLoadImageFromFile(bkpic, 0))) { fprintf(stderr, "Failed to load image file \"%s\"\n", bkpic); } GrGetImageInfo(picID, &picIF); for(i=0;i<4;i++) { if(!(icon[i] = GrLoadImageFromFile(picfile[i], 0))) { fprintf(stderr, "Failed to load image file \"%s\"\n", picfile[i]); } GrGetImageInfo(icon[i], &iconIF[i]); } drawMainWin(gc); drawBar(gcfn); setBackGround(); pthread_create(&th_com, NULL, doTime, 0); //pthread_join(th_com, &retval);while (1) { //doTime(gc); GR_EVENT event; GrCheckNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); case GR_EVENT_TYPE_BUTTON_DOWN: doEventButtonDown(&event.button,gcfn); break; case GR_EVENT_TYPE_BUTTON_UP: doEventButtonUp(&event.button); break; case GR_EVENT_TYPE_MOUSE_ENTER: doEventMouseEnter(&event.mouse,gcfn); break; case GR_EVENT_TYPE_MOUSE_EXIT: doEventMouseExit(&event.mouse,gcfn); break; //case GR_EVENT_TYPE_TIMEOUT: } //GrDestroyFont(fontid); } GrFlush(); GrDestroyFont(fontid); GrDestroyGC(gcfn); GrDestroyGC(gc); GrClose(); return 0;}////////////////////////////////////////////////////////////////////////////////////////////////////void drawMainWin(GR_GC_ID gc){ window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, WIDTH, HEIGHT-2,1,BLACK,BLUE); GrSelectEvents(window, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT); GrMapWindow(window); //GrFreeImage(picID); //GrDestroyWindow(window);}//////////////////////////////////////////////////////////////////////////////////////////////////void drawBar(GR_GC_ID gc){ bt1=GrNewWindow(GR_ROOT_WINDOW_ID,0,215,70,23,2,GREEN,BLUE); bt2=GrNewWindow(GR_ROOT_WINDOW_ID,70,215,180,23,2,GREEN,BLUE); bt3=GrNewWindow(GR_ROOT_WINDOW_ID,250,215,70,23,2,GREEN,BLUE); GrSelectEvents(bt1,GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(bt2,GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(bt3,GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrMapWindow(bt1); GrMapWindow(bt2); GrMapWindow(bt3); GrSetGCForeground(gc, WHITE); GrSetGCUseBackground(gc, GR_FALSE); GrSetGCFont(gc, fontid); GrText(bt1, gc, 13, 15, "开 始", -1, GR_TFASCII); GrText(bt2, gc,1, 15, "博创PDAwww.up-tech.com", -1, GR_TFASCII); }/*********************************************************************/void setBackGround(){ GrDrawImageToFit(window, gc, 0, 0, picIF.width, picIF.height, picID); doShortCut(fileName[1],0,gcfn,20,20,icon[0],iconIF[0]); doShortCut(fileName[2],1,gcfn,20,80,icon[1],iconIF[1]); doShortCut(fileName[3],2,gcfn,20,140,icon[2],iconIF[2]); doShortCut(fileName[4],3,gcfn,80,20,icon[3],iconIF[3]);}/*********************************************************/void loadImage(GR_IMAGE_ID picID, GR_IMAGE_INFO picIF, char *picfile){ GR_IMAGE_ID pic_ID; GR_IMAGE_INFO pic_IF; if(!(picID = GrLoadImageFromFile(picfile, 0))) { fprintf(stderr, "Failed to load image file \"%s\"\n", picfile); } GrGetImageInfo(picID, &picIF); picID=pic_ID; picIF=pic_IF;}/**********************************************************/void doStartMenu(int fileNum,GR_GC_ID gc){ int i; char* startMenuFileName[fileNum+1]; int smbW,smbH; smbW=100; smbH=20; GrSetGCForeground(gc, MWRGB(255,0,0)); GrSetGCUseBackground(gc, GR_FALSE); GrSetGCFont(gc, fontid); for(i=0;i<fileNum;i++) { smb[i]=GrNewWindow(GR_ROOT_WINDOW_ID,1,192-i*smbH,smbW,smbH,2,GREEN,BLUE); GrSelectEvents(smb[i],GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT); GrMapWindow(smb[i]); startMenuFileName[i]=fileName[i]; GrText(smb[i],gc,13,15,startMenuFileName[i],-1,GR_FALSE); } }//////////////////////////////////////////////////////////////////////////////////////////////////////void doEventMouseEnter(GR_EVENT_MOUSE *mevent,GR_GC_ID gc){ GrSetGCFont(gc, fontid); GrSetGCForeground(gc, YELLOW); if(mevent->wid==smb[0]) { GrText(smb[0],gc,13,15,fileName[0],-1,GR_FALSE); } if(mevent->wid==smb[1]) { GrText(smb[1],gc,13,15,fileName[1],-1,GR_FALSE); } if(mevent->wid==smb[2]) { GrText(smb[2],gc,13,15,fileName[2],-1,GR_FALSE); } if(mevent->wid==smb[3]) { GrText(smb[3],gc,13,15,fileName[3],-1,GR_FALSE); } if(mevent->wid==smb[4]) { GrText(smb[4],gc,13,15,fileName[4],-1,GR_FALSE); } if(mevent->wid==smb[5]) { GrText(smb[5],gc,13,15,fileName[5],-1,GR_FALSE); } if(mevent->wid==smb[6]) { GrText(smb[6],gc,13,15,fileName[6],-1,GR_FALSE); } if(mevent->wid==smb[7]) { GrText(smb[7],gc,13,15,fileName[7],-1,GR_FALSE); } }//////////////////////////////////////////////////////////////////////////////////////////////////////void doEventMouseExit(GR_EVENT_MOUSE *mevent,GR_GC_ID gc){ GrSetGCFont(gc, fontid); GrSetGCForeground(gc, MWRGB(255,0,0)); if(mevent->wid==smb[0]) { GrText(smb[0],gc,13,15,fileName[0],-1,GR_FALSE); } if(mevent->wid==smb[1]) { GrText(smb[1],gc,13,15,fileName[1],-1,GR_FALSE); } if(mevent->wid==smb[2]) { GrText(smb[2],gc,13,15,fileName[2],-1,GR_FALSE); } if(mevent->wid==smb[3]) { GrText(smb[3],gc,13,15,fileName[3],-1,GR_FALSE); } if(mevent->wid==smb[4]) { GrText(smb[4],gc,13,15,fileName[4],-1,GR_FALSE); } if(mevent->wid==smb[5]) { GrText(smb[5],gc,13,15,fileName[5],-1,GR_FALSE); } if(mevent->wid==smb[6]) { GrText(smb[6],gc,13,15,fileName[6],-1,GR_FALSE); } if(mevent->wid==smb[7]) { GrText(smb[7],gc,13,15,fileName[7],-1,GR_FALSE); } }//////////////////////////////////////////////////////////////////////////////////////////////////////void doEventButtonDown(GR_EVENT_BUTTON *bevent,GR_GC_ID gc){ if(bevent->wid==window) { drawMainWin(gc); setBackGround(); } if(bevent->wid==bt1) { doStartMenu(7,gcfn); } if(bevent->wid==bt2) { GrSetGCForeground(gc,BLACK); GrSetGCBackground(gc,BLACK); GrFillRect(window,gc,0,0,320,220); } if(bevent->wid==bt3) { } if(bevent->wid==smb[0]) { GrClose(); exit(0); } if(bevent->wid==smb[1]) { } if(bevent->wid==smb[2]) { } if(bevent->wid==smb[3]) { } if(bevent->wid==smb[4]) { ret=system("/mnt/yaffs/mw/demotpdraw"); //GrClose(); //exit(3); //exit(0); //drawMainWin(gc); //setBackGround(); } if(bevent->wid==smb[5]) { } if(bevent->wid==smb[6]) { } if(bevent->wid==scb[0]) { //demoDraw(); } if(bevent->wid==scb[1]) { } if(bevent->wid==scb[2]) { GrClose(); exit(2); } if(bevent->wid==scb[3]) { ret=system("/mnt/yaffs/mw/demotpdraw"); drawMainWin(gc); drawBar(gcfn); setBackGround(); //GrClose(); //exit(3); } if(bevent->wid==scb[4]) { GrClose(); exit(0); } if(bevent->wid==scb[5]) { } }/////////////////////////////////////////////////////////////////////////////////////////////////////void doEventButtonUp(GR_EVENT_BUTTON *bevent){ }//////////////////////////////////////////////////////////////////////////////////////////////////////void* doTime(void* data){ struct tm *tm_ptr; time_t timer; GrSetGCUseBackground(gcfn, GR_FALSE); GrSetGCFont(gcfn, fontid); GrSetGCForeground(gcfn, 255); while(1) { time(&timer); tm_ptr=localtime(&timer); strftime(datetime.year,10,"%Y",tm_ptr); strftime(datetime.mon,10,"%m",tm_ptr); strftime(datetime.day,10,"%d",tm_ptr); strftime(datetime.week,10,"%w",tm_ptr); strftime(datetime.hour,10,"%I",tm_ptr); strftime(datetime.min,10,"%M",tm_ptr); strftime(datetime.sec,10,"%S",tm_ptr); snprintf(datetime.date,sizeof(datetime.date),"%s/%s/%s",datetime.year,datetime.mon,datetime.day); snprintf(datetime.dateTime,sizeof(datetime.dateTime),"%s:%s:%s",datetime.hour,datetime.min,datetime.sec); GrSetGCForeground(gc,GREEN); GrSetGCBackground(gc,BLACK); GrFillRect(bt3,gc,0,0,70,23); GrText(bt3, gcfn, 5, 15, datetime.dateTime, -1, GR_TFASCII); usleep(100000); }}///////////////////////////////////////////////////////////////////////////////////////////////////////void doShortCut(char *fileName,int fileNum,GR_GC_ID gc,int x,int y,GR_IMAGE_ID icon,GR_IMAGE_INFO iconIF){ int scbW,scbH; scbW=40; scbH=30; scb[fileNum]=GrNewWindow(window,x,y,scbW,scbH,0,GREEN,BLUE); GrSelectEvents(scb[fileNum],GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT); GrMapWindow(scb[fileNum]); GrSetGCForeground(gc, MWRGB(555,55,55)); GrSetGCUseBackground(gc, GR_FALSE); GrSetGCFont(gc, fontid); GrSetFontSize(fontid, 12); GrDrawImageToFit(scb[fileNum], gc, 0, 0, iconIF.width, iconIF.height, icon); GrText(window,gc,x+1,y+scbH+20,fileName,-1,GR_FALSE);} ///////////////////////////////////////////////////////////////////////////////////////////////////////void highLightStartMenu(int i){ //char* startMenuFileName[fileNum+1]; int smbW,smbH; smbW=100; smbH=20; smb[i]=GrNewWindow(GR_ROOT_WINDOW_ID,1,192-i*smbH,smbW,smbH,2,YELLOW,BLUE); GrSelectEvents(smb[i],GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT); GrMapWindow(smb[i]); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -