Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Creating a new line in text

Author
Message
Superdeath360
13
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 31st Dec 2010 23:25
I've created a simple chatting program in which dbText() is used to display messages sent and received from different computers. My problem is that the messages eventually end up running over the edge of the screen. Is there a way to make the text go to a new line when it reaches the edge of the screen?
Thanks!

herp derp
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 2nd Jan 2011 16:42
\n in text is a new line,to know whether the text is on the edge of screen or not, you can use this to get the width of the line in pixels: number of line characters * size of font

Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 2nd Jan 2011 16:58
Hassan,

" number of line characters * size of font"

I didn't think that worked, or am I missing a function that exists somewhere?

Different type faces have very different pixel widths for their characters (so that "A" in 10 point Verdana would take more pixels than "A" in Times New Roman, etc), and in most fonts (except the fixed ones such as Courier), the letter "i" would be much thinner than "x", for example.

Your method would calculate the same number of pixels for all characters , including full stops ".", regardess fo type face or character involved, wouldn't it?

The DBPro method works wonderfully well, but I'm not sure that there is an equivalent in GDK. If there is, I'd love to see the example. I have been struggling with this one for a couple of weeks, on and off.

Amazing Simulation
www.amazing-forum.com
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 3rd Jan 2011 14:51
well i think that's true, but for some fonts it works, well i don't know other precise method of doing this

Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 4th Jan 2011 15:17
I hate the fonts that don't have the same number of pixels for each character. It caused me problems when making my GUI. The solution I have for the text-wrap is to make a block of memory for the text and add "\n" at the end of each line.... It's a pain to do, but it works (basically what Hassan said). Beware, large arrays of text will cause significant slowdown if you don't use a mechanism to render the text as a continuous line. That statement might not make sense, but if you are constantly updating the text by adding the "\n" to the end of each line, it will bogg down your system.

I would say that this is a shameless plug, but here it is anyway: Check out my GUI http://forum.thegamecreators.com/?m=forum_view&t=178271&b=22 it has a text editor built in. Rip it apart and get what you need from it. Or you can use the GUI in it's entirety. What you would be looking for is in the "Menu Functions.h" file in the TEXTBOXCLASS. Look at the latest post with a download for the newest version of that file.

The fastest code is the code never written.
Superdeath360
13
Years of Service
User Offline
Joined: 23rd Nov 2010
Location:
Posted: 8th Jan 2011 18:30
thank you, all. Much appreciated

herp derp

Login to post a reply

Server time is: 2024-06-28 01:36:18
Your offset time is: 2024-06-28 01:36:18