SFML community forums

Help => Graphics => Topic started by: dabo on August 10, 2008, 01:00:21 pm

Title: Appending text
Post 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:

Code: [Select]
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.
Title: Appending text
Post by: zac on August 10, 2008, 04:01:44 pm
Try:
Code: [Select]

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...
Title: Appending text
Post by: dabo on August 11, 2008, 02:43:09 pm
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.
Title: Appending text
Post by: Laurent on August 12, 2008, 01:00:57 pm
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 ;)
Title: Appending text
Post by: dabo on August 12, 2008, 01:28:41 pm
Quote from: "Laurent"
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.
Title: Appending text
Post by: Laurent on August 12, 2008, 03:26:14 pm
Just cast the result of GetText() to any type of string you want, append the text, then put it back into the sf::String.
Title: Appending text
Post by: dabo on August 12, 2008, 04:18:13 pm
Ahh I see, it works perfectly.
Title: Appending text
Post by: fixus971 on August 23, 2008, 12:38:48 pm
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:

Code: [Select]

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);