391 lines
8.6 KiB
C
391 lines
8.6 KiB
C
#include "mywin_inc.h"
|
||
#include "mywin_user_status_bar.h"
|
||
#include "date.h"
|
||
|
||
|
||
|
||
//状态栏,继承自MYWIN框架
|
||
//用户界面,根据具体显示用途编写,没有通用性
|
||
#define WIN_STATUSBAR_TYPE "WIN_StatusBarStruct"
|
||
|
||
|
||
|
||
|
||
WIN_StatusBarStruct *WIN_CreatStatusBar (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))STATUSBAR_DefaultMsgLoop;
|
||
}
|
||
|
||
WIN_StatusBarStruct *ret=mymalloc (sizeof ( WIN_StatusBarStruct));
|
||
//调用父类的构造函数
|
||
if (ret)
|
||
{
|
||
mymemset (ret,0,sizeof ( WIN_StatusBarStruct));
|
||
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_STATUSBAR_TYPE;
|
||
//((WIN_WindowStruct *)ret)->keyShield=1;//屏蔽按键和触摸消息
|
||
//构造一个
|
||
ret->img_xsize=40;
|
||
ret->backColor=0;
|
||
ret->color=0xffffffff;
|
||
mymemcpy (ret->stat.time,"示例时间 00:00",15);
|
||
mymemcpy (ret->stat.mode,"示例模式",9);
|
||
ret->timerIdGet=WIN_CreatTimer ((WIN_WindowStruct *)ret,100);
|
||
//WIN_SetAsTopWin ((WIN_WindowStruct *)ret);//窗口置顶
|
||
ret->y_size_def=y_size;
|
||
ret->app_y_step=30;
|
||
}
|
||
}
|
||
|
||
|
||
return ret;
|
||
}
|
||
|
||
|
||
//状态信息更新
|
||
void STATUSBAR_StateUpdata (WIN_StatusBarStruct *statusbar,STATUSBAR_DataStruct *s)
|
||
{
|
||
int temp=statusbar->stat.mode_x;
|
||
|
||
//使用内存复制的方法复制结构体
|
||
mymemcpy (& statusbar->stat,s,sizeof (STATUSBAR_DataStruct));
|
||
if (strlen(statusbar->stat.mode)>8)
|
||
{
|
||
//字符串过长时使用滚动显示
|
||
if (statusbar->timerId==0)
|
||
{
|
||
statusbar->timerId=WIN_CreatTimer ((WIN_WindowStruct *)statusbar,100);
|
||
statusbar->stat.mode_x=WIN_GetFontWidth()*4/2;
|
||
}
|
||
else
|
||
{
|
||
statusbar->stat.mode_x=temp;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (statusbar->timerId)
|
||
{
|
||
WIN_DeleteTimer(statusbar->timerId);
|
||
statusbar->timerId=0;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
//设置资源文件
|
||
void STATUSBAR_SetRes (WIN_StatusBarStruct *statusbar,STATUSBAR_ResStruct *r)
|
||
{
|
||
//使用内存复制的方法复制结构体
|
||
mymemcpy (& statusbar->res,r,sizeof (STATUSBAR_ResStruct));
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
//设置背景图片
|
||
void STATUSBAR_SetBackPic (WIN_StatusBarStruct *statusbar,WIN_PicStruct *pic)
|
||
{
|
||
if (pic)
|
||
{
|
||
mymemcpy(&statusbar->pic,pic,sizeof(WIN_PicStruct));
|
||
}
|
||
else
|
||
{
|
||
mymemset(&statusbar->pic,0,sizeof(WIN_PicStruct));
|
||
}
|
||
}
|
||
|
||
|
||
void STATUSBAR_ScanApp(WIN_StatusBarStruct *bar)
|
||
{
|
||
for(int i=0;i<APPM_LIST_MAXLEN;i++)
|
||
{
|
||
app_struct *app=appm_get(i);
|
||
if(app)
|
||
{
|
||
bar->app_item[bar->app_num].app=app;
|
||
bar->app_num++;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
void STATUSBAR_ClearApp(WIN_StatusBarStruct *bar)
|
||
{
|
||
bar->app_num=0;
|
||
}
|
||
|
||
|
||
|
||
//默认绘制函数
|
||
void STATUSBAR_DefaultPaint (WIN_StatusBarStruct *statusbar)
|
||
{
|
||
|
||
int x=0;
|
||
int y=0;
|
||
int x_size=((WIN_WindowStruct *)statusbar)->x_size;
|
||
// int y_size=((WIN_WindowStruct *)statusbar)->y_size;
|
||
int y_size=20;
|
||
int tag_xsize=0;//绘制目标的宽度
|
||
|
||
//显示背景
|
||
WIN_SetLcdBkColor (statusbar->backColor);
|
||
//如果有图片就显示图片
|
||
if (statusbar->pic.data)
|
||
{
|
||
WIN_FillRect (0,0,((WIN_WindowStruct *)statusbar)->x_size,((WIN_WindowStruct *)statusbar)->y_size,
|
||
statusbar->pic.data,((WIN_WindowStruct *)statusbar)->x,((WIN_WindowStruct *)statusbar)->y,statusbar->pic.xsize,statusbar->pic.ysize);
|
||
}
|
||
else
|
||
{
|
||
WIN_Clear();
|
||
}
|
||
|
||
u32 font_type =WIN_SetFontSize (16);
|
||
|
||
WIN_SetLcdColor (statusbar->color);
|
||
|
||
//显示时间
|
||
WIN_SetFontMode (WIN_DRAWMODE_ALONE);
|
||
WIN_SetLcdBkColor (statusbar->color);
|
||
if (statusbar->stat.time[0])
|
||
{
|
||
WIN_DrawTxtAt (statusbar->stat.time,x,y_size/2-WIN_GetFontHight()/2);
|
||
}
|
||
|
||
//显示模式
|
||
if (statusbar->stat.mode[0])
|
||
{
|
||
WIN_DrawTxtHCenterAt (statusbar->stat.mode,x_size/2,y_size/2-WIN_GetFontHight()/2);
|
||
}
|
||
|
||
//显示电池百分比,从右向左绘制
|
||
if (statusbar->stat.betty[0])
|
||
{
|
||
tag_xsize=strlen(statusbar->stat.betty)*WIN_GetFontWidth()/2;
|
||
WIN_DrawTxtAt (statusbar->stat.betty,x_size-tag_xsize-1,y_size/2-WIN_GetFontHight()/2);
|
||
x_size-=tag_xsize;
|
||
}
|
||
|
||
|
||
int y_step=statusbar->app_y_step;
|
||
x=15;
|
||
y=statusbar->y_size_def+10;
|
||
x_size=((WIN_WindowStruct *)statusbar)->x_size;
|
||
char txt[20]={0};
|
||
for(int i=0;i<statusbar->app_num;i++)
|
||
{
|
||
int txt_y=y+(y_step-WIN_GetFontHight())/2;
|
||
STATUSBAR_AppStruct *app_item=&statusbar->app_item[i];
|
||
RECT_Struct *rect=0;
|
||
WIN_DrawTxtAt(app_item->app->app_info->name,x,txt_y);
|
||
if(app_item->app->run_state)
|
||
WIN_DrawTxtAt("活动中",x+x_size*1/4,txt_y);
|
||
rect=&app_item->enter;
|
||
rect->x_size=x_size/4;
|
||
rect->y_size=y_step;
|
||
rect->x=x+x_size*2/4;rect->y=y;
|
||
WIN_DrawTxtAt("打开",rect->x,txt_y);
|
||
rect=&app_item->exit;
|
||
rect->x=x+x_size*3/4;rect->y=y;
|
||
rect->x_size=x_size/4;
|
||
rect->y_size=y_step;
|
||
WIN_DrawTxtAt("删除",rect->x,txt_y);
|
||
|
||
y+=y_step;
|
||
WIN_DrawHLine(10,y,x_size-1-10);
|
||
}
|
||
|
||
WIN_SetFontSize (font_type);
|
||
}
|
||
|
||
|
||
|
||
|
||
int STATUSBAR_AppButton(WIN_StatusBarStruct *bar,WIN_MoveStruct *m)
|
||
{
|
||
WIN_WindowStruct *win=(WIN_WindowStruct *)bar;
|
||
for(int i=0;i<bar->app_num;i++)
|
||
{
|
||
STATUSBAR_AppStruct *app_item=&bar->app_item[i];
|
||
RECT_Struct *rect=0;
|
||
rect=&app_item->enter;
|
||
if(POS_InRect(rect->x,rect->y,rect->x_size,rect->y_size,m->x_move,m->y_move))
|
||
{
|
||
//打开编号为i的app
|
||
WIN_SetSize (win,win->x_size,bar->y_size_def);
|
||
bar->dis=0;
|
||
app_run(app_item->app);
|
||
return 0;
|
||
}
|
||
rect=&app_item->exit;
|
||
if(POS_InRect(rect->x,rect->y,rect->x_size,rect->y_size,m->x_move,m->y_move))
|
||
{
|
||
//退出编号为i的app
|
||
if(app_exit(app_item->app) !=0)
|
||
{
|
||
MSGBOX_TipsTime ((WIN_WindowStruct *)bar,"错误","删除进程失败","确定",5*1000);
|
||
}
|
||
WIN_SetSize (win,win->x_size,bar->y_size_def);
|
||
bar->dis=0;
|
||
return 0;
|
||
}
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
|
||
int STATUSBAR_TouchMove(WIN_StatusBarStruct *statusbar,WIN_MoveStruct *m)
|
||
{
|
||
WIN_WindowStruct *win=(WIN_WindowStruct *)statusbar;
|
||
int y_max=WIN_GetWinStruct()->lcd->getLcdSizeY();
|
||
switch(m->moveType)
|
||
{
|
||
case MOVE_DATA_SHORT:
|
||
STATUSBAR_AppButton(statusbar,m);
|
||
break;
|
||
case MOVE_DATA_MOVED:
|
||
if(statusbar->mov_start)
|
||
{
|
||
int y_temp=win->y_size+m->y_move;
|
||
if(y_temp<statusbar->y_size_def) y_temp=statusbar->y_size_def;
|
||
WIN_SetSize (win,win->x_size,y_temp);
|
||
}
|
||
break;
|
||
case MOVE_DATA_TOUCHIN:
|
||
if(statusbar->mov_start==0)
|
||
{
|
||
//在屏幕边缘的滑动用于改变窗口大小
|
||
//if(m->y_move<20||m->y_move>y_max-20)
|
||
{
|
||
statusbar->mov_start=1;
|
||
if (statusbar->dis==0)
|
||
{
|
||
statusbar->dis=1;
|
||
WIN_SetSize (win,win->x_size,100);
|
||
}
|
||
else
|
||
{
|
||
statusbar->dis=0;
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case MOVE_DATA_TOUCHOUT:
|
||
case MOVE_DATA_MOVEOUT:
|
||
if(statusbar->mov_start)
|
||
{
|
||
if(statusbar->dis==1)
|
||
{
|
||
if(win->y_size>200)
|
||
{
|
||
WIN_SetSize (win,win->x_size,y_max);
|
||
}
|
||
else
|
||
{
|
||
WIN_SetSize (win,win->x_size,statusbar->y_size_def);
|
||
statusbar->dis=0;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(win->y_size<y_max-100)
|
||
{
|
||
WIN_SetSize (win,win->x_size,statusbar->y_size_def);
|
||
}
|
||
else
|
||
{
|
||
WIN_SetSize (win,win->x_size,y_max);
|
||
statusbar->dis=1;
|
||
}
|
||
}
|
||
statusbar->mov_start=0;
|
||
}
|
||
break;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
//默认消息处理函数
|
||
void STATUSBAR_DefaultMsgLoop (WIN_StatusBarStruct *statusbar,WIN_MsgStruct *msg)
|
||
{
|
||
WIN_MoveStruct *m=0;
|
||
WIN_TouchStruct *t=0;
|
||
STATUSBAR_DataStruct *s=0;
|
||
switch (msg->msg)
|
||
{
|
||
case WIN_MSG_PAINT:
|
||
STATUSBAR_DefaultPaint(statusbar);
|
||
break;
|
||
case WIN_MSG_KEY:
|
||
break;
|
||
case WIN_MSG_MOVE:
|
||
m=msg->data.p;
|
||
STATUSBAR_TouchMove(statusbar,m);
|
||
break;
|
||
case WIN_MSG_TIMER:
|
||
if (msg->data.v==statusbar->timerId)
|
||
{
|
||
}
|
||
else if (msg->data.v==statusbar->timerIdGet)
|
||
{
|
||
int Hours=0;int Minutes=0;int Seconds;
|
||
STATUSBAR_DataStruct *statu=mymalloc (sizeof (STATUSBAR_DataStruct));
|
||
mymemset (statu,0,sizeof (STATUSBAR_DataStruct));
|
||
date_rtc_get_time (&Hours,&Minutes,&Seconds);
|
||
if (statusbar->sec!=Seconds)
|
||
{
|
||
//更新状态栏
|
||
statusbar->sec=Seconds;
|
||
sprintf (statu->time,"%02d:%02d:%02d", Hours,Minutes,Seconds);
|
||
sprintf (statu->mode,"mem:%.1f,exm:%.1f",mem_perused()/100.0,exmem_perused()/100.0);
|
||
sprintf (statu->betty,"电量:100%%");
|
||
STATUSBAR_StateUpdata (statusbar,statu);
|
||
|
||
STATUSBAR_ClearApp(statusbar);
|
||
STATUSBAR_ScanApp(statusbar);
|
||
|
||
WIN_SetInvalidWhenTop ((WIN_WindowStruct *)statusbar);
|
||
}
|
||
myfree(statu);
|
||
}
|
||
break;
|
||
//状态栏接收的外部消息是为 STATUSBAR_Struct 类型的结构体
|
||
case WIN_MSG_EXTMSG:
|
||
s=msg->data.p;
|
||
STATUSBAR_StateUpdata (statusbar,s);
|
||
WIN_SetInvalid ((WIN_WindowStruct *)statusbar);
|
||
break;
|
||
default:
|
||
WIN_DefaultMsgLoop((WIN_WindowStruct *)statusbar,msg);
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|