#include "include.h" #include "func.h" #include "func_menu.h" #include "app_variable.h" #if TRACE_EN #define TRACE(...) printf(__VA_ARGS__) #else #define TRACE(...) #endif #ifdef MENU_CHANGE_STYLE_DRUM #define ONG_PIC_CHANG_X (GUI_SCREEN_WIDTH/8) //左右切换单位宽度 #define SWITCHING_TICK_AUTO 180 //快速松手视为自动模式(ms) #define CTP_SHORT_DX (GUI_SCREEN_WIDTH/3) //快速滑动判定宽度 enum { COMPO_ID_PIC_ANIM = 1, COMPO_ID_TXT_STYLE, }; typedef struct f_style_t_ { } f_style_t; static const u32 tbl_sytle_list[] = { STR_SYTLE_1, // 蜂窝 STR_SYTLE_2, // 瀑布 STR_SYTLE_3, // 菜单列表 STR_SYTLE_4, // 网格 STR_SYTLE_5, // 环形 STR_SYTLE_6, // 万花筒 }; static const u32 ui_buf_style_anim[] = { UI_BUF_STYLE_01_BIN, UI_BUF_STYLE_02_BIN, UI_BUF_STYLE_03_BIN, UI_BUF_STYLE_04_BIN, UI_BUF_STYLE_05_BIN, UI_BUF_STYLE_06_BIN, UI_BUF_STYLE_07_BIN, UI_BUF_STYLE_08_BIN, UI_BUF_STYLE_09_BIN, UI_BUF_STYLE_10_BIN, UI_BUF_STYLE_11_BIN, UI_BUF_STYLE_12_BIN, }; //创建主菜单窗体,创建窗体中不要使用功能结构体 func_cb.f_cb compo_form_t *func_style_form_create(void) { //新建窗体 compo_form_t *frm = compo_form_create(true); compo_button_t *btn; btn = compo_button_create_by_image(frm, ui_buf_style_anim[2*(SysVariable.menu_style)]); compo_setid(btn, COMPO_ID_PIC_ANIM); compo_button_set_pos(btn, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y); compo_textbox_t *txt = compo_textbox_create(frm, 50); compo_setid(txt, COMPO_ID_TXT_STYLE); compo_textbox_set(txt, i18n[tbl_sytle_list[SysVariable.menu_style]]); compo_textbox_set_location(txt, GUI_SCREEN_CENTER_X, 30, 80, 40); return frm; } //点进图标进入应用 static void func_style_icon_short(bool flag) { f_style_t *f_set = (f_style_t *)func_cb.f_cb; compo_button_t *btn = compo_getobj_byid(COMPO_ID_PIC_ANIM); compo_button_t *txt = compo_getobj_byid(COMPO_ID_TXT_STYLE); s32 short_set; s32 dx=0; s32 dy=0; s32 menu_style = 2*SysVariable.menu_style; s32 dx_auto; u32 tick = tick_get(); bool flag_change; bool flag_press; u32 anim_tick; for(;;){ flag_press = ctp_get_dxy(&dx, &dy); if(flag_press == true) { if(dx > 0) dx_auto = dx/((s32)ONG_PIC_CHANG_X) + 1; else dx_auto = dx/((s32)ONG_PIC_CHANG_X) - 1; menu_style = 2*SysVariable.menu_style - dx_auto; printf("------------dx = %d ,dx_auto = %d ,menu_style = %d\n",dx,dx_auto,menu_style); if(menu_style >11){ menu_style = menu_style - 12; } else if(menu_style < 0){ menu_style = menu_style + 12; } compo_button_set_bgimg(btn, ui_buf_style_anim[menu_style]); compo_textbox_set(txt, i18n[tbl_sytle_list[menu_style/2]]); } else{ if(tick_get()-tick < SWITCHING_TICK_AUTO) { int i = menu_style; if (flag == true) { SysVariable.menu_style = SysVariable.menu_style + 1; if (SysVariable.menu_style > 5) SysVariable.menu_style = 0; } else{ if (SysVariable.menu_style == 0) SysVariable.menu_style = 5; else SysVariable.menu_style = SysVariable.menu_style - 1; } for (;;) { s32 dx_short; s32 dy_short; flag_press = ctp_get_dxy(&dx_short, &dy_short); printf("===========dx = %d\n",dx); if (tick_check_expire(anim_tick, 50)) { anim_tick = tick_get(); if(flag == true){ if (i > 11) menu_style = i - 12; else menu_style = i; compo_button_set_bgimg(btn, ui_buf_style_anim[menu_style]); compo_textbox_set(txt, i18n[tbl_sytle_list[menu_style/2]]); i++; } else{ if (i < 0) menu_style = i + 12; else menu_style = i; compo_button_set_bgimg(btn, ui_buf_style_anim[menu_style]); compo_textbox_set(txt, i18n[tbl_sytle_list[menu_style/2]]); i--; } } if(flag) { if( dx > -CTP_SHORT_DX && dx <= 0) short_set = 4 + 2 * SysVariable.menu_style; else if( dx > -2*CTP_SHORT_DX && dx <= -CTP_SHORT_DX) short_set = 8 + 2 * SysVariable.menu_style; else if( dx > -3*CTP_SHORT_DX && dx <= -2*CTP_SHORT_DX) short_set = 12 + 2 * SysVariable.menu_style; printf("===========short_set = %d ,i = %d\n",short_set,i); if (i > short_set || flag_press == true) break; } else{ if( dx >= 0 && dx < CTP_SHORT_DX) short_set = 2 * SysVariable.menu_style - 4; else if( dx >= CTP_SHORT_DX && dx < 2*CTP_SHORT_DX) short_set = 2 * SysVariable.menu_style - 8; else if( dx >= 2*CTP_SHORT_DX && dx < 3*CTP_SHORT_DX) short_set = 2 * SysVariable.menu_style - 12; if (i < short_set || flag_press == true) break; } func_process(); } } if (flag == true) { if (menu_style % 2 == 1) { menu_style = menu_style + 1; if (menu_style == 12) menu_style = 0; } compo_button_set_bgimg(btn, ui_buf_style_anim[menu_style]); compo_textbox_set(txt, i18n[tbl_sytle_list[menu_style/2]]); SysVariable.menu_style = menu_style / 2; } else { if (menu_style % 2 == 1) { menu_style = menu_style - 1; } compo_button_set_bgimg(btn, ui_buf_style_anim[menu_style]); compo_textbox_set(txt, i18n[tbl_sytle_list[menu_style/2]]); SysVariable.menu_style = menu_style / 2; } break; } func_process(); } } void msg_qec_style_menu(bool flag) { compo_button_t *btn = compo_getobj_byid(COMPO_ID_PIC_ANIM); compo_button_t *txt = compo_getobj_byid(COMPO_ID_TXT_STYLE); static s32 menu_style; if(flag) { SysVariable.menu_style = SysVariable.menu_style + 1; menu_style = 2*SysVariable.menu_style - 1; if (SysVariable.menu_style > 5) SysVariable.menu_style = 0; printf("menu_style = %d ,SysVariable.menu_style = %d",menu_style,SysVariable.menu_style); compo_button_set_bgimg(btn, ui_buf_style_anim[menu_style]); compo_button_set_bgimg(btn, ui_buf_style_anim[2*SysVariable.menu_style]); compo_textbox_set(txt, i18n[tbl_sytle_list[SysVariable.menu_style]]); } else{ if (SysVariable.menu_style == 0) SysVariable.menu_style = 6; SysVariable.menu_style = SysVariable.menu_style - 1; menu_style = 2*SysVariable.menu_style + 1; printf("menu_style = %d ,SysVariable.menu_style = %d",menu_style,SysVariable.menu_style); compo_button_set_bgimg(btn, ui_buf_style_anim[menu_style]); compo_button_set_bgimg(btn, ui_buf_style_anim[2*SysVariable.menu_style]); compo_textbox_set(txt, i18n[tbl_sytle_list[SysVariable.menu_style]]); } } //主菜单功能事件处理 static void func_style_process(void) { f_style_t *f_set = (f_style_t *)func_cb.f_cb; func_process(); } //进入设置主菜单页面 static void func_style_enter(void) { func_cb.f_cb = func_zalloc(sizeof(f_style_t)); func_cb.frm_main = func_style_form_create(); func_cb.menu_idx = 0; } //主菜单功能消息处理 static void func_style_message(size_msg_t msg) { f_style_t *f_set = (f_style_t *)func_cb.f_cb; int id = compo_get_button_id(); switch (msg) { case MSG_CTP_CLICK: if(id == COMPO_ID_PIC_ANIM) func_switch_to_menu(); //退回到主菜单 break; case MSG_CTP_LONG: break; case MSG_CTP_SHORT_LEFT: func_style_icon_short(true); break; case MSG_CTP_SHORT_RIGHT: func_style_icon_short(false); break; case MSG_QDEC_FORWARD: msg_qec_style_menu(true); break; case MSG_QDEC_BACKWARD: msg_qec_style_menu(false); break; case MSG_CTP_COVER: break; default: func_message(msg); break; } } //退出菜单样式 void func_style_exit(void) { printf("func_set_sub_exit\r\n"); f_style_t *f_set = (f_style_t *)func_cb.f_cb; //释放移动控制块 func_cb.last = FUNC_STYLE; SysVariable.duty_flag = true; } //主菜单功能 void func_style(void) { func_style_enter(); while (func_cb.sta == FUNC_STYLE) { func_style_process(); func_style_message(msg_dequeue()); } func_style_exit(); } #else #define SYTLE_LIST_CNT ((int)(sizeof(tbl_sytle_list) / sizeof(tbl_sytle_list[0]))) enum { COMPO_ID_LISTBOX = 1, }; typedef struct f_style_t_ { compo_listbox_t *listbox; } f_style_t; #if 1 /* FLASH_SIZE == FSIZE_2M */ static const compo_listbox_item_t tbl_sytle_list[] = { {STR_SYTLE_1, UI_BUF_STYLE_ICON_01_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_HONEYCOMB}, {STR_SYTLE_2, UI_BUF_STYLE_ICON_03_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_LIST}, {STR_SYTLE_3, UI_BUF_STYLE_ICON_02_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_ROLLER}, {STR_SYTLE_4, UI_BUF_STYLE_ICON_04_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_DISK}, {STR_SYTLE_5, UI_BUF_STYLE_ICON_05_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_WATERFALL}, {STR_SYTLE_6, UI_BUF_STYLE_ICON_06_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_RING}, {STR_SYTLE_7, UI_BUF_STYLE_ICON_07_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_GRID}, {STR_SYTLE_8, UI_BUF_STYLE_ICON_08_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_SUDOKU_HRZ}, {STR_SYTLE_9, UI_BUF_STYLE_ICON_09_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_CUM_SUDOKU}, {STR_SYTLE_10, UI_BUF_STYLE_ICON_10_BIN, .func_sta = FUNC_MENU, .item_mode = COMPO_LISTBOX_ITEM_MODE_SWITCH, .vidx = MENU_STYLE_KALE}, }; #else static const compo_listbox_item_t tbl_sytle_list[] = { {STR_SYTLE_1, UI_BUF_STYLE_01_BIN, .func_sta = FUNC_MENU}, //亮度调节 {STR_SYTLE_2, UI_BUF_STYLE_02_BIN, .func_sta = FUNC_MENU}, //息屏时长 {STR_SYTLE_3, UI_BUF_STYLE_03_BIN, .func_sta = FUNC_MENU}, //抬腕亮屏 {STR_SYTLE_4, UI_BUF_STYLE_04_BIN, .func_sta = FUNC_MENU}, //勿扰模式 {STR_SYTLE_5, UI_BUF_STYLE_05_BIN, .func_sta = FUNC_MENU}, //声音与振动 {STR_SYTLE_6, UI_BUF_STYLE_06_BIN, .func_sta = FUNC_MENU}, //语言设置 {STR_SYTLE_7, UI_BUF_STYLE_07_BIN, .func_sta = FUNC_MENU}, //时间设置 {STR_SYTLE_8, UI_BUF_STYLE_08_BIN, .func_sta = FUNC_MENU}, //日期设置 {STR_SYTLE_9, UI_BUF_STYLE_09_BIN, .func_sta = FUNC_MENU}, //密码锁 {STR_SYTLE_10, UI_BUF_STYLE_10_BIN, .func_sta = FUNC_MENU}, //关于 }; #endif u8 get_ctlbit_style(uint n) { return (SysVariable.menu_style == n); } //创建主菜单窗体,创建窗体中不要使用功能结构体 func_cb.f_cb compo_form_t *func_style_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_STYLE]); //新建菜单列表 // compo_listbox_t *listbox = compo_listbox_create(frm, COMPO_LISTBOX_STYLE_TITLE); // compo_listbox_set(listbox, tbl_sytle_list, SYTLE_LIST_CNT); // compo_listbox_set_bgimg(listbox, UI_BUF_COMMON_BG_BIN); // compo_setid(listbox, COMPO_ID_LISTBOX); // compo_listbox_set_sta_icon(listbox, UI_BUF_COMMON_SELECT_ON_BIN, UI_BUF_COMMON_SELECT_BIN); // compo_listbox_set_bithook(listbox, bsp_sys_get_ctlbit); compo_listbox_t *listbox = compo_listbox_create(frm, COMPO_LISTBOX_STYLE_TITLE_NORMAL); compo_listbox_set(listbox, tbl_sytle_list, SYTLE_LIST_CNT); // compo_listbox_set_bgimg(listbox, UI_BUF_COMMON_BG_BIN); compo_setid(listbox, COMPO_ID_LISTBOX); compo_listbox_set_sta_icon_center(listbox, UI_BUF_COMMON_BG_BLUE_BIN, UI_BUF_COMMON_BG_BIN); // compo_listbox_set_item_text(listbox, 12, 23, 160, 40, false); compo_listbox_set_bithook(listbox, get_ctlbit_style); u8 set_idx = SysVariable.menu_style; if (set_idx < 1) { set_idx = 1; } compo_listbox_set_focus_byidx(listbox, set_idx); compo_listbox_update(listbox); return frm; } //点进图标进入应用 static void func_style_icon_click(void) { int icon_idx; f_style_t *f_set = (f_style_t *)func_cb.f_cb; compo_listbox_t *listbox = f_set->listbox; icon_idx = compo_listbox_select(listbox, ctp_get_sxy()); if (icon_idx < 0 || icon_idx >= SYTLE_LIST_CNT) { return; } SysVariable.menu_style = icon_idx; compo_listbox_update(listbox); func_cb.menu_idx = 0; //根据图标索引获取应用ID // func_sta = tbl_sytle_list[icon_idx].func_sta; // // //切入应用 // // if (func_sta > 0) { // // compo_form_t *frm = func_create_form(func_sta); // // func_switching(FUNC_SWITCH_ZOOM_FADE | FUNC_SWITCH_AUTO, listbox->sel_icon); // // compo_form_destroy(frm); // // func_cb.sta = func_sta; // // } } // //切换到设置菜单页面 // static void func_style_switch_to_clock(void) // { // u8 func_sta = FUNC_CLOCK; // f_style_t *f_set = (f_style_t *)func_cb.f_cb; // compo_listbox_t *listbox = f_set->listbox; // widget_icon_t *icon = compo_listbox_select_byidx(listbox, 0); // compo_form_t *frm = func_create_form(func_sta); // func_switching(FUNC_SWITCH_ZOOM_FADE_ENTER | FUNC_SWITCH_AUTO, icon); // compo_form_destroy(frm); // func_switch_to_assign_screen(func_sta, false); // } //主菜单功能事件处理 static void func_style_process(void) { f_style_t *f_set = (f_style_t *)func_cb.f_cb; compo_listbox_move(f_set->listbox); func_process(); } //进入设置主菜单页面 static void func_style_enter(void) { func_cb.f_cb = func_zalloc(sizeof(f_style_t)); func_cb.frm_main = func_style_form_create(); f_style_t *f_set = (f_style_t *)func_cb.f_cb; f_set->listbox = compo_getobj_byid(COMPO_ID_LISTBOX); compo_listbox_t *listbox = f_set->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, 1), compo_listbox_gety_byidx(listbox, SYTLE_LIST_CNT - 2)); func_cb.enter_tick = tick_get(); } //主菜单功能消息处理 static void func_style_message(size_msg_t msg) { f_style_t *f_set = (f_style_t *)func_cb.f_cb; compo_listbox_t *listbox = f_set->listbox; if (compo_listbox_message(listbox, msg)) { return; //处理列表框信息 } switch (msg) { case MSG_CTP_CLICK: func_style_icon_click(); //单击图标 break; case MSG_CTP_LONG: break; case MSG_CTP_SHORT_RIGHT: func_message(msg); break; default: func_message(msg); break; } } //退出菜单样式 void func_style_exit(void) { printf("func_set_sub_exit\r\n"); f_style_t *f_set = (f_style_t *)func_cb.f_cb; compo_listbox_t *listbox = f_set->listbox; func_free(listbox->mcb); //释放移动控制块 func_cb.last = FUNC_STYLE; SysVariable.duty_flag = true; } //主菜单功能 void func_style(void) { func_style_enter(); while (func_cb.sta == FUNC_STYLE) { func_style_process(); func_style_message(msg_dequeue()); } func_style_exit(); } #endif