Posted: 18th Apr 2004 15:35
Here is my day's work on a nice command used to display text in a custom drawn box, prefferably used for talking in rpgs. This is how it's used:

textbox(textstring$,xpos,ypos,endxpos)

textstring$: The text in the box.
xpos: The x position (duh!)
ypos: The y position
endxpos: The maximum x position

Currently it works only by letters, but im trying to make it word based, so it doesnt split the text into pieces. The box will stretch down to how much space is needed to display the text. Im also gonna make it sort of 3d based, so that it follows the person talking. Anyway, I've said enough, tell me what you think

The image used with it:
http://sephiroth7769.tripod.com/sitebuildercontent/sitebuilderpictures/textbox.bmp

+ Code Snippet
sync on
sync rate 0
ink rgb(100,100,100),0

do
textbox("The current time is "+GET TIME$(),mousex(),mousey(),350)
print screen fps()
sync
cls
loop

function textbox(text$,x,y,endx)
textsize=10
rem makes the textbox sprite by cutting an image into 3x3 squares.
create animated sprite 1,"textbox.bmp",3,3,1
spritesizex=sprite width(1)
spritesizey=sprite height(1)
boxwidth=endx-x
rem gets number of lines relying on the width of the box
lines=1
for lcheck=1 to 50
   if len(text$)*textsize<boxwidth*lcheck then lines=lcheck:goto endofcheck
next lcheck
endofcheck:
dim line$(lines)
rem sets the frame to topleft and pastes it in x,y
set sprite frame 1,0
paste sprite 1,x,y
set sprite frame 1,1
for height=0 to lines
   for top=1 to boxwidth/15-1
      if height=0
         set sprite frame 1,1
         paste sprite 1,x+(top*15),y
         if top=boxwidth/15-1 then set sprite frame 1,2:paste sprite 1,x+((top+1)*15),y
      else
         if height<>lines
            set sprite frame 1,3
            paste sprite 1,x,y+(height*15)
            set sprite frame 1,4
            paste sprite 1,x+(top*15),y+(height*15)
         endif
         if height=lines
            set sprite frame 1,6
            paste sprite 1,x,y+((lines)*15)
            set sprite frame 1,7
            paste sprite 1,x+(top*15),y+((lines)*15)
         endif
         if top=boxwidth/15-1 and height<lines
            set sprite frame 1,5
            paste sprite 1,x+((boxwidth/15)*15),y+(height*15)
         endif
         if height=lines and top=boxwidth/15-1
            set sprite frame 1,8
            paste sprite 1,x+((boxwidth/15)*15),y+((lines)*15)
         endif
      endif
   next top
next height
rem puts the right amount of characters into each line.
charsinline=boxwidth/textsize
for processlines=0 to lines
  for character=processlines*charsinline to processlines*charsinline+charsinline-1
     line$(processlines) = line$(processlines) + mid$(text$,character)
  next character
next processlines
rem prints the text on the screen with the lines in the right positions.
for printing=0 to lines
  text x+10,y+(printing*textsize)+6,line$(printing)
next printing
rem frees some memory by deleting a few things.
undim line$()
delete sprite 1
endfunction
Posted: 18th Apr 2004 15:45
Pretty cool - maybe you could get him to make a paste image version too for non-3d stuff (sprites force 3D mode).


Van-B
Posted: 18th Apr 2004 15:52
There'd be only one problem with that, too many images. In this version, you have one image(that can be easily modified), instead of 9 images that need too be loaded and edited seperately. But there might be a way around this, i'll see what i can do
Posted: 19th Apr 2004 9:01
Wow, some tough coding, but it's almost complete. This time I made it scroll(like the one in ff9), and it deosnt go through the sides of the screen. move it with the mouse, leftclick=bigger, rightclick=smaller. Hope you like it

Same pic as last time:
http://sephiroth7769.tripod.com/sitebuildercontent/sitebuilderpictures/textbox.bmp

And a speechbubble thingy:
http://sephiroth7769.tripod.com/sitebuildercontent/sitebuilderpictures/talk.bmp

+ Code Snippet
sync on
sync rate 0
ink rgb(100,100,100),0
size=300


do
if mouseclick()=1 then inc size,1
if mouseclick()=2 then dec size,1
if size<30 then size=30
textbox("The current time is "+GET TIME$(),mousex(),mousey(),size)
print "FPS:"+str$(screen fps())
sync
cls
loop

