Boolean CCEGLView::Create(int nWidthInPoints, int nHeightInPoints) { // record the window size in points m_tSizeInPoints.SetWidth(nWidthInPoints); m_tSizeInPoints.SetHeight(nHeightInPoints); // get the screen size TApplication* pApp = TApplication::GetCurrentApplication(); Int32 nWidth = pApp->GetScreenWidth(); Int32 nHeight = pApp->GetScreenHeight(); // calculate the factor and the rect of viewport m_fScreenScaleFactor = MIN((float)nWidth / nWidthInPoints, (float)nHeight / nHeightInPoints); int viewPortW = (int)(m_tSizeInPoints.Width() * m_fScreenScaleFactor); int viewPortH = (int)(m_tSizeInPoints.Height() * m_fScreenScaleFactor); m_rcViewPort.SetX((nWidth - viewPortW) / 2); m_rcViewPort.SetY((nHeight - viewPortH) / 2); m_rcViewPort.SetWidth(viewPortW); m_rcViewPort.SetHeight(viewPortH); Boolean bRet = TWindow::Create(&TRectangle(0, 0, nWidth, nHeight)); if (bRet) { s_pMainWindow = this; } return bRet; }
const char* getDiffResolutionPath(const char *pszPath) { CCString *pRet = new CCString(pszPath); pRet->autorelease(); do { TApplication* pApp = TApplication::GetCurrentApplication(); CC_BREAK_IF(!pApp); // get the Resolution int nScreenWidth = pApp->GetScreenWidth(); int nScreenHeight = pApp->GetScreenHeight(); // it's default resolution, do nothing CC_BREAK_IF(nScreenWidth == 320 && nScreenHeight == 480); if (nScreenWidth == 480 && nScreenHeight == 800) { // it's WVGA CC_BREAK_IF(pRet->m_sString.find("@WVGA") != -1); std::string filePathWithoutExtension = pszPath; std::string extension = ""; std::string filePath = pszPath; int nExPos = filePath.find_last_of("."); if (nExPos != -1) { filePathWithoutExtension = filePath.substr(0, nExPos); extension = filePath.substr(nExPos); } // new path, add "@WVGA" before the extension pRet->m_sString = filePathWithoutExtension + "@WVGA" + extension; // not find the resource of new path,use the original path if (! isResourceExist(pRet->m_sString.c_str())) { pRet->m_sString = filePath; } } else { // not support resolution CCAssert(0, "it's not supportted resolution."); } } while (0); return pRet->m_sString.c_str(); }
int drawText(TUChar* pszText, int nLen, TSize& tSize, UInt32 style) { int nRet = 0; do { CC_BREAK_IF(! pszText); if (tSize.Width() <= 0 || tSize.Height() <= 0) { CC_BREAK_IF(! getTextExtentPoint(pszText, nLen, tSize)); } CC_BREAK_IF(tSize.Width() <= 0 || tSize.Height() <= 0); CC_BREAK_IF(! prepareBitmap(tSize.Width(), tSize.Height())); Int32 nWidth = tSize.Width(); Int32 nHeight = tSize.Height(); // create memory window if (m_pMemWnd) { TRectangle rcMemWnd(0, 0, 0, 0); m_pMemWnd->GetClientBounds(&rcMemWnd); if (rcMemWnd.Width() < nWidth || rcMemWnd.Height() < nHeight) { m_pMemWnd->CloseWindow(); m_pMemWnd = NULL; } } do { // if memory window is already break CC_BREAK_IF(m_pMemWnd); TApplication* pApp = TApplication::GetCurrentApplication(); CC_BREAK_IF(! pApp || ! (m_pMemWnd = new TWindow(pApp))); Coord nCurrentWidth = pApp->GetScreenWidth(); Coord nCurrentHeight = pApp->GetScreenHeight(); Coord nMemWndW = (nWidth >= nCurrentWidth) ? nWidth : nCurrentWidth; Coord nMemWndH = (nHeight >= nCurrentHeight) ? nHeight : nCurrentHeight; CC_BREAK_IF(m_pMemWnd->CreateMemWindow(nMemWndW, nMemWndH,screenAlphaFormat)); delete m_pMemWnd; m_pMemWnd = NULL; } while (0); CC_BREAK_IF(! m_pMemWnd); // create DC TDC dc(m_pMemWnd); // draw text m_pMemWnd->GetMemWindowTBitmapPtr()->Fill32(RGBA(0, 0, 0, 0), 0, 0, nWidth, nHeight); TRectangle rect(0, 0, nWidth, nHeight); dc.DrawTextInRectangleEx(pszText, 0, RGBA(255,255,255,255), RGBA(0,0,0,255), m_hFont, &rect, style); dc.ReadBitmap(m_pBmp, 0, 0); nRet = true; } while (0); return nRet; }