extern K_ModuleItem_Typedef video_player_board; k_ModuleInit(); k_ModuleAdd(&audio_player_board); |
typedef struct { uint8_t id; const char *name; GUI_CONST_STORAGE GUI_BITMAP ** open_icon; GUI_CONST_STORAGE GUI_BITMAP ** close_icon; void (*startup) (WM_HWIN , uint16_t, uint16_t ); void (*DirectOpen) (char * ); } K_ModuleItem_Typedef; |
K_ModuleItem_Typedef audio_recorder_board = { 7, "audio recorder ", open_recorder, 0, Startup, NULL, } |
typedef struct { const K_ModuleItem_Typedef *module; uint8_t in_use; uint8_t win_state; } K_ModulePropertyTypedef; |
typedef struct { char ext[4]; const K_ModuleItem_Typedef *module; } K_ModuleOpenTypedef; |
void k_ModuleInit(void) { module_num = 0; openlink_num = 0; memset(module_prop, 0, sizeof(module_prop)); memset(open_link, 0, sizeof(module_prop)); } |
K_ModulePropertyTypedef module_prop [MAX_MODULES_NUM]; K_ModuleOpenTypedef open_link [MAX_MODULES_NUM] |
uint8_t k_ModuleAdd(K_ModuleItem_Typedef *module) { module_prop[module_num].in_use = 0; module_prop[module_num].win_state = 0; module_prop[module_num].module = module; module_num++; return 0; } |
void k_InitMenu(void) { uint8_t i = 0; WM_HWIN hItem; WM_SetCallback(WM_GetDesktopWindowEx(0), _cbBk); hIcon = ST_AnimatedIconView_CreateEx(0, 0, LCD_GetXSize() - 80, LCD_GetYSize() - 0, WM_GetDesktopWindowEx(0), WM_CF_SHOW | WM_CF_HASTRANS , 0, ID_ICONVIEW_MENU, 100, 120, 40, 5); ST_AnimatedIconView_SetDualFont(hIcon, &GUI_FontLubalGraph16, &GUI_FontLubalGraph16); ST_AnimatedIconView_SetSpace(hIcon, GUI_COORD_Y, 0); ST_AnimatedIconView_SetSpace(hIcon, GUI_COORD_X, 0); ST_AnimatedIconView_SetFrame(hIcon, GUI_COORD_Y, 0); ST_AnimatedIconView_SetFrame(hIcon, GUI_COORD_X, 0); ST_AnimatedIconView_SetTextColor(hIcon, ICONVIEW_CI_UNSEL, GUI_STCOLOR_LIGHTBLUE); ST_AnimatedIconView_SetBkColor(hIcon, ICONVIEW_CI_UNSEL, GUI_WHITE); ST_AnimatedIconView_SetBkColor(hIcon, ICONVIEW_CI_SEL, GUI_WHITE); ST_AnimatedIconView_SetSel(hIcon, -1); ST_AnimatedIconView_SetDualTextColor(hIcon, ICONVIEW_CI_SEL, GUI_STCOLOR_LIGHTBLUE, GUI_STCOLOR_DARKBLUE ); for (i = 0; i < k_ModuleGetNumber(); i++) { ST_AnimatedIconView_AddIcon(hIcon, module_prop.module->open_icon, module_prop.module->close_icon, (char *)module_prop.module->name); } hItem = TEXT_CreateEx(407, 152, 260, 20, WM_GetDesktopWindowEx(0), WM_CF_SHOW, TEXT_CF_LEFT, ID_FEATURES_FPU, "FPU : ON"); TEXT_SetFont(hItem, GUI_FONT_8_1); TEXT_SetTextColor(hItem, GUI_WHITE); hItem = TEXT_CreateEx(407, 167, 260, 20, WM_GetDesktopWindowEx(0), WM_CF_SHOW, TEXT_CF_LEFT, ID_FEATURES_IC, "I-Cache : ON"); TEXT_SetFont(hItem, GUI_FONT_8_1); TEXT_SetTextColor(hItem, GUI_WHITE); hItem = TEXT_CreateEx(407, 182, 260, 20, WM_GetDesktopWindowEx(0), WM_CF_SHOW, TEXT_CF_LEFT, ID_FEATURES_DC, "D-Cache : ON"); TEXT_SetFont(hItem, GUI_FONT_8_1); TEXT_SetTextColor(hItem, GUI_WHITE); hCPULoad = TEXT_CreateEx(407, 198, 260, 20, WM_GetDesktopWindowEx(0), WM_CF_SHOW, TEXT_CF_LEFT, ID_FEATURES_CPU, "MCU Load : --%"); TEXT_SetFont(hCPULoad, GUI_FONT_8_1); TEXT_SetTextColor(hCPULoad, GUI_WHITE); hItem = TEXT_CreateEx(407, 212, 260, 20, WM_GetDesktopWindowEx(0), WM_CF_SHOW, TEXT_CF_LEFT, ID_FEATURES_FREQ, "Clk : 200 MHz"); TEXT_SetFont(hItem, GUI_FONT_8_1); TEXT_SetTextColor(hItem, GUI_WHITE); hRefreshTimer = WM_CreateTimer(WM_GetDesktopWindowEx(0), 0, 500, 0); } |
static void _cbBk(WM_MESSAGE * pMsg) { uint32_t NCode, Id; static uint8_t sel; WM_HWIN hItem; char tmp[16]; switch (pMsg->MsgId) { case WM_PAINT: GUI_SetBkColor(GUI_WHITE); GUI_Clear(); /*H/W Information */ GUI_SetColor(0x007C18CC); GUI_AA_FillRoundedRect(400, 31, 780, 238, 15); GUI_DrawBitmap(&bmF7Logo, 400, 47); break; case WM_TIMER: hItem = WM_GetDialogItem(pMsg->hWin, ID_FEATURES_CPU); sprintf((char *)tmp , "MCU Load : %d%%", osGetCPUUsage()); TEXT_SetText(hItem, tmp); WM_InvalidateWindow(hItem); WM_Update(hItem); WM_RestartTimer(pMsg->Data.v, 1000); break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; //这里开始处理图标响应 switch (NCode) { case WM_NOTIFICATION_RELEASED: if (Id == ID_ICONVIEW_MENU)//点击的是菜单 { sel = ST_AnimatedIconView_GetSel(pMsg->hWinSrc);//得到点击图标的idex if(sel < k_ModuleGetNumber()) { ST_AnimatedIconView_SetSel(pMsg->hWinSrc, -1); if(module_prop[sel].in_use == 0) { module_prop[sel].module->startup(pMsg->hWin, 0, 0);//进入此功能app module_prop[sel].in_use = 1;//注明正在运行 } else if(module_prop[sel].win_state == 1)//如果是后台运行 { module_prop[sel].module->startup(pMsg->hWin, 0, 0); } } else { WM_InvalidateWindow (pMsg->hWinSrc); } } break; case WM_NOTIFICATION_CHILD_DELETED://退出功能 module_prop[sel].in_use = 0; module_prop[sel].win_state = 0; break; default: break; } break; default: WM_DefaultProc(pMsg); } } |
引用: arthasarthas 发表于 2015-12-22 10:42
DEMO的代码真不是一时半会儿能学会的。
看了一天只是看了个皮毛,结构弄清楚了点。
确实是高手写的啊。