/******************************************************************* * * _ShowBMP * * Shows the contents of a bitmap file */ static void _ShowBMP(const char * sFilename) { int XSize, YSize, XPos, YPos; DWORD NumBytesRead; HANDLE hFile = CreateFile(sFilename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); DWORD FileSize = GetFileSize(hFile, NULL); char * pFile = malloc(FileSize); ReadFile(hFile, pFile, FileSize, &NumBytesRead, NULL); CloseHandle(hFile); GUI_ClearRect(0, 60, 319, 239); XSize = GUI_BMP_GetXSize(pFile); YSize = GUI_BMP_GetYSize(pFile); XPos = (XSize > 320) ? 0 : 160 - (XSize / 2); YPos = (YSize > 180) ? 60 : 150 - (YSize / 2); if (!GUI_BMP_Draw(pFile, XPos, YPos)) { GUI_Delay(2000); } free(pFile); }
/* 显示BMP图片 */ static int _DrawBMPFile(char *path) { FRESULT rc; uint32_t size; FIL fil; uint8_t *pFile = (uint8_t*)SRAM_START_ADDRESS; UINT br; /* 读取文件 */ rc = f_open(&fil, path, FA_READ); ERROR_TRACE(rc); if(rc) return 1; size = f_size(&fil); printf("file size:%d\r\n", size); if(size > SRAM_SIZE) { printf("file size to large\r\n"); rc = f_close(&fil); return 2; } rc = f_read(&fil, pFile, size, &br); if(rc || br != size) { printf("file data read failed\r\n"); rc = f_close(&fil); return 3; } printf("Xsize:%d Ysize:%d\r\n", GUI_BMP_GetXSize(pFile), GUI_BMP_GetYSize(pFile)); GUI_Clear(); if(GUI_BMP_Draw(pFile, 0, 0)) { GUI_DispString("BMP file display failed!"); } rc = f_close(&fil); ERROR_TRACE(rc); return 0; }
static void _cbDialog(WM_MESSAGE * pMsg) { int i; WM_HWIN hItem; int NCode; int Id; gui_msg_t msg; msg.exec = RT_NULL; switch (pMsg->MsgId) { case WM_INIT_DIALOG: hItem = pMsg->hWin; WM_EnableMemdev(hItem); //WM_MoveTo(hItem, 0, -30); //WM_MOTION_SetMoveable(hItem, WM_CF_MOTION_Y, 1); WINDOW_SetBkColor(hItem, GUI_WHITE); int fd; /* load APP */ for(i=0;i<GUI_COUNTOF(UIApp);i++) { hItem = BUTTON_CreateAsChild(10, 10, 50, 50, pMsg->hWin, UIApp[i].GUID, WM_CF_SHOW); BUTTON_SetText(hItem, UIApp[i].text); WM_EnableMemdev(hItem); struct stat s; stat(UIApp[i].logoPath, &s); UIApp[i].plogo = rt_malloc(s.st_size); if(UIApp[i].plogo) { fd = open(UIApp[i].logoPath, O_RDONLY , 0); if(fd >=0) { rt_kprintf("%s", UIApp[i].logoPath); read(fd, UIApp[i].plogo, s.st_size); //WM_MoveTo(hItem, 0+(i%2)*120, (i/2)*120 + 0); WM_SetSize(hItem, GUI_BMP_GetXSize(UIApp[i].plogo), GUI_BMP_GetYSize(UIApp[i].plogo)); //xPos+= xSize; //yPos+= ySize; BUTTON_SetBMPEx(hItem, BUTTON_BI_UNPRESSED, UIApp[i].plogo ,0, 0); BUTTON_SetBMPEx(hItem, BUTTON_BI_PRESSED, UIApp[i].plogo ,1, 1); BUTTON_SetTextOffset(hItem, 0, 50); close(fd); } } else { rt_kprintf("no mem!\r\n"); } } /* algin Apps */ int xPos, yPos, xSize, ySize; xPos = 0; xSize = 0; yPos = 0; ySize = 0; for(i=0;i<GUI_COUNTOF(UIApp);i++) { hItem = WM_GetDialogItem(pMsg->hWin, UIApp[i].GUID); xSize = GUI_BMP_GetXSize(UIApp[i].plogo); ySize = GUI_BMP_GetYSize(UIApp[i].plogo); if(xSize == 0 || xSize > 9999) { xSize = 60; } if(ySize == 0 || ySize > 9999) { ySize = 60; } if(abs(LCD_GetXSize() - xPos) >= xSize) { WM_MoveTo(hItem, xPos, yPos); xPos+=xSize; } else { xPos = 0; yPos+=ySize; WM_MoveTo(hItem, xPos, yPos); xPos+=xSize; } } // char *p; // p = rt_malloc(38399); // fd = open("/SD/DESKTOP.JPG",O_RDONLY , 0); // read(fd, p, 38399); // hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE_0); // WM_EnableMemdev(hItem); // IMAGE_SetJPEG(hItem, p, 38399); break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; if(NCode == WM_NOTIFICATION_RELEASED) { for(i=0;i<GUI_COUNTOF(UIApp);i++) { if(Id == UIApp[i].GUID) { msg.exec = UIApp[i].exec; break; } } if(msg.exec != RT_NULL) { rt_mq_send(guimq, &msg, sizeof(msg)); } } break; default: WM_DefaultProc(pMsg); break; } }