Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Appending text  (Read 5278 times)

0 Members and 1 Guest are viewing this topic.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Appending text
« 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.

zac

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Appending text
« Reply #1 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...

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Appending text
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Appending text
« Reply #3 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 ;)
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Appending text
« Reply #4 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Appending text
« Reply #5 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.
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Appending text
« Reply #6 on: August 12, 2008, 04:18:13 pm »
Ahh I see, it works perfectly.

fixus971

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
    • http://www.fixweb.it
Appending text
« Reply #7 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);
^_^=>Il calcolatore รจ straordinariamente veloce, accurato e stupido. Gli uomini sono incredibilmente lenti, imprecisi e creativi. L'insieme dei due costituisce una forza incalcolabile. (Albert Einstein)