223 lines
7.7 KiB
C
223 lines
7.7 KiB
C
#include "mywin_user_backlightset.h"
|
|
#include "date.h"
|
|
#include "mywin_inc.h"
|
|
|
|
#define WIN_BACKLIGHTSETBOX_TYPE "WIN_BackLightSetboxStruct"
|
|
|
|
WIN_BackLightSetboxStruct *WIN_CreatBackLightSetbox(
|
|
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))BACKLIGHTSETBOX_defaultMsgLoop;
|
|
}
|
|
|
|
WIN_BackLightSetboxStruct *ret = mymalloc(sizeof(WIN_BackLightSetboxStruct));
|
|
// 调用父类的构造函数
|
|
if (ret) {
|
|
mymemset(ret, 0, sizeof(WIN_BackLightSetboxStruct));
|
|
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_BACKLIGHTSETBOX_TYPE;
|
|
// 构造一个消息框
|
|
ret->title = "显示设置";
|
|
ret->light = ui_getScreenBrightness();
|
|
ret->autoLight = ui_getScreenAutoLight();
|
|
ret->offTime = ui_getScreenOffTime();
|
|
ret->lightSave = ret->light;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
void BACKLIGHTSETBOX_Add(WIN_BackLightSetboxStruct *backlightsetbox) {
|
|
if (backlightsetbox->index == 0) {
|
|
if (backlightsetbox->offTime < 30 * 60)
|
|
backlightsetbox->offTime += 30;
|
|
} else if (backlightsetbox->index == 1) {
|
|
if (backlightsetbox->light < 100)
|
|
backlightsetbox->light += 10;
|
|
if (backlightsetbox->light > 100)
|
|
backlightsetbox->light = 100;
|
|
ui_setScreenBrightness(backlightsetbox->light);
|
|
} else if (backlightsetbox->index == 2) {
|
|
backlightsetbox->autoLight = !backlightsetbox->autoLight;
|
|
}
|
|
}
|
|
|
|
void BACKLIGHTSETBOX_Sub(WIN_BackLightSetboxStruct *backlightsetbox) {
|
|
if (backlightsetbox->index == 0) {
|
|
if (backlightsetbox->offTime > 0)
|
|
backlightsetbox->offTime -= 30;
|
|
if (backlightsetbox->offTime < 0)
|
|
backlightsetbox->offTime = 0;
|
|
} else if (backlightsetbox->index == 1) {
|
|
if (backlightsetbox->light > 1)
|
|
backlightsetbox->light -= 10;
|
|
if (backlightsetbox->light < 1)
|
|
backlightsetbox->light = 1;
|
|
ui_setScreenBrightness(backlightsetbox->light);
|
|
} else if (backlightsetbox->index == 2) {
|
|
backlightsetbox->autoLight = !backlightsetbox->autoLight;
|
|
}
|
|
}
|
|
|
|
// 消息框的绘制函数
|
|
void BACKLIGHTSETBOX_DefaultPaint(WIN_BackLightSetboxStruct *backlightsetbox) {
|
|
|
|
int x = 0;
|
|
int y = 0;
|
|
int x_size = ((WIN_WindowStruct *)backlightsetbox)->x_size;
|
|
int y_size = ((WIN_WindowStruct *)backlightsetbox)->y_size;
|
|
char txt_buff[20] = {0};
|
|
|
|
WIN_PaintBackGround((WIN_WindowStruct *)backlightsetbox);
|
|
|
|
// 绘制标题
|
|
WIN_SetFontMode(WIN_DRAWMODE_ALONE);
|
|
WIN_SetLcdColor(((WIN_WindowStruct *)backlightsetbox)->color);
|
|
WIN_DrawTxtHCenterAt(backlightsetbox->title, x_size / 2, y);
|
|
y += WIN_GetFontHight();
|
|
|
|
// 绘制选中框
|
|
int rect_y_step = (y_size - WIN_GetFontHight()) / 3;
|
|
int rect_x = x;
|
|
int rect_y = y;
|
|
int rect_xsize = x_size;
|
|
int rect_ysize = rect_y_step;
|
|
WIN_SetLcdColor(0x00ff0080);
|
|
if (backlightsetbox->index < 3) {
|
|
rect_y += rect_ysize * backlightsetbox->index;
|
|
WIN_FillRectByColor(rect_x, rect_y, rect_xsize, rect_ysize);
|
|
}
|
|
|
|
// 显示文本
|
|
WIN_SetLcdColor(((WIN_WindowStruct *)backlightsetbox)->color);
|
|
sprintf(txt_buff, "%d 秒后自动休眠", backlightsetbox->offTime);
|
|
WIN_DrawTxtHCenterAt(txt_buff, x_size / 2,
|
|
y + rect_y_step / 2 - WIN_GetFontHight() / 2);
|
|
sprintf(txt_buff, "亮度 %d", backlightsetbox->light);
|
|
WIN_DrawTxtHCenterAt(txt_buff, x_size / 2,
|
|
y + rect_y_step / 2 - WIN_GetFontHight() / 2 +
|
|
rect_y_step);
|
|
if (backlightsetbox->autoLight)
|
|
WIN_DrawTxtHCenterAt("自动亮度 ★", x_size / 2,
|
|
y + rect_y_step / 2 - WIN_GetFontHight() / 2 +
|
|
rect_y_step * 2);
|
|
else
|
|
WIN_DrawTxtHCenterAt("自动亮度 ☆", x_size / 2,
|
|
y + rect_y_step / 2 - WIN_GetFontHight() / 2 +
|
|
rect_y_step * 2);
|
|
}
|
|
|
|
// 消息框的消息处理函数
|
|
void BACKLIGHTSETBOX_defaultMsgLoop(WIN_BackLightSetboxStruct *backlightsetbox,
|
|
WIN_MsgStruct *msg) {
|
|
WIN_MoveStruct *m = 0;
|
|
WIN_KeyStruct *k = 0;
|
|
switch (msg->msg) {
|
|
case WIN_MSG_PAINT:
|
|
BACKLIGHTSETBOX_DefaultPaint(backlightsetbox);
|
|
break;
|
|
case WIN_MSG_INIT:
|
|
break;
|
|
case WIN_MSG_KEY:
|
|
k = msg->data.p;
|
|
// 收到确定或返回键
|
|
if (k->shortPress & KEY_VALUE_UP) {
|
|
BACKLIGHTSETBOX_Add(backlightsetbox);
|
|
} else if (k->shortPress & KEY_VALUE_DOWN) {
|
|
BACKLIGHTSETBOX_Sub(backlightsetbox);
|
|
} else if (k->shortPress & KEY_VALUE_ENTER) {
|
|
if (backlightsetbox->index < 2)
|
|
backlightsetbox->index++;
|
|
else
|
|
backlightsetbox->index = 0;
|
|
}
|
|
if (k->shortPress) {
|
|
WIN_SetInvalidRect((WIN_WindowStruct *)backlightsetbox, 0, 16,
|
|
((WIN_WindowStruct *)backlightsetbox)->x_size,
|
|
((WIN_WindowStruct *)backlightsetbox)->y_size - 16);
|
|
}
|
|
if (k->shortPress & KEY_VALUE_HOME) {
|
|
ui_setScreenBrightness(backlightsetbox->lightSave);
|
|
MSGBOX_TipsTime((WIN_WindowStruct *)backlightsetbox, "提示",
|
|
"设置没有保存", "确定", 5000);
|
|
((WIN_WindowStruct *)backlightsetbox)
|
|
->deleteWindow((WIN_WindowStruct *)backlightsetbox);
|
|
} else if (k->longPress & KEY_VALUE_ENTER) {
|
|
ui_setScreenAutoLight(backlightsetbox->autoLight);
|
|
ui_setScreenOffTime(backlightsetbox->offTime);
|
|
ui_setScreenBrightness(backlightsetbox->light);
|
|
MSGBOX_TipsTime((WIN_WindowStruct *)backlightsetbox, "提示", "设置已保存",
|
|
"确定", 5000);
|
|
((WIN_WindowStruct *)backlightsetbox)
|
|
->deleteWindow((WIN_WindowStruct *)backlightsetbox);
|
|
}
|
|
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 *)backlightsetbox)
|
|
->deleteWindow((WIN_WindowStruct *)backlightsetbox);
|
|
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:
|
|
backlightsetbox->press = 0;
|
|
WIN_SetInvalidRect((WIN_WindowStruct *)backlightsetbox, 0,
|
|
((WIN_WindowStruct *)backlightsetbox)->y_size - 16,
|
|
((WIN_WindowStruct *)backlightsetbox)->x_size, 16);
|
|
break;
|
|
case MOVE_DATA_TOUCHOUT:
|
|
if (backlightsetbox->press)
|
|
((WIN_WindowStruct *)backlightsetbox)
|
|
->deleteWindow((WIN_WindowStruct *)backlightsetbox);
|
|
break;
|
|
case MOVE_DATA_TOUCHIN:
|
|
backlightsetbox->press = 1;
|
|
// WIN_SetInvalid ((WIN_WindowStruct *)msgbox);
|
|
WIN_SetInvalidRect((WIN_WindowStruct *)backlightsetbox, 0,
|
|
((WIN_WindowStruct *)backlightsetbox)->y_size - 16,
|
|
((WIN_WindowStruct *)backlightsetbox)->x_size, 16);
|
|
break;
|
|
default:
|
|
WIN_DefaultMsgLoop((WIN_WindowStruct *)backlightsetbox, msg);
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
WIN_DefaultMsgLoop((WIN_WindowStruct *)backlightsetbox, msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 显示设置
|
|
int BACKLIGHTSETBOX_BackLightSet(void) {
|
|
WIN_BackLightSetboxStruct *backlightsetbox = WIN_CreatBackLightSetbox(
|
|
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 *)backlightsetbox);
|
|
return WIN_RunBlock((WIN_WindowStruct *)backlightsetbox);
|
|
}
|