function textbox(text$,tx,ty,boxwidth)
rem text size, only temporary
textsize=10

rem makes the textbox sprite by cutting an image into 3x3 squares.
create animated sprite 1,"textbox.bmp",3,3,1
spritesizex=sprite width(1)
spritesizey=sprite height(1)

rem load the talk image
load image "talk.bmp",2,1

rem gets the x and y vars, by changing the tx and ty.
ty=ty-15
tx=tx-15
if tx-boxwidth>0 then x=tx-boxwidth+15
if tx<15 then tx=15
if tx>x+boxwidth-15 then tx=x+boxwidth-15

rem gets number of lines relying on the width of the box
lines=1
for lcheck=1 to 50
   if len(text$)*textsize<boxwidth*lcheck then lines=lcheck:goto endofcheck
next lcheck
endofcheck:
dim line$(lines)

rem not letting box go over screen
y=ty-lines*15-10
if y<0 then y=0 :ty=y+lines*15+10

rem pastes all the frames in their correct positions
set sprite frame 1,0
paste sprite 1,x,y
set sprite frame 1,1
for height=0 to lines
   if height>0 and height<lines
      set sprite frame 1,3
      paste sprite 1,x,y+(height*15)
   endif
   for top=1 to boxwidth/15-1
      if height=0
         set sprite frame 1,1
         paste sprite 1,x+(top*15),y
         if top=boxwidth/15-1 then set sprite frame 1,2:paste sprite 1,x+((top+1)*15),y
      else
         if height<>lines
            set sprite frame 1,4
            paste sprite 1,x+(top*15),y+(height*15)
         endif
         if height=lines
            set sprite frame 1,6
            paste sprite 1,x,y+((lines)*15)
            set sprite frame 1,7
            paste sprite 1,x+(top*15),y+((lines)*15)
         endif
         if top=boxwidth/15-1 and height<lines
            set sprite frame 1,5
            paste sprite 1,x+((boxwidth/15)*15),y+(height*15)
         endif
         if height=lines and top=boxwidth/15-1
            set sprite frame 1,8
            paste sprite 1,x+((boxwidth/15)*15),y+((lines)*15)
         endif
      endif
   next top
next height

paste image 2,tx,ty

rem puts the right amount of characters into each line.
charsinline=boxwidth/textsize
for processlines=0 to lines
  for character=processlines*charsinline to processlines*charsinline+charsinline-1
     line$(processlines) = line$(processlines) + mid$(text$,character)
  next character
next processlines

rem prints the text on the screen with the lines in the right positions.
for printing=0 to lines
  text x+10,y+(printing*textsize)+6,line$(printing)
next printing

rem frees some memory by deleting a few things.
undim line$()
delete sprite 1
delete image 1
delete image 2
endfunction


Its a little slow, but i think thats because of 'text'. You can try making image/sprite based text, and that should make it faster.
Posted: 21st Apr 2004 6:32
Awsome, I can use this in the game I'm working on. I'll credit you of course. Thanks a bunch!
Posted: 21st Apr 2004 10:14
Wait Guldan, im still gonna update it, probably today. Actually i might as well work on it now...
Posted: 21st Apr 2004 11:27
This should be my last update. Im gonna give up on the word thing, there seems to be no way to get it working. In this version, it reacts to all 4 sides of the screen. Ive also included a little 3d world, so that you can see how to use it. Tell me if you like it, or what can be improved(apart from the word seperating). Enjoy

the new image for the textbox(just a bit better looking) :
http://sephiroth7769.tripod.com/sitebuildercontent/sitebuilderpictures/textbox2.bmp

+ Code Snippet
rem initial vars
sync on
sync rate 60
autocam off
hide mouse



for xdots=0 to 254
   for zdots=0 to 254
      g=rnd(20)+100
      dot xdots,zdots,rgb(50,g,50)
   next zdots
next xdots
GET IMAGE 3,0,0,256,256

rem simple world
make matrix 1,1000,1000,50,50
prepare matrix texture 1,3,1,1
randomize matrix 1,8
update matrix 1
make object sphere 1,50
position object 1,500,50,650
color object 1,rgb(250,100,100)
make object sphere 2,50
make object sphere 3,25
position object 2,450,30,630
position object 3,500,100,670
color object 2,rgb(100,255,100)
color object 3,rgb(100,100,255)
position camera 500,50,500
color backdrop rgb(100,100,200)

