#include "include.h" #include "func.h" #include "app_variable.h" #if TRACE_EN #define TRACE(...) printf(__VA_ARGS__) #else #define TRACE(...) #endif #define MENU_LIST_CNT ((int)(sizeof(tbl_sport_list) / sizeof(tbl_sport_list[0]))) enum { COMPO_ID_LISTBOX = 1, }; typedef struct f_sport_list_t_ { compo_listbox_t *listbox; } f_sport_list_t; const compo_listbox_item_t tbl_sport_list[] = { {STR_OUTDOOR_RUNNING, UI_BUF_SPORT_BEFORE_EXERCISE_OUTDOOR_RUNNING_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 0, .func_sta = FUNC_SPORT_SWITCH}, //户外跑步 {STR_OUTDOOR_WALKING, UI_BUF_SPORT_BEFORE_EXERCISE_OUTDOOR_WALKING_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 0, .func_sta = FUNC_SPORT_SWITCH}, //户外步行 {STR_INDOOR_CYCLING, UI_BUF_SPORT_BEFORE_EXERCISE_INDOOR_CYCLING_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 2, .func_sta = FUNC_SPORT_SWITCH}, //室内单车 {STR_FOOTBALL, UI_BUF_SPORT_BEFORE_EXERCISE_FOOTBALL_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 0, .func_sta = FUNC_SPORT_SWITCH}, //足球 {STR_BASKETBALL, UI_BUF_SPORT_BEFORE_EXERCISE_BASKETBALL_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 0, .func_sta = FUNC_SPORT_SWITCH}, //篮球 {STR_INDOOR_RUN, UI_BUF_SPORT_BEFORE_EXERCISE_INDOOR_RUNNING_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 2, .func_sta = FUNC_SPORT_SWITCH}, //室内跑步 {STR_INDOOR_WALKING, UI_BUF_SPORT_BEFORE_EXERCISE_WALK_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 2, .func_sta = FUNC_SPORT_SWITCH}, //室内步行 {STR_ON_FOOT, UI_BUF_SPORT_BEFORE_EXERCISE_ON_FOOT_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 0, .func_sta = FUNC_SPORT_SWITCH}, //徒步 {STR_ELLIPTICAL_MACHINE, UI_BUF_SPORT_BEFORE_EXERCISE_ELLIPTICAL_MACHINE_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 2, .func_sta = FUNC_SPORT_SWITCH}, //椭圆机 #ifdef REMOVE_SPORT_WATER_ABOUT #else {STR_SWIMING_IN_THE_POOL, UI_BUF_SPORT_BEFORE_EXERCISE_SWIM_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 1, .func_sta = FUNC_SPORT_SWITCH}, //泳池游泳 {STR_FREE_SWIMMING, UI_BUF_SPORT_BEFORE_EXERCISE_FREE_SWIM_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 1, .func_sta = FUNC_SPORT_SWITCH}, //自由游泳 #endif {STR_FREE_TRAINING, UI_BUF_SPORT_BEFORE_EXERCISE_FREE_TRAINING_BIN, .item_mode = COMPO_LISTBOX_ITEM_MODE_NORMAL, .type = 2, .func_sta = FUNC_SPORT_SWITCH}, //自由训练 }; //创建运动窗体,创建窗体中不要使用功能结构体 func_cb.f_cb compo_form_t *func_sport_form_create(void) { //新建窗体和背景 compo_form_t *frm = compo_form_create(true); u8 sport_idx = sys_cb.sport_idx; //设置标题栏 compo_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME); compo_form_set_title(frm, i18n[STR_SPORTS]); //新建菜单列表 compo_listbox_t *listbox = compo_listbox_create(frm, COMPO_LISTBOX_STYLE_MENU_NORMAL); compo_listbox_set(listbox, tbl_sport_list, MENU_LIST_CNT); // int y = compo_listbox_gety_byidx(listbox, sys_cb.sport_idx); // compo_listbox_set_focus(listbox, y-10); compo_listbox_set_bgimg(listbox, UI_BUF_SPORT_BEFORE_EXERCISE_BG_BIN); compo_setid(listbox, COMPO_ID_LISTBOX); //图片位置偏移设置 compo_listbox_set_item_icon_xy_modify(listbox, 24, 24, 36, 36); //文字展示位置调整 compo_listbox_set_item_text(listbox, 7, 50, GUI_SCREEN_WIDTH - 20, 20, false); compo_listbox_set_focus_byidx(listbox, sport_idx); compo_listbox_update(listbox); return frm; } //点进图标进入应用 static void func_sport_list_icon_click(void) { int icon_idx; f_sport_list_t *f_sport = (f_sport_list_t *)func_cb.f_cb; compo_listbox_t *listbox = f_sport->listbox; u8 func_sta; icon_idx = compo_listbox_select(listbox, ctp_get_sxy()); if (icon_idx < 0 || icon_idx >= MENU_LIST_CNT) { return; } //根据图标索引获取应用ID func_sta = tbl_sport_list[icon_idx].func_sta; //切入应用 if (func_sta > 0 && !listbox->flag_area) { compo_form_t *frm = func_create_form(func_sta); func_switching(FUNC_SWITCH_ZOOM_ENTER | FUNC_SWITCH_AUTO, listbox->sel_icon); compo_form_destroy(frm); func_switch_to_assign_screen(func_sta, false); sys_cb.sport_idx = icon_idx; //记住当前编号 SysVariable.curSportRecord.sportmode = icon_idx; } // if(listbox->flag_area) { // func_cb.sta = FUNC_SPORT_CONFIG; // listbox->flag_area = 0; // } } //运动功能事件处理 static void func_sport_process(void) { f_sport_list_t *f_sport = (f_sport_list_t *)func_cb.f_cb; compo_listbox_move(f_sport->listbox); func_process(); } //运动功能消息处理 static void func_sport_message(size_msg_t msg) { f_sport_list_t *f_sport = (f_sport_list_t *)func_cb.f_cb; compo_listbox_t *listbox = f_sport->listbox; if (compo_listbox_message(listbox, msg)) { return; //处理列表框信息 } switch (msg) { case MSG_CTP_CLICK: func_sport_list_icon_click(); //单击图标 break; case MSG_CTP_LONG: break; case MSG_CTP_SHORT_RIGHT: func_message(msg); sys_cb.sport_idx = 0; break; case KU_DELAY_BACK: // if (tick_check_expire(func_cb.enter_tick, TICK_IGNORE_KEY)) { // func_menu_sub_list_switch_to_clock(); //返回时钟表盘界面 // } break; default: func_message(msg); break; } } //进入运动功能 static void func_sport_enter(void) { func_cb.f_cb = func_zalloc(sizeof(f_sport_list_t)); func_cb.frm_main = func_sport_form_create(); f_sport_list_t *f_sport = (f_sport_list_t *)func_cb.f_cb; f_sport->listbox = compo_getobj_byid(COMPO_ID_LISTBOX); compo_listbox_t *listbox = f_sport->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, compo_listbox_gety_byidx(listbox, 0), compo_listbox_gety_byidx(listbox, MENU_LIST_CNT - 1)); func_cb.enter_tick = tick_get(); } //退出运动功能 static void func_sport_exit(void) { f_sport_list_t *f_sport = (f_sport_list_t *)func_cb.f_cb; compo_listbox_t *listbox = f_sport->listbox; func_free(listbox->mcb); func_cb.last = FUNC_SPORT; } //运动功能 void func_sport(void) { printf("%s\n", __func__); func_sport_enter(); while (func_cb.sta == FUNC_SPORT) { func_sport_process(); func_sport_message(msg_dequeue()); } func_sport_exit(); }