272 lines
7.0 KiB
C
272 lines
7.0 KiB
C
#include "mywin_inc.h"
|
|
#include "mywin_user_timeset.h"
|
|
#include "date.h"
|
|
|
|
|
|
|
|
|
|
#define WIN_TIMESETBOX_TYPE "WIN_TimeSetboxStruct"
|
|
|
|
|
|
|
|
WIN_TimeSetboxStruct *WIN_CreatTimeSetbox (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))TIMESETBOX_defaultMsgLoop;
|
|
}
|
|
|
|
WIN_TimeSetboxStruct *ret=mymalloc (sizeof ( WIN_TimeSetboxStruct));
|
|
//调用父类的构造函数
|
|
if (ret)
|
|
{
|
|
mymemset (ret,0,sizeof ( WIN_TimeSetboxStruct));
|
|
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_TIMESETBOX_TYPE;
|
|
//构造一个消息框
|
|
ret->title="时间日期设置";
|
|
date_rtc_get_date (&ret->year,&ret->mounth,&ret->date);
|
|
date_rtc_get_time (&ret->hour,&ret->min,&ret->sec);
|
|
}
|
|
}
|
|
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//参数增加
|
|
void TIMESETBOX_Add (WIN_TimeSetboxStruct *timesetbox)
|
|
{
|
|
if (timesetbox->index==0)
|
|
{
|
|
if (timesetbox->year<date_get_year_max()) timesetbox->year++;
|
|
else timesetbox->year=date_get_year_min();
|
|
}
|
|
else if (timesetbox->index==1)
|
|
{
|
|
if (timesetbox->mounth<12) timesetbox->mounth++;
|
|
else timesetbox->mounth=1;
|
|
}
|
|
else if (timesetbox->index==2)
|
|
{
|
|
if (timesetbox->date<date_get_month_day_max(timesetbox->year,timesetbox->mounth)) timesetbox->date++;
|
|
else timesetbox->date=1;
|
|
}
|
|
else if (timesetbox->index==3)
|
|
{
|
|
if (timesetbox->hour<23) timesetbox->hour++;
|
|
else timesetbox->hour=0;
|
|
}
|
|
else if (timesetbox->index==4)
|
|
{
|
|
if (timesetbox->min<59) timesetbox->min++;
|
|
else timesetbox->min=0;
|
|
}
|
|
else if (timesetbox->index==5)
|
|
{
|
|
if (timesetbox->sec<59) timesetbox->sec++;
|
|
else timesetbox->sec=0;
|
|
}
|
|
}
|
|
|
|
//参数减少
|
|
void TIMESETBOX_Sub (WIN_TimeSetboxStruct *timesetbox)
|
|
{
|
|
if (timesetbox->index==0)
|
|
{
|
|
if (timesetbox->year>date_get_year_min()) timesetbox->year--;
|
|
else timesetbox->year=date_get_year_max();
|
|
}
|
|
else if (timesetbox->index==1)
|
|
{
|
|
if (timesetbox->mounth>1) timesetbox->mounth--;
|
|
else timesetbox->mounth=12;
|
|
}
|
|
else if (timesetbox->index==2)
|
|
{
|
|
if (timesetbox->date>1) timesetbox->date--;
|
|
else timesetbox->date=date_get_month_day_max(timesetbox->year,timesetbox->mounth);
|
|
}
|
|
else if (timesetbox->index==3)
|
|
{
|
|
if (timesetbox->hour>0) timesetbox->hour--;
|
|
else timesetbox->hour=23;
|
|
}
|
|
else if (timesetbox->index==4)
|
|
{
|
|
if (timesetbox->min>0) timesetbox->min--;
|
|
else timesetbox->min=59;
|
|
}
|
|
else if (timesetbox->index==5)
|
|
{
|
|
if (timesetbox->sec>0) timesetbox->sec--;
|
|
else timesetbox->sec=59;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//消息框的绘制函数
|
|
void TIMESETBOX_DefaultPaint (WIN_TimeSetboxStruct *timesetbox)
|
|
{
|
|
|
|
int x=0;
|
|
int y=0;
|
|
int x_size=((WIN_WindowStruct *)timesetbox)->x_size;
|
|
int y_size=((WIN_WindowStruct *)timesetbox)->y_size;
|
|
char txt_buff[20]={0};
|
|
|
|
WIN_PaintBackGround ((WIN_WindowStruct *)timesetbox);
|
|
|
|
//绘制标题
|
|
WIN_SetFontMode(WIN_DRAWMODE_ALONE);
|
|
WIN_SetLcdColor(((WIN_WindowStruct *)timesetbox)->color);
|
|
WIN_DrawTxtHCenterAt (timesetbox->title,x_size/2,y);
|
|
y+=WIN_GetFontHight();
|
|
|
|
//绘制选中框
|
|
int rect_y_step=y_size/4;
|
|
int rect_x=10;
|
|
int rect_y=y+rect_y_step-WIN_GetFontHight()/2;
|
|
int rect_xsize=(x_size-20)/3;
|
|
int rect_ysize=WIN_GetFontHight();
|
|
WIN_SetLcdColor(0x00ff0080);
|
|
if (timesetbox->index<3)
|
|
{
|
|
rect_x+=rect_xsize*timesetbox->index;
|
|
WIN_FillRectByColor (rect_x,rect_y,rect_xsize,rect_ysize);
|
|
}
|
|
else
|
|
{
|
|
rect_y+=rect_y_step;
|
|
rect_x+=rect_xsize*(timesetbox->index-3);
|
|
WIN_FillRectByColor (rect_x,rect_y,rect_xsize,rect_ysize);
|
|
}
|
|
|
|
//显示文本
|
|
WIN_SetLcdColor(((WIN_WindowStruct *)timesetbox)->color);
|
|
sprintf (txt_buff,"%04d 年 %02d 月 %02d 日",timesetbox->year,timesetbox->mounth,timesetbox->date );
|
|
WIN_DrawTxtHCenterAt (txt_buff,x_size/2,y+rect_y_step-WIN_GetFontHight()/2);
|
|
sprintf (txt_buff,"%02d 时 %02d 分 %02d 秒",timesetbox->hour,timesetbox->min,timesetbox->sec );
|
|
WIN_DrawTxtHCenterAt (txt_buff,x_size/2,y+rect_y_step-WIN_GetFontHight()/2+rect_y_step);
|
|
|
|
}
|
|
|
|
|
|
|
|
//消息框的消息处理函数
|
|
void TIMESETBOX_defaultMsgLoop (WIN_TimeSetboxStruct *timesetbox,WIN_MsgStruct *msg)
|
|
{
|
|
WIN_MoveStruct *m=0;
|
|
WIN_KeyStruct *k=0;
|
|
switch (msg->msg)
|
|
{
|
|
case WIN_MSG_PAINT:
|
|
TIMESETBOX_DefaultPaint(timesetbox);
|
|
break;
|
|
case WIN_MSG_INIT:
|
|
break;
|
|
case WIN_MSG_KEY:
|
|
k=msg->data.p;
|
|
//收到确定或返回键
|
|
if (k->shortPress&KEY_VALUE_UP)
|
|
{
|
|
TIMESETBOX_Add (timesetbox);
|
|
}
|
|
else if (k->shortPress&KEY_VALUE_DOWN)
|
|
{
|
|
TIMESETBOX_Sub (timesetbox);
|
|
}
|
|
else if (k->shortPress&KEY_VALUE_ENTER)
|
|
{
|
|
if (timesetbox->index<5) timesetbox->index++;
|
|
else timesetbox->index=0;
|
|
}
|
|
if (k->shortPress)
|
|
{
|
|
WIN_SetInvalidRect ((WIN_WindowStruct *)timesetbox,0,16,((WIN_WindowStruct *)timesetbox)->x_size,((WIN_WindowStruct *)timesetbox)->y_size-16);
|
|
}
|
|
if (k->shortPress&KEY_VALUE_HOME)
|
|
{
|
|
MSGBOX_TipsTime ((WIN_WindowStruct *)timesetbox,"提示","设置没有保存","确定",5000);
|
|
((WIN_WindowStruct *)timesetbox)->deleteWindow((WIN_WindowStruct *)timesetbox);
|
|
}
|
|
else if (k->longPress&KEY_VALUE_ENTER)
|
|
{
|
|
date_rtc_set_date (timesetbox->year,timesetbox->mounth,timesetbox->date);
|
|
date_rtc_set_time (timesetbox->hour,timesetbox->min,timesetbox->sec);
|
|
MSGBOX_TipsTime ((WIN_WindowStruct *)timesetbox,"提示","设置已保存","确定",5000);
|
|
((WIN_WindowStruct *)timesetbox)->deleteWindow((WIN_WindowStruct *)timesetbox);
|
|
}
|
|
break;//case WIN_MSG_KEY:
|
|
case WIN_MSG_TOUCH:
|
|
break;
|
|
case WIN_MSG_CHID:
|
|
break;
|
|
case WIN_MSG_DELETE:
|
|
break;
|
|
case WIN_MSG_TIMER:
|
|
//定时器时间到
|
|
((WIN_WindowStruct *)timesetbox)->deleteWindow((WIN_WindowStruct *)timesetbox);
|
|
break;
|
|
case WIN_MSG_MOVE:
|
|
m=msg->data.p;
|
|
switch (m->moveType)
|
|
{
|
|
case MOVE_DATA_MOVEIN:
|
|
break;
|
|
case MOVE_DATA_MOVED:
|
|
break;
|
|
case MOVE_DATA_LONG:
|
|
break;
|
|
case MOVE_DATA_MOVEOUT:
|
|
case MOVE_DATA_OUTSIDE:
|
|
timesetbox->press=0;
|
|
WIN_SetInvalidRect ((WIN_WindowStruct *)timesetbox,0,((WIN_WindowStruct *)timesetbox)->y_size-16,((WIN_WindowStruct *)timesetbox)->x_size,16);
|
|
break;
|
|
case MOVE_DATA_TOUCHOUT:
|
|
if (timesetbox->press)
|
|
((WIN_WindowStruct *)timesetbox)->deleteWindow((WIN_WindowStruct *)timesetbox);
|
|
break;
|
|
case MOVE_DATA_TOUCHIN:
|
|
timesetbox->press=1;
|
|
//WIN_SetInvalid ((WIN_WindowStruct *)msgbox);
|
|
WIN_SetInvalidRect ((WIN_WindowStruct *)timesetbox,0,((WIN_WindowStruct *)timesetbox)->y_size-16,((WIN_WindowStruct *)timesetbox)->x_size,16);
|
|
break;
|
|
default:
|
|
WIN_DefaultMsgLoop((WIN_WindowStruct *)timesetbox,msg);
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
WIN_DefaultMsgLoop((WIN_WindowStruct *)timesetbox,msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
//设置时间
|
|
int TIMESETBOX_TimeSet (void)
|
|
{
|
|
WIN_TimeSetboxStruct *timesetbox=WIN_CreatTimeSetbox (0,0,WIN_GetBaseWindow()->x_size/4,WIN_GetBaseWindow()->y_size/4,
|
|
WIN_GetBaseWindow()->x_size/2,WIN_GetBaseWindow()->y_size/2);
|
|
WIN_ShowWindow((WIN_WindowStruct *)timesetbox);
|
|
return WIN_RunBlock ((WIN_WindowStruct *)timesetbox);
|
|
}
|
|
|
|
|
|
|