const sf::Font* ResourceManager::GetFont( const std::string& path ) { if( path.empty() ) { if( m_use_default_font ) { return &sf::Font::getDefaultFont(); } return NULL; } FontMap::const_iterator font_iter( m_fonts.find( path ) ); if( font_iter != m_fonts.end() ) { return font_iter->second.first; } // Try to load. ResourceLoader* loader( GetMatchingLoader( path ) ); if( !loader ) { if( m_use_default_font ) { return &sf::Font::getDefaultFont(); } return NULL; } const sf::Font* font( loader->LoadFont( GetFilename( path, *loader ) ) ); if( !font ) { return m_use_default_font ? &sf::Font::getDefaultFont() : NULL; } // Cache. m_fonts[path] = FontPair( font, true ); return font; }
const sf::Texture* ResourceManager::GetTexture( const std::string& path ) { TextureMap::const_iterator texture_iter( m_textures.find( path ) ); if( texture_iter != m_textures.end() ) { return texture_iter->second.first; } // Try to load. ResourceLoader* loader( GetMatchingLoader( path ) ); if( !loader ) { return NULL; } const sf::Texture* texture( loader->LoadTexture( GetFilename( path, *loader ) ) ); if( !texture ) { return NULL; } // Cache. m_textures[path] = TexturePair( texture, true ); return texture; }
std::shared_ptr<const sf::Image> ResourceManager::GetImage( const std::string& path ) { auto image_iter = m_images.find( path ); if( image_iter != m_images.end() ) { return image_iter->second; } // Try to load. auto loader = GetMatchingLoader( path ); if( !loader ) { return std::shared_ptr<const sf::Image>(); } auto image = loader->LoadImage( GetFilename( path, *loader ) ); if( !image ) { return std::shared_ptr<const sf::Image>(); } // Cache. m_images[path] = image; return image; }
std::shared_ptr<const sf::Font> ResourceManager::GetFont( const std::string& path ) { { auto font_iter = m_fonts.find( path ); if( font_iter != m_fonts.end() ) { return font_iter->second; } } if( path == "Default" ) { if( m_use_default_font ) { #if defined( SFGUI_INCLUDE_FONT ) auto font = std::make_shared<sf::Font>( LoadDejaVuSansFont() ); #else #if defined( SFGUI_DEBUG ) std::cerr << "SFGUI warning: No default font available. (SFGUI_INCLUDE_FONT = FALSE)\n"; #endif auto font = std::make_shared<sf::Font>(); #endif m_fonts[path] = font; return font; } return std::shared_ptr<const sf::Font>(); } // Try to load. auto loader = GetMatchingLoader( path ); if( !loader ) { std::shared_ptr<const sf::Font> font; if( m_use_default_font ) { auto font_iter = m_fonts.find( path ); if( font_iter == m_fonts.end() ) { #if defined( SFGUI_INCLUDE_FONT ) font = std::make_shared<sf::Font>( LoadDejaVuSansFont() ); #else #if defined( SFGUI_DEBUG ) std::cerr << "SFGUI warning: No default font available. (SFGUI_INCLUDE_FONT = FALSE)\n"; #endif font = std::make_shared<sf::Font>(); #endif m_fonts[path] = font; } else { font = font_iter->second; } } return font; } auto font = loader->LoadFont( GetFilename( path, *loader ) ); if( !font ) { if( m_use_default_font ) { auto font_iter = m_fonts.find( path ); if( font_iter == m_fonts.end() ) { #if defined( SFGUI_INCLUDE_FONT ) font = std::make_shared<sf::Font>( LoadDejaVuSansFont() ); #else #if defined( SFGUI_DEBUG ) std::cerr << "SFGUI warning: No default font available. (SFGUI_INCLUDE_FONT = FALSE)\n"; #endif font = std::make_shared<sf::Font>(); #endif m_fonts[path] = font; } else { font = font_iter->second; } } return font; } // Cache. m_fonts[path] = font; return font; }