// load the image header field from stream bool tgaLoadHeader(unsigned char* Buffer, unsigned long bufSize, tImageTGA *psInfo) { bool bRet = false; do { size_t step = sizeof(unsigned char) * 2; CCX_BREAK_IF((step + sizeof(unsigned char)) > bufSize); memcpy(&psInfo->type, Buffer + step, sizeof(unsigned char)); step += sizeof(unsigned char) * 2; step += sizeof(signed short) * 4; CCX_BREAK_IF((step + sizeof(signed short) * 2 + sizeof(unsigned char)) > bufSize); memcpy(&psInfo->width, Buffer + step, sizeof(signed short)); memcpy(&psInfo->height, Buffer + step + sizeof(signed short), sizeof(signed short)); memcpy(&psInfo->pixelDepth, Buffer + step + sizeof(signed short) * 2, sizeof(unsigned char)); step += sizeof(unsigned char); step += sizeof(signed short) * 2; CCX_BREAK_IF((step + sizeof(unsigned char)) > bufSize); unsigned char cGarbage; memcpy(&cGarbage, Buffer + step, sizeof(unsigned char)); psInfo->flipped = 0; if ( cGarbage & 0x20 ) { psInfo->flipped = 1; } bRet = true; } while (0); return bRet; }
Boolean CCXEGLView::OnPenMove(EventType* pEvent) { do { CCX_BREAK_IF(!m_pDelegate); Int32 nCount = EvtGetPenMultiPointCount(pEvent); CCX_BREAK_IF(nCount <= 0 || nCount > MAX_TOUCHES); NSSet set; Int32 nPosX, nPosY; for (Int32 i = 0; i < nCount; ++i) { CCTouch* pTouch = s_pTouches[i]; CCX_BREAK_IF(!pTouch); EvtGetPenMultiPointXY(pEvent, i, &nPosX, &nPosY); pTouch->SetTouchInfo(0, (float) nPosX, (float) nPosY); set.addObject(pTouch); } m_pDelegate->touchesMoved(&set, NULL); } while (0); return FALSE; }
int CCXEGLView::setDeviceOrientation(int eOritation) { do { bool bVertical = (CCDeviceOrientationPortrait == eOritation || kCCDeviceOrientationPortraitUpsideDown == eOritation) ? true : false; CCX_BREAK_IF(m_bOrientationReverted && bVertical != m_bOrientationInitVertical); CCX_BREAK_IF(! m_bOrientationReverted && bVertical == m_bOrientationInitVertical); RECT rc; GetClientRect(m_hWnd, &rc); // swap width and height LONG nTmp = rc.right; rc.right = rc.bottom; rc.bottom = nTmp; // calc new window size AdjustWindowRectEx(&rc, GetWindowLong(m_hWnd, GWL_STYLE), false, GetWindowLong(m_hWnd, GWL_EXSTYLE)); // change width and height SetWindowPos(m_hWnd, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); if (m_pEGL) { m_pEGL->resizeSurface(); } m_bOrientationReverted = (bVertical == m_bOrientationInitVertical) ? false : true; } while (0); return m_eInitOrientation; }
CCXApplication::CCXApplication() : m_bRunning(FALSE) , m_bNeedStop(FALSE) , m_bInBackground(FALSE) { memset(&m_tMsg, 0, sizeof(m_tMsg)); SS_GetCurrentGTID(&m_tMsg.gtid); m_tMsg.type = CCX_ON_APPLICATION_IDLE; Sys_RegisterMessageCallBack(CCX_ON_APPLICATION_IDLE, CCXApplication::_OnAppIdle, (UInt32)this); memset(m_AppDataPath, 0, sizeof(char) * EOS_FILE_MAX_PATH); do { TUChar AppID[EOS_FILE_MAX_PATH] = {0}; UInt32 nCmdType = 0; Int32 nRet = SS_AppRequest_GetAppName(AppID, &nCmdType); CCX_BREAK_IF(nRet < 0); TUChar AppPath[EOS_FILE_MAX_PATH] = {0}; SS_GetApplicationPath(AppID, SS_APP_PATH_TYPE_EXECUTABLE, AppPath); TUString::StrUnicodeToStrUtf8((Char*) m_AppDataPath, AppPath); } while (0); }
static CCXEGL * create(CCXEGLView * pWindow) { CCXEGL * pEGL = new CCXEGL; BOOL bSuccess = FALSE; do { CCX_BREAK_IF(! pEGL); pEGL->m_eglNativeWindow = pWindow->getHWnd(); pEGL->m_eglNativeDisplay = GetDC(pEGL->m_eglNativeWindow); EGLDisplay eglDisplay; CCX_BREAK_IF(EGL_NO_DISPLAY == (eglDisplay = eglGetDisplay(pEGL->m_eglNativeDisplay))); EGLint nMajor, nMinor; CCX_BREAK_IF(EGL_FALSE == eglInitialize(eglDisplay, &nMajor, &nMinor) || 1 != nMajor); const EGLint aConfigAttribs[] = { EGL_LEVEL, 0, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NATIVE_RENDERABLE, EGL_FALSE, EGL_DEPTH_SIZE, 16, EGL_NONE, }; EGLint iConfigs; EGLConfig eglConfig; CCX_BREAK_IF(EGL_FALSE == eglChooseConfig(eglDisplay, aConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1)); EGLContext eglContext; eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL); CCX_BREAK_IF(EGL_NO_CONTEXT == eglContext); EGLSurface eglSurface; eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, pEGL->m_eglNativeWindow, NULL); CCX_BREAK_IF(EGL_NO_SURFACE == eglSurface); CCX_BREAK_IF(EGL_FALSE == eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)); pEGL->m_eglDisplay = eglDisplay; pEGL->m_eglConfig = eglConfig; pEGL->m_eglContext = eglContext; pEGL->m_eglSurface = eglSurface; bSuccess = TRUE; } while (0); if (! bSuccess) { CCX_SAFE_DELETE(pEGL); } return pEGL; }
bool CCScene::init() { bool bRet = false; do { CCDirector * pDirector; CCX_BREAK_IF( ! (pDirector = CCDirector::sharedDirector()) ); this->setContentSize(pDirector->getWinSize()); // success bRet = true; } while (0); return bRet; }
UIImage::UIImage(CCXBitmapDC * pBmpDC) { do { CCX_BREAK_IF(! pBmpDC); // init imageinfo int nWidth = pBmpDC->getWidth(); int nHeight = pBmpDC->getHeight(); CCX_BREAK_IF(nWidth <= 0 || nHeight <= 0); int nLen = nWidth * nHeight * 4; m_imageInfo.data = new unsigned char [nLen]; CCX_BREAK_IF(! m_imageInfo.data); memcpy(m_imageInfo.data, pBmpDC->getData(), nLen); m_imageInfo.height = nHeight; m_imageInfo.width = nWidth; m_imageInfo.hasAlpha = true; m_imageInfo.isPremultipliedAlpha = true; m_imageInfo.bitsPerComponent = 8; } while (0); }
void CCSprite::setDirtyRecursively(bool bValue) { m_bDirty = m_bRecursiveDirty = bValue; // recursively set dirty if (m_bHasChildren) { CCSprite *pChild; NSMutableArray<CCNode*>::NSMutableArrayIterator iter; for (iter = m_pChildren->begin(); iter != m_pChildren->end(); ++iter) { pChild = (CCSprite*)(*iter); CCX_BREAK_IF(! pChild); pChild->setDirtyRecursively(true); } } }
void CCSprite::removeAllChildrenWithCleanup(bool bCleanup) { if (m_bUsesBatchNode) { CCSprite *pChild; NSMutableArray<CCNode*>::NSMutableArrayIterator iter; for (iter = m_pChildren->begin(); iter != m_pChildren->end(); ++iter) { pChild = (CCSprite*)(*iter); CCX_BREAK_IF(! pChild); m_pobBatchNode->removeSpriteFromAtlas(pChild); } } CCNode::removeAllChildrenWithCleanup(bCleanup); m_bHasChildren = false; }
bool tgaLoadImageData(unsigned char *Buffer, unsigned long bufSize, tImageTGA *psInfo) { bool bRet = false; do { int mode,total,i; unsigned char aux; size_t step = (sizeof(unsigned char) + sizeof(signed short)) * 6; // mode equal the number of components for each pixel mode = psInfo->pixelDepth / 8; // total is the number of unsigned chars we'll have to read total = psInfo->height * psInfo->width * mode; size_t dataSize = sizeof(unsigned char) * total; CCX_BREAK_IF((step + dataSize) > bufSize); memcpy(psInfo->imageData, Buffer + step, dataSize); // mode=3 or 4 implies that the image is RGB(A). However TGA // stores it as BGR(A) so we'll have to swap R and B. if (mode >= 3) { for (i=0; i < total; i+= mode) { aux = psInfo->imageData[i]; psInfo->imageData[i] = psInfo->imageData[i+2]; psInfo->imageData[i+2] = aux; } } bRet = true; } while (0); return bRet; }
bool tgaLoadRLEImageData(unsigned char* Buffer, unsigned long bufSize, tImageTGA *psInfo) { bool bRet = false; unsigned int mode,total,i, index = 0; unsigned char aux[4], runlength = 0; unsigned int skip = 0, flag = 0; size_t step = (sizeof(unsigned char) + sizeof(signed short)) * 6; // mode equal the number of components for each pixel mode = psInfo->pixelDepth / 8; // total is the number of unsigned chars we'll have to read total = psInfo->height * psInfo->width; for( i = 0; i < total; i++ ) { // if we have a run length pending, run it if ( runlength != 0 ) { // we do, update the run length count runlength--; skip = (flag != 0); } else { // otherwise, read in the run length token CCX_BREAK_IF((step + sizeof(unsigned char)) > bufSize); memcpy(&runlength, Buffer + step, sizeof(unsigned char)); step += sizeof(unsigned char); // see if it's a RLE encoded sequence flag = runlength & 0x80; if ( flag ) { runlength -= 128; } skip = 0; } // do we need to skip reading this pixel? if ( !skip ) { // no, read in the pixel data CCX_BREAK_IF((step + sizeof(unsigned char) * mode) > bufSize); memcpy(aux, Buffer + step, sizeof(unsigned char) * mode); step += sizeof(unsigned char) * mode; // mode=3 or 4 implies that the image is RGB(A). However TGA // stores it as BGR(A) so we'll have to swap R and B. if ( mode >= 3 ) { unsigned char tmp; tmp = aux[0]; aux[0] = aux[2]; aux[2] = tmp; } } // add the pixel to our image memcpy(&psInfo->imageData[index], aux, mode); index += mode; } return true; }
bool CCParticleSystem::initWithDictionary(NSDictionary<std::string, NSObject*> *dictionary) { bool bRet = false; unsigned char *buffer = NULL; unsigned char *deflated = NULL; UIImage *image = NULL; do { int maxParticles = atoi(valueForKey("maxParticles", dictionary)); // self, not super if(this->initWithTotalParticles(maxParticles)) { // angle m_fAngle = (float)atof(valueForKey("angle", dictionary)); m_fAngleVar = (float)atof(valueForKey("angleVariance", dictionary)); // duration m_fDuration = (float)atof(valueForKey("duration", dictionary)); // blend function m_tBlendFunc.src = atoi(valueForKey("blendFuncSource", dictionary)); m_tBlendFunc.dst = atoi(valueForKey("blendFuncDestination", dictionary)); // color m_tStartColor.r = (float)atof(valueForKey("startColorRed", dictionary)); m_tStartColor.g = (float)atof(valueForKey("startColorGreen", dictionary)); m_tStartColor.b = (float)atof(valueForKey("startColorBlue", dictionary)); m_tStartColor.a = (float)atof(valueForKey("startColorAlpha", dictionary)); m_tStartColorVar.r = (float)atof(valueForKey("startColorVarianceRed", dictionary)); m_tStartColorVar.g = (float)atof(valueForKey("startColorVarianceGreen", dictionary)); m_tStartColorVar.b = (float)atof(valueForKey("startColorVarianceBlue", dictionary)); m_tStartColorVar.a = (float)atof(valueForKey("startColorVarianceAlpha", dictionary)); m_tEndColor.r = (float)atof(valueForKey("finishColorRed", dictionary)); m_tEndColor.g = (float)atof(valueForKey("finishColorGreen", dictionary)); m_tEndColor.b = (float)atof(valueForKey("finishColorBlue", dictionary)); m_tEndColor.a = (float)atof(valueForKey("finishColorAlpha", dictionary)); m_tEndColorVar.r = (float)atof(valueForKey("finishColorVarianceRed", dictionary)); m_tEndColorVar.g = (float)atof(valueForKey("finishColorVarianceGreen", dictionary)); m_tEndColorVar.b = (float)atof(valueForKey("finishColorVarianceBlue", dictionary)); m_tEndColorVar.a = (float)atof(valueForKey("finishColorVarianceAlpha", dictionary)); // particle size m_fStartSize = (float)atof(valueForKey("startParticleSize", dictionary)); m_fStartSizeVar = (float)atof(valueForKey("startParticleSizeVariance", dictionary)); m_fEndSize = (float)atof(valueForKey("finishParticleSize", dictionary)); m_fEndSizeVar = (float)atof(valueForKey("finishParticleSizeVariance", dictionary)); // position m_tPosition.x = (float)atof(valueForKey("sourcePositionx", dictionary)); m_tPosition.y = (float)atof(valueForKey("sourcePositiony", dictionary)); m_tPosVar.x = (float)atof(valueForKey("sourcePositionVariancex", dictionary)); m_tPosVar.y = (float)atof(valueForKey("sourcePositionVariancey", dictionary)); m_nEmitterMode = atoi(valueForKey("emitterType", dictionary)); // Mode A: Gravity + tangential accel + radial accel if( m_nEmitterMode == kCCParticleModeGravity ) { // gravity modeA.gravity.x = (float)atof(valueForKey("gravityx", dictionary)); modeA.gravity.y = (float)atof(valueForKey("gravityy", dictionary)); // speed modeA.speed = (float)atof(valueForKey("speed", dictionary)); modeA.speedVar = (float)atof(valueForKey("speedVariance", dictionary)); const char * pszTmp = NULL; // radial acceleration pszTmp = valueForKey("radialAcceleration", dictionary); modeA.radialAccel = (pszTmp) ? (float)atof(pszTmp) : 0; pszTmp = valueForKey("radialAccelVariance", dictionary); modeA.radialAccelVar = (pszTmp) ? (float)atof(pszTmp) : 0; // tangential acceleration pszTmp = valueForKey("tangentialAcceleration", dictionary); modeA.tangentialAccel = (pszTmp) ? (float)atof(pszTmp) : 0; pszTmp = valueForKey("tangentialAccelVariance", dictionary); modeA.tangentialAccelVar = (pszTmp) ? (float)atof(pszTmp) : 0; } // or Mode B: radius movement else if( m_nEmitterMode == kCCParticleModeRadius ) { modeB.startRadius = (float)atof(valueForKey("maxRadius", dictionary)); modeB.startRadiusVar = (float)atof(valueForKey("maxRadiusVariance", dictionary)); modeB.endRadius = (float)atof(valueForKey("minRadius", dictionary)); modeB.endRadiusVar = 0; modeB.rotatePerSecond = (float)atof(valueForKey("rotatePerSecond", dictionary)); modeB.rotatePerSecondVar = (float)atof(valueForKey("rotatePerSecondVariance", dictionary)); } else { NSAssert( false, "Invalid emitterType in config file"); CCX_BREAK_IF(true); } // life span m_fLife = (float)atof(valueForKey("particleLifespan", dictionary)); m_fLifeVar = (float)atof(valueForKey("particleLifespanVariance", dictionary)); // emission Rate m_fEmissionRate = m_nTotalParticles / m_fLife; // texture // Try to get the texture from the cache char *textureName = (char *)valueForKey("textureFileName", dictionary); std::string fullpath = CCFileUtils::fullPathFromRelativeFile(textureName, m_sPlistFile.c_str()); if (strlen(textureName) > 0) { // set not pop-up message box when load image failed bool bNotify = UIImage::getIsPopupNotify(); UIImage::setIsPopupNotify(false); this->m_pTexture = CCTextureCache::sharedTextureCache()->addImage(fullpath.c_str()); // reset the value of UIImage notify UIImage::setIsPopupNotify(bNotify); } // if it fails, try to get it from the base64-gzipped data char *textureData = NULL; if ( ! m_pTexture && (textureData = (char *)valueForKey("textureImageData", dictionary))) { int dataLen = strlen(textureData); if(dataLen != 0) { int decodeLen = base64Decode((unsigned char*)textureData, dataLen, &buffer); NSAssert( buffer != NULL, "CCParticleSystem: error decoding textureImageData"); CCX_BREAK_IF(!buffer); int deflatedLen = ZipUtils::ccInflateMemory(buffer, decodeLen, &deflated); NSAssert( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData"); CCX_BREAK_IF(!deflated); image = new UIImage(); bool isOK = image->initWithData(deflated, deflatedLen); NSAssert(isOK, "CCParticleSystem: error init image with Data"); CCX_BREAK_IF(!isOK); m_pTexture = CCTextureCache::sharedTextureCache()->addUIImage(image, fullpath.c_str()); } } NSAssert( this->m_pTexture != NULL, "CCParticleSystem: error loading the texture"); CCX_BREAK_IF(!m_pTexture); this->m_pTexture->retain(); bRet = true; } } while (0); CCX_SAFE_DELETE_ARRAY(buffer); CCX_SAFE_DELETE_ARRAY(deflated); CCX_SAFE_DELETE(image); return bRet; }
static CCXEGL * create(TWindow * pWindow) { CCXEGL * pEGL = new CCXEGL; Boolean bSuccess = FALSE; do { CCX_BREAK_IF(! pEGL); TUChar szError[] = {'E','R','R','O','R',0}; TUChar szEglInitFailed[] = {'e','g','l','I','n','i','t','i','a','l','i','z','e',' ','f','a','i','l','e','d',0}; TUChar szCreateContextFailed[] = {'e','g','l','C','r','e','a','t','e','C','o','n','t','e','x','t',' ','f','a','i','l','e','d',0}; TUChar szEglCreateWindowSurfaceFailed[] = {'e','g','l','C','r','e','a','t','e','W','i','n','d','o','w','S','u','r','f','a','c','e',' ','f','a','i','l','e','d',0}; TUChar szEglMakeCurrentFailed[] = {'e','g','l','M','a','k','e','C','u','r','r','e','n','t',' ','f','a','i','l','e','d',0}; pEGL->m_eglNativeWindow = pWindow; EGLDisplay eglDisplay; CCX_BREAK_IF(EGL_NO_DISPLAY == (eglDisplay = eglGetDisplay(pEGL->m_eglNativeDisplay))); EGLint nMajor, nMinor; EGLBoolean bEglRet; bEglRet = eglInitialize(eglDisplay, &nMajor, &nMinor); if ( EGL_FALSE == bEglRet || 1 != nMajor ) { TApplication::GetCurrentApplication()->MessageBox(szEglInitFailed, szError, WMB_OK); break; } const EGLint aConfigAttribs[] = { EGL_LEVEL, 0, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NATIVE_RENDERABLE, EGL_FALSE, EGL_DEPTH_SIZE, 16, EGL_NONE, }; EGLint iConfigs; EGLConfig eglConfig; CCX_BREAK_IF( EGL_FALSE == eglChooseConfig(eglDisplay, aConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1) ); EGLContext eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL); if (EGL_NO_CONTEXT == eglContext) { TApplication::GetCurrentApplication()->MessageBox(szCreateContextFailed, szError, WMB_OK); break; } EGLSurface eglSurface; eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, pEGL->m_eglNativeWindow, NULL); if (EGL_NO_SURFACE == eglSurface) { TApplication::GetCurrentApplication()->MessageBox(szEglCreateWindowSurfaceFailed, szError, WMB_OK); break; } bEglRet = eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); if (EGL_FALSE == bEglRet) { TApplication::GetCurrentApplication()->MessageBox(szEglMakeCurrentFailed, szError, WMB_OK); break; } pEGL->m_eglDisplay = eglDisplay; pEGL->m_eglConfig = eglConfig; pEGL->m_eglContext = eglContext; pEGL->m_eglSurface = eglSurface; bSuccess = TRUE; } while (0); if (! bSuccess) { CCX_SAFE_DELETE(pEGL); } return pEGL; }
Boolean CCXEGLView::EventHandler(TApplication * pApp, EventType * pEvent) { Boolean bHandled = FALSE; switch(pEvent->eType) { case EVENT_WinInit: CfgRegisterScreenSwitchNotify(GetWindowHwndId(), 0); bHandled = TRUE; break; case EVENT_WinPaint: if (CfgGetScreenStatus()) { // draw CCDirector::sharedDirector()->mainLoop(); } bHandled = TRUE; break; case EVENT_PenDown: bHandled = OnPenDown(pEvent, 0); break; case EVENT_PenMove: bHandled = OnPenMove(pEvent); break; case EVENT_PenUp: bHandled = OnPenUp(pEvent, 0); break; case EVENT_MultiTouchDown: bHandled = OnPenDown(pEvent, pEvent->lParam3); break; case EVENT_MultiTouchUp: bHandled = OnPenUp(pEvent, pEvent->lParam3); break; case EVENT_KeyCommand: { if (pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_UP || pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_LONG) { bHandled = CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked); } else if (pEvent->sParam1 == SYS_KEY_SOFTKEY_LEFT_UP || pEvent->sParam1 == SYS_KEY_SOFTKEY_LEFT_LONG) { bHandled = CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeMenuClicked); } } break; case MESSAGE_SENSORS_DATA: { TG3SensorsDataType data; if (Sys_GetMessageBody((MESSAGE_t *)pEvent, &data, sizeof(TG3SensorsDataType)) == sizeof(TG3SensorsDataType) && TG3_SENSOR_TYPE_ACCELEROMETER == data.sensorMask) { // convert the data to iphone format UIAcceleration AccValue; AccValue.x = -(data.acceleration.x / TG3_GRAVITY_EARTH); AccValue.y = -(data.acceleration.y / TG3_GRAVITY_EARTH); AccValue.z = -(data.acceleration.z / TG3_GRAVITY_EARTH); AccValue.timestamp = (double) TimGetTicks() / 100; // call delegates' didAccelerate function UIAccelerometer::sharedAccelerometer()->didAccelerate(&AccValue); bHandled = TRUE; } } break; case EVENT_WinClose: CfgUnRegisterScreenSwitchNotify(GetWindowHwndId(), 0); // Stop the application since the main form has been closed pApp->SendStopEvent(); break; case EVENT_ScreenSwitchNotify: { bool bInBack = CCXApplication::sharedApplication()->isInBackground(); // if the app have be in background,don't handle this message CCX_BREAK_IF(bInBack); if (! pEvent->sParam1) // turn off screen { // CCDirector::sharedDirector()->pause(); CCXApplication::sharedApplication()->applicationDidEnterBackground(); CCXApplication::sharedApplication()->StopMainLoop(); } else { // CCDirector::sharedDirector()->resume(); CCXApplication::sharedApplication()->applicationWillEnterForeground(); CCXApplication::sharedApplication()->StartMainLoop(); } break; } } // { // char szType[32]; // sprintf(szType, "%d", pEvent->eType); // const char * pszType = szType; // switch (pEvent->eType) // { // case EVENT_ScreenSwitchNotify: // pszType = "EVENT_ScreenSwitchNotify"; // break; // // case EVENT_GlesUpdateNotify: // pszType = "EVENT_GlesUpdateNotify"; // break; // // case EVENT_WinPaint: // pszType = "EVENT_GlesUpdateNotify"; // break; // } // if (pszType) // { // char szMsg[256]; // sprintf(szMsg, "%d: %s: %d \r\n", TimGetTicks(), pszType, pEvent->sParam1); // #if defined (_TRANZDA_VM_) // #define LOG_FILE_NAME "d:/Work7/NEWPLUS/TDA_DATA/UserData/mesagelog.txt" // #else // #define LOG_FILE_NAME "/NEWPLUS/TDA_DATA/UserData/mesagelog.txt" // #endif // FILE * pf = fopen(LOG_FILE_NAME, "a+"); // fwrite(szMsg, 1, strlen(szMsg), pf); // fclose(pf); // } // } if (! bHandled) { return TWindow::EventHandler(pApp, pEvent); } return bHandled; }
// this is the function to call when we want to load an image tImageTGA * tgaLoad(const char *pszFilename) { int mode,total; tImageTGA *info = NULL; FileData data; unsigned long nSize = 0; unsigned char* pBuffer = data.getFileData(pszFilename, "rb", &nSize); do { CCX_BREAK_IF(! pBuffer); info = (tImageTGA *)malloc(sizeof(tImageTGA)); // get the file header info if (! tgaLoadHeader(pBuffer, nSize, info)) { info->status = TGA_ERROR_MEMORY; break; } // check if the image is color indexed if (info->type == 1) { info->status = TGA_ERROR_INDEXED_COLOR; break; } // check for other types (compressed images) if ((info->type != 2) && (info->type !=3) && (info->type !=10) ) { info->status = TGA_ERROR_COMPRESSED_FILE; break; } // mode equals the number of image components mode = info->pixelDepth / 8; // total is the number of unsigned chars to read total = info->height * info->width * mode; // allocate memory for image pixels info->imageData = (unsigned char *)malloc(sizeof(unsigned char) * total); // check to make sure we have the memory required if (info->imageData == NULL) { info->status = TGA_ERROR_MEMORY; break; } bool bLoadImage = false; // finally load the image pixels if ( info->type == 10 ) { bLoadImage = tgaLoadRLEImageData(pBuffer, nSize, info); } else { bLoadImage = tgaLoadImageData(pBuffer, nSize, info); } // check for errors when reading the pixels if (! bLoadImage) { info->status = TGA_ERROR_READING_FILE; break; } info->status = TGA_OK; if ( info->flipped ) { tgaFlipImage( info ); if ( info->flipped ) { info->status = TGA_ERROR_MEMORY; } } } while(0); return info; }
CCXBitmapDC::CCXBitmapDC(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize) : m_pBitmap(NULL) { TUChar *pText = NULL; do { // create font TFont font; CCX_BREAK_IF(! font.Create(0, (Int32)fontSize)); // text Int32 len = strlen(text) + 1; CCX_BREAK_IF(! (pText = new TUChar[len])); TUString::StrGBToUnicode(pText, (Char*)text); // calculate text size if (CGSize::CGSizeEqualToSize(dimensions, CGSizeZero)) { m_tSize.width = font.CharsWidth(pText,len); m_tSize.height = font.LineHeight(); }else { m_tSize = dimensions; } Int16 width = (Int16)m_tSize.width; Int16 height = (Int16)m_tSize.height; // create bitmap CCX_BREAK_IF(! (m_pBitmap = TBitmap::Create(width, height, 32))); // create memory window if (s_pMemWnd) { TRectangle rcMemWnd(0, 0, 0, 0); s_pMemWnd->GetClientBounds(&rcMemWnd); if (rcMemWnd.Width() < width || rcMemWnd.Height() < height) { s_pMemWnd->CloseWindow(); s_pMemWnd = NULL; } } do { // if memery window is already break CCX_BREAK_IF(s_pMemWnd); CCX_BREAK_IF(! (s_pMemWnd = new TWindow(CCXApplication::sharedApplication()))); Coord nCurrentWidth = CCXApplication::GetCurrentApplication()->GetScreenWidth(); Coord nCurrentHeight = CCXApplication::GetCurrentApplication()->GetScreenHeight(); Coord nMemWndW = (width >= nCurrentWidth) ? width : nCurrentWidth; Coord nMemWndH = (height >= nCurrentHeight) ? height : nCurrentHeight; CCX_BREAK_IF(s_pMemWnd->CreateMemWindow(nMemWndW, nMemWndH,screenTransparentFormat)); delete s_pMemWnd; s_pMemWnd = NULL; } while (0); CCX_BREAK_IF(! s_pMemWnd); // create DC TDC dc(s_pMemWnd); // set DC styles UInt32 styles = GUI_API_STYLE_SPECIFY_FORE_COLOR | GUI_API_STYLE_ROP_MODE_TRANSPARENT | GUI_API_STYLE_SPECIFY_BACK_COLOR | GUI_API_STYLE_ALIGNMENT_MIDDLE | GUI_API_STYLE_SPECIFY_FONT; switch (alignment) { case UITextAlignmentLeft: styles |= GUI_API_STYLE_ALIGNMENT_LEFT; break; case UITextAlignmentCenter: styles |= GUI_API_STYLE_ALIGNMENT_CENTER; break; case UITextAlignmentRight: styles |= GUI_API_STYLE_ALIGNMENT_RIGHT; break; default: styles |= GUI_API_STYLE_ALIGNMENT_CENTER; break; } s_pMemWnd->GetMemWindowTBitmapPtr()->Fill32(RGBA(0, 0, 0, 0), 0, 0, width, height); TRectangle rect(0, 0, width, height); dc.DrawTextInRectangleEx(pText, 0, RGBA(255,255,255,255), RGBA(0,0,0,255), font, &rect, styles); dc.ReadBitmap(m_pBitmap, 0, 0); } while (0); if (pText) { delete[] pText; pText = NULL; } }
bool CCXEGLView::Create(LPCTSTR pTitle, int w, int h) { bool bRet = false; do { CCX_BREAK_IF(m_hWnd); HINSTANCE hInstance = GetModuleHandle( NULL ); WNDCLASS wc; // Windows Class Structure // Redraw On Size, And Own DC For Window. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = _WindowProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data wc.hInstance = hInstance; // Set The Instance wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL wc.lpszMenuName = NULL; // We Don't Want A Menu wc.lpszClassName = kWindowClassName; // Set The Class Name CCX_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); // center window position RECT rcDesktop; GetWindowRect(GetDesktopWindow(), &rcDesktop); RECT rect = {(rcDesktop.right + rcDesktop.left - w) / 2, (rcDesktop.bottom + rcDesktop.top - h) / 2, 0, 0}; rect.right = rect.left + w; rect.bottom = rect.top + h; AdjustWindowRectEx(&rect, WS_CAPTION | WS_POPUPWINDOW, false, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE); // create window m_hWnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window kWindowClassName, // Class Name pTitle, // Window Title WS_CAPTION | WS_POPUPWINDOW, // Defined Window Style rect.left, rect.top, // Window Position rect.right - rect.left, // Window Width rect.bottom - rect.top, // Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance NULL ); CCX_BREAK_IF(! m_hWnd); // init egl m_pEGL = CCXEGL::create(this); if (! m_pEGL) { DestroyWindow(m_hWnd); m_hWnd = NULL; break; } ShowWindow(m_hWnd, SW_SHOW); pMainWindow = this; bRet = true; } while (0); return bRet; }