//------------------------------------------------------------------------------ uint32 CGUIShader_opengl_base::BuildShader(const CGUIString& rSource, uint32 shaderType) { #if defined(GUIEX_RENDER_OPENGL) || defined(GUIEX_RENDER_OPENGL_ES2) ///read file IGUIInterfaceFileSys* pFileSys = CGUIInterfaceManager::Instance()->GetInterfaceFileSys(); CGUIDataChunk aShaderDataChunk; if( 0 != pFileSys->ReadFile( rSource, aShaderDataChunk, IGUIInterfaceFileSys::eOpenMode_String )) { //failed GUI_THROW( GUI_FORMAT("[CGUIShader_opengl_base::BuildShader]: failed to read file <%s>!", rSource.c_str())); return -1; } GLuint shaderHandle = glCreateShader(shaderType); const char* data = (const char*)aShaderDataChunk.GetDataPtr(); glShaderSource(shaderHandle, 1, &data, 0); glCompileShader(shaderHandle); GLint compileSuccess; glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &compileSuccess); if (compileSuccess == GL_FALSE) { char messages[256]; glGetShaderInfoLog(shaderHandle, sizeof(messages), 0, &messages[0]); GUI_THROW( GUI_FORMAT( "[CGUIShader_opengl_base::BuildShader]: %s", messages )); return 0; } return shaderHandle; #else ////#if defined(GUIEX_RENDER_OPENGL) || defined(GUIEX_RENDER_OPENGL_ES2) return 0; #endif //#if defined(GUIEX_RENDER_OPENGL) || defined(GUIEX_RENDER_OPENGL_ES2) }
/** * @brief get current time */ void CGUITimer::UpdateTime() { if(m_aFrequency.QuadPart == 0 ) { if( !QueryPerformanceFrequency(&m_aFrequency)) { GUI_THROW( "[CGUITimer::UpdateTime]: failed in function QueryPerformanceFrequency()!"); } } if( !QueryPerformanceCounter(&m_aTimeCounter)) { GUI_THROW( "[CGUITimer::UpdateTime]: failed in function QueryPerformanceCounter()!"); } }
int32 StringToValue<EImageOrientation>( const CGUIString& rString, EImageOrientation& rValue) { if( rString == "eImageOrientation_Normal" ) { rValue = eImageOrientation_Normal; } else if( rString == "eImageOrientation_90CW" ) { rValue = eImageOrientation_90CW; } else if( rString == "eImageOrientation_90CCW" ) { rValue = eImageOrientation_90CCW; } else if( rString == "eImageOrientation_FlipHorizon" ) { rValue = eImageOrientation_FlipHorizon; } else if( rString == "eImageOrientation_FlipVertical" ) { rValue = eImageOrientation_FlipVertical; } else { GUI_THROW( GUI_FORMAT( "[StringToValue[EImageOrientation]]: string value format is wrong! <%s>", rString.c_str())); return -1; } return 0; }
int32 ValueToString<EImageOrientation>( const EImageOrientation& rValue, CGUIString& rString ) { switch(rValue) { case eImageOrientation_Normal: rString = CGUIString("eImageOrientation_Normal"); break; case eImageOrientation_90CW: rString = CGUIString("eImageOrientation_90CW"); break; case eImageOrientation_90CCW: rString = CGUIString("eImageOrientation_90CCW"); break; case eImageOrientation_FlipHorizon: rString = CGUIString("eImageOrientation_FlipHorizon"); break; case eImageOrientation_FlipVertical: rString = CGUIString("eImageOrientation_FlipVertical"); break; default: GUI_THROW( GUI_FORMAT( "[ValueToString[EImageOrientation]]: unknown image orientation <%d>", rValue)); return -1; } return 0; }
//------------------------------------------------------------------------------ CGUIFontData* IGUIFont_ft2::CreateFontData( const CGUIString& rName, const CGUIString& rSceneName, const SFontInfo& rFontInfo ) { //check if( rFontInfo.m_uID >= m_arrayFontDatas.size() || m_arrayFontDatas[rFontInfo.m_uID] != NULL ) { GUI_THROW( GUI_FORMAT("[IGUIFont_ft2::CreateFontData]: invalid font id <%d>", rFontInfo.m_uID )); return NULL; } //create font face CGUIFontFace_ft2* pFontFace = NULL; CGUIString strFullFontPath = CGUISceneManager::Instance()->GetScenePath( rSceneName ) + rFontInfo.m_strPath; TMapFontFace::iterator itor = m_mapFontFace.find( rFontInfo.m_strPath ); if( itor == m_mapFontFace.end() ) { pFontFace = new CGUIFontFace_ft2( this, strFullFontPath ); pFontFace->RefRetain(); m_mapFontFace.insert( std::make_pair( rFontInfo.m_strPath, pFontFace ) ); } else { pFontFace = itor->second; pFontFace->RefRetain(); } m_arrayFontDatas[rFontInfo.m_uID] = new CGUIFontData_ft2( rName, rSceneName, rFontInfo, pFontFace ); return m_arrayFontDatas[rFontInfo.m_uID]; }
//------------------------------------------------------------------------------ int32 CGUIFramework_IOS::InitializeSystem( const CGUIIntSize& rScreenSize, const char* pDataPath ) { //setup log system SetupLogSystem(); //init system if( GSystem != NULL ) { GUI_THROW( "[CGUIFramework_IOS::InitializeSystem] GSystem has been created!" ); return -1; } GSystem = new CGUISystem; if( 0 != GSystem->Initialize()) { return -1; } //set screen size GSystem->SetRawScreenSize( rScreenSize ); //set date path GSystem->SetDataPath( pDataPath ); //register interface RegisterInterfaces(); //register widget RegisterWidgetGenerators(); return 0; }
//------------------------------------------------------------------------------ CGUIWidget* DoCreateWidget( const CGUIProperty* pPropertySet, const CGUIString& rOwnSceneName, const CGUIString& rWorkingSceneName, bool bIsDynamicPage, CGUIWidget* pPageRoot) { /// create widget const CGUIString& strWidgetType = pPropertySet->GetValue( ); const CGUIString& strWidgetName = pPropertySet->GetName( ); CGUIWidget* pWidget = CGUIWidgetManager::Instance()->CreateWidget(strWidgetType, strWidgetName, rOwnSceneName, !bIsDynamicPage ); if( !pWidget ) { GUI_THROW( GUI_FORMAT( "[DoCreateWidget]: failed to create widget <%s:%s>!", strWidgetType.c_str(), strWidgetName.c_str())); return NULL; } pWidget->SetWorkingSceneName( rWorkingSceneName ); pWidget->SetDynamic( bIsDynamicPage ); if( !pPageRoot ) { pPageRoot = pWidget; } pWidget->SetPage( pPageRoot ); //set parent const CGUIProperty* pParentProperty = pPropertySet->GetProperty( "parent", ePropertyType_String ); if( pParentProperty ) { pWidget->ProcessProperty( *pParentProperty ); } return pWidget; }
//------------------------------------------------------------------------------ int32 CGUIShader_opengl_base::LoadAndCompile(const CGUIString& rVertexShaderFileName, const CGUIString& rFragmentShaderFileName) { #if defined(GUIEX_RENDER_OPENGL) || defined(GUIEX_RENDER_OPENGL_ES2) DestroyShader(); //create shader m_uVertexShader = BuildShader(rVertexShaderFileName, GL_VERTEX_SHADER); m_uFragmentShader = BuildShader(rFragmentShaderFileName, GL_FRAGMENT_SHADER); m_uProgramId = glCreateProgram(); glAttachShader(m_uProgramId, m_uVertexShader); glAttachShader(m_uProgramId, m_uFragmentShader); glLinkProgram(m_uProgramId); GLint linkSuccess; glGetProgramiv(m_uProgramId, GL_LINK_STATUS, &linkSuccess); if (linkSuccess == GL_FALSE) { char messages[256]; glGetProgramInfoLog(m_uProgramId, sizeof(messages), 0, &messages[0]); GUI_THROW( GUI_FORMAT( "[CGUIShader_opengl_base::LoadAndCompile]: %s", messages )); return -1; } CacheAttributeLoc(); CacheUniformLoc(); #endif //#if defined(GUIEX_RENDER_OPENGL) || defined(GUIEX_RENDER_OPENGL_ES2) return 0; }
//------------------------------------------------------------------------------ int AppMultiByteToWideChar( const CGUIString& rSrc, CGUIStringW& rDst ) { IGUIInterfaceStringConv* pStringConv = CGUIInterfaceManager::Instance()->GetInterfaceStringConv(); if( !pStringConv ) { GUI_THROW( "[AppMultiByteToWideChar]: not found interface to convert string code"); return -1; } return pStringConv->Utf8ToWChar( rSrc, rDst ); }
//------------------------------------------------------------------------------ int32 CGUIMusicData_openal::DoLoad() { // identify file type by extension CGUIString strExt; size_t pos = m_strPath.find_last_of("."); if( pos != CGUIString::npos ) { strExt = m_strPath.substr(pos); } for ( uint32 i=0; i<strExt.size(); ++i) { strExt[i] = tolower(strExt[i]); } CGUIString strScenePath = CGUISceneManager::Instance()->GetScenePath( m_strSceneName ) + m_strPath; CGUIString strFullPath; GSystem->GenerateFullPath( strScenePath, strFullPath ); if (strExt == ".ogg") { //load ogg file if( LoadOggFile( strFullPath ) != true) { GUI_THROW( GUI_FORMAT("[CGUISoundData_openal::DoLoad]: failed to load ogg file <%s>!", m_strPath.c_str())); return -1; } } else { GUI_THROW( GUI_FORMAT("[CGUISoundData_openal::DoLoad]: doesn't support the sound type <%s>!", strExt.c_str())); return -1; } //assign the buffer to this source //alSourcei( m_nSourceId, AL_BUFFER, m_nBufferId); //set source position alSource3f( m_nSourceId,AL_POSITION, 0, 0, 0); //set source velocity alSource3f( m_nSourceId,AL_VELOCITY, 0, 0, 0); return 0; }
//------------------------------------------------------------------------------ CGUIFontData_ft2* IGUIFont_ft2::GetFontData( uint16 uFontID ) { //check if( uFontID >= m_arrayFontDatas.size() || m_arrayFontDatas[uFontID] == NULL ) { GUI_THROW( GUI_FORMAT("[IGUIFont_ft2::GetFontData]: invalid font id <%d>", uFontID )); return NULL; } return m_arrayFontDatas[uFontID]; }
//------------------------------------------------------------------------------ void CGUIFramework_IOS::ReleaseSystem() { //release system if( GSystem == NULL ) { GUI_THROW( "[CGUIFramework_IOS::ReleaseSystem] GSystem has been released!" ); return; } GSystem->Release(); delete GSystem; GSystem = NULL; }
int32 StringToValue<int16>( const CGUIString& rString, int16& rValue) { long value = strtol(rString.c_str(), 0, 10); if( value > (long)(std::numeric_limits<int16>::max())) { GUI_THROW( GUI_FORMAT( "[StringToValue[int16]]: Value <%s> exceeds range of destination type", rString.c_str())); return -1; } rValue = static_cast<int16>(value); return 0; }
int32 StringToValue<uint8>( const CGUIString& rString, uint8& rValue) { unsigned long value = strtoul(rString.c_str(), 0, 10); if( value > std::numeric_limits<uint8>::max() ) { GUI_THROW( GUI_FORMAT( "[StringToValue[uint8]]: Value <%s> exceeds range of destination type", rString.c_str())); return -1; } rValue = static_cast<uint8>(value); return 0; }
//------------------------------------------------------------------------------ void IGUIFont_ft2::DestroyFontData( CGUIFontData* pData ) { GUI_ASSERT( pData, "invalid parameter" ); //check CGUIFontData_ft2* pFontData = m_arrayFontDatas[pData->GetFontID()]; if( pFontData != pData ) { GUI_THROW( GUI_FORMAT( "[IGUIFont_ft2::DestroyFontData]: the font<%s:%s> doesn't existing", pData->GetName().c_str(), pData->GetSceneName().c_str())); return; } //update font face TMapFontFace::iterator itor = m_mapFontFace.find( pData->GetFontPath() ); if( itor == m_mapFontFace.end() ) { GUI_THROW( GUI_FORMAT( "[IGUIFont_ft2::DestroyFontData]: failed to font font face by path <%s>", pData->GetFontPath().c_str())); return; } itor->second->RefRelease(); //delete font face if( itor->second->GetRefCount() == 0 ) { delete itor->second; m_mapFontFace.erase( itor ); } //clear font m_arrayFontDatas[pData->GetFontID()] = NULL; delete pData; }
int32 StringToValue<CGUIVector2>( const CGUIString& rString, CGUIVector2& rValue) { //string should have format as "x,y" std::vector<CGUIString> aListString= StringToVector(rString); if( aListString.size() != 2 ) { GUI_THROW( GUI_FORMAT( "[StringToValue[StringToValue]]: string value format is wrong! <%s>", rString.c_str())); return -1; } StringToValue(aListString[0], rValue.x); StringToValue(aListString[1], rValue.y); return 0; }
int32 StringToValue<CGUIIntSize>( const CGUIString& rString, CGUIIntSize& rValue) { //string should have format as "width,height" std::vector<CGUIString> aListString= StringToVector(rString); if( aListString.size() != 2 ) { GUI_THROW( GUI_FORMAT( "[StringToValue[CGUIIntSize]]: string value format is wrong! <%s>", rString.c_str())); return -1; } StringToValue( aListString[0], rValue.m_uWidth ); StringToValue( aListString[1], rValue.m_uHeight ); return 0; }
int32 ValueToString<EScreenValue>( const EScreenValue& rValue, CGUIString& rString ) { switch(rValue) { case eScreenValue_Pixel: rString = CGUIString("eScreenValue_Pixel"); break; case eScreenValue_Percentage: rString = CGUIString("eScreenValue_Percentage"); break; default: GUI_THROW( GUI_FORMAT( "[ValueToString[EScreenValue]]: unknown image orientation <%d>", rValue)); return -1; } return 0; }
int32 ValueToString<EOrientation>( const EOrientation& rValue, CGUIString& rString ) { switch(rValue) { case eOrientation_Vertical: rString = CGUIString("eOrientation_Vertical"); break; case eOrientation_Horizontal: rString = CGUIString("eOrientation_Horizontal"); break; default: GUI_THROW( GUI_FORMAT( "[ValueToString[EOrientation]]: unknown EOrientation enum <%d>", rValue)); return -1; } return 0; }
int32 StringToValue<CGUIRotator>( const CGUIString& rString, CGUIRotator& rValue) { //string should have format as "pitch,yaw,roll" std::vector<CGUIString> aListString= StringToVector(rString); if( aListString.size() != 3 ) { GUI_THROW( GUI_FORMAT( "[StringToValue[StringToValue]]: string value format is wrong! <%s>", rString.c_str())); return -1; } StringToValue(aListString[0], rValue.Pitch); StringToValue(aListString[1], rValue.Yaw); StringToValue(aListString[2], rValue.Roll); return 0; }
int32 StringToValue<CGUIRect>( const CGUIString& rString, CGUIRect& rValue) { //string should have format as "left, top, right,bottom" std::vector<CGUIString> aListString= StringToVector(rString); if( aListString.size() != 4 ) { GUI_THROW( GUI_FORMAT( "[StringToValue[CGUIRect]]: string value format is wrong! <%s>", rString.c_str())); return -1; } StringToValue( aListString[0], rValue.m_fLeft ); StringToValue( aListString[1], rValue.m_fTop ); StringToValue( aListString[2], rValue.m_fRight ); StringToValue( aListString[3], rValue.m_fBottom ); return 0; }
int32 ValueToString<EParticle2DSystemMode>( const EParticle2DSystemMode& rValue, CGUIString& rString ) { switch(rValue) { case eParticle2DSystemMode_Gravity: rString = CGUIString("eParticle2DSystemMode_Gravity"); break; case eParticle2DSystemMode_Radius: rString = CGUIString("eParticle2DSystemMode_Radius"); break; default: GUI_THROW( GUI_FORMAT( "[ValueToString[EParticle2DSystemMode]]: unknown EParticle2DSystemMode enum <%d>", rValue)); return -1; } return 0; }
const Graphics::TFont* TCustomFontsCache::load(const TCustomFont& font_) { const Key key = makeKey(font_); if (isLoaded(key) == true) { return loadedFonts.at(key).get(); } Entry& font = loadedFonts[key]; font.reset(new Graphics::TFont); string fontPath = font_.GetName(); if (font->loadFromFile(fontPath) == false) { #if defined(_DEBUG) GUI_THROW("Font file '" + fontPath + "' not found"); #else // TODO: ... #endif } return font.get(); }
int32 StringToValue<EParticle2DSystemMode>( const CGUIString& rString, EParticle2DSystemMode& rValue) { if( rString == "eParticle2DSystemMode_Gravity" ) { rValue = eParticle2DSystemMode_Gravity; } else if( rString == "eParticle2DSystemMode_Radius" ) { rValue = eParticle2DSystemMode_Radius; } else { GUI_THROW( GUI_FORMAT( "[StringToValue[EParticle2DSystemMode]]: string value format is wrong! <%s>", rString.c_str())); return -1; } return 0; }
//------------------------------------------------------------------------------ int32 CGUITiledMap::ParseTMXFile( const CGUIString& rFileName ) { Reset(); m_pMapInfo = new CGUITiledMapInfo; if( 0 != m_pMapInfo->InitWithTMXFile( rFileName ) ) { GUI_THROW( GUI_FORMAT("[CGUITiledMap::ParseTMXFile]: failed parse tmx file %s", rFileName.c_str() )); return -1; } for( uint32 i=0; i<m_pMapInfo->GetLayerInfos().size(); ++i ) { CGUITiledMapLayer* pLayer = new CGUITiledMapLayer( this, i ); m_arrayLayer.push_back( pLayer ); } return 0; }
int32 StringToValue<EScreenValue>( const CGUIString& rString, EScreenValue& rValue) { if( rString == "eScreenValue_Pixel" ) { rValue = eScreenValue_Pixel; } else if( rString == "eScreenValue_Percentage" ) { rValue = eScreenValue_Percentage; } else { GUI_THROW( GUI_FORMAT( "[StringToValue[EScreenValue]]: string value format is wrong! <%s>", rString.c_str())); return -1; } return 0; }
//------------------------------------------------------------------------------ int32 CGUIParticle2DSystemQuad::DoLoad() { if( 0 != CGUIParticle2DSystem::DoLoad() ) { return -1; } // allocating data space m_pQuads = new SVertexFormat_V2F_T2F_C4UB_Quad[m_uTotalParticles]; m_pIndices = new uint16[m_uTotalParticles * 6]; if( !m_pQuads || !m_pIndices ) { if( m_pQuads ) { delete[] m_pQuads; m_pQuads = NULL; } if(m_pIndices) { delete[] m_pIndices; m_pIndices = NULL; } GUI_THROW( " Particle system: not enough memory"); return -1; } // initialize only once the texCoords and the indices InitTexCoordsWithUVRect( CGUIRect(0.f,0.f,1.f,1.f) ); InitIndices(); #if CC_USES_VBO // create the VBO buffer glGenBuffers(1, &m_pQuadsID); // initial binding glBindBuffer(GL_ARRAY_BUFFER, m_pQuadsID); glBufferData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0])*m_uTotalParticles, m_pQuads,GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); #endif return 0; }
int32 StringToValue<EBlendFunc>( const CGUIString& rString, EBlendFunc& rValue) { if( rString == "eBlendFunc_ZERO" ) { rValue = eBlendFunc_ZERO; } else if( rString == "eBlendFunc_ONE" ) { rValue = eBlendFunc_ONE; } else if( rString == "eBlendFunc_SRC_COLOR" ) { rValue = eBlendFunc_SRC_COLOR; } else if( rString == "eBlendFunc_ONE_MINUS_SRC_COLOR" ) { rValue = eBlendFunc_ONE_MINUS_SRC_COLOR; } else if( rString == "eBlendFunc_SRC_ALPHA" ) { rValue = eBlendFunc_SRC_ALPHA; } else if( rString == "eBlendFunc_ONE_MINUS_SRC_ALPHA" ) { rValue = eBlendFunc_ONE_MINUS_SRC_ALPHA; } else if( rString == "eBlendFunc_DST_ALPHA" ) { rValue = eBlendFunc_DST_ALPHA; } else if( rString == "eBlendFunc_ONE_MINUS_DST_ALPHA" ) { rValue = eBlendFunc_ONE_MINUS_DST_ALPHA; } else { GUI_THROW( GUI_FORMAT( "[StringToValue[EBlendFunc]]: string value format is wrong! <%s>", rString.c_str())); return -1; } return 0; }
int32 StringToValue<EOrientation>( const CGUIString& rString, EOrientation& rValue) { if( rString == "eOrientation_Vertical" ) { rValue = eOrientation_Vertical; } else if( rString == "eOrientation_Horizontal" ) { rValue = eOrientation_Horizontal; } else { GUI_THROW( GUI_FORMAT( "[StringToValue[EOrientation]]: string value format is wrong! <%s>", rString.c_str())); return -1; } return 0; }
int32 StringToValue<bool>( const CGUIString& rString, bool& rValue) { if( rString == "true") { rValue = true; return 0; } else if ( rString == "false") { rValue = false; return 0; } else { GUI_THROW( GUI_FORMAT( "[StringToValue[bool]]: string value format is wrong! <%s>", rString.c_str())); return -1; } }