本文整理汇总了C++中sf::String类的典型用法代码示例。如果您正苦于以下问题:C++ String类的具体用法?C++ String怎么用?C++ String使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了String类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void LogManager::SetLogFile(const sf::String& logFile)
{
myLogFile.open(logFile.ToAnsiString().c_str(), std::ios::out | std::ios::trunc);
if (!myLogFile)
std::cerr << "Impossible d'ouvrir le fichier " << logFile.ToAnsiString() << std::endl;
}
示例2: breakTextLines
void breakTextLines(sf::Text& t, float maxX)
{
sf::String s = t.getString();
std::size_t lastBreakCharIdx = s.getSize();
static sf::String const breakBeforeChars("([{\"'`'");
static auto const isBreakBeforeChar = [] (sf::Uint32 c) {
return breakBeforeChars.find(c) != sf::String::InvalidPos;
};
for (std::size_t i = 0; i < s.getSize(); ++i) {
if (t.findCharacterPos(i).x > maxX) {
if (lastBreakCharIdx > i)
lastBreakCharIdx = i;
if (s.getSize() > lastBreakCharIdx &&
!std::iswgraph(static_cast<std::wint_t>(s[lastBreakCharIdx + 1]))
) {
s[lastBreakCharIdx + 1] = '\n';
} else {
s.insert(lastBreakCharIdx + 1, '\n');
}
t.setString(s);
i += 1;
}
if (!std::iswalnum(static_cast<std::wint_t>(s[i]))) {
lastBreakCharIdx = i;
if (i > 0 && isBreakBeforeChar(s[i]))
lastBreakCharIdx -= 1;
}
}
}
示例3: lire_Texte
void Param::lire_Texte(std::ifstream &fichier, sf::String &destination, sf::Font &myFont)
{
std::string ligne;
int x, y, z;
lire_string(fichier, ligne);
destination.SetText(traduire(ligne.c_str()));
lire_position(fichier, x, y);
destination.SetPosition(x, y);
lire_string(fichier, ligne);
if(ligne != "default" && !myFont.LoadFromFile(ligne))
{
std::cerr << "Erreur lors du chargement de la police '" << ligne << "'" << std::endl;
myFont = sf::Font::GetDefaultFont();
}
else if(ligne == "default")
myFont = sf::Font::GetDefaultFont();
lire_int(fichier, x);
destination.SetSize(x);
lire_string(fichier, ligne);
set_police(destination, ligne.c_str());
lire_couleur(fichier, x, y, z);
destination.SetColor(sf::Color(x, y, z));
lire_int(fichier, x);
destination.SetRotation(x);
}
示例4: drawScore
void drawScore(sf::RenderWindow& App, Player* player, sf::String& KillCount,
sf::String& Timer, sf::String& HP, sf::String& Score, int running_time)
{
std::stringstream kill, s2, s3, s4;
kill << player->getKill();
KillCount.SetText("Kills: " + kill.str());
App.Draw(KillCount);
s2 << (int)running_time;
std::string time_string;
s2 >> time_string;
Timer.SetText("Time: " + time_string);
App.Draw(Timer);
s3 << player->getHealth()/100;
std::string hp_string;
s3 >> hp_string;
HP.SetText("HP: " + hp_string);
App.Draw(HP);
s4 << player->getKill() + (int)running_time;
std::string score_string;
s4 >> score_string;
Score.SetText("Score: " + score_string);
}
示例5: str
VALUE wrap< sf::String >(const sf::String &cstr )
{
std::string str(cstr.begin(),cstr.end());
#ifdef HAVE_RUBY_ENCODING_H
return rb_enc_str_new(str.c_str(),strlen(str.c_str()),rb_utf8_encoding());
#else
return rb_str_new2(str.c_str());
#endif
}
示例6: toDebugLog
void toDebugLog(const sf::String &pStr)
{
#ifndef DEBUG
std::ofstream lfile;
lfile.open(gDebugLog.ToAnsiString(), std::ios::app);
lfile<<pStr.ToAnsiString()<<std::endl;
lfile.close();
#else
//std::cout<<pStr.ToAnsiString()<<std::endl;
#endif
}
示例7: set_string_position
void KeyboardMenu::set_string_position(sf::String &string, int v_pos, int screen_width)
{
if( default_hpos == HorizontalPositions::LEFT )
{
string.SetPosition(10, v_pos);
}
else
{
string.SetPosition(screen_width - string.GetRect().GetWidth() - 10, v_pos);
}
}
示例8: parseDataFile
std::map<sf::String, sf::String> parseDataFile(const sf::String &pFile)
{
std::map<sf::String, sf::String> lReturn;
std::ifstream t(pFile.ToAnsiString());
if(!t.is_open())
return lReturn;
std::string str;
t.seekg(0, std::ios::end);
str.reserve(t.tellg());
t.seekg(0, std::ios::beg);
str.assign((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
std::string lStrData(str);
lStrData.erase(std::remove_if(lStrData.begin(), lStrData.end(), ::isspace), lStrData.end());
std::vector<std::string> lLine = split(lStrData, ';');
for(int i = 0; i < lLine.size(); i++)
{
std::vector<std::string> lValue = split(lLine.at(i), '=');
lReturn[lValue.at(0)] = lValue.at(1);
}
return lReturn;
}
示例9: getAllFolders
std::vector<std::string> getAllFolders(const sf::String &pFolder)
{
DIR *lDir;
struct dirent *ent;
std::vector<std::string> mReturn;
// *********** IMAGE LOADING ****/////////////////////////
lDir = opendir (pFolder.ToAnsiString().c_str());
if (lDir != NULL)
{
/* print all the files and directories within directory */
while ((ent = readdir (lDir)) != NULL)
{
if(ent->d_type == DT_DIR)
{
sf::String lStr(ent->d_name);
if(lStr == "." || lStr == "..")
continue;
mReturn.push_back(lStr.ToAnsiString());
}
}
closedir (lDir);
}
return mReturn;
}
示例10: sendSfString
void PC::sendSfString(Entity* entity, sf::String message)
{
playButtonSound();
if(message.getSize() <= 5)
{
msfString = message;
}
}
示例11: initDebugLog
void initDebugLog()
{
#ifndef DEBUG
std::ofstream lfile;
lfile.open(gDebugLog.ToAnsiString(), std::ios::out);
lfile.close();
#endif
}
示例12: glGetUniformLocation
void Program::Send(const sf::String& name, float value)
{
if (!myIsLinked)
return;
GLint loc = glGetUniformLocation(myProgram, name.ToAnsiString().c_str());
glUseProgram(myProgram);
glUniform1f(loc, value);
}
示例13: vShader
// Program class
Program::Program(const sf::String& vertex, const sf::String& fragment)
: myIsLinked(false)
{
myProgram = glCreateProgram();
if (!vertex.IsEmpty())
{
Shader vShader(Shader::VERTEX_SHADER, vertex);
Attach(vShader);
}
if (!fragment.IsEmpty())
{
Shader fShader(Shader::FRAGMENT_SHADER, fragment);
Attach(fShader);
}
if (!fragment.IsEmpty() || !vertex.IsEmpty())
Link();
}
示例14: fixResourceName
// enforces limitations on XMPP resource name
static sf::String fixResourceName (const sf::String & s) {
// max 63 characters, no empties, no '/'
sf::String result;
for (size_t i = 0; i < 64 && i < s.length(); i++) {
char c = s[i];
if (c != '/' && c != '.' && c != '_' && c != ' '&& c >= 32 && c < 128) result += c;
}
if (result.empty()) result = "SF";
return result;
}
示例15:
ResourceCache::ResourceCache(sf::String& contentDirectory)
{
gLogger.Write("Resource Cache: Created");
ContentDirectory = contentDirectory.ToAnsiString();
gLogger.Write("Resource Cache: Directory: " + ContentDirectory);
}