#include "mywin_inc.h" #include "mywin_user_stat.h" #define WIN_STAT_TYPE "WIN_StatStruct" WIN_StatStruct *WIN_CreatStat (WIN_WindowStruct *base, void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg), int x,int y,int x_size,int y_size) { //重设消息循环 if (msgLoop==0) { msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))STAT_DefaultMsgLoop; } WIN_StatStruct *ret=mymalloc (sizeof ( WIN_StatStruct)); //调用父类的构造函数 if (ret) { mymemset (ret,0,sizeof ( WIN_StatStruct)); if (0==WIN_CreatWindowExt((WIN_WindowStruct *)ret,base,msgLoop,x,y,x_size,y_size)) { //创建失败 myfree (ret); ret=0; } else { ((WIN_WindowStruct *)ret)->winType=WIN_STAT_TYPE; ((WIN_WindowStruct *)ret)->keyShield=1;//屏蔽按键和触摸消息 ((WIN_WindowStruct *)ret)->bkcolor=0x000000; ((WIN_WindowStruct *)ret)->color=0xffffff; //构造一个 WIN_SetAsTopWin ((WIN_WindowStruct *)ret);//窗口置顶 } } return ret; } //设置显示文字,成功返回1 int STAT_SetTxt (WIN_StatStruct *stat,char *txt) { int ret=0; int len=strlen(txt); if (len>=STAT_TXT_MAXLEN) { ret=0; len=STAT_TXT_MAXLEN-1; mymemcpy (stat->txt,txt,len); stat->txt[len]=0; } else { ret=1; mymemcpy (stat->txt,txt,len+1); } return ret; } //设置图标 int STAT_SetImg (WIN_StatStruct *stat,u8 *img) { stat->img=img; return 1; } //默认绘制函数 void STAT_DefaultPaint (WIN_StatStruct *stat) { int x=0; int y=0; int x_size=((WIN_WindowStruct *)stat)->x_size; int y_size=((WIN_WindowStruct *)stat)->y_size; WIN_PaintBackGround ((WIN_WindowStruct *)stat); int img_xsize=0; //图标横向尺寸 int img_ysize=0; //图标纵向尺寸 int img_x=x_size-1; //图标起点 int img_y=0; //图标起点 int font_size=WIN_SetFontSize(12); WIN_SetLcdColor (((WIN_WindowStruct *)stat)->color); if (stat->img) { WIN_GetImageSize (stat->img,&img_xsize,&img_ysize); if (img_xsize>x_size) img_xsize=x_size; if (img_ysize>y_size) img_ysize=y_size; img_x=x_size/2-img_xsize/2; img_y=y_size/2-img_ysize/2; //开启状态,显示彩色 if (1) {WIN_DrawImag (img_x,img_y, img_xsize,img_ysize,stat->img);} } else if (stat->txt[0]) { WIN_DrawTxtHCenterAt (stat->txt,x_size/2,y_size/2-WIN_GetFontHight()/2); } WIN_SetFontSize (font_size); } //默认消息处理函数 void STAT_DefaultMsgLoop (WIN_StatStruct *stat,WIN_MsgStruct *msg) { WIN_MoveStruct *m=0; WIN_TouchStruct *t=0; switch (msg->msg) { case WIN_MSG_PAINT: STAT_DefaultPaint(stat); break; case WIN_MSG_TIMER: if (stat->TimerCallBack) stat->TimerCallBack(stat); break; default: WIN_DefaultMsgLoop((WIN_WindowStruct *)stat,msg); break; } }