I need a second more educated opinion on this.
First here is the code:
Set Display Mode 1024,768,16
Sync On
Sync Rate 0
Hide Mouse
backdrop on
`Set Text Properties
set text font "COURIER"
set text size 16
ink RGB(255,255,255), RGB(0,0,0)
ls_text$ = "This is a long text line and it should appear to be nice and in a boxed way which is very difficult an accomplisment. Let's see if it works eh? That's it now!"
img_text = box_text(ls_text$, 250)
do
PASTE IMAGE img_text, 100, 100
SYNC
loop
END
` FUNCTION SECTION
function box_text(as_text$, width)
`Get Text Properties
font_height = TEXT HEIGHT(as_text$)
font_width = TEXT SIZE()
ls_message$ = as_text$
chars = len(ls_message$)
`make box based on text given
text_box = 1
limit = (width / font_width)
height = ((chars / limit) + 1) * font_height
CREATE BITMAP text_box, width, height
set current bitmap text_box
newx = 0: newy = 0
while chars > 0
`extract the current line to write
line$ = left$(ls_message$, limit)
` HELP! Is this a Bug?
` If I let it execute the next command it get's stuck...
`line$ = cleanText(line$)
`move to the rest of the message and chop
chars = len(ls_message$)
rest = chars - len(line$) :`newlimit
restMsg$ = right$(ls_message$, rest)
ls_message$ = restMsg$
`write new complete word and increase line
text newx, newy, line$
inc newy, font_height
endwhile
`now grab the text_box and make is an image and return it
get Image text_box, 0, 0, width, height
delete bitmap text_box
SET CURRENT BITMAP 0
endfunction text_box
function cleanText(as_text$)
ls_line$ = as_text$
newlimit = len(ls_line$)
while right$(ls_line$, 1) <> " ":`dont chop a word in half
dec newlimit, 1
ls_line$ = left$(ls_line$, newlimit)
endwhile
endfunction ls_line$
Now there are 2 funtions there, both working fine on their own, but when I call one from the other it seems to freeze in the second - in the while statement - and it gets stuck.
What the code does is.
1. Gets a long string
2. loop and break it in sections
3.
check if the section ends in space or reduce it until it does.
4. write the text in a bitmap
5. crop the bitmap so the text is "boxed" as an image
6. return the image
7. main loop just pastes the image on the screen (bitmap 0)
Step three is the second function call. And I can't make go through it at all.
I tried it by doing all the work on Bitmap 0 and not on a bitmap I created; well that works fine...
I also tried it by puting the code of the
cleantext() function as part of the main function box_text() and it doesnt work.
Now you can appreciate the benefit of a function like this. Faster and multy line text boxes instead of writting big text in the main loop...
Any Ideas??? You are more than welcome to use or change the code but please if you have a breakthrough, comments, suggestions or tips do let me know...
-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy