wchar_t 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.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

wchar_t new line?

Post by JP »

Is it possible to put a new line in a wchar_t? I've tried the following:

L"blah\nblah"

but it just results in "blah blah" :?
Image Image Image
stef_
Posts: 53
Joined: Tue Apr 18, 2006 9:39 pm
Contact:

Post by stef_ »

Hi,

on my linux box:

Code: Select all

#include <stdio.h>
#include <wchar.h>

int main()
{
        wprintf(L"blah\nblah\n");

        return 0;
}
prints:
blah
blah

Bye
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

That works, but it doesn't work when i do it by passing it to a gui command.
Image Image Image
chaoslion
Posts: 25
Joined: Sun Oct 30, 2005 1:44 pm

Post by chaoslion »

nope it isnt working because the gui element isnt parsing the line, which you are about to add. You may need to create a new element and go through the string and if you find a \n you simply create a new line and add the rest of the string after \n...
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

I couldn't get the XML writer to write wide \n's for some reason, they'd always end up as one char...
however, L"\u000D\u000A" seems to work okay, at least here in windows. I didn't really investigate why, it was a trial and error thing
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Compiler tells me \u000D and \u000A are not valid universal characters!

(using dev-c++)
Image Image Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

L"\u000D\u000A" seems to work okay, at least here in windows
Maybe with your version of the compiler...

Code: Select all

C:\>type t.cpp && cl /c t.cpp
#include <wchar.h>
#include <stdio.h>

int main(void)
{
  return wprintf(L"\u000d\u000a");
}

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.00.9466 for 80x86
Copyright (C) Microsoft Corporation 1984-2001. All rights reserved.

t.cpp
t.cpp(6) : warning C4129: 'u' : unrecognized character escape sequence
t.cpp(6) : warning C4129: 'u' : unrecognized character escape sequence
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

So is there an easy way of accomplishing the task of doing a newline / CR / LF in a staticText? Haven't tried an edit box yet but I'm assuming the same things happens when trying to do a standard "\n".

Currently I'm using a listbox because I was tired of wasting time looking through code and chat examples.

Anyone? Thanks in advance for any replies.
Image
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

hmm looks like \x works instead of \u, can't try with irrlicht til i get home though
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

bitplane wrote:hmm looks like \x works instead of \u, can't try with irrlicht til i get home though
I'll try that in a bit. Thanks for the response ;).
Image
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

That doesn't work either :(
Image Image Image
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

JP wrote:That doesn't work either :(
Damn, I thought you figured it out by now JP ;). It's pretty odd that you can't do any type of newline type stuff on a staticText (and edit box?). And pretty frustrating too. There's gotta be a simple way of doing it...

Xhrit from IRC showed me an example that parses the text but I haven't tried it yet (or tried to understand it yet for that matter):

Code: Select all

for ( int i = 0; i < (*m_sim).messages.size(); i++){
	dataStream.str("");
	dataStream.clear();

	dataStream << (*m_sim).messages[i].strMessageText << flush;
	result = result + "\n" + dataStream.str();
}

swtmp = result.c_str();
wstmp = swtmp.c_str();
m_textbox_message_text->setText(wstmp);
m_textbox_message_text->setLineFeed();
Image
stef_
Posts: 53
Joined: Tue Apr 18, 2006 9:39 pm
Contact:

Post by stef_ »

My 2 cents.

Looking in irrlicht source the drawing text routine is CGUIFont::draw(...) in
CGUIFont.cpp.

It does:

Code: Select all

        while(*text)
        {
                n = (*text) - 32;
                if ( n > Positions.size())
                        n = WrongCharacter;

                Driver->draw2DImage(Texture, offset, Positions[n], clip, color, true);

                offset.X += Positions[n].getWidth();

                ++text;
        }
So, how can it understands your "\n"?

Bye
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Okay, it doesn't work for writing text using CGUIText, line breaks have to be inserted manually. see breakText() in CGUIStaticText.
it compares the text to a L'\n', which I is held internally as a token eg 0x000a (depending on compiler?) until its written out then its converted.. unless of course you're writing out to disk in binary mode (which the xml writer does), then the internal representation is written out.
in text mode \x0a's are replaced with the platform specific \n characters

using guiStaticText->setText(L"Some\nNewline") works fine for me, how were you using it JP?
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

bitplane wrote:Okay, it doesn't work for writing text using CGUIText, line breaks have to be inserted manually. see breakText() in CGUIStaticText.
it compares the text to a L'\n', which I is held internally as a token eg 0x000a (depending on compiler?) until its written out then its converted.. unless of course you're writing out to disk in binary mode (which the xml writer does), then the internal representation is written out.
in text mode \x0a's are replaced with the platform specific \n characters

using guiStaticText->setText(L"Some\nNewline") works fine for me, how were you using it JP?
If I used it like you said (and like I was trying initially), it prints out a [] (box) character. No screenies atm but I can show one later. I'm using Dev-C++ with gcc (g++) to compile it on windows.

I'll take a look at breakText a bit later. Thanks bitplane.
Image
Post Reply