A simple Text field input system for adding fields for whatever occasion. You set the number of fields, their length, and screen location, and let the program do the rest of the work. Not a wonderful GUI, but it does the job for those quick and dirty apps we all throw together.
`========================================================================
` _textInput.dba for DarkBasic Pro
`
` A very simple text field editor
` Simply type to enter text
` Backspace to delete text
` Tab to move between fields, wraps bottom to top
`
` Author: [email protected]
`========================================================================
TYPE INP
x AS INTEGER
y AS INTEGER
tdata AS STRING
tlength AS INTEGER
ENDTYPE
GLOBAL INPmax = 5
DIM INPtext(INPmax) AS INP
GLOBAL currentiINP = 0
GLOBAL timeCount = 0
GLOBAL Keydelay = 0
GLOBAL Keytimeout = 12 `time delay FOR tab AND backspace
createInput(0,20,20,20,"Some Text")
createInput(1,20,40,10,"Hello")
createInput(2,20,60,5,"")
createInput(3,20,80,40,"World")
createInput(4,20,100,20,"")
`Force 3d camera view - There are many other methods, this is just a cheap way
MAKE OBJECT SPHERE 1,1 : DELETE OBJECT 1
`----------------------------------------------------------------------
SYNC on: SYNC RATE 60
DO
doInput()
SYNC
LOOP
END
`----------------------------------------------------------------------
FUNCTION createInput(num AS integer,x as integer, y as integer,clength as integer,txt as string)
INPtext(num).x = x
INPtext(num).y = y
INPtext(num).tlength = clength
INPtext(num).tdata = txt
ENDFUNCTION
`----------------------------------------------------------------------
FUNCTION doInput()
drawInput()
userInput()
ENDFUNCTION
`----------------------------------------------------------------------
FUNCTION userInput()
Keydelay = Keydelay + 1
IF Keydelay > Keytimeout
Keydelay = Keytimeout
ENDIF
id = currentiINP
s$ = INPtext(id).tdata
L = INPtext(id).tlength
`add typed character
IF LEN(s$) < L+1
a$ = ENTRY$(1)
vaild = 0
IF ASC(a$)>31 AND asc(a$)<127 THEN valid = 1
IF LEN(a$) > 0 AND valid > 0
s$ = s$ + a$
ENDIF
ENDIF
`backspace
IF SCANCODE() = 14 AND LEN(s$) > 0
IF Keydelay = Keytimeout
s$ = LEFT$(s$,LEN(s$)-1)
Keydelay = 0
ENDIF
ENDIF
INPtext(id).tdata = s$
`Tab cycle through input items
IF SCANCODE() = 15
IF Keydelay = Keytimeout
Keydelay = 0
currentiINP = currentiINP + 1
IF currentiINP > INPmax -1
currentiINP = 0
ENDIF
ENDIF
ENDIF
CLEAR ENTRY BUFFER
ENDFUNCTION
`----------------------------------------------------------------------
FUNCTION drawinput()
`use timeCount to control the flashing cursor
timeCount = timeCount + 1
IF timeCount > 60 THEN timeCount = 0 `time with SYNC RATE 60
FOR i = 0 TO INPmax-1
`display text for each input
TEXT INPtext(i).x,inptext(i).y,inptext(i).tdata
UL$ = "_"
CRT$ = ""
`display underscore for each input
FOR j = 1 TO INPtext(i).tlength
UL$ = UL$ + "_"
NEXT j
TEXT INPtext(i).x,inptext(i).y,UL$
`flash carret for current input item
IF i = currentiINP
IF timeCount < 40 `40 frames on, 20 frames off
L = LEN(inptext(i).tdata)
FOR j = 1 TO L
CRT$ = CRT$ + " "
NEXT j
CRT$ = CRT$ + "|"
TEXT INPtext(i).x,inptext(i).y,CRT$
ENDIF
ENDIF
NEXT i
ENDFUNCTION