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.

Newcomers DBPro Corner / Some help on justifying text for a 'text box'

Author
Message
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 13th Apr 2009 20:44
Hey all, it's been a while since I've played with Dark Basic and my skills are a tad rusty.

At the moment I am trying to code a function that will create an image from some supplied text (and a bitmap font). If the text has control codes written in, such as \n, the function bumps the folowing text down a line.

The purpose of the function is to be able to produce a scrollable textbox for any given supplied text.

My function is clever enough to introduce new lines when the desired textbox width is reached, but this happens in the middle of words, which I want to avoid. I.e., at the moment I may have:

This is a te
st section o
f text!

being displayed.

I'd rather end up with:

This is a
test section
of text!

An ideally even that would be 'fully justified' (i.e. spaced out to the margins)

Has anyone got any ideas how I could do this?

Cheers!

My function code at the moment is:


"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 14th Apr 2009 04:12 Edited at: 14th Apr 2009 04:12
Why not increase the line number if the function hits a space and there are only a few characters left on the line (that is, (max characters per line) - (current character on this line) is less than (a certain number) ).

OR you could even find the number of characters in the NEXT word and see if it goes over. If so, increase the line number at the next space.

Here's a little example that needs IanM's Matrix1 plugin that doesn't use the above tactic at all so it may or may not be helpful... It doesn't work on long words either. Move the mouse to change the text box width.



<---Spell casting battle game!

Login to post a reply

Server time is: 2024-11-25 08:44:35
Your offset time is: 2024-11-25 08:44:35