rem loads images
create animated sprite 1,"textbox2.bmp",3,3,1
load image "talk.bmp",2,1
sprite 2,0,0,2
hide sprite 2

ink rgb(100,100,100),0
do
if mouseclick()=1 then move camera 3
if mouseclick()=2 then move camera -3
yrotate camera wrapvalue(camera angle y()+mousemovex()/2)
xrotate camera wrapvalue(camera angle x()+mousemovey()/2)
position camera camera position x(),get ground height(1,camera position x(),camera position x())+20,camera position z()
if size<30 then size=30
if object screen x(1)>-50 and object screen x(1)<1024+50 and object screen y(1)>-50 and object screen y(1)<768+50
  if object in screen(1)=1 then textbox("The red sphere is talking to you...",object screen x(1),object screen y(1),185)
endif
sync
loop

function textbox(text$,tx,ty,boxwidth)
rem text size, only temporary
textsize=10
rem makes the textbox sprite by cutting an image into 3x3 squares.
spritesizex=sprite width(1)
spritesizey=sprite height(1)
set sprite frame 1,0
segmentsize=sprite width(1)
rem ts the x and y vars, by changing the tx and ty.
ty=ty-segmentsize
tx=tx-segmentsize
if tx>screen width()-30 then tx=screen width()-30
if tx-boxwidth>0 then x=tx-boxwidth+segmentsize
if tx<15 then tx=segmentsize
if tx>x+boxwidth-segmentsize then tx=x+boxwidth-segmentsize
rem gets number of lines relying on the width of the box
lines=1
for lcheck=1 to 50
   if len(text$)*textsize<boxwidth*lcheck then lines=lcheck:goto endofcheck
next lcheck
endofcheck:
dim line$(lines)
rem not letting box go over screen
y=ty-lines*segmentsize-10
if y<0
   y=0 :ty=y+lines*segmentsize+10
   `if y>screen height()-lines*segmentsize-(segmentsize*2) then y=screen height()-(lines*segmentsize)-(segmentsize*2)
else
   if ty>screen height()-segmentsize then ty=screen height()-segmentsize
   y=ty-lines*segmentsize-10
endif
rem pastes all the frames in their correct positions
set sprite frame 1,0
paste sprite 1,x,y
set sprite frame 1,1
for height=0 to lines
   if height>0 and height<lines
      set sprite frame 1,3
      paste sprite 1,x,y+(height*segmentsize)
   endif
   for top=1 to boxwidth/segmentsize-1
      if height=0
         set sprite frame 1,1
         paste sprite 1,x+(top*segmentsize),y
         if top=boxwidth/segmentsize-1 then set sprite frame 1,2:paste sprite 1,x+((top+1)*segmentsize),y
      else
         if height<>lines
            set sprite frame 1,4
            paste sprite 1,x+(top*segmentsize),y+(height*segmentsize)
         endif
         if height=lines
            set sprite frame 1,6
            paste sprite 1,x,y+((lines)*segmentsize)
            set sprite frame 1,7
            paste sprite 1,x+(top*segmentsize),y+((lines)*segmentsize)
         endif
         if top=boxwidth/segmentsize-1 and height<lines
            set sprite frame 1,5
            paste sprite 1,x+((boxwidth/segmentsize)*segmentsize),y+(height*segmentsize)
         endif
         if height=lines and top=boxwidth/segmentsize-1
            set sprite frame 1,8
            paste sprite 1,x+((boxwidth/segmentsize)*segmentsize),y+((lines)*segmentsize)
         endif
      endif
   next top
next height
set sprite frame 1,0
hide sprite 1
if tx<boxwidth/2
   mirror sprite 2
   paste sprite 2,tx,ty
   mirror sprite 2
else
   paste sprite 2,tx,ty
endif
rem puts the right amount of characters into each line.
charsinline=boxwidth/textsize
for processlines=0 to lines
  for character=processlines*charsinline to processlines*charsinline+charsinline-1
     line$(processlines) = line$(processlines) + mid$(text$,character)
  next character
next processlines
rem prints the text on the screen with the lines in the right positions.
for printing=0 to lines
   ink rgb(50,50,50),0
   text x+10,y+(printing*textsize)+6,line$(printing)
   ink rgb(150,150,150),0
   text x+10-1,y+(printing*textsize)+6-1,line$(printing)
next printing
ink rgb(100,100,100),0
rem frees some memory by deleting a few things.
undim line$()
endfunction
Posted: 22nd Apr 2004 19:27
hmm.. when I read "text box", I thought it was something like a "type='input'" in HTML..
I wrote one and thought it would be well to see one and improve mine or give ideas...
+ Code Snippet
`%Gniârk, not in a project file%
`======================
`©%Atreides - Mathias Seuret%
`======================
`Not Main Source File : Only One Function
sync on
sync rate 50

