Custom Textfield Function

BlitzMax Forums/BlitzMax Beginners Area/Custom Textfield Function

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

if you ever figure out the commands here is an example that might help you figure out how to do that:


'crates a text of Length characters in width

'allows input of a string.

'return a string after pressing enter if a string was inputed.

'returns (chr(13)/return/enter) if no text was entered and return/enter was pressed.

'continues waiting for text input until (return/enter) is pressed. and is completeley interactive (may be

'is executed while other parts of the program are running in the background.  



Type TtextBox

	Field FieldLength%

	Field CharArray$

	Field x%

	Field y%

	Field Text$

	Function create:TtextBox(Length%,x%=0, y%=0) 'length = characters allowed for input, x = x start of text y = y start of text

		Local Rectbox:Ttextbox = New TtextBox

		RectBox.FieldLength = Length

		RectBox.x = x

		RectBox.y = y

		Return RectBox

	End Function

	

	Method Input_string:String()

		'set color to red

		SetColor 100,0,0

		'draw a rectangle the size of the field of characters to input

		DrawRect(x+10,y,TextWidth("X")*(FieldLength+1),TextHeight("X"))

		' get a key from the keyboard buffer

		Local c:String = Chr(GetChar())

		'check for maximum nuber of characters 

		If text.length < FieldLength Then 

			'check for a valid ascii character between 32 and 127 

			If Asc(c) => 32 And Asc(c) <= 127 Then

			  	'add character to text field.

				text=text+c

			EndIf

		EndIf

		'check for a back space key pressed

		If KeyHit(KEY_BACKSPACE) And SizeOf(text)>1 Then

			'remove the last character from the text field

			text = Left$(text,text.length-1) 

		End If

		SetColor 255,255,255

		'display the entered text at set location

		DrawText text,x+10,y

		'draw character cursor

		DrawRect x+10+TextWidth(text),y+TextHeight(text)-4,TextWidth("X"),4

		'check For enter key

		If KeyHit(KEY_ENTER)

		 	'return text Entered

			If text = Null  Return Chr(13)

			Local name:String = text; 

			text = Null ;Return name

		EndIf

		'return blank if still waiting for text

		Return Null

	End Method 	

End Type



Graphics 800,600

Local text$ = Null

Local TextBox:TtextBox = TtextBox.create(20,100,100)

Local angle% = 0



AutoMidHandle(1)



Repeat 

	Cls

	text = TextBox.input_string()



	' to ilustrate interactivity



	SetRotation angle

	DrawLine 200,200,220,200

	SetRotation angle+180

	DrawLine 200,200,220,200

	SetRotation 0

	angle = (angle+1)Mod 360

	

	Flip()



Until text



DrawText text,300,300

Flip

Delay 1000



You do need to know the commands mentioned by CS_TBL and how to manipulate arrays(strings are also arrays).

<EDITED>
sorry about all those other post I deleted. I guess the bmax server was not working. I kept on trying to post the same post but it wouldn't show on the page. when it finally showed I saw the same post a bunch of times. and That was the only way I know to remove them.