Page 1 of 1

wchar_t and new line

Posted: Tue Jul 07, 2009 2:11 pm
by crosel
Ok so im trying to display the "objectives" of my game only when tab is being pressed. Font->draw() can do this for me. However, it needs to be in wchar_t format.

So i created a string like so:

Code: Select all

stringw objectiveText("Press 'Left Click' To fire.\n"
		"Kill 5 enemy's to proceed.\n"
		"Press 'E' to activate the teleportation sphere.\n"
		"Press 'Escape' to quit.");
I then convert this string to wchar_t and then draw it.

Code: Select all

	const wchar_t * wide = objectiveText.c_str(); 

	if(drawObjective == true)
	{
		font->draw(wide,
		core::rect<s32>(125,10,200, 200), 
		SColor(255,1,1,255));
	}
However, this doesnt work. it doesnt recongise the \n for a new line. Is there a way to correct this?

Also, how would i go about display a int in a wchar_t? as im assuing "%d" wont work with this either.. This is so i can display something like "score: 5"

Thanks

Posted: Tue Jul 07, 2009 3:04 pm
by Acki
I'm not sure, but AFAIK the font->draw methode ignores escape sequences, so You'll have to parse the string and split it at new lines on your own...

for adding numeric values you'll have to do it this way:

Code: Select all

int theValue = 666;
stringw theString = L"the number is: "; // don't forget the L in front of the string
theString += theValue;
and btw you don't need to create a wchat_t out of the string, you can use it directly:

Code: Select all

      font->draw(objectiveText.c_str(),
      core::rect<s32>(125,10,200, 200),
      SColor(255,1,1,255));

Posted: Tue Jul 07, 2009 3:10 pm
by hybrid
Better use the IGUIStaticText for this purpose, which handles line wrapping etc.
@Acki: He doesn't convert to wchar_t, just takes the pointer to the string...

Posted: Tue Jul 07, 2009 3:26 pm
by Acki
hybrid wrote:@Acki: He doesn't convert to wchar_t, just takes the pointer to the string...
either case he doesn't need to.. ;)

Posted: Wed Jul 08, 2009 12:21 am
by crosel
Hey guys,

Thanks for the advice.

Using GUIStaticText is better for me to draw the text, but my problem is i cant get rid of the text.

I need it to show only at a certain time (when tab is pressed).

Is it possible to do this, with staticText? Hide doesnt seem to work :P

Posted: Wed Jul 08, 2009 12:24 am
by CuteAlien
yourStatic->setVisible(false) should work.
You can also delete the content by setting an empty string: yourStatic->setText(L"");

Posted: Wed Jul 08, 2009 1:27 am
by crosel
works perfectly. TY so much :D

Posted: Wed Jul 08, 2009 1:27 am
by Acki
or remove it and create a new one when needed... :lol:
ok, the smartest probably is to hide it (setVisible)... ;)