#### Archived

This topic is now archived and is closed to further replies.

# Making text do what i want it to do. sounds greedy huh.

## Recommended Posts

Nibbles    569
Hi, I'm having a problem with displaying text using NeHe's code. You can see my problem Here. What I'm trying to do is to test the text with boundaries to see if should wrap around to the next line. I'd appreciate any help. btw: the text in the screenshot is just for an example, it's really not gonna be that cheesy Thanks, Scott Email Website
"If you try and don't succeed, destroy all evidence that you tried." Edited by - wojtos on October 16, 2001 1:56:57 AM

##### Share on other sites
XaOs    122
Hey Scott!!

Just check your length off the text lines, and if they goes
out of your predefined bounderies....just instert a newline!

That should be easy enough.... he he he....

Take Care!

- -- ---[XaOs]--- -- -

[ project fy ]

##### Share on other sites
Nibbles    569
ok, but how do i check the length? I never did spend much time playing with strings

for example:
char *s;
s = "hello";

how do i parse s to see how many characters are in it? and also, if they''re are any spaces.

thanks,
Scott

##### Share on other sites
barazor    122
you can use strlen(stringname) to find the length, and to find spaces loop through the string and look for '' '' characters...

##### Share on other sites
HardSniper    122
just look at the screenshot...

like for the first objective, start a new line after ''at''

HardSniper

##### Share on other sites
Authustian    125
i think this code will work for ya

  include char *s;s="hello";int length = strlen(s); // length = 5

-------------------------------------------------
Don''t take life too seriously, you''''ll never get out of it alive. -Bugs Bunny

##### Share on other sites
ThomW    122
It would actually be more complicated than that. You would want to make sure the text doesn''t wrap in the middle of a word.

To do this, you will want to know how many characters fit on a line. Start at that character in your string and walk through the characters in your string backwards from that point and find the first space. Print everything up to that space on that line, truncate the string (remove the space as well) and repeat until everything in your string is printed.

When you''re done with that, visit LMNOpc and download Bitmap Font Builder to make some cool fonts for your program.

Good luck!

ThomW
www.LMNOpc.com

##### Share on other sites
Nibbles    569
Alrighty... I have no idea how to find out how long a string is... in pixels that is. Finding out how many characters is simple (thank you Authustian), but now I have to find out how "wide" each letter is.

Thanks,
Scott

##### Share on other sites
Guest Anonymous Poster
Er, surely you know how ''wide'' a character is because you drew it to the screen?

##### Share on other sites
ThomW    122
woj -

If you use textures created by Bitmap Font Builder, you can export a file containing the widths of each character in pixels, or in CharABCWidths. See my site for more information.

Good luck!

ThomW
www.LMNOpc.com

##### Share on other sites
Nibbles    569
Cool, I like that program! Thank you.

Now I just have to figure out how to use it in coding

Scott

##### Share on other sites
Eber Kain    130
I use this for text display, it has a console mode that might do what you are after. it may even have a wrapping feature im not aware of.

http://romka.demonews.com/projects/glf/index_eng.htm

##### Share on other sites
ncsu121978    1344
just manuallly insert the \n in the string when you call your text output function. You already know where the \n should be so just put it there before you call the function
You only need the other way if you have no idea what the string is going to be so you dont know when to wrap it. But for your examples, you know what the string to output is gonna be and where it needs to be wrapped.

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

##### Share on other sites
Coconut    122
The average character width of a Windows Font can be found in the LOGFONT Win32 structure. This struct can be obtained about the current font that has been selected into the GDI with a call to GetTextMetrics(*Device Context*, *Address of LOGFONT structure you want to use*));
the actual variable you would want is something like AveCharWidth with the usual Hungarian prefixes.

-Brent Robinson

##### Share on other sites
Dactylos    122
quote:
Original post by ncsu121978
just manuallly insert the \n in the string when you call your text output function. You already know where the \n should be so just put it there before you call the function
You only need the other way if you have no idea what the string is going to be so you dont know when to wrap it. But for your examples, you know what the string to output is gonna be and where it needs to be wrapped.

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

It''s so much better to write a generic print-function that takes care of that automatically, because what if you want to change the text of the mission-objectives? You would have to re-run the program to see were the lines should break, and then re-insert new-lines in the text. Or what if you decide to use a different font, or change the size of the text-window?

It''s alot easier to just let the program worry about how to break long lines in the text (especially since it''s not difficult to implement).