245 lines
7.1 KiB
C
245 lines
7.1 KiB
C
#include "include.h"
|
|
#include "func.h"
|
|
|
|
#if TRACE_EN
|
|
#define TRACE(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define TRACE(...)
|
|
#endif
|
|
|
|
//组件ID
|
|
enum {
|
|
//按键
|
|
COMPO_ID_BTN_REDUCE = 1,
|
|
COMPO_ID_BTN_INCREASE,
|
|
|
|
//图像
|
|
COMPO_ID_PIC_LEVEL1, //亮度等级 1~5
|
|
COMPO_ID_PIC_LEVEL2,
|
|
COMPO_ID_PIC_LEVEL3,
|
|
COMPO_ID_PIC_LEVEL4,
|
|
COMPO_ID_PIC_LEVEL5,
|
|
COMPO_ID_PIC_REDUCE_CLICK, //按钮触摸效果图
|
|
COMPO_ID_PIC_INCREASE_CLICK,
|
|
};
|
|
|
|
typedef struct f_light_t_ {
|
|
u8 light_level;
|
|
} f_light_t;
|
|
|
|
//创建亮度调节窗体,创建窗体中不要使用功能结构体 func_cb.f_cb
|
|
compo_form_t *func_light_form_create(void)
|
|
{
|
|
|
|
//新建窗体和背景
|
|
compo_form_t *frm = compo_form_create(true);
|
|
compo_form_add_image(frm, UI_BUF_SETTING_LIGHT_LIGHT_BIN, 160, 158);
|
|
compo_form_add_image(frm, UI_BUF_COMMON_BG1_BIN, 160, 309);
|
|
|
|
//创建文本
|
|
compo_textbox_t *txt_title = compo_textbox_create(frm, 4);
|
|
compo_textbox_set_location(txt_title, 30, 22, 140, 40);
|
|
compo_textbox_set(txt_title, "亮度调节");
|
|
|
|
func_text_time_create(frm); //时间文本框
|
|
|
|
//新建按钮
|
|
compo_button_t *btn;
|
|
btn = compo_button_create_by_image(frm, UI_BUF_COMMON_REDUCE_BIN);
|
|
compo_setid(btn, COMPO_ID_BTN_REDUCE);
|
|
compo_button_set_pos(btn, 54, 309);
|
|
|
|
btn = compo_button_create_by_image(frm, UI_BUF_COMMON_INCREASE_BIN);
|
|
compo_setid(btn, COMPO_ID_BTN_INCREASE);
|
|
compo_button_set_pos(btn, 266, 309);
|
|
|
|
//新建图像
|
|
compo_picturebox_t *pic_level[5];
|
|
pic_level[0] = compo_picturebox_create(frm, UI_BUF_COMMON_BG2_BIN);
|
|
compo_setid(pic_level[0], COMPO_ID_PIC_LEVEL1);
|
|
compo_picturebox_set_pos(pic_level[0], 108, 309);
|
|
widget_set_visible(pic_level[0]->img,false);
|
|
|
|
pic_level[1] = compo_picturebox_create(frm, UI_BUF_COMMON_BG2_BIN);
|
|
compo_setid(pic_level[1], COMPO_ID_PIC_LEVEL2);
|
|
compo_picturebox_set_pos(pic_level[1], 134, 309);
|
|
widget_set_visible(pic_level[1]->img,false);
|
|
|
|
pic_level[2] = compo_picturebox_create(frm, UI_BUF_COMMON_BG2_BIN);
|
|
compo_setid(pic_level[2], COMPO_ID_PIC_LEVEL3);
|
|
compo_picturebox_set_pos(pic_level[2], 160, 309);
|
|
widget_set_visible(pic_level[2]->img,false);
|
|
|
|
pic_level[3] = compo_picturebox_create(frm, UI_BUF_COMMON_BG2_BIN);
|
|
compo_setid(pic_level[3], COMPO_ID_PIC_LEVEL4);
|
|
compo_picturebox_set_pos(pic_level[3], 186, 309);
|
|
widget_set_visible(pic_level[3]->img,false);
|
|
|
|
pic_level[4] = compo_picturebox_create(frm, UI_BUF_COMMON_BG2_BIN);
|
|
compo_setid(pic_level[4], COMPO_ID_PIC_LEVEL5);
|
|
compo_picturebox_set_pos(pic_level[4], 212, 309);
|
|
widget_set_visible(pic_level[4]->img,false);
|
|
|
|
printf("%s-->light_level:%d\n",__func__, sys_cb.light_level);
|
|
for (u8 i=0; i<sys_cb.light_level; i++) {
|
|
widget_set_visible(pic_level[i]->img,true);
|
|
}
|
|
|
|
compo_picturebox_t *pic_button;
|
|
pic_button = compo_picturebox_create(frm, UI_BUF_COMMON_REDUCE_CLICK_BIN);
|
|
compo_setid(pic_button, COMPO_ID_PIC_REDUCE_CLICK);
|
|
compo_picturebox_set_pos(pic_button, 54, 309);
|
|
widget_set_visible(pic_button->img,false);
|
|
|
|
pic_button = compo_picturebox_create(frm, UI_BUF_COMMON_INCREASE_CLICK_BIN);
|
|
compo_setid(pic_button, COMPO_ID_PIC_INCREASE_CLICK);
|
|
compo_picturebox_set_pos(pic_button, 266, 309);
|
|
widget_set_visible(pic_button->img,false);
|
|
|
|
return frm;
|
|
}
|
|
|
|
//触摸按钮效果处理
|
|
static void func_light_button_touch_handle(void)
|
|
{
|
|
int id = compo_get_button_id();
|
|
compo_picturebox_t *pic_reduce = compo_getobj_byid(COMPO_ID_PIC_REDUCE_CLICK);
|
|
compo_picturebox_t *pic_increase = compo_getobj_byid(COMPO_ID_PIC_INCREASE_CLICK);
|
|
|
|
switch (id) {
|
|
case COMPO_ID_BTN_REDUCE:
|
|
widget_set_visible(pic_reduce->img, true);
|
|
break;
|
|
|
|
case COMPO_ID_BTN_INCREASE:
|
|
widget_set_visible(pic_increase->img, true);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
//释放按钮效果处理
|
|
static void func_light_button_release_handle(void)
|
|
{
|
|
compo_picturebox_t *pic_reduce = compo_getobj_byid(COMPO_ID_PIC_REDUCE_CLICK);
|
|
compo_picturebox_t *pic_increase = compo_getobj_byid(COMPO_ID_PIC_INCREASE_CLICK);
|
|
widget_set_visible(pic_reduce->img, false);
|
|
widget_set_visible(pic_increase->img, false);
|
|
}
|
|
|
|
//单击按钮
|
|
static void func_light_button_click(void)
|
|
{
|
|
int id = compo_get_button_id();
|
|
compo_picturebox_t *pic_level[5];
|
|
pic_level[0] = compo_getobj_byid(COMPO_ID_PIC_LEVEL1);
|
|
pic_level[1] = compo_getobj_byid(COMPO_ID_PIC_LEVEL2);
|
|
pic_level[2] = compo_getobj_byid(COMPO_ID_PIC_LEVEL3);
|
|
pic_level[3] = compo_getobj_byid(COMPO_ID_PIC_LEVEL4);
|
|
pic_level[4] = compo_getobj_byid(COMPO_ID_PIC_LEVEL5);
|
|
|
|
switch (id) {
|
|
case COMPO_ID_BTN_REDUCE:
|
|
if (sys_cb.light_level > 0 && sys_cb.light_level <= 5) {
|
|
sys_cb.light_level--;
|
|
}
|
|
break;
|
|
|
|
case COMPO_ID_BTN_INCREASE:
|
|
if (sys_cb.light_level >= 0 && sys_cb.light_level < 5) {
|
|
sys_cb.light_level++;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
for (u8 i=0; i<5; i++) {
|
|
if (i < sys_cb.light_level) {
|
|
widget_set_visible(pic_level[i]->img,true);
|
|
} else {
|
|
widget_set_visible(pic_level[i]->img,false);
|
|
}
|
|
}
|
|
func_light_button_release_handle();
|
|
}
|
|
|
|
//亮度调节功能事件处理
|
|
static void func_light_process(void)
|
|
{
|
|
func_process();
|
|
}
|
|
|
|
//亮度调节功能消息处理
|
|
static void func_light_message(size_msg_t msg)
|
|
{
|
|
compo_form_t *frm = NULL;
|
|
bool res = false;
|
|
switch (msg) {
|
|
case MSG_CTP_TOUCH:
|
|
func_light_button_touch_handle();
|
|
break;
|
|
|
|
case MSG_CTP_CLICK:
|
|
func_light_button_click();
|
|
break;
|
|
|
|
case MSG_CTP_SHORT_UP:
|
|
case MSG_CTP_SHORT_DOWN:
|
|
case MSG_CTP_SHORT_LEFT:
|
|
case MSG_CTP_LONG:
|
|
func_light_button_release_handle();
|
|
break;
|
|
|
|
case MSG_CTP_SHORT_RIGHT:
|
|
func_light_button_release_handle();
|
|
if(func_cb.last == FUNC_SETTING) {
|
|
frm = func_create_form(FUNC_SETTING);
|
|
res = func_switching(FUNC_SWITCH_LR_ZOOM_RIGHT,NULL);
|
|
compo_form_destroy(frm); //切换完成或取消,销毁窗体
|
|
if (res) {
|
|
func_cb.sta = FUNC_SETTING;
|
|
}
|
|
}else {
|
|
func_switching_to_menu(); //右滑缓慢退出任务
|
|
}
|
|
break;
|
|
|
|
case MSG_QDEC_FORWARD:
|
|
case MSG_QDEC_REVERSE:
|
|
break;
|
|
|
|
default:
|
|
func_message(msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
//进入亮度调节功能
|
|
static void func_light_enter(void)
|
|
{
|
|
func_cb.f_cb = func_zalloc(sizeof(f_light_t));
|
|
func_cb.frm_main = func_light_form_create();
|
|
}
|
|
|
|
//退出亮度调节功能
|
|
static void func_light_exit(void)
|
|
{
|
|
func_cb.last = FUNC_LIGHT;
|
|
}
|
|
|
|
//亮度调节功能
|
|
void func_light(void)
|
|
{
|
|
printf("%s\n", __func__);
|
|
func_light_enter();
|
|
while (func_cb.sta == FUNC_LIGHT) {
|
|
func_light_process();
|
|
func_light_message(msg_dequeue());
|
|
}
|
|
func_light_exit();
|
|
}
|