SFML community forums
Help => Graphics => Topic started by: dabo on August 10, 2008, 01:00:21 pm
-
Hello, when updating to the newest svn my code won't compile anymore. Appending text could be done like this earlier:
sf::String sMessage("Hello");
std::string sNew("...");
sMessage.SetText(sMessage.GetText() + sNew);
But thanks to the new Unicode stuff ( :evil: :lol: ) it doesn't work anymore. I found an "operator std::string" but I don't know how to use it (or if that's the solution).
The unicode tutorial at the website is blank.
-
Try:
std::wstring w = L"TEXT1";
sf::String smsg(w);
smsg.SetText(w+std::wstring(L"TEXT2"));
The unicode stuff is working very well and is indeed making sense for multilingual applications...
-
But I would still need to get the std::string from the sf::Text instance. There must be a way, if not it should be added.
-
As the tutorial says, sf::String is purely graphical, it doesn't deal with string functions such as appending text etc. So in any case you need to first get the text of your sf::String, modify it, and put it back.
However, I admit the latest modifications make the syntax a little more difficult. But everything is much more flexible regarding encodings ;)
-
As the tutorial says, sf::String is purely graphical, it doesn't deal with string functions such as appending text etc. So in any case you need to first get the text of your sf::String, modify it, and put it back.
However, I admit the latest modifications make the syntax a little more difficult. But everything is much more flexible regarding encodings ;)
But how would it be done? I'm stuck.
-
Just cast the result of GetText() to any type of string you want, append the text, then put it back into the sf::String.
-
Ahh I see, it works perfectly.
-
Hi. I'm just study the problem because now I use VisualStudio9 and with it get the "Slow SetText conversion" problem.. I have a lot of small text to write.
For who need a more C++ style solution I can propose this:
std::wstringstream swss;
swss << mID; // int mID
sf::String sfs( swss.str() ); // dt=0.010
// using std::stringstream // dt=0.060
// without this instruction // dt=0.006
sfs.SetPosition(mX,mY);
sWindow->Draw(sfs);