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 / Zotoaster`s Text Wrap Function

Author
Message
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 26th May 2010 17:11 Edited at: 27th May 2010 09:49


This is the code i`m interesting with, it works really well.Except that if the text goes longer it goes slower, from ~1000 FPS uncaped to ~15 with some other longer text, it have something related to spaces, but i can`t understand the code well because i can`t understand what means every variable by itself.

If Zotoaster can help on this.Or somebody else who knows how text wraping work.

Any tutorials and explanations are welcome.

EDIT: Sorry for bother it look this is some old stuff, cloggy`s d3d dll does the same with few lines of code and run with ~2000FPS with 4-5 times longer text wraped.
I just wanted you to know if someone need text wrap "d3d_boxtext" is the comand, very usefull plugin really!

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th May 2010 03:37 Edited at: 28th May 2010 03:39
WOW, that text wrap function is mad, I wonder how old that is. I had a hunt round my giant library of code snippets sitting on my hard drive. This is a text wrap function I wrote awhile ago:



Note: It's function specific, so text to short or wrap width to short I wouldn't class as wrap-able. I don't see a point in using a WrapText function for something that's not wrap-able, hence the reason I didn't put measures in place to deal with unwrap-able text.

Anyway, one issue everyone has is that DBP's 2D drawing commands are really really slow, hence why everyone uses cloggy`s d3d dll which has a 500 percent (not kidding) increase over DBP's 2D stuff. So this is the reason for the massive performance increase.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 28th May 2010 09:06
Are you using some particular algorithm?
I read about the greedy algorithm which wrap the text by words, if last word can`t fit to the end of the line border, it`s pasted on the next one...



This is what i`ve done so far with using cloggy, it`s a bit messy.But i managed it to make it like i wanted it last night.It can improve more.Just have no time now.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th May 2010 14:10
When you look at it, text wrap is very simple. Take mine for instance, the main part is just:

for i = 1 to length
if mid$(txt, i) = " " Then wIndex = i
if text width(left$(txt, i)) > Width then exit
next i

Basically every time a space appears the position is stored in wIndex and we keep storing each spaces position until text width is greater than are defined wrap width. Then we simply text up to the stored space (-1), removing the text behind are space and repeating the process and. This way, you don't even need to check if a word fits, just checking spaces is all you need.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 29th May 2010 12:50
Is that greedy algorithm?

Where there is a will, there is a way.
I often edit my posts, that`s who i am

Login to post a reply

Server time is: 2024-11-24 15:39:24
Your offset time is: 2024-11-24 15:39:24