472 lines
15 KiB
C
472 lines
15 KiB
C
#include "mywin_user_time.h"
|
|
#include "date.h"
|
|
#include "mywin_inc.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) {
|
|
// 重设消息循环
|
|
if (msgLoop == 0) {
|
|
msgLoop = (void (*)(struct _WIN_WindowStruct *win,
|
|
WIN_MsgStruct *msg))TIMEBOX_defaultMsgLoop;
|
|
}
|
|
|
|
WIN_TimeboxStruct *ret = mymalloc(sizeof(WIN_TimeboxStruct));
|
|
// 调用父类的构造函数
|
|
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)) {
|
|
// 创建失败
|
|
myfree(ret);
|
|
ret = 0;
|
|
} else {
|
|
((WIN_WindowStruct *)ret)->winType = WIN_TIMEBOX_TYPE;
|
|
((WIN_WindowStruct *)ret)->intercept = 1;
|
|
// 构造一个消息框
|
|
ret->title = "时间日期设置";
|
|
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;
|
|
}
|
|
|
|
// 参数增加
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 参数减少
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 确认
|
|
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);
|
|
MSGBOX_TipsTime((WIN_WindowStruct *)timesetbox, "提示", "设置已保存",
|
|
"确定", 5000);
|
|
((WIN_WindowStruct *)timesetbox)
|
|
->deleteWindow((WIN_WindowStruct *)timesetbox);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TIMEBOX_Back(WIN_TimeboxStruct *timesetbox) {}
|
|
|
|
// page==0时显示的内容
|
|
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;
|
|
|
|
// 绘制矩形
|
|
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);
|
|
|
|
// 绘制文字
|
|
if (timesetbox->time12Hours) {
|
|
WIN_SetLcdColor(timesetbox->selectTxtColor);
|
|
} else {
|
|
WIN_SetLcdColor(timesetbox->txtColor);
|
|
}
|
|
WIN_DrawTxtHCenterAt("12小时", x + x_step / 2,
|
|
y + y_step / 2 - WIN_GetFontHight() / 2);
|
|
if (timesetbox->time12Hours) {
|
|
WIN_SetLcdColor(timesetbox->txtColor);
|
|
} else {
|
|
WIN_SetLcdColor(timesetbox->selectTxtColor);
|
|
}
|
|
WIN_DrawTxtHCenterAt("24小时", x + x_step + x_step / 2,
|
|
y + y_step / 2 - WIN_GetFontHight() / 2);
|
|
if (timesetbox->index == 1) {
|
|
if (timesetbox->selectItem == 0) {
|
|
WIN_SetLcdColor(timesetbox->selectTxtColor);
|
|
} else {
|
|
WIN_SetLcdColor(timesetbox->txtColor);
|
|
}
|
|
} else {
|
|
WIN_SetLcdColor(timesetbox->txtColor);
|
|
}
|
|
WIN_DrawTxtHCenterAt("手动授时", x + x_size / 2,
|
|
y + y_step + y_step / 2 - WIN_GetFontHight() / 2);
|
|
if (timesetbox->index == 1) {
|
|
if (timesetbox->selectItem == 1) {
|
|
WIN_SetLcdColor(timesetbox->selectTxtColor);
|
|
} else {
|
|
WIN_SetLcdColor(timesetbox->txtColor);
|
|
}
|
|
} else {
|
|
WIN_SetLcdColor(timesetbox->txtColor);
|
|
}
|
|
WIN_DrawTxtHCenterAt("卫星授时", x + x_size / 2,
|
|
y + y_step * 2 + y_step / 2 - WIN_GetFontHight() / 2);
|
|
}
|
|
|
|
// 手动
|
|
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;
|
|
|
|
// 绘制矩形
|
|
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);
|
|
}
|
|
|
|
// 消息框的绘制函数
|
|
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);
|
|
|
|
// 绘制标题
|
|
WIN_SetFontMode(WIN_DRAWMODE_ALONE);
|
|
WIN_SetLcdColor(((WIN_WindowStruct *)timesetbox)->color);
|
|
WIN_DrawTxtHCenterAt(timesetbox->title, x_size / 4, 8);
|
|
|
|
// 显示内容
|
|
if (timesetbox->page == 0) {
|
|
TIMEBOX_PaintPage0(timesetbox);
|
|
} else if ((timesetbox->page == 1) && (timesetbox->selectItem == 0)) {
|
|
TIMEBOX_PaintPage1Hand(timesetbox);
|
|
}
|
|
}
|
|
|
|
// 消息框的消息处理函数
|
|
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;
|
|
// 收到确定或返回键
|
|
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);
|
|
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:
|
|
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:
|
|
// 定时器时间到
|
|
((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);
|
|
BUTTON_SetKeyString(timesetbox->key_enter, "确定");
|
|
timesetbox->key_back =
|
|
WIN_CreatButton(((WIN_WindowStruct *)timesetbox), 0, x_size - 70,
|
|
y_size / 2 + 15 + 45, 60, 30);
|
|
BUTTON_SetKeyString(timesetbox->key_back, "返回");
|
|
timesetbox->key_up =
|
|
WIN_CreatButton(((WIN_WindowStruct *)timesetbox), 0, x_size - 70,
|
|
y_size / 2 - 45 - 45, 60, 30);
|
|
BUTTON_SetKeyString(timesetbox->key_up, "向上");
|
|
timesetbox->key_down =
|
|
WIN_CreatButton(((WIN_WindowStruct *)timesetbox), 0, x_size - 70,
|
|
y_size / 2 - 45, 60, 30);
|
|
BUTTON_SetKeyString(timesetbox->key_down, "向下");
|
|
WIN_SetInvalid((WIN_WindowStruct *)timesetbox);
|
|
}
|
|
break;
|
|
default:
|
|
WIN_DefaultMsgLoop((WIN_WindowStruct *)timesetbox, msg);
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
WIN_DefaultMsgLoop((WIN_WindowStruct *)timesetbox, msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 设置时间
|
|
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;
|
|
}
|