/** * @brief Callback function of the image frame * @param pMsg: pointer to data structure of type WM_MESSAGE * @retval None */ static void _cbImageWindow(WM_MESSAGE * pMsg) { WM_HWIN hItem; GUI_RECT r; int Id; const GUI_PID_STATE * pState; switch (pMsg->MsgId) { case WM_TOUCH: pState = (const GUI_PID_STATE *)pMsg->Data.p; if(pImageList->ptr > 0) { if (pState) { if (pState->Pressed == 1) { IMAGE_Enlarge ^= 1; if (IMAGE_Enlarge) { WM_AttachWindowAt(pMsg->hWin, WM_HBKWIN, 0, 0); WM_SetSize(pMsg->hWin, LCD_GetXSize(), LCD_GetYSize()); } else { WM_AttachWindowAt(pMsg->hWin, IMAGE_hWin, 15, 15); WM_SetSize(pMsg->hWin, 420, 370); } WM_InvalidateWindow(pMsg->hWin); } } } break; case WM_PAINT: WM_GetInsideRect(&r); GUI_ClearRectEx(&r); if (pImageList->ptr > 0) { if(_DrawImage(&Image_File, IMAGE_Enlarge, IMAGE_Type) > 0) { f_close(&Image_File); GUI_ClearRectEx(&r); GUI_DispStringAt("Error : Image cannot be displayed", 35, 100); if(hTimerTime != 0) { slideshow_state = OFF; hItem = WM_GetDialogItem(IMAGE_hWin, ID_SLIDE_BUTTON); WM_InvalidateWindow(hItem); WM_Update(hItem); WM_DeleteTimer(hTimerTime); hTimerTime = 0; } } } break; case WM_TIMER: Id = WM_GetTimerId(pMsg->Data.v); if(Id == ID_SLIDER_TIMER) { if(pImageList->ptr > 1) { if (file_pos < (pImageList->ptr - 1)) { file_pos++; } else if (file_pos == (pImageList->ptr - 1)) { file_pos=0; } if((strstr((char *)pImageList->file[file_pos].name, ".bmp")) || (strstr((char *)pImageList->file[file_pos].name, ".BMP"))) { IMAGE_Type = IMAGE_TYPE_BMP; } else if((strstr((char *)pImageList->file[file_pos].name, ".jpg")) || (strstr((char *)pImageList->file[file_pos].name, ".JPG"))) { IMAGE_Type = IMAGE_TYPE_JPG; } f_close(&Image_File); f_open(&Image_File, (char const *)pImageList->file[file_pos].name, FA_OPEN_EXISTING | FA_READ); WM_InvalidateWindow(imFrame); hItem = WM_GetDialogItem(IMAGE_hWin, ID_IMAGE_LIST); LISTBOX_SetSel(hItem, file_pos); } WM_RestartTimer(pMsg->Data.v, (ImSettings.b.ss_timer * 1000)); } else if (Id == ID_PLAYLIST_TIMER) { playlist_select = 0; } break; case WM_DELETE: if(hTimerTime != 0) { WM_DeleteTimer(hTimerTime); hTimerTime = 0; } break; default: WM_DefaultProc(pMsg); } }
/********************************************************************* * * LISTBOX_OwnerDraw */ int LISTBOX_OwnerDraw(const WIDGET_ITEM_DRAW_INFO* pDrawItemInfo) { switch (pDrawItemInfo->Cmd) { case WIDGET_ITEM_GET_XSIZE: { LISTBOX_Obj* pObj; const GUI_FONT GUI_UNI_PTR* pOldFont; const char* s; int DistX; pObj = LISTBOX_H2P(pDrawItemInfo->hWin); pOldFont = GUI_SetFont(pObj->Props.pFont); s = LISTBOX__GetpString(pObj, pDrawItemInfo->ItemIndex); DistX = GUI_GetStringDistX(s); GUI_SetFont(pOldFont); return DistX; } case WIDGET_ITEM_GET_YSIZE: { LISTBOX_Obj* pObj; pObj = LISTBOX_H2P(pDrawItemInfo->hWin); return GUI_GetYDistOfFont(pObj->Props.pFont) + pObj->ItemSpacing; } case WIDGET_ITEM_DRAW: { LISTBOX_Obj* pObj; LISTBOX_ITEM* pItem; WM_HMEM hItem; GUI_RECT r; int FontDistY; int ItemIndex = pDrawItemInfo->ItemIndex; const char* s; int ColorIndex; char IsDisabled; char IsSelected; pObj = LISTBOX_H2P(pDrawItemInfo->hWin); hItem = GUI_ARRAY_GethItem(&pObj->ItemArray, ItemIndex); pItem = (LISTBOX_ITEM *)GUI_ALLOC_h2p(hItem); WM_GetInsideRect(&r); FontDistY = GUI_GetFontDistY(); /* Calculate color index */ IsDisabled = (pItem->Status & LISTBOX_ITEM_DISABLED) ? 1 : 0; IsSelected = (pItem->Status & LISTBOX_ITEM_SELECTED) ? 1 : 0; if (pObj->Flags & LISTBOX_SF_MULTISEL) { if (IsDisabled) { ColorIndex = 3; } else { ColorIndex = (IsSelected) ? 2 : 0; } } else { if (IsDisabled) { ColorIndex = 3; } else { if (ItemIndex == pObj->Sel) { ColorIndex = (pObj->Widget.State & WIDGET_STATE_FOCUS) ? 2 : 1; } else { ColorIndex = 0; } } } /* Display item */ LCD_SetBkColor(pObj->Props.aBackColor[ColorIndex]); LCD_SetColor (pObj->Props.aTextColor[ColorIndex]); s = LISTBOX__GetpString(pObj, ItemIndex); GUI_SetTextMode(GUI_TM_TRANS); GUI_Clear(); GUI_DispStringAt(s, pDrawItemInfo->x0 + 1, pDrawItemInfo->y0); /* Display focus rectangle */ if ((pObj->Flags & LISTBOX_SF_MULTISEL) && (ItemIndex == pObj->Sel)) { GUI_RECT rFocus; rFocus.x0 = pDrawItemInfo->x0; rFocus.y0 = pDrawItemInfo->y0; rFocus.x1 = r.x1; rFocus.y1 = pDrawItemInfo->y0 + FontDistY - 1; LCD_SetColor(GUI_WHITE - pObj->Props.aBackColor[ColorIndex]); GUI_DrawFocusRect(&rFocus, 0); } return 0; } } return 0; }
/** * @brief Callback function of the MJPEG frame * @param pMsg: pointer to a data structure of type WM_MESSAGE * @retval None */ static void _cbVideoWindow(WM_MESSAGE * pMsg) { char temp[20]; static WM_HTIMER hTimerTime; WM_HWIN hItem; const GUI_PID_STATE * pState; GUI_RECT r; WM_GetInsideRect(&r); switch (pMsg->MsgId) { case WM_TOUCH: if(VideoPlayer_State == VIDEO_PLAY) { pState = (const GUI_PID_STATE *)pMsg->Data.p; if (pState) { if (pState->Pressed == 1) { VIDEO_Enlarge ^= 1; if(VIDEO_Enlarge) { GUI_SetOrientation(GUI_SWAP_XY | GUI_MIRROR_Y); TS_Orientation = 1; WM_AttachWindowAt(pMsg->hWin, WM_GetDesktopWindowEx(1), 0, 0); WM_SetSize(pMsg->hWin, LCD_GetXSize(), LCD_GetYSize()); } else { WM_AttachWindow(pMsg->hWin, bkparent); GUI_SetOrientation(0); TS_Orientation = 0; WM_InvalidateWindow(bkparent); WM_AttachWindowAt(pMsg->hWin, VIDEO_hWin, 5, 16); WM_SetSize(pMsg->hWin,230, 170); do_clear = 1; } } } } break; case WM_CREATE: /* Create timer */ hTimerTime = WM_CreateTimer(pMsg->hWin, 0, 50, 0); break; case WM_TIMER: WM_InvalidateWindow(pMsg->hWin); WM_RestartTimer(pMsg->Data.v, 0); break; case WM_DELETE: WM_DeleteTimer(hTimerTime); break; case WM_PAINT: if(do_clear) { GUI_ClearRectEx(&r); do_clear = 0; } if(VideoPlayer_State == VIDEO_PLAY) { if(_PlayMJPEG(&Video_File) < 0) { VideoPlayer_State = VIDEO_PLAY; ImageOffset = 0; time_start = GUI_GetTime(); f_close(&Video_File); goto_next_file(); hItem = WM_GetDialogItem(WM_GetParent(pMsg->hWin), ID_VIDEO_FILE); TEXT_SetText(hItem, (char *)FILEMGR_FileList.file[FILEMGR_FileList.idx].line); } hItem = WM_GetDialogItem(WM_GetParent(pMsg->hWin), ID_VIDEO_PROGRESS); if (progress_bar == 0) { SLIDER_SetValue(hItem, (ImageOffset * 100 )/ Video_File.fsize); } hItem = WM_GetDialogItem(WM_GetParent(pMsg->hWin), ID_VIDEO_DURATION); duration = (GUI_GetTime() - time_start )/1000; if(duration < 0) duration = 0; sprintf(temp,"%02d:%02d", duration/60, duration%60); TEXT_SetText(hItem, temp); } else if(VideoPlayer_State == VIDEO_IDLE) { GUI_ClearRectEx(&r); } break; default: WM_DefaultProc(pMsg); } }
WM_HWIN WM_CreateWindowAsChild( int x0, int y0, int width, int height ,WM_HWIN hParent, U16 Style, WM_CALLBACK* cb ,int NumExtraBytes) { WM_Obj* pWin; WM_HWIN hWin; WM_LOCK(); Style |= WM__CreateFlags; /* Get Parent info */ if (!hParent) { if (WM__NumWindows) { hParent = WM_HBKWIN; } } if (hParent) { GUI_RECT Rect; // Rect = WM_H2P(hParent)->Rect; WM_GetInsideRect(hParent, &Rect); WM__Client2Screen(WM_H2P(hParent), &Rect); x0 += Rect.x0; y0 += Rect.y0; if (width==0) width = Rect.x1-Rect.x0+1; if (height==0) height = Rect.y1-Rect.y0+1; } if ((hWin = (WM_HWIN) WM_ALLOC(NumExtraBytes+sizeof(WM_Obj))) == 0) { GUI_DEBUG_ERROROUT("WM_CreateWindow: No memory to create window"); } else { WM__NumWindows++; pWin = WM_H2P(hWin); memset (pWin, 0, sizeof(WM_Obj)); /* erase this data structure The explicit zero-init is no longer needed since the entire data structure is already zeroed. The advantage is that it reduces program size. */ pWin->Rect.x0 = x0; pWin->Rect.y0 = y0; pWin->Rect.x1 = x0+width-1; pWin->Rect.y1 = y0+height-1; pWin->Status = WM_SF_INUSE; /* Mark window as in use */ pWin->cb = cb; /* Add to linked lists */ pWin->hParent = hParent; _AddChild(hParent, hWin, Style & WM_CF_STAYONTOP); _AddToLinList(hWin); /* Put Window on top (or bottom) of windows stack */ if (Style & WM_CF_ACTIVATE /*| (cb==NULL)*/) { WM_SelectWindow(hWin); /* This is not needed if callbacks are being used, but it does not cost a lot and makes life easier ... */ } /* Mark client area as invalid */ WM__SendMsgNoData(hWin, WM_CREATE); /* Handle the Style flags, one at a time */ if (Style & WM_CF_SHOW) { WM_ShowWindow(hWin); } /* Hide if parent is not visible */ if (hParent) { WM_Obj* pWinParent = WM_H2P(hParent); if (!(pWinParent->Status & WM_SF_ISVIS)) { WM_HideWindow(hWin); } } /* Copy the flags which can simply be accepted */ pWin->Status |= (Style & (WM_SF_MEMDEV|WM_SF_STAYONTOP|WM_SF_HASTRANS)); } WM_UNLOCK(); return hWin; }