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.

DarkBASIC Professional Discussion / Text within a box

Author
Message
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th Feb 2010 04:06
How do I confine text to within an area. I would like to stop a line from running past the edge of a box and even have a wrap-text functionality..... I COULD work my way around it, but I would like to know if there is some hidden DBP functions to do this....

The fastest code is the code never written.
bitJericho
23
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 25th Feb 2010 05:08 Edited at: 25th Feb 2010 05:11
Hey Hawk, this is not possible without you programming it yourself or using a third party dll. That said, I'm working on a set of functions to use bitmap fonts that will solve your problem. I'm making an announcement in WIP in a few days when the core of it is done.

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 25th Feb 2010 05:08
Cloggy's D3D functions can do that.

Check them out here

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 25th Feb 2010 14:53
First off, check how many characters total the box can contain. Then once that amount of characters is excided move the last character to the front of the string.

If it hasn't exploded yet, I haven't touched it.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th Feb 2010 14:56
I came up with some simple ideas in my sleep last night and will try them when I get home. Thanks for the responses guys. If my ideas don't turn out, I'll check out yours....

The fastest code is the code never written.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Feb 2010 17:12
OK.... I would like to know how to determine the pixel width of a character without manually doing it. I want to display text within a box with text-wrap capabilities. The predecessor to that functionality would be to stop the text when it get's to the edge and only render what's within my boundary.

Any help?

The fastest code is the code never written.
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 26th Feb 2010 18:38 Edited at: 26th Feb 2010 18:40
As I mentioned above, the (free) D3D functions plugin has a command to do this. It wraps with left, center, and right justification.

If you prefer to "roll your own", then you may determine the width of a string, in pixels, with the TEXT WIDTH() command.

With that command, you could start with a long sentence or paragraph and parse through it for spaces. At each space found, you could find the TEXT WIDTH of the LEFT$ up to that space. If it is within a certain distance of your target width, without going over the target width, you could then print the LEFT$, and then remove what you just printed, with the RIGHT$ command.

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 26th Feb 2010 19:56
Thanks RD

The fastest code is the code never written.

Login to post a reply

Server time is: 2026-07-28 15:38:59
Your offset time is: 2026-07-28 15:38:59