void WrapText(Face* face, const rString& text, const rSize& size, std::function<void(Glyph**, size_t, int, int)> wordFunc){ std::vector<Font::Glyph*> wordGlyphs; int xPos = 0; int yPos = face->GetAscender(); int wordWidth = 0; int spaceLeft = size.x; int lineCount = 0; for (size_t i = 0; i < text.size(); i++){ int c = text[i]; if (c == '\n'){ if (wordWidth > spaceLeft){ //current word will not fit on this line yPos += face->GetLineHeight(); xPos = 0; } wordFunc(wordGlyphs.data(), wordGlyphs.size(), xPos, yPos); wordGlyphs.clear(); yPos += face->GetLineHeight(); xPos = 0; spaceLeft = size.x; wordWidth = 0; } else{ Font::Glyph* glyph = face->GetGlyph(c); if (c == ' '){ if (wordWidth + glyph->advance > spaceLeft){ //current word will not fit on this line yPos += face->GetLineHeight(); xPos = 0; spaceLeft = size.x; } wordFunc(wordGlyphs.data(), wordGlyphs.size(), xPos, yPos); wordGlyphs.clear(); spaceLeft -= wordWidth + glyph->advance; xPos += wordWidth + glyph->advance; wordWidth = 0; } else{ wordWidth += glyph->advance; wordGlyphs.push_back(glyph); } } } if (wordGlyphs.size() > 0){ wordFunc(wordGlyphs.data(), wordGlyphs.size(), xPos, yPos); wordGlyphs.clear(); } }
ruiOverlayLoader::ruiParseItemMethod ruiOverlayLoader::GetParseItemMethod (const rString& itemName){ rString item = itemName; for (size_t i =0; i < itemName.size(); i++) item[i] = tolower(itemName[i]); if (s_parseItemMap.count(item)) return s_parseItemMap[item]; else return NULL; }
rString gfx::MaterialBank::GetDir(rString& filename) { bool found = false; for (int i = static_cast<int>(filename.size()); i > 0; i--) { if (filename.c_str()[i] == '/' || filename.c_str()[i] == '\\' ) found = true; if (!found) { filename.erase(i); } } return filename; }
rString gfx::ShaderProgram::GetDir ( rString filename ) { bool found = false; for ( int i = static_cast<int> ( filename.size() ); i > 0; i-- ) { if ( filename.c_str() [i] == '/' ) { found = true; } if ( !found ) { filename.erase ( i ); } } return filename; }
rString gfx::TextureAtlas::GetDir ( rString str ) { bool found = false; for ( int i = static_cast<int> ( str.size() ); i > 0; i-- ) { if ( str.c_str() [i] == '/' ) { found = true; } if ( !found ) { str.erase ( i ); } } return str; }