Need text wrapping code

Started by
10 comments, last by ontheheap 15 years, 10 months ago
Hi. I would like someone to make a text wrapping function for me (or possibly provide a link to code on the web). Given a string s and a font width of fontWidth, the code should draw the text using my function:

void printText(int x, int y, string text)


For a given width, width, the code should add the width of each character and split the string at the closest word before it goes over width. When it splits it, the code should draw the string using printText and increment the y position by fontHeight. I am looking for someone to do this for me rather that just tell me how to do it since i have other stuff i need to do for my game and i don't have time to try and figure this out. This can moved to the Help Wanted section if need be. thanks [Edited by - XTAL256 on June 12, 2008 5:18:15 PM]
[Window Detective] - Windows UI spy utility for programmers
Advertisement
If you can't be bothered to figure it out, why should anyone else? Most people here are busy enough with their own projects than to write code for free for someone else.

It sounds like something you really should learn? Have you tried implementing it yourself?
This is actually a fairly complicated algorithm. You end up running into lots of unusual cases such as the one where a single word is longer than an entire line, and hence has to be broken up. If I had access to my regular computer (The GPU just died), I'd post some code/psuedo-code I use, but I don't. If you want to make this easier on yourself, use mono-size types so that you can specify width in the number of characters. If it's not a monotype font, you'll need another function that finds the width of a string.
You are having a laugh aren't you?

If you need help or stuck with something, people will generally give you helpful pointers, but expecting someone to do the work for you sheer stupidity and laziness.
Quote:Original post by Dave
If you can't be bothered to figure it out, why should anyone else? Most people here are busy enough with their own projects than to write code for free for someone else.
It sounds like something you really should learn? Have you tried implementing it yourself?

I understand that most people here have their own projects and i don't expect them to go out of their way to do this for me. But some people here are looking for projects to help with (that's what the Help Wanted forum is for). I myself would be looking for a project to help with if i didn't already have one of my own. So, if anyone here wants to help me with my game/project then they can do this for me.

@Ezbez: at the moment i am using fixed width (monotype) fonts but they don't look as good as they would if they were variable width so in the future i might implement variable width fonts. You can just assume that i will use a function to get the width of a character:
// Returns the width in pixels of the given character.int Font::charWidth(char ch)

But just say fontWidth for now.
[Window Detective] - Windows UI spy utility for programmers
Quote:Original post by XTAL256
I understand that most people here have their own projects and i don't expect them to go out of their way to do this for me. But some people here are looking for projects to help with (that's what the Help Wanted forum is for).


That certainly wasn't implied in your first post, mainly because you said you "couldn't be bothered", but also because you haven't even told us what your project is !!!
The problem you have here is that until someone can get your entire codebase and everything you have for testing out your code, it's going to be hard to write it. Someone can provide pseudo code for the solution, but you'd end up translating it since they have no means to test it.

So basically, yeah its best if you attempt to recruit for your project. Be warned though, it's unlikely anyone would join just to write a function.
Quote:Original post by Daedalus AI
...mainly because you said you "couldn't be bothered"

Yeah, i thought some people might take that the wrong way. I really should have said "don't have time" or something. I mean, i could do it if i want, i'm not under any time constraints or anything but i really need other people to do some code for me since i am the only one working on my project at the moment.
And if you want to find out more about my project, just click the link in my sig (my game's called Ballistic).

Quote:Original post by Dave
...it's unlikely anyone would join just to write a function.

Yeah, that's why i posted here and not in the Help Wanted section.

[Edited by - XTAL256 on June 12, 2008 6:03:20 AM]
[Window Detective] - Windows UI spy utility for programmers
Quote:Original post by XTAL256
I really should have said "don't have time" or something. I mean, i could do it if i want, i'm not under any time constraints or anything


Emphasis added. Do you have the time or not? If the only thing stopping you is that you don't want to do it I'm afraid you're looking for help in the wrong place.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Quote:Original post by nobodynews
Do you have the time or not? If the only thing stopping you is that you don't want to do it...

I started my project at the start of the year. Currently it's taken me this long just to do the GUI, and i'm still not done with it (this text wrapping problem is for the GUI). So if i were to do the whole thing myself without anyone's help, the earliest the game would be completed would be around 2012. :(

Quote:I'm afraid you're looking for help in the wrong place.

Well then where can i look? This section is for people to ask for help but the Help Wanted section is for people looking for a team. I am sure that someone here at GD would like to help me but i just don't know where to look. I'm starting to think it would be quicker for me to just google it.
[Window Detective] - Windows UI spy utility for programmers

This topic is closed to new replies.

Advertisement