Files
player/Project/Src/MyWinApp/mywin_user_time.c

509 lines
13 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "mywin_inc.h"
#include "mywin_user_time.h"
#include "date.h"
#define WIN_TIMEBOX_TYPE "WIN_TimeboxStruct"
WIN_TimeboxStruct *WIN_CreatTimebox (WIN_WindowStruct *base,
void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg),
int x,int y,int x_size,int y_size)
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣѭ<CFA2><D1AD>
2025-06-27 00:32:57 +08:00
if (msgLoop==0)
{
msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))TIMEBOX_defaultMsgLoop;
}
WIN_TimeboxStruct *ret=mymalloc (sizeof ( WIN_TimeboxStruct));
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><ECBAAF>
2025-06-27 00:32:57 +08:00
if (ret)
{
mymemset (ret,0,sizeof ( WIN_TimeboxStruct));
// if (0==WIN_CreatWindowExt((WIN_WindowStruct *)ret,base,msgLoop,x,y,x_size,y_size))
if (0==WIN_CreatTouchEx((WIN_TouchWinStruct *)ret,base,msgLoop,x,y,x_size,y_size))
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
2025-06-27 00:32:57 +08:00
myfree (ret);
ret=0;
}
else
{
((WIN_WindowStruct *)ret)->winType=WIN_TIMEBOX_TYPE;
((WIN_WindowStruct *)ret)->intercept=1;
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
ret->title="ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
2025-06-27 00:32:57 +08:00
ret->rectColor=0x221f18;
ret->txtColor=0x342e27;
ret->selectRectColor=0x342f2a;
ret->selectTxtColor=0xc2ae9b;
date_rtc_get_date (&ret->year,&ret->mounth,&ret->date);
date_rtc_get_time (&ret->hour,&ret->min,&ret->sec);
}
}
return ret;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void TIMEBOX_Add (WIN_TimeboxStruct *timesetbox)
{
if (timesetbox->page==0)
{
if (timesetbox->index==0)
{
timesetbox->time12Hours=!timesetbox->time12Hours;
}
else if (timesetbox->index==1)
{
if (timesetbox->selectItem<1) timesetbox->selectItem++;
else timesetbox->selectItem=0;
}
}
else if ((timesetbox->page==1)&&(timesetbox->selectItem==0))
{
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;
}
}
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void TIMEBOX_Sub (WIN_TimeboxStruct *timesetbox)
{
if (timesetbox->page==0)
{
if (timesetbox->index==0)
{
timesetbox->time12Hours=!timesetbox->time12Hours;
}
else if (timesetbox->index==1)
{
if (timesetbox->selectItem>0) timesetbox->selectItem--;
else timesetbox->selectItem=1;
}
}
else if ((timesetbox->page==1)&&(timesetbox->selectItem==0))
{
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;
}
}
}
2025-07-05 19:47:28 +08:00
//ȷ<><C8B7>
2025-06-27 00:32:57 +08:00
void TIMEBOX_Enter (WIN_TimeboxStruct *timesetbox)
{
if (timesetbox->page==0)
{
if (timesetbox->index<1) {timesetbox->index++;}
else {timesetbox->page++;timesetbox->index=0;}
}
else if ((timesetbox->page==1)&&(timesetbox->selectItem==0))
{
if (timesetbox->index<6) {timesetbox->index++;}
else
{
date_rtc_set_date (timesetbox->year,timesetbox->mounth,timesetbox->date);
date_rtc_set_time (timesetbox->hour,timesetbox->min,timesetbox->sec);
2025-07-05 19:47:28 +08:00
MSGBOX_TipsTime ((WIN_WindowStruct *)timesetbox,"<EFBFBD><EFBFBD>ʾ","<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD><EFBFBD><EFBFBD>","ȷ<EFBFBD><EFBFBD>",5000);
2025-06-27 00:32:57 +08:00
((WIN_WindowStruct *)timesetbox)->deleteWindow((WIN_WindowStruct *)timesetbox);
}
}
}
void TIMEBOX_Back (WIN_TimeboxStruct *timesetbox)
{
}
2025-07-05 19:47:28 +08:00
//page==0ʱ<30><CAB1>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void TIMEBOX_PaintPage0 (WIN_TimeboxStruct *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};
x+=25;x_size-=25*2;
y+=45;y_size-=45*2;
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ƾ<EFBFBD><C6BE><EFBFBD>
2025-06-27 00:32:57 +08:00
int x_step=x_size/2;
int y_step=y_size/3;
x+=(x_size-x_step*2)/2;
y+=(y_size-y_step*3)/2;
x_size=x_step*2;
y_size=y_step*3;
if (timesetbox->time12Hours)
{ WIN_SetLcdColor (timesetbox->selectRectColor); }
else
{ WIN_SetLcdColor (timesetbox->rectColor); }
//WIN_FillRectByColor (x,y,x_step-1,y_step-1);
WIN_FillRectByColorAlpha (x,y,x_step-1,y_step-1,16);
if (timesetbox->time12Hours)
{ WIN_SetLcdColor (timesetbox->rectColor); }
else
{ WIN_SetLcdColor (timesetbox->selectRectColor); }
//WIN_FillRectByColor (x+x_step,y,x_step-1,y_step-1);
WIN_FillRectByColorAlpha (x+x_step,y,x_step-1,y_step-1,16);
if (timesetbox->index==1)
{
if (timesetbox->selectItem==0)
{ WIN_SetLcdColor (timesetbox->selectRectColor); }
else
{ WIN_SetLcdColor (timesetbox->rectColor); }
}else { WIN_SetLcdColor (timesetbox->rectColor); }
//WIN_FillRectByColor (x,y+y_step,x_size-1,y_step-1);
WIN_FillRectByColorAlpha (x,y+y_step,x_size-1,y_step-1,16);
if (timesetbox->index==1)
{
if (timesetbox->selectItem==1)
{ WIN_SetLcdColor (timesetbox->selectRectColor); }
else
{ WIN_SetLcdColor (timesetbox->rectColor); }
}else { WIN_SetLcdColor (timesetbox->rectColor); }
//WIN_FillRectByColor (x,y+y_step*2,x_size-1,y_step-1);
WIN_FillRectByColorAlpha (x,y+y_step*2,x_size-1,y_step-1,16);
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
if (timesetbox->time12Hours)
{ WIN_SetLcdColor (timesetbox->selectTxtColor); }
else
{ WIN_SetLcdColor (timesetbox->txtColor); }
2025-07-05 19:47:28 +08:00
WIN_DrawTxtHCenterAt ("12Сʱ",x+x_step/2,y+y_step/2-WIN_GetFontHight()/2);
2025-06-27 00:32:57 +08:00
if (timesetbox->time12Hours)
{ WIN_SetLcdColor (timesetbox->txtColor); }
else
{ WIN_SetLcdColor (timesetbox->selectTxtColor); }
2025-07-05 19:47:28 +08:00
WIN_DrawTxtHCenterAt ("24Сʱ",x+x_step+x_step/2,y+y_step/2-WIN_GetFontHight()/2);
2025-06-27 00:32:57 +08:00
if (timesetbox->index==1)
{
if (timesetbox->selectItem==0)
{ WIN_SetLcdColor (timesetbox->selectTxtColor); }
else
{ WIN_SetLcdColor (timesetbox->txtColor); }
} else { WIN_SetLcdColor (timesetbox->txtColor); }
2025-07-05 19:47:28 +08:00
WIN_DrawTxtHCenterAt ("<EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD>ʱ",x+x_size/2,y+y_step+y_step/2-WIN_GetFontHight()/2);
2025-06-27 00:32:57 +08:00
if (timesetbox->index==1)
{
if (timesetbox->selectItem==1)
{ WIN_SetLcdColor (timesetbox->selectTxtColor); }
else
{ WIN_SetLcdColor (timesetbox->txtColor); }
} else { WIN_SetLcdColor (timesetbox->txtColor); }
2025-07-05 19:47:28 +08:00
WIN_DrawTxtHCenterAt ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ",x+x_size/2,y+y_step*2+y_step/2-WIN_GetFontHight()/2);
2025-06-27 00:32:57 +08:00
}
2025-07-05 19:47:28 +08:00
//<2F>ֶ<EFBFBD>
2025-06-27 00:32:57 +08:00
void TIMEBOX_PaintPage1Hand (WIN_TimeboxStruct *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};
x+=25;x_size-=25*2;
y+=45;y_size-=45*2;
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ƾ<EFBFBD><C6BE><EFBFBD>
2025-06-27 00:32:57 +08:00
int x_step=x_size/3;
int y_step=y_size/3;
x+=(x_size-x_step*3)/2;
y+=(y_size-y_step*3)/2;
x_size=x_step*3;
y_size=y_step*3;
WIN_SetLcdColor (timesetbox->rectColor);
//WIN_FillRectByColor (x,y+y_step,x_size-1,y_step-1);
WIN_FillRectByColorAlpha (x,y+y_step,x_size-1,y_step-1,16);
char txt[30]={0};
WIN_SetLcdColor (timesetbox->selectRectColor);
int txt_x;
int txt_xsize;
int txt_len=22;
if (timesetbox->index==0)
{
txt_x=x+x_size/2-txt_len*WIN_GetFontWidth()/4;
txt_xsize=4*WIN_GetFontWidth()/2;
}
else if (timesetbox->index==1)
{
txt_x=x+x_size/2-txt_len*WIN_GetFontWidth()/4;
txt_x+=5*WIN_GetFontWidth()/2;
txt_xsize=2*WIN_GetFontWidth()/2;
}
else if (timesetbox->index==2)
{
txt_x=x+x_size/2-txt_len*WIN_GetFontWidth()/4;
txt_x+=8*WIN_GetFontWidth()/2;
txt_xsize=2*WIN_GetFontWidth()/2;
}
else if (timesetbox->index==3)
{
txt_x=x+x_size/2-txt_len*WIN_GetFontWidth()/4;
txt_x+=11*WIN_GetFontWidth()/2;
txt_xsize=2*WIN_GetFontWidth()/2;
}
else if (timesetbox->index==4)
{
txt_x=x+x_size/2-txt_len*WIN_GetFontWidth()/4;
txt_x+=14*WIN_GetFontWidth()/2;
txt_xsize=2*WIN_GetFontWidth()/2;
}
else if (timesetbox->index==5)
{
txt_x=x+x_size/2-txt_len*WIN_GetFontWidth()/4;
txt_x+=17*WIN_GetFontWidth()/2;
txt_xsize=2*WIN_GetFontWidth()/2;
}
else if (timesetbox->index==6)
{
txt_x=x+x_size/2-txt_len*WIN_GetFontWidth()/4;
txt_x+=20*WIN_GetFontWidth()/2;
txt_xsize=2*WIN_GetFontWidth()/2;
}
//WIN_FillRectByColor (txt_x,y+y_step,txt_xsize,y_step-1);
WIN_FillRectByColorAlpha (txt_x,y+y_step,txt_xsize,y_step-1,16);
sprintf (txt,"%04d-%02d-%02d %02d:%02d:%02d OK",timesetbox->year,timesetbox->mounth,timesetbox->date,
timesetbox->hour,timesetbox->min,timesetbox->sec);
WIN_SetLcdColor (timesetbox->selectTxtColor);
WIN_DrawTxtHCenterAt (txt,x+x_size/2,y+y_step+y_step/2-WIN_GetFontHight()/2);
}
2025-07-05 19:47:28 +08:00
//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD>Ļ<EFBFBD><C4BB>ƺ<EFBFBD><C6BA><EFBFBD>
2025-06-27 00:32:57 +08:00
void TIMEBOX_DefaultPaint (WIN_TimeboxStruct *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);
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD>
2025-06-27 00:32:57 +08:00
WIN_SetFontMode(WIN_DRAWMODE_ALONE);
WIN_SetLcdColor (((WIN_WindowStruct *)timesetbox)->color);
WIN_DrawTxtHCenterAt (timesetbox->title,x_size/4,8);
2025-07-05 19:47:28 +08:00
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
if (timesetbox->page==0)
{
TIMEBOX_PaintPage0 (timesetbox);
}
else if ((timesetbox->page==1)&&(timesetbox->selectItem==0))
{
TIMEBOX_PaintPage1Hand (timesetbox);
}
}
2025-07-05 19:47:28 +08:00
//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void TIMEBOX_defaultMsgLoop (WIN_TimeboxStruct *timesetbox,WIN_MsgStruct *msg)
{
WIN_MoveStruct *m=0;
WIN_KeyStruct *k=0;
switch (msg->msg)
{
case WIN_MSG_PAINT:
TIMEBOX_DefaultPaint(timesetbox);
break;
case WIN_MSG_INIT:
break;
case WIN_MSG_KEY:
k=msg->data.p;
2025-07-05 19:47:28 +08:00
//<2F>յ<EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>򷵻ؼ<F2B7B5BB>
2025-06-27 00:32:57 +08:00
if (k->shortPress&KEY_VALUE_UP)
{
TIMEBOX_Add (timesetbox);
}
else if (k->shortPress&KEY_VALUE_DOWN)
{
TIMEBOX_Sub (timesetbox);
}
else if (k->shortPress&KEY_VALUE_ENTER)
{
TIMEBOX_Enter (timesetbox);
}
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)
{
((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);
2025-07-05 19:47:28 +08:00
MSGBOX_TipsTime ((WIN_WindowStruct *)timesetbox,"<EFBFBD><EFBFBD>ʾ","<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD><EFBFBD><EFBFBD>","ȷ<EFBFBD><EFBFBD>",5000);
2025-06-27 00:32:57 +08:00
((WIN_WindowStruct *)timesetbox)->deleteWindow((WIN_WindowStruct *)timesetbox);
}
break;//case WIN_MSG_KEY:
case WIN_MSG_TOUCH:
break;
case WIN_MSG_CHID:
switch (msg->data.v)
{
case CHID_DELETE:
break;
case CHID_USER:
{
if (msg->data2.v==BUTTON_PRESSED)
{
WIN_KeyStruct key={0};
if (msg->srcWin==timesetbox->key_back)
{
((WIN_WindowStruct *)timesetbox)->deleteWindow((WIN_WindowStruct *)timesetbox);
}
else if (msg->srcWin==timesetbox->key_up)
{
TIMEBOX_Add (timesetbox);
}
else if (msg->srcWin==timesetbox->key_down)
{
TIMEBOX_Sub (timesetbox);
}
else if (msg->srcWin==timesetbox->key_enter)
{
TIMEBOX_Enter (timesetbox);
}
WIN_SetInvalid ((WIN_WindowStruct *)timesetbox);
}
}
break;
default:
break;
}
break;
case WIN_MSG_DELETE:
break;
case WIN_MSG_TIMER:
2025-07-05 19:47:28 +08:00
//<2F><>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>
2025-06-27 00:32:57 +08:00
((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_SHORT:
if (timesetbox->touch_support==0)
{
timesetbox->touch_support=1;
int y_size=((WIN_WindowStruct *)timesetbox)->y_size;
int x_size=((WIN_WindowStruct *)timesetbox)->x_size;
timesetbox->key_enter=WIN_CreatButton(((WIN_WindowStruct *)timesetbox),0,x_size-70,y_size/2+15,60,30);
2025-07-05 19:47:28 +08:00
BUTTON_SetKeyString(timesetbox->key_enter,"ȷ<EFBFBD><EFBFBD>");
2025-06-27 00:32:57 +08:00
timesetbox->key_back=WIN_CreatButton(((WIN_WindowStruct *)timesetbox),0,x_size-70,y_size/2+15+45,60,30);
2025-07-05 19:47:28 +08:00
BUTTON_SetKeyString(timesetbox->key_back,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
2025-06-27 00:32:57 +08:00
timesetbox->key_up=WIN_CreatButton(((WIN_WindowStruct *)timesetbox),0,x_size-70,y_size/2-45-45,60,30);
2025-07-05 19:47:28 +08:00
BUTTON_SetKeyString(timesetbox->key_up,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
2025-06-27 00:32:57 +08:00
timesetbox->key_down=WIN_CreatButton(((WIN_WindowStruct *)timesetbox),0,x_size-70,y_size/2-45,60,30);
2025-07-05 19:47:28 +08:00
BUTTON_SetKeyString(timesetbox->key_down,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
2025-06-27 00:32:57 +08:00
WIN_SetInvalid((WIN_WindowStruct *)timesetbox);
}
break;
default:
WIN_DefaultMsgLoop((WIN_WindowStruct *)timesetbox,msg);
break;
}
break;
default:
WIN_DefaultMsgLoop((WIN_WindowStruct *)timesetbox,msg);
break;
}
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
2025-06-27 00:32:57 +08:00
int TIMEBOX_TimeSet (WIN_WindowStruct *base)
{
WIN_TimeboxStruct *timesetbox=WIN_CreatTimebox (base,0,0,0,base->x_size,base->y_size);
WIN_SetBackPicPath ((WIN_WindowStruct *)timesetbox,base->pic_path);
WIN_ShowWindow((WIN_WindowStruct *)timesetbox);
//return WIN_RunBlock ((WIN_WindowStruct *)timesetbox);
return 0;
}