rem you can use the font and the size you want
set text font "arial"
set text size 18+rnd(5)

txt as string = "Click here to write"
do
	cls
	set cursor 0,0
	print "The text is ",txt
	txt = text_box(150, 300 ,txt, 200, rgb(128,128,128), rgb(0,0,0))
	sync
loop

function text_box(x as integer, y as integer ,txt as string, width as integer, color as dword, text_color as dword)
   box x,y,x+width+7,y+text height("|")+7,color-rgb(30,30,30),color-rgb(30,30,30),color-rgb(30,30,30),color-rgb(30,30,30)
   box x+2,y+2,x+width+5,y+text height("|")+5,color,color,color,color
   if text width(txt)>width
      chr_to_show = 0
      repeat
         inc chr_to_show
      until text width(right$(txt,chr_to_show+1))>width
   else
      chr_to_show = len(txt)
   endif
   ink text_color,0
   text x+2,y+2,right$(txt,chr_to_show)
   if mousex()>x and mousex()<x+width+7
      if mousey()>y and mousey()<y+text height("|")+7
         if mouseclick()=1
            clear entry buffer
            repeat:until mouseclick()=0
            repeat
               box x,y,x+width+7,y+text height("|")+7,color-rgb(30,30,30),color-rgb(30,30,30),color-rgb(30,30,30),color-rgb(30,30,30)
               box x+2,y+2,x+width+5,y+text height("|")+5,color,color,color,color
               if mouseclick()=1
                  if mousex()<x or mousex()>x+width+7 or mousey()<y or mousey()>y+text height("|")+7
                     cond=1
                  else
                     cond=0
                  endif
               endif
               if returnkey()=1 then cond = 1
               if returnkey()=0 then txt = txt + entry$()
               if scancode()=14
                  txt = left$(txt,len(txt)-1)
                  pause=0
                  repeat
                     inc pause
                     wait 1
                  until pause=20 or keystate(14)=0
               endif
               if text width(txt)>width-5
                  chr_to_show = 0
                  repeat
                     inc chr_to_show
                  until text width(right$(txt+"|",chr_to_show+1))>=width-5
               else
                  chr_to_show = len(txt)
               endif
               inc barre_fin
               ink text_color,0
               if barre_fin < 20
                  text x+2,y+2,right$(txt,chr_to_show)+"|"
               else
                  text x+2,y+2,right$(txt,chr_to_show)+""
                  if barre_fin>40 then barre_fin=0
               endif
               clear entry buffer
               sync
            until cond=1
         endif
      endif
   endif
   ink rgb(255,255,255),0
endfunction txt


but I see that you've problems to cut your text.. I don't know if you've repaired that since the first version, I don't have enough time to look at the latest version.. I had a similar problem when I made pseudo-windows in an application...
Here's my code that cut the text, that may give you ideas

+ Code Snippet
if text width(question)>sizex-10
      repeat
         chr_to_show = 0
         repeat
            inc chr_to_show
         until text width(left$(right$(question,len(question)-already_showed),chr_to_show+1))>sizex-10 or already_showed + chr_to_show >= len(question)
         if already_showed + chr_to_show <> len(question)
            while mid$(question,already_showed+chr_to_show)<>" " or chr_to_show=<0
               dec chr_to_show
            endwhile
         endif
         inc posy
         text x+4,y+4+text height("|")*(posy-1),left$(right$(question,len(question)-already_showed),chr_to_show)
         already_showed = already_showed + chr_to_show
         if already_showed => len(question) then text_showed = 1
         sync
      until text_showed = 1
   else
      text x+4,y+4,question
   endif


yeah, I know, my code is ugly and hard to read... but it works... I should use more comments
Posted: 23rd Apr 2004 1:54
your web site seems to be unavailable at the moment. It asked me if I was the owner and told me how to create a web page. I thought you might be a bit cross with me if I did, so I didn't.