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; }
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; }
//------------------------------------------------------------------------------ void CGUIWgtParticle2D::SetParticle2D( const CGUIString& rParticle2DName ) { GUI_TRACE( GUI_FORMAT( "[CGUIWgtParticle2D::SetParticle2D]: play particle %s", rParticle2DName.c_str())); if( rParticle2DName.empty() ) { //clear SetParticle2D( NULL ); } else { CGUIParticle2DSystem* pParticle2D = CGUIParticle2DManager::Instance()->AllocateResource( rParticle2DName ); SetParticle2D( pParticle2D ); pParticle2D->RefRelease(); } }
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 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 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<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 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<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 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<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; } }
int32 StringToValue<EInterpolationType>( const CGUIString& rString, EInterpolationType& rValue) { if( rString == "eInterpolationType_Linear" ) { rValue = eInterpolationType_Linear; } else if( rString == "eInterpolationType_EaseIn" ) { rValue = eInterpolationType_EaseIn; } else if( rString == "eInterpolationType_EaseInOut" ) { rValue = eInterpolationType_EaseInOut; } else { GUI_THROW( GUI_FORMAT( "[StringToValue[EInterpolationType]]: string value format is wrong! <%s>", rString.c_str())); return -1; } return 0; }
int32 StringToValue<ETextAlignmentHorz>( const CGUIString& rString, ETextAlignmentHorz& rValue) { if( rString == "eTextAlignment_Horz_Left" ) { rValue = eTextAlignment_Horz_Left; } else if( rString == "eTextAlignment_Horz_Right" ) { rValue = eTextAlignment_Horz_Right; } else if( rString == "eTextAlignment_Horz_Center" ) { rValue = eTextAlignment_Horz_Center; } else { GUI_THROW( GUI_FORMAT( "[StringToValue[ETextAlignmentHorz]]: string value format is wrong! <%s>", rString.c_str())); return -1; } return 0; }
int32 StringToValue<ETextAlignmentVert>( const CGUIString& rString, ETextAlignmentVert& rValue) { if( rString == "eTextAlignment_Vert_Up" ) { rValue = eTextAlignment_Vert_Up; } else if( rString == "eTextAlignment_Vert_Down" ) { rValue = eTextAlignment_Vert_Down; } else if( rString == "eTextAlignment_Vert_Center" ) { rValue = eTextAlignment_Vert_Center; } else { GUI_THROW( GUI_FORMAT( "[StringToValue[ETextAlignmentVert]]: string value format is wrong! <%s>", rString.c_str())); return -1; } return 0; }
int32 StringToValue<CGUIColor>( const CGUIString& rString, CGUIColor& rValue) { //string should have format as "r,g,b,a" std::vector<CGUIString> aListString= StringToVector(rString); if( aListString.size() != 4 ) { GUI_THROW( GUI_FORMAT( "[StringToValue[CGUIColor]]: string value format is wrong! <%s>", rString.c_str())); return -1; } uint8 nColor; StringToValue(aListString[0], nColor ); rValue.SetRed( nColor / 255.0f ); StringToValue(aListString[1], nColor ); rValue.SetGreen( nColor / 255.0f ); StringToValue(aListString[2], nColor ); rValue.SetBlue( nColor / 255.0f ); StringToValue(aListString[3], nColor ); rValue.SetAlpha( nColor / 255.0f ); return 0; }
//------------------------------------------------------------------------------ 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) }
//------------------------------------------------------------------------------ void UpdateGridProperty( wxPropertyGridManager* pSheetMgr, CGUIWidget* pWidget, const CGUIString& rPropertyName, const CGUIString& rPropertyType ) { const CGUIProperty& rSet = CPropertyConfigMgr::Instance()->GetPropertySet(pWidget->GetType()); const CGUIProperty* pDefaultProp = rSet.GetProperty(rPropertyName, rPropertyType); if( !pDefaultProp ) { throw CGUIException( "[UpdateGridProperty]: failed to get default property by name <%s>", rPropertyName.c_str() ); } pWidget->DumpToProperty(); const CGUIProperty* pProp = pWidget->GetProperty().GetProperty(rPropertyName, rPropertyType); if( !pProp ) { throw CGUIException( "[UpdateGridProperty]: failed to get property by name <%s> from widget <%s>", rPropertyName.c_str(), pWidget->GetName().c_str() ); } CGUIProperty aProp = *pProp; aProp.SetData( pDefaultProp->GetData() ); CPropertyConvertorMgr::Instance()->GuiProperty2GridProperty( pSheetMgr, NULL, aProp ); }
//------------------------------------------------------------------------------ int IGUIStringConv_iconv::Utf8ToWChar( const CGUIString& rSrc, CGUIStringW& rDst ) { if( rSrc.empty()) { rDst.clear(); return 0; } //open iconv iconv_t cd = iconv_open ("UTF-16LE", "UTF-8"); if( cd == (iconv_t)-1 ) { throw CGUIException( "[MultiByteToWideChar]: failed to open iconv, errno is %d", errno); return -1; } //convert size_t buf_size = rSrc.size()+1; size_t inbytesleft = rSrc.size(); size_t outbytesleft = buf_size; char* dst = (char*)(new wchar[buf_size]); char* pOutBuf = NULL; char* pInBuf = (char*)(rSrc.c_str()); bool bError = false; while(inbytesleft > 0) { pOutBuf = dst; outbytesleft = buf_size*sizeof(wchar); size_t retbytes = iconv(cd, &pInBuf, &inbytesleft, &pOutBuf, &outbytesleft); if (dst != pOutBuf) { // wchar is 4byte in mac, but iconv return a "utf-16" buff which is 2byte per code if (sizeof(wchar) == 4) { for (int iChar = 0; iChar < (pOutBuf-dst)/2; iChar++) { unsigned short* pU16Char = (unsigned short*)&dst[2*iChar]; rDst.push_back((wchar)*pU16Char); } } else if (sizeof(wchar) == 2) { rDst.append((wchar*)dst, (pOutBuf-dst)/sizeof(wchar)); } } //check ret if( retbytes == size_t(-1) ) { if( errno == E2BIG ) { continue; } else { bError = true; break; } } else { //success break; } } delete[] dst; if( bError) { switch(errno) { case EILSEQ: throw CGUIException( "[MultiByteToWideChar]: failed to iconv, errno is EILSEQ"); return -1; case EINVAL: throw CGUIException( "[MultiByteToWideChar]: failed to iconv, errno is EINVAL"); return -1; default: throw CGUIException( "[MultiByteToWideChar]: failed to iconv, errno is %d", errno); return -1; } } //close iconv int ret = iconv_close(cd); if( ret == -1 ) { throw CGUIException( "[MultiByteToWideChar]: failed to close iconv, errno is %d", errno); return -1; } return 0; }
//------------------------------------------------------------------------------ bool CGUIMusicData_openal::LoadOggFile( const CGUIString& rFilename ) const { //open file FILE *pFile = fopen( rFilename.c_str(), "rb" ); if( !pFile) { return false; } ov_callbacks sCallbacks; sCallbacks.read_func = ov_read_func; sCallbacks.seek_func = ov_seek_func; sCallbacks.close_func = ov_close_func; sCallbacks.tell_func = ov_tell_func; if (ov_open_callbacks(pFile, &m_aVorbisFile, NULL, 0, sCallbacks) != 0) { fclose( pFile ); return false; } // Get some information about the file (Channels, Format, and Frequency) if( false == GetOggVorbisInfo( &m_aVorbisFile, &m_nFrequency, &m_nFormat, &m_nFormat, &m_nBufferSize ) ) { ov_clear(&m_aVorbisFile); return false; } // Allocate a buffer to be used to store decoded data for all Buffers m_pDecodeBuffer = (char*)malloc(m_nBufferSize); if ( !m_pDecodeBuffer ) { ov_clear(&m_aVorbisFile); return false; } // Generate a Source to playback the Buffers alGenSources(1, &m_nSourceId); if (alGetError() != AL_NO_ERROR) { return false; } // Generate some AL Buffers for streaming alGenBuffers( GUI_MUSIC_NUMBUFFERS, m_nBuffers ); if (alGetError() != AL_NO_ERROR) { return false; } // Fill all the Buffers with decoded audio data from the OggVorbis file for (int iLoop = 0; iLoop < GUI_MUSIC_NUMBUFFERS; iLoop++) { unsigned long ulBytesWritten = DecodeOggVorbis(&m_aVorbisFile, m_pDecodeBuffer, m_nBufferSize, m_nChannels); if (ulBytesWritten) { alBufferData(m_nBuffers[iLoop], m_nFormat, m_pDecodeBuffer, ulBytesWritten, m_nFrequency); alSourceQueueBuffers(m_nSourceId, 1, &m_nBuffers[iLoop]); } } return true; }
//------------------------------------------------------------------------------ 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; }
int32 StringToValue<real>( const CGUIString& rString, real& rValue) { rValue = static_cast<real>(strtod(rString.c_str(), 0)); return 0; }
/** * @brief read config file and load data */ int32 CGUIConfigFileLoader::LoadResourceConfigFile( const CGUIString& rPath, const CGUIString& rSceneName) { //get interface of config file IGUIInterfaceConfigFile* pConfigFile = CGUIInterfaceManager::Instance()->GetInterfaceConfigFile(); if( !pConfigFile ) { GUI_THROW( "[LoadResourceConfigFile]: failed to get interface <IGUIConfigFile>!"); } //get property set CGUIProperty aPropertySet; if( 0 != pConfigFile->LoadConfigFile(rPath, aPropertySet) ) { GUI_THROW( GUI_FORMAT( "[LoadResourceConfigFile]: failed to load config file <%s : %s>!", rSceneName.c_str(), rPath.c_str())); } //parse it uint32 nSize = aPropertySet.GetPropertyCount(); for( uint32 i=0; i<nSize; ++i ) { const CGUIProperty* pProperty = aPropertySet.GetProperty(i); CGUIResourceManagerBase* pResourceManager = NULL; switch( pProperty->GetType() ) { case ePropertyType_Set: if( 0 != DoLoadConfig_Set( pProperty, rSceneName )) { return -1; } break; case ePropertyType_ImageDefine: pResourceManager = CGUIImageManager::Instance(); break; case ePropertyType_AnimationDefine: pResourceManager = CGUIAnimationManager::Instance(); break; case ePropertyType_FontDefine: pResourceManager = CGUIFontManager::Instance(); break; case ePropertyType_SoundDefine: pResourceManager = CGUISoundManager::Instance(); break; case ePropertyType_MusicDefine: pResourceManager = CGUIMusicManager::Instance(); break; case ePropertyType_AsDefine: pResourceManager = CGUIAsManager::Instance(); break; case ePropertyType_ShaderDefine: pResourceManager = CGUIShaderManager::Instance(); break; case ePropertyType_Particle2DDefine: pResourceManager = CGUIParticle2DManager::Instance(); break; case ePropertyType_TiledMapDefine: pResourceManager = CGUITiledMapManager::Instance(); break; default: { GUI_THROW( GUI_FORMAT( "[LoadResourceConfigFile], unknown property type <%s:%s:%s>", pProperty->GetName().c_str(), pProperty->GetTypeAsString().c_str(), pProperty->GetValue().c_str())); } return -1; } if( pResourceManager ) { if( 0 != pResourceManager->RegisterResource( rSceneName, *pProperty ) ) { GUI_THROW( GUI_FORMAT( "[CGUIConfigFileLoader::LoadResourceConfigFile], failed to register resource with name <%s:%s:%s>!", pProperty->GetName().c_str(), pProperty->GetTypeAsString().c_str(), pProperty->GetValue().c_str())); return -1; } } } return 0; }