wchar_t and new line

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
crosel
Posts: 11
Joined: Fri May 29, 2009 6:53 am

wchar_t and new line

Post 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
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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));
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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...
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post 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.. ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
crosel
Posts: 11
Joined: Fri May 29, 2009 6:53 am

Post 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
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

yourStatic->setVisible(false) should work.
You can also delete the content by setting an empty string: yourStatic->setText(L"");
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
crosel
Posts: 11
Joined: Fri May 29, 2009 6:53 am

Post by crosel »

works perfectly. TY so much :D
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

or remove it and create a new one when needed... :lol:
ok, the smartest probably is to hide it (setVisible)... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply