455 lines
16 KiB
C
455 lines
16 KiB
C
#include "include.h"
|
|
#include "func.h"
|
|
#include "spirit_island_api.h"
|
|
#if TRACE_EN
|
|
#define TRACE(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define TRACE(...)
|
|
#endif
|
|
|
|
#define NUM_REC_COLOR make_color(2, 132, 253)
|
|
#define NUM_REC_COLOR_PRESS make_color(1, 60, 117)
|
|
|
|
//组件ID
|
|
enum {
|
|
//按键
|
|
COMPO_ID_BTN_RECORD_VIEW = 1, //查看记录
|
|
COMPO_ID_BTN_RECORD, //记录当前时间
|
|
COMPO_ID_BTN_AFRESH, //重新开始
|
|
COMPO_ID_BTN_START_REC, //开始计时
|
|
//数字文本
|
|
COMPO_ID_NUM_STOPWATCH_TIME, //当前计时
|
|
COMPO_ID_NUM_STOPWATCH_REC, //记录数
|
|
|
|
COMPO_ID_SHAPE, //矩形
|
|
COMPO_ID_LISTBOX,
|
|
};
|
|
|
|
typedef struct f_stopwatch_t_ {
|
|
compo_listbox_t *listbox;
|
|
u8 min; //分
|
|
u8 sec; //秒
|
|
u16 msec; //毫秒
|
|
} f_stopwatch_t;
|
|
|
|
static u32 func_stopwatch_tick_get(void)
|
|
{
|
|
return sys_cb.stopwatch_tick;
|
|
}
|
|
|
|
static u32 func_stopwatch_tick_reset(void)
|
|
{
|
|
sys_cb.stopwatch_tick = 0;
|
|
}
|
|
|
|
//创建秒表窗体,创建窗体中不要使用功能结构体 func_cb.f_cb
|
|
compo_form_t *func_stopwatch_form_create(void)
|
|
{
|
|
// 新建窗体和背景
|
|
compo_form_t *frm = compo_form_create(true);
|
|
|
|
// 设置标题栏
|
|
compo_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME);
|
|
compo_form_set_title(frm, i18n[STR_STOP_WATCH]);
|
|
|
|
// 新建按钮
|
|
u32 res_addr;
|
|
compo_button_t *btn;
|
|
res_addr = sys_cb.stopwatch_sta ? UI_BUF_COMMON_STOP_BIN : UI_BUF_COMMON_START_BIN; // 开始/暂停
|
|
btn = compo_button_create_by_image(frm, res_addr);
|
|
compo_setid(btn, COMPO_ID_BTN_START_REC);
|
|
compo_button_set_pos(btn, !sys_cb.stopwatch_total_msec ? GUI_SCREEN_CENTER_X : GUI_SCREEN_CENTER_X + 34, 115 + 16);
|
|
|
|
btn = compo_button_create_by_image(frm, UI_BUF_COMMON_RESET_BIN); // 复位
|
|
compo_setid(btn, COMPO_ID_BTN_AFRESH);
|
|
compo_button_set_pos(btn, GUI_SCREEN_CENTER_X - 34, 115 + 16);
|
|
compo_button_set_visible(btn, sys_cb.stopwatch_total_msec > 0);
|
|
|
|
btn = compo_button_create_by_image(frm, UI_BUF_COMMON_NODE_BIN); // 计次
|
|
compo_setid(btn, COMPO_ID_BTN_RECORD);
|
|
compo_button_set_pos(btn, GUI_SCREEN_CENTER_X - 34, 115 + 16);
|
|
compo_button_set_visible(btn, sys_cb.stopwatch_sta != 0);
|
|
|
|
btn = compo_button_create(frm); // 计次详情
|
|
compo_setid(btn, COMPO_ID_BTN_RECORD_VIEW);
|
|
compo_button_set_location(btn, GUI_SCREEN_CENTER_X, 45+33, 200, 60);
|
|
// compo_button_set_pos(btn, GUI_SCREEN_CENTER_X, 130);
|
|
compo_button_set_visible(btn, sys_cb.stopwatch_rec_cnt > 0);
|
|
|
|
// 创建数字文本
|
|
compo_textbox_t *txt_num;
|
|
char str_buff[15] = {0};
|
|
u8 min, sec;
|
|
u16 msec;
|
|
min = ((sys_cb.stopwatch_total_msec / 1000) % 3600) / 60;
|
|
sec = (sys_cb.stopwatch_total_msec / 1000) % 60;
|
|
msec = sys_cb.stopwatch_total_msec % 1000;
|
|
|
|
// 绿色
|
|
compo_shape_t *masklayer;
|
|
masklayer = compo_radius_shape_create(frm, COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE, 1);
|
|
compo_shape_set_color(masklayer, make_color(12, 237, 65));
|
|
compo_setid(masklayer, COMPO_ID_SHAPE);
|
|
compo_shape_set_location(masklayer, GUI_SCREEN_CENTER_X, 48, GUI_SCREEN_WIDTH, 1);
|
|
compo_shape_set_alpha(masklayer, 0);
|
|
|
|
txt_num = compo_textbox_create(frm, 8); // 当前计时
|
|
compo_setid(txt_num, COMPO_ID_NUM_STOPWATCH_TIME);
|
|
compo_textbox_set_location(txt_num, GUI_SCREEN_CENTER_X, 28+8, 300, 30);
|
|
compo_textbox_set_font(txt_num, UI_BUF_0FONT_FONT_DIN_PRO_NUM_20_BIN);
|
|
snprintf(str_buff, sizeof(str_buff), "%02d:%02d:%02d", min, sec, msec / 10);
|
|
compo_textbox_set(txt_num, str_buff);
|
|
|
|
u8 min_recode = 0;
|
|
u8 sec_recode = 0;
|
|
u16 msec_recode = 0;
|
|
|
|
min_recode = ((sys_cb.stopwatch_rec_view[0] / 1000) % 3600) / 60;
|
|
sec_recode = (sys_cb.stopwatch_rec_view[0] / 1000) % 60;
|
|
msec_recode = sys_cb.stopwatch_rec_view[0] % 1000;
|
|
snprintf(str_buff, sizeof(str_buff), "%02d. %02d:%02d.%02d", sys_cb.stopwatch_rec_cnt, min_recode, sec_recode, msec_recode / 10);
|
|
|
|
txt_num = compo_textbox_create(frm, 12); // 记录数
|
|
compo_setid(txt_num, COMPO_ID_NUM_STOPWATCH_REC);
|
|
compo_textbox_set_location(txt_num, GUI_SCREEN_CENTER_X, 56+7, 300, 60);
|
|
compo_textbox_set_font(txt_num, UI_BUF_0FONT_FONT_DIN_LIGHT_NUM_15_BIN);
|
|
|
|
compo_textbox_set(txt_num, str_buff);
|
|
compo_textbox_set_forecolor(txt_num, NUM_REC_COLOR);
|
|
compo_textbox_set_visible(txt_num, sys_cb.stopwatch_rec_cnt > 0);
|
|
|
|
// compo_listbox_t *listbox = compo_listbox_create(frm, COMPO_LISTBOX_STYLE_TITLE);
|
|
// compo_listbox_set(listbox, tbl_stopwatch_list, sys_cb.stopwatch_rec_cnt);
|
|
// compo_setid(listbox, COMPO_ID_LISTBOX);
|
|
|
|
// compo_listbox_set_bgimg(listbox, UI_BUF_COMMON_BG_BIN);
|
|
// compo_listbox_set_text_modify(listbox, tbl_stopwatch_txt_list);
|
|
|
|
// u8 min_recode = 0;
|
|
// u8 sec_recode = 0;
|
|
// u16 msec_recode = 0;
|
|
// for (u8 i = 0; i < sys_cb.stopwatch_rec_cnt; i++) {
|
|
// min_recode = ((sys_cb.stopwatch_rec_view[i] / 1000) % 3600) / 60;
|
|
// sec_recode = (sys_cb.stopwatch_rec_view[i] / 1000) % 60;
|
|
// msec_recode = sys_cb.stopwatch_rec_view[i] % 1000;
|
|
// sprintf(tbl_stopwatch_txt_list[i].str_txt, "%2d. %02d:%02d.%02d", sys_cb.stopwatch_rec_cnt - i, min_recode, sec_recode, msec_recode / 10);
|
|
// }
|
|
// compo_listbox_set_focus_byidx(listbox, 1);
|
|
// compo_listbox_update(listbox);
|
|
|
|
return frm;
|
|
}
|
|
|
|
//触摸按钮效果处理
|
|
static void func_stopwatch_button_touch_handle(void)
|
|
{
|
|
u32 res_addr;
|
|
int id = compo_get_button_id();
|
|
|
|
// 获取按钮组件的地址
|
|
compo_button_t *btn_start = compo_getobj_byid(COMPO_ID_BTN_START_REC);
|
|
compo_button_t *btn_afresh = compo_getobj_byid(COMPO_ID_BTN_AFRESH);
|
|
compo_button_t *btn_record = compo_getobj_byid(COMPO_ID_BTN_RECORD);
|
|
compo_button_t *btn_record1 = compo_getobj_byid(COMPO_ID_BTN_RECORD_VIEW);
|
|
|
|
// 获取数字组件的地址
|
|
compo_textbox_t *num_rec = compo_getobj_byid(COMPO_ID_NUM_STOPWATCH_REC);
|
|
switch (id) {
|
|
case COMPO_ID_BTN_RECORD_VIEW:
|
|
// if (sys_cb.stopwatch_rec_cnt) {
|
|
// compo_button_set_bgimg(btn_record1, UI_BUF_COMMON_BG_BIN);
|
|
// compo_textbox_set_forecolor(num_rec, NUM_REC_COLOR_PRESS);
|
|
// }
|
|
break;
|
|
|
|
case COMPO_ID_BTN_RECORD:
|
|
// compo_button_set_bgimg(btn_record, UI_BUF_STOPWATCH_RECORD_CLICK_BIN);
|
|
if (sys_cb.stopwatch_rec_cnt && sys_cb.stopwatch_sta) {
|
|
// compo_textbox_set_forecolor(num_rec, NUM_REC_COLOR_PRESS);
|
|
}
|
|
break;
|
|
|
|
case COMPO_ID_BTN_AFRESH:
|
|
// compo_button_set_bgimg(btn_afresh, UI_BUF_STOPWATCH_AFRESH_CLICK_BIN);
|
|
break;
|
|
|
|
case COMPO_ID_BTN_START_REC:
|
|
res_addr = sys_cb.stopwatch_sta ? UI_BUF_COMMON_STOP_BIN : UI_BUF_COMMON_START_BIN;
|
|
compo_button_set_bgimg(btn_start, res_addr);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
//释放按钮效果处理
|
|
static void func_stopwatch_button_release_handle(void)
|
|
{
|
|
// 获取按钮组件的地址
|
|
compo_button_t *btn_start = compo_getobj_byid(COMPO_ID_BTN_START_REC);
|
|
compo_button_t *btn_afresh = compo_getobj_byid(COMPO_ID_BTN_AFRESH);
|
|
compo_button_t *btn_record = compo_getobj_byid(COMPO_ID_BTN_RECORD);
|
|
compo_button_t *btn_record1 = compo_getobj_byid(COMPO_ID_BTN_RECORD_VIEW);
|
|
// compo_shape_t *shape = compo_getobj_byid(COMPO_ID_SHAPE);
|
|
|
|
u32 res_addr = sys_cb.stopwatch_sta ? UI_BUF_COMMON_STOP_BIN : UI_BUF_COMMON_START_BIN;
|
|
compo_button_set_bgimg(btn_start, res_addr);
|
|
compo_button_set_pos(btn_start, !sys_cb.stopwatch_total_msec && !sys_cb.stopwatch_sta ? GUI_SCREEN_CENTER_X : GUI_SCREEN_CENTER_X + 34, 115 + 16);
|
|
|
|
compo_button_set_bgimg(btn_afresh, UI_BUF_COMMON_RESET_BIN); // 复位
|
|
compo_button_set_visible(btn_afresh, sys_cb.stopwatch_total_msec > 0 || sys_cb.stopwatch_sta);
|
|
compo_button_set_bgimg(btn_record, UI_BUF_COMMON_NODE_BIN); // 计次
|
|
compo_button_set_visible(btn_record, sys_cb.stopwatch_sta != 0);
|
|
// compo_button_set_bgimg(btn_record1, UI_BUF_STOPWATCH_RECORD1_BIN); //计次详情
|
|
compo_button_set_visible(btn_record1, sys_cb.stopwatch_rec_cnt > 0);
|
|
// compo_shape_set_visible(shape, sys_cb.stopwatch_rec_cnt > 0);
|
|
|
|
// 获取数字组件的地址
|
|
compo_textbox_t *num_rec = compo_getobj_byid(COMPO_ID_NUM_STOPWATCH_REC);
|
|
|
|
compo_textbox_set_forecolor(num_rec, NUM_REC_COLOR);
|
|
compo_textbox_set_visible(num_rec, sys_cb.stopwatch_rec_cnt > 0);
|
|
}
|
|
|
|
static void stopwatch_data_reset(void)
|
|
{
|
|
f_stopwatch_t *f_stopwatch = (f_stopwatch_t *)func_cb.f_cb;
|
|
|
|
compo_textbox_t *num_time = compo_getobj_byid(COMPO_ID_NUM_STOPWATCH_TIME);
|
|
compo_textbox_t *num_rec = compo_getobj_byid(COMPO_ID_NUM_STOPWATCH_REC);
|
|
|
|
func_stopwatch_tick_reset();
|
|
|
|
f_stopwatch->min = 0;
|
|
f_stopwatch->sec = 0;
|
|
f_stopwatch->msec = 0;
|
|
|
|
memset(sys_cb.stopwatch_rec_view, 0, sizeof(sys_cb.stopwatch_rec_view));
|
|
sys_cb.stopwatch_rec_cnt = 0;
|
|
sys_cb.stopwatch_rec_cnt = 0;
|
|
sys_cb.stopwatch_temp_msec = 0;
|
|
sys_cb.stopwatch_total_msec = 0;
|
|
|
|
compo_textbox_set(num_time, "00:00:00");
|
|
compo_textbox_set(num_rec, "0");
|
|
}
|
|
|
|
//单击按钮
|
|
static void func_stopwatch_button_click(void)
|
|
{
|
|
int id = compo_get_button_id();
|
|
f_stopwatch_t *f_stopwatch = (f_stopwatch_t *)func_cb.f_cb;
|
|
char str_buff[15] = {0};
|
|
|
|
u8 min_recode = 0;
|
|
u8 sec_recode = 0;
|
|
u16 msec_recode = 0;
|
|
|
|
// 获取数字组件的地址
|
|
compo_textbox_t *num_time = compo_getobj_byid(COMPO_ID_NUM_STOPWATCH_TIME);
|
|
compo_textbox_t *num_rec = compo_getobj_byid(COMPO_ID_NUM_STOPWATCH_REC);
|
|
|
|
switch (id) {
|
|
case COMPO_ID_BTN_RECORD_VIEW:
|
|
if (sys_cb.stopwatch_rec_cnt) {
|
|
func_switch_to_assign_screen(FUNC_STOPWATCH_SUB_RECORD, false);
|
|
}
|
|
break;
|
|
|
|
case COMPO_ID_BTN_RECORD:
|
|
//插入记录到头部
|
|
// if (sys_cb.stopwatch_sta) {
|
|
// sys_cb.stopwatch_rec_cnt += (sys_cb.stopwatch_rec_cnt < STOPWATCH_REC_NUM_MAX);
|
|
// for (u8 i = sys_cb.stopwatch_rec_cnt - 1; i > 0; i--) {
|
|
// sys_cb.stopwatch_rec_view[i] = sys_cb.stopwatch_rec_view[i - 1];
|
|
// }
|
|
// sys_cb.stopwatch_rec_view[0] = sys_cb.stopwatch_total_msec;
|
|
|
|
// snprintf(str_buff, sizeof(str_buff), "%02d", sys_cb.stopwatch_rec_cnt);
|
|
// compo_textbox_set(num_rec, str_buff);
|
|
// }
|
|
break;
|
|
|
|
case COMPO_ID_BTN_AFRESH:
|
|
if (sys_cb.stopwatch_sta == 0) {
|
|
stopwatch_data_reset();
|
|
}
|
|
else {
|
|
/* 插入记录到头部 */
|
|
sys_cb.stopwatch_rec_cnt += (sys_cb.stopwatch_rec_cnt < STOPWATCH_REC_NUM_MAX);
|
|
|
|
for (u8 i = sys_cb.stopwatch_rec_cnt - 1; i > 0; i--)
|
|
{
|
|
sys_cb.stopwatch_rec_view[i] = sys_cb.stopwatch_rec_view[i - 1];
|
|
}
|
|
sys_cb.stopwatch_rec_view[0] = sys_cb.stopwatch_total_msec;
|
|
|
|
min_recode = ((sys_cb.stopwatch_rec_view[0] / 1000) % 3600) / 60;
|
|
sec_recode = (sys_cb.stopwatch_rec_view[0] / 1000) % 60;
|
|
msec_recode = sys_cb.stopwatch_rec_view[0] % 1000;
|
|
|
|
// snprintf(str_buff, sizeof(str_buff), "%02d", sys_cb.stopwatch_rec_cnt);
|
|
snprintf(str_buff, sizeof(str_buff), "%02d. %02d:%02d.%02d", sys_cb.stopwatch_rec_cnt, min_recode, sec_recode, msec_recode / 10);
|
|
compo_textbox_set(num_rec, str_buff);
|
|
}
|
|
break;
|
|
|
|
case COMPO_ID_BTN_START_REC:
|
|
func_stopwatch_tick_reset();
|
|
|
|
sys_cb.stopwatch_sta = !sys_cb.stopwatch_sta;
|
|
sys_cb.stopwatch_temp_msec = sys_cb.stopwatch_total_msec;
|
|
break;
|
|
}
|
|
|
|
func_stopwatch_button_release_handle();
|
|
}
|
|
|
|
//秒表功能事件处理
|
|
static void func_stopwatch_process(void)
|
|
{
|
|
f_stopwatch_t *f_stopwatch = (f_stopwatch_t *)func_cb.f_cb;
|
|
|
|
compo_shape_t *masklayer;
|
|
masklayer = compo_getobj_byid(COMPO_ID_SHAPE);
|
|
|
|
if (f_stopwatch == NULL || masklayer == NULL)
|
|
return;
|
|
|
|
if (sys_cb.stopwatch_sta)
|
|
{
|
|
/* 10ms刷新时间 */
|
|
sys_cb.stopwatch_total_msec = sys_cb.stopwatch_temp_msec + func_stopwatch_tick_get();
|
|
|
|
u8 min = ((sys_cb.stopwatch_total_msec / 1000) % 3600) / 60;
|
|
u8 sec = (sys_cb.stopwatch_total_msec / 1000) % 60;
|
|
u16 msec = sys_cb.stopwatch_total_msec % 1000;
|
|
char str_buff[9];
|
|
f_stopwatch_t *f_stopwatch = (f_stopwatch_t *)func_cb.f_cb;
|
|
|
|
// 获取数字组件的地址
|
|
compo_textbox_t *num_time = compo_getobj_byid(COMPO_ID_NUM_STOPWATCH_TIME);
|
|
|
|
if (f_stopwatch->msec != msec || f_stopwatch->sec != sec || f_stopwatch->min != min)
|
|
{
|
|
f_stopwatch->min = min;
|
|
f_stopwatch->sec = sec;
|
|
f_stopwatch->msec = msec;
|
|
|
|
snprintf(str_buff, sizeof(str_buff), "%02d:%02d.%02d", min, sec, msec / 10);
|
|
compo_textbox_set(num_time, str_buff);
|
|
}
|
|
}
|
|
|
|
if (sys_cb.stopwatch_rec_cnt > 0) {
|
|
compo_shape_set_alpha(masklayer, 255);
|
|
} else {
|
|
compo_shape_set_alpha(masklayer, 0);
|
|
}
|
|
func_process();
|
|
}
|
|
|
|
//秒表功能消息处理
|
|
static void func_stopwatch_message(size_msg_t msg)
|
|
{
|
|
switch (msg) {
|
|
case MSG_CTP_TOUCH:
|
|
func_stopwatch_button_touch_handle();
|
|
break;
|
|
|
|
case MSG_CTP_CLICK:
|
|
func_stopwatch_button_click();
|
|
break;
|
|
|
|
case KU_BACK:
|
|
case KU_LEFT:
|
|
case KU_RIGHT:
|
|
if (sys_cb.stopwatch_sta) {
|
|
sys_cb.stopwatch_sta = !sys_cb.stopwatch_sta;
|
|
func_stopwatch_button_release_handle();
|
|
} else {
|
|
func_message(msg);
|
|
|
|
/* 用户主动操作按键退出重置数据 */
|
|
if (func_cb.sta != FUNC_STOPWATCH) {
|
|
stopwatch_data_reset();
|
|
}
|
|
}
|
|
break;
|
|
|
|
case MSG_CTP_SHORT_UP:
|
|
case MSG_CTP_SHORT_DOWN:
|
|
|
|
case MSG_CTP_LONG:
|
|
func_stopwatch_button_release_handle();
|
|
if (func_cb.flag_sort) {
|
|
func_message(msg);
|
|
}
|
|
break;
|
|
case MSG_CTP_SHORT_LEFT:
|
|
case MSG_CTP_SHORT_RIGHT:
|
|
if (sys_cb.stopwatch_sta) {
|
|
sys_cb.stopwatch_sta = !sys_cb.stopwatch_sta;
|
|
func_stopwatch_button_release_handle();
|
|
} else {
|
|
func_message(msg);
|
|
if (func_cb.sta != FUNC_STOPWATCH) {
|
|
stopwatch_data_reset();
|
|
}
|
|
}
|
|
break;
|
|
|
|
default:
|
|
func_message(msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
//进入秒表功能
|
|
static void func_stopwatch_enter(void)
|
|
{
|
|
func_cb.f_cb = func_zalloc(sizeof(f_stopwatch_t));
|
|
func_cb.frm_main = func_stopwatch_form_create();
|
|
|
|
// f_stopwatch_t *f_stopwatch = (f_stopwatch_t *)func_cb.f_cb;
|
|
// f_stopwatch->listbox = compo_getobj_byid(COMPO_ID_LISTBOX);
|
|
|
|
// compo_listbox_t *listbox = f_stopwatch->listbox;
|
|
// if (listbox->type != COMPO_TYPE_LISTBOX) {
|
|
// halt(HALT_GUI_COMPO_LISTBOX_TYPE);
|
|
// }
|
|
// listbox->mcb = func_zalloc(sizeof(compo_listbox_move_cb_t)); //建立移动控制块,退出时需要释放
|
|
// compo_listbox_move_init_modify(listbox, 127, compo_listbox_gety_byidx(listbox, STOPWATCH_REC_NUM_MAX - 2));
|
|
// func_cb.enter_tick = tick_get();
|
|
}
|
|
|
|
//退出秒表功能
|
|
static void func_stopwatch_exit(void)
|
|
{
|
|
// f_stopwatch_t *f_stopwatch = (f_stopwatch_t *)func_cb.f_cb;
|
|
// compo_listbox_t *listbox = f_stopwatch->listbox;
|
|
// func_free(listbox->mcb);
|
|
// func_cb.last = FUNC_STOPWATCH;
|
|
|
|
#ifdef TJD_GUI_SPIRIT_ISLAND_SHOW
|
|
if (sys_cb.stopwatch_sta) {
|
|
si_activated_task(stopwatch, 0);
|
|
} else {
|
|
si_delet_task(stopwatch);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
//秒表功能
|
|
void func_stopwatch(void)
|
|
{
|
|
printf("%s\n", __func__);
|
|
func_stopwatch_enter();
|
|
while (func_cb.sta == FUNC_STOPWATCH) {
|
|
func_stopwatch_process();
|
|
func_stopwatch_message(msg_dequeue());
|
|
}
|
|
func_stopwatch_exit();
|
|
}
|