Page 1 of 2

wchar_t new line?

Posted: Fri Oct 27, 2006 6:36 pm
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" :?

Posted: Sat Oct 28, 2006 11:59 am
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

Posted: Sat Oct 28, 2006 6:22 pm
by JP
That works, but it doesn't work when i do it by passing it to a gui command.

Posted: Sat Oct 28, 2006 6:30 pm
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...

Posted: Sat Oct 28, 2006 6:54 pm
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

Posted: Sat Oct 28, 2006 7:17 pm
by JP
Compiler tells me \u000D and \u000A are not valid universal characters!

(using dev-c++)

Posted: Sat Oct 28, 2006 9:44 pm
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

Posted: Tue Oct 31, 2006 7:06 am
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.

Posted: Tue Oct 31, 2006 10:30 am
by bitplane
hmm looks like \x works instead of \u, can't try with irrlicht til i get home though

Posted: Tue Oct 31, 2006 4:44 pm
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 ;).

Posted: Tue Oct 31, 2006 6:07 pm
by JP
That doesn't work either :(

Posted: Tue Oct 31, 2006 6:19 pm
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();

Posted: Tue Oct 31, 2006 6:46 pm
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

Posted: Tue Oct 31, 2006 7:21 pm
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?

Posted: Tue Oct 31, 2006 8:00 pm
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.