Public Group

# ID3DXFont - Muliple Lines

This topic is 4132 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How would I get a string to display on multiple lines. I have made sure the rectangle is large enough to fit both lines, and have inserted the \n in the string where I want the new line, but still it displays on one line and actually shows the /n in the string that is rendered on the screen. Any ideas?

##### Share on other sites
can't think off the top of my head, i don't think i've tried to do it on two lines. you may have to write a function to parse the string for carraige returns and then write to a new line.

##### Share on other sites
I don't think there's any native support for multi-lined strings. This means that you'll probably have to parse the string yourself if you want to handle things like line breaks and other control characters. If all you care about is wrapping to the next line when space on the current one runs out, just keep a count of the width of the characters as they are printed and translate down a character when it's time for a new row.

You only need to do this whenever the text changes, and then store the "formatted" results in a vector of strings, one string per line, so it won't be a big performance hit. I did something much like this when working on a GL gui library, and can give you some more tips if you need them, but the ID3DXFont specifics will have to come from someone else.

Hope this helps!
-jouley

##### Share on other sites
The strings are being read in from an XML file, which is passing the string in as /n, as in two characters instead of the newline character. It looks as if i'm either going to have to find a method to parse a char array, to the C++ rules so that /n = newline in much the same way as it does with the code we write.

Or I'm going to have to write a method myself.

anyone know of such a function?, I'm sure there is one there somewhere as the compiler must use it when it parses strings.

##### Share on other sites
Quote:
 Original post by gunner_uk2000The strings are being read in from an XML file, which is passing the string in as /n, as in two characters instead of the newline character. It looks as if i'm either going to have to find a method to parse a char array...

Firstly, do the strings contain /n or \n?

Secondly, since you're using C++, I'd go with a std::string, instead of a char array. Check it:
#include <string>#include <vector>int main( ){	std::string strInput = "hello\nthis is a\nnew line.";	std::vector<std::string> vecToDisplay;	int nPos = strInput.find_first_of('\n');	while (nPos != -1)	{		vecToDisplay.push_back(strInput.substr(0, nPos));		strInput.erase(0, nPos + 1);		nPos = strInput.find_first_of('\n');	}	vecToDisplay.push_back(strInput.substr(0, nPos));	for (int i =0; i < vecToDisplay.size( ); ++i)		std::cout << vecToDisplay << "\n";    return 0;}

There are certainly other ways of doing it, but that one's pretty simple and straightforward.

##### Share on other sites
From the DX docs:
Quote:
 All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.
So, if you're using \n, DrawText() should manage multiple lines itself, unless you've told it not to.

##### Share on other sites
Quote:
Original post by Evil Steve
From the DX docs:
Quote:
 All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.
So, if you're using \n, DrawText() should manage multiple lines itself, unless you've told it not to.

Whoops. I stand by my firstly.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 30
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631408
• Total Posts
2999922
×