/* * 函数名称: PicBrowser::Init() * 功能介绍: 该函数为PicBrowser类的初始化函数,载入必要的资源。 * 输入参数: N/A * 输出参数: N/A * 返回值: 返回是否初始化成功 * 可能出现的意外: N/A */ boolean PicBrowser::Init() { AEEImageInfo mi; int nByteLoad=0; m_pwszTitle=(AECHAR *)MALLOC(MAX_STRING_LEN+1); //申请字符串资源空间 if(m_pwszTitle!=NULL) { nByteLoad=ISHELL_LoadResString(m_pIShell,FK_RES_FILE,IDS_TITLE,m_pwszTitle,MAX_STRING_LEN); //载入字符串 } m_pImage=ISHELL_LoadResImage(m_pIShell,FK_RES_FILE,IDB_PIC); //载入图片 if(m_pImage==NULL || nByteLoad==0) { m_bInitSuccess=FALSE; //资源装载失败 } else { m_nRed=255; //颜色值的R值初始化为255 //取图片信息 IIMAGE_GetInfo(m_pImage,&mi); m_nWidth=(int)mi.cx; m_nHeight=(int)mi.cy; //设置剪切矩形和图片初始位置 SETAEERECT(&m_rctImage,0,pApp->nNoarmalFontH,pApp->lcdW,pApp->lcdH-pApp->nNoarmalFontH); m_nImageDrawX=m_rctImage.x+(m_rctImage.dx-m_nWidth)/2; m_nImageDrawY=m_rctImage.y+(m_rctImage.dy-m_nHeight)/2; m_bInitSuccess=TRUE;//装载成功 } return m_bInitSuccess; }
/*=========================================================================== This function draws the image and centers it within the specified rectangle if bCenter is TRUE. - note��return if image bot fit in the rect ===========================================================================*/ void TS_DrawImage(IImage * pImage, AEERect * pRect, boolean bCenter) { AEEImageInfo ii; int x; int y; IIMAGE_GetInfo(pImage, &ii); // Do not display if image does not fit in the allocated rectangle. if (ii.cx > pRect->dx || ii.cy > pRect->dy) return; if (bCenter) { x = pRect->x + (pRect->dx / 2) - (ii.cxFrame / 2); y = pRect->y + (pRect->dy / 2) - (ii.cy / 2); } else { x = pRect->x; y = pRect->y; } IIMAGE_Start(pImage, x, y); }
/*=========================================================================== This function draws the splash screen and brings up the main window after the splash timer runs out. ===========================================================================*/ void TS_DrawSplash(CTopSoupApp * pme,AECHAR* prompt,int msTimeout,PFNNOTIFY on_splashOver,void* pUser) { if( NULL == prompt ) return; if (pme->m_pWin) CTopSoupApp_DisableWin(pme); { IImage * pi = ISHELL_LoadResImage(pme->a.m_pIShell, NAVIGATE_RES_FILE, IDP_OBJECT_PROMPT); IStatic * pInfoStatic = NULL; if (pi) { AEERect rect; AEEImageInfo info; int16 x,y; IIMAGE_GetInfo(pi,&info); x = ( pme->m_rectWin.dx - info.cx ) / 2; y = pme->m_rectWin.y + ( pme->m_rectWin.dy - info.cy ) / 2; SETAEERECT(&rect,x,y,info.cx,info.cy); TS_DrawImage(pi, &rect, TRUE); ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_STATIC, (void **)&pInfoStatic); ISTATIC_SetRect(pInfoStatic, &rect); ISTATIC_SetProperties(pInfoStatic, ST_MIDDLETEXT | ST_CENTERTEXT | ST_NOSCROLL); TS_FitStaticText(pme->a.m_pIDisplay, pInfoStatic, AEE_FONT_LARGE, prompt); TS_RELEASEIF(pi); TS_RELEASEIF(pInfoStatic); } // start the timer. if ( on_splashOver ) ISHELL_SetTimer(pme->a.m_pIShell, msTimeout, (PFNNOTIFY)on_splashOver, pUser); else ISHELL_SetTimer(pme->a.m_pIShell, msTimeout, (PFNNOTIFY)CTopSoupApp_onSplashDrawOver, pme); } }
/*=========================================================================== FUNCTION: CGMENUCTL_Redraw DESCRIPTION: Redraws the control on the device screen. If the control currently has focus, the control is drawn with a border. PARAMETERS: pCtl [in] - A pointer to a CGMeuCtl instance DEPENDENCIES: None RETURN VALUE: None SIDE EFFECTS: Updates the device screen. ===========================================================================*/ extern void CGMENUCTL_Redraw(CGMeuCtl* pMe) { AEEApplet* pApp = (AEEApplet*)GETAPPINSTANCE(); AEERect rRect; if (pMe) { int i, j, height, h, a, b; AEEImageInfo infSe, infIc; AEERect rec; int xx, yy, dxx, dyy; RGBVAL oldColor; GMenuItem * pData = NULL; TQueueList * p = pMe->m_pDataList; ZEROAT(&infSe); IDISPLAY_EraseRect(pApp->m_pIDisplay, &pMe->m_Rect); h = IDISPLAY_GetFontMetrics(pApp->m_pIDisplay, AEE_FONT_NORMAL, &a, &b); //绘制背景图 if (pMe->m_pImageBk) { IIMAGE_SetDrawSize(pMe->m_pImageBk, pMe->m_Rect.dx, pMe->m_Rect.dy); IIMAGE_Draw(pMe->m_pImageBk, pMe->m_Rect.x, pMe->m_Rect.y); } //确定菜单高度 if (pMe->m_pImageSe) { IIMAGE_GetInfo(pMe->m_pImageSe, &infSe); IIMAGE_SetDrawSize(pMe->m_pImageSe, pMe->m_Rect.dx, infSe.cy); } else { infSe.cx = pMe->m_Rect.dx; infSe.cy = h; } //绘制菜单项 i = 0; j = 0; height = pMe->m_Rect.y + 5; while (p) { AECHAR iTemText[256]; if (i < pMe->m_startIndex) { p = p->pNext; i++; continue; } if (j >= pMe->m_pageSize) { break; } pData = (GMenuItem*)p->pData; //加载菜单ICON if (pData->pImage == NULL && pData->pszResImage != NULL && pData->wImage != 0) { pData->pImage = ISHELL_LoadResImage(pApp->m_pIShell, pData->pszResImage, pData->wImage); } //加载菜单Text if (pData->pszResText != NULL && pData->wText != 0) { MEMSET(iTemText, 0, sizeof(AECHAR)*256); ISHELL_LoadResString(pApp->m_pIShell, pData->pszResText, pData->wText, iTemText, sizeof(AECHAR)* 256); pData->pText = iTemText; } if (i == pMe->m_Index) { if (pMe->m_pImageSe) IIMAGE_Draw(pMe->m_pImageSe, pMe->m_Rect.x, height + 2); ZEROAT(&infIc); if (pData->pImage) { IIMAGE_GetInfo(pData->pImage, &infIc); IIMAGE_Draw(pData->pImage, pMe->m_Rect.x, height + (infSe.cy - infIc.cy) / 2); } xx = pMe->m_Rect.x + infIc.cx + 2; yy = height + (infSe.cy - h) / 2 + 2; dxx = pMe->m_Rect.x + pMe->m_Rect.dx - xx; dyy = h; SETAEERECT(&rec, xx, yy, dxx, dyy); oldColor = IDISPLAY_SetColor(pApp->m_pIDisplay, CLR_USER_TEXT, pMe->m_Colors.cSelText); if (pMe->m_Properties & 0x02) IDISPLAY_DrawText(pApp->m_pIDisplay, AEE_FONT_NORMAL, pData->pText + pMe->m_textPos, -1, xx + 1, yy, &rec, IDF_TEXT_TRANSPARENT); IDISPLAY_DrawText(pApp->m_pIDisplay, AEE_FONT_NORMAL, pData->pText + pMe->m_textPos, -1, xx, yy, &rec, IDF_TEXT_TRANSPARENT); if (pMe->m_isActive) { if (IDISPLAY_MeasureText(pApp->m_pIDisplay, AEE_FONT_NORMAL, pData->pText) > dxx) { if (IDISPLAY_MeasureText(pApp->m_pIDisplay, AEE_FONT_NORMAL, pData->pText + pMe->m_textPos) > dxx) { pMe->m_textPos++; } else pMe->m_textPos = 0; //单行太长的话,动态显示 ISHELL_SetTimer(pApp->m_pIShell, 300, (PFNNOTIFY)CGMENUCTL_Redraw, (void*)pMe); } } height += infSe.cy; IDISPLAY_SetColor(pApp->m_pIDisplay, CLR_USER_TEXT, oldColor); } else { ZEROAT(&infIc); if (pData->pImage) { IIMAGE_GetInfo(pData->pImage, &infIc); IIMAGE_Draw(pData->pImage, pMe->m_Rect.x, height + (infSe.cy - infIc.cy) / 2); } xx = pMe->m_Rect.x + infIc.cx + 2; yy = height + (infSe.cy - h) / 2 + 2; dxx = pMe->m_Rect.x + pMe->m_Rect.dx - xx; dyy = h; SETAEERECT(&rec, xx, yy, dxx, dyy); oldColor = IDISPLAY_SetColor(pApp->m_pIDisplay, CLR_USER_TEXT, pMe->m_Colors.cText); if (pMe->m_Properties & 0x01) IDISPLAY_DrawText(pApp->m_pIDisplay, AEE_FONT_NORMAL, pData->pText, -1, xx + 1, yy, &rec, IDF_TEXT_TRANSPARENT); IDISPLAY_DrawText(pApp->m_pIDisplay, AEE_FONT_NORMAL, pData->pText, -1, xx, yy, &rec, IDF_TEXT_TRANSPARENT); height += infSe.cy; IDISPLAY_SetColor(pApp->m_pIDisplay, CLR_USER_TEXT, oldColor); } p = p->pNext; i++; j++; } IDISPLAY_Update(pApp->m_pIDisplay); return ; } }
/** || Function || -------- || static void StatusBox_Init(StatusBox *me) || || Description || ----------- || load the IImage, calculate rectangles || || Parameters || ---------- || StatusBox *me: the status box || || Returns || ------- || nothing || || Remarks || ------- || */ static void StatusBox_Init(StatusBox *me) { AEEImageInfo ii; ZEROAT(&ii); /* re-init this stuff every time */ if ((IImage *)0 != me->piImage) { IIMAGE_GetInfo(me->piImage, &ii); if ((ii.cx == 0) || (ii.cy == 0)) { /* IIMAGE barfed */ RELEASEIF(me->piImage); ZEROAT(&ii); } else if (ii.bAnimated) { me->bSelfAnimated = TRUE; me->nFrame = -1; IIMAGE_SetParm(me->piImage, IPARM_REDRAW, (int)me->pfnInvalidate, (int)me->pInvalidateData); } else { uint16 uFrameWidth; if (me->uFrameWidth != 0) { uFrameWidth = me->uFrameWidth; } else { /* use the height, for square frames */ uFrameWidth = ii.cy; } me->nFrames = MAX(1,ii.cx/uFrameWidth); if ((me->nFrames * uFrameWidth) != ii.cx) { /* not exact frames, don't animate */ me->nFrames = 1; } else { ii.cx = uFrameWidth; /* fake out rect calc stuff below */ } if (0 == me->uFrameDuration) { me->uFrameDuration = 150; } IIMAGE_SetFrameCount(me->piImage, me->nFrames); me->nFrame = 0; /* Don't do this, run animation myself for invalidation code to work animate over 1 second... IIMAGE_SetAnimationRate(me->piImage, 1000/nFrames); */ } } /* initialize status rectangles */ /* if we found the image above and it's non-empty...*/ if (0 != ii.cy) { me->rcImage.y = me->rcCenter.y + ((me->rcCenter.dy - ii.cy) / 2) - 1; me->rcImage.x = me->rcCenter.x + ((me->rcCenter.dx - ii.cx) / 2) - 1; /* insist on square */ me->rcImage.dy = ii.cy + 2; me->rcImage.dx = ii.cx + 2; /* image too big for screen, fuggedaboudit */ if ((me->rcImage.dy > me->rcCenter.dy) || (me->rcImage.dx > me->rcCenter.dx)) { RELEASEIF(me->piImage); ZEROAT(&me->rcImage); } } else {/* no image, just text box... */ ZEROAT(&me->rcImage); } { int nAscent; int nDescent; IDISPLAY_GetFontMetrics(me->piDisplay,AEE_FONT_NORMAL, &nAscent,&nDescent); me->rcText.dy = nAscent + nDescent + 4; } if ((0 == me->rcImage.dy) || (me->rcImage.dy + me->rcText.dy - 1 > me->rcCenter.dy)) { me->rcText.y = me->rcCenter.y + ((me->rcCenter.dy - me->rcText.dy) / 2); } else { me->rcImage.y -= me->rcText.dy/2; me->rcText.y = me->rcImage.y + me->rcImage.dy - 1; } }