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

256 lines
7.9 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "mywin_user_timeset.h"
#include "date.h"
#include "mywin_inc.h"
2025-06-27 00:32:57 +08:00
#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) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣѭ<CFA2><D1AD>
if (msgLoop == 0) {
msgLoop = (void (*)(struct _WIN_WindowStruct *win,
WIN_MsgStruct *msg))TIMESETBOX_defaultMsgLoop;
}
WIN_TimeSetboxStruct *ret = mymalloc(sizeof(WIN_TimeSetboxStruct));
// <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><ECBAAF>
if (ret) {
mymemset(ret, 0, sizeof(WIN_TimeSetboxStruct));
if (0 == WIN_CreatWindowExt((WIN_WindowStruct *)ret, base, msgLoop, x, y,
x_size, y_size)) {
// <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
myfree(ret);
ret = 0;
} else {
((WIN_WindowStruct *)ret)->winType = WIN_TIMESETBOX_TYPE;
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
ret->title = "ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
date_rtc_get_date(&ret->year, &ret->mounth, &ret->date);
date_rtc_get_time(&ret->hour, &ret->min, &ret->sec);
}
}
return ret;
2025-06-27 00:32:57 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
}
2025-06-27 00:32:57 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
}
2025-06-27 00:32:57 +08:00
}
// <20><>Ϣ<EFBFBD><CFA2><EFBFBD>Ļ<EFBFBD><C4BB>ƺ<EFBFBD><C6BA><EFBFBD>
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);
// <20><><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD>
WIN_SetFontMode(WIN_DRAWMODE_ALONE);
WIN_SetLcdColor(((WIN_WindowStruct *)timesetbox)->color);
WIN_DrawTxtHCenterAt(timesetbox->title, x_size / 2, y);
y += WIN_GetFontHight();
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD>п<EFBFBD>
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);
}
// <20><>ʾ<EFBFBD>ı<EFBFBD>
WIN_SetLcdColor(((WIN_WindowStruct *)timesetbox)->color);
sprintf(txt_buff, "%04d <20><> %02d <20><> %02d <20><>", 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 <20><> %02d <20><>", timesetbox->hour,
timesetbox->min, timesetbox->sec);
WIN_DrawTxtHCenterAt(txt_buff, x_size / 2,
y + rect_y_step - WIN_GetFontHight() / 2 + rect_y_step);
2025-06-27 00:32:57 +08:00
}
// <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
// <20>յ<EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>򷵻ؼ<F2B7B5BB>
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, "<EFBFBD><EFBFBD>ʾ", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>",
"ȷ<EFBFBD><EFBFBD>", 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, "<EFBFBD><EFBFBD>ʾ", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD><EFBFBD><EFBFBD>",
"ȷ<EFBFBD><EFBFBD>", 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:
// <20><>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>
((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;
}
2025-06-27 00:32:57 +08:00
}
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
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);
2025-06-27 00:32:57 +08:00
}