Input string

Blitz3D Forums/Blitz3D Beginners Area/Input string

Well here you have some very basic code, but you can delete and wrap words.

;******* VERY BASIC TEXT EDITOR ********
;
; By MadMax     (Made in 5 minutes)
;
;***************************************

Graphics 640,480,16

;Include "key_code.bb"

Dim novel(5000); This should allow for a page of text

curson=CreateImage(8,8)
cursoff=CreateImage(8,12); these to are the cursors

SetBuffer ImageBuffer(curson)

Color 255,0,255

Rect 0,0,8,8,True

SetBuffer ImageBuffer(cursoff)

Color 0,0,0
Rect 0,0,8,12,True

SetBuffer FrontBuffer()

Color 255,255,255

MaskImage cursoff,50,50,50

h=10;horizontal cursor location
y=10;vertical cursor location 

;********** MAIN LOOP *************
While Not KeyDown(1)

 DrawImage curson,h,y+4

 value=GetKey()

   If value<>0

;******** DELETE ****************
      If value=8

         DrawImage cursoff,h,y+2
         h=h-8
         DrawImage cursoff,h,y+2
         pos=pos-1

      EndIf

;******** CARRIAGE RETURN ******

      If value=13

         DrawImage cursoff,h,y+2

         h=10
         y=y+16
         pos=pos+1

      EndIf

;******** TEXT PRINT ************

      If value>31

         novel(pos)=value
         pos=pos+1

         DrawImage cursoff,h,y+2

         Locate h,y

         Write Chr$(value)

         h=h+8

;*********** CHECK LINE END *********

            If h>630

;  Here if the end of the line has been reached
;  it starts a new one, but only if the end of line
;  coincides with the end of a word.

               If value=32
               h=10
               y=y+16

;  Here what to do if the line end doesn't 
;  coincide with the end of word 

               Else
               wrap=pos;  remember position

;******* delete word **********

                 Repeat
                   DrawImage cursoff,h,y+2
                   h=h-8
                   pos=pos-1
                 Until novel(pos)=32

               h=10
               y=y+16
               pos=pos+1

;******* reprint word in new line *****

                  Repeat
                    Locate h,y
                    Write Chr$(novel(pos))
                    h=h+8
                    pos=pos+1
                  Until pos=wrap

               EndIf

            EndIf

      EndIf

   EndIf

Wend



Hope it helps.