Graphical Input ? (Equivalent of Blitz3D Input)

BlitzMax Forums/BlitzMax Beginners Area/Graphical Input ? (Equivalent of Blitz3D Input)

Heya friends :)
I'm currently porting some tool apps I made in Blitz3D sometimes ago.
I know that print, inptut, etc... are now only console functions.
In blitz3D they were graphical functions so
I'm looking for a Input which is an equivalent of the Blitz3D Input.
Can someone tel me how can I do that ?

Many, many thanks

McFox

Does this help...
Input

Amazing... many thanks tonyg

You're helping me a lot

Hi !

I tried the two functions...
And I have a Problem...

See, an exemple in B3D :

Graphics 800,600,32,2

While Not KeyHit(1)
	Cls
	Color 255,0,0
	Rect 10,10,100,100
	Locate 200,200
	Color 255,255,255
	name$=Input$("What is your name?")
	Write "Hello there, " + name$ + "!" 
	Flip
	Wend
WaitKey


You can see there are a Red Rect and a Input

Now, the blitzmax equivalent :

Graphics 800,600,0

While Not KeyHit(KEY_ESCAPE)
	Cls
	SetColor 255,0,0
	DrawRect 10,10,90,90
	SetColor 255,255,255
	name$=InputText$("What is your name?",200,200)
	DrawText "Hello there, " + name$ + "!",220,220 
	Flip
	Wend
WaitKey


Almost the same thing happen, except there is NO red rect...
Simply because InputText perform a Repeat...Until with Cls and Flip...

I tried the DynamicInput but the key detection is very random whene there are many things in the loop...
Realy a borring problem :(

So... Can someone help me ?

Thanks a lot

McFox

You have to draw the cursor yourself.

Replace the Text() function within the TInput declaration with this...

Function Text$(Text$,X,Y)
    
        Local aKeytoGet = GetChar()
        If aKeytoGet'Anykey was pressed
        
            If aKeytoGet = 13 'ENTER


                Text$ = tempText$
                If Text$ = "" Then Text = " "
                tempText$ = ""
                FlushKeys
                Return Text$
            Else If aKeytoGet = 8 Or aKeytoGet = 4 'AscII For Backspace And Delete
                If Len( tempText$ ) > 0 Then tempText$ = Left$( tempText$, Len(tempText$) -1 )    
            Else' If aKeytoGet>=32 And aKeytoGet<=122 And Len(Message)<52
                tempText$:+ Chr$(aKeytoGet)
            EndIf

        EndIf
        
        DrawText Text$ + tempText,X,Y
        If (MilliSecs() Mod 750) < 375
            DrawRect X + TextWidth(Text$ + tempText), Y, TextWidth(" "), TextHeight(" ")
        EndIf
        
        Return ""

EndFunction


Well Thanks...
But I'm not looking for the cursor :)

I want to be able to have an input on screen without clearing the back of the screen (as Blitz3D does, look at my exemple: the red Square stay while there is the input on B3D, it doesn't on BMax)

Haha...Sorry, I obvously didnt read your post properly. :o)

Either set a viewport for the text or draw a rectangle the same colour as the background over the text instead of the cls.

There's a 'flip;cls' command in InputText function. Take out the cls and you'll see the red rect BUT the text field won't clear and will look odd if there is a mistake.
Not sure of the solution. Maybe Wave thought of something?

Graphics 800,600,0

While Not KeyHit(KEY_ESCAPE)
	Cls
	SetColor 255,0,0
	DrawRect 10,10,90,90
	SetColor 255,255,255
	
	name$=InputText("What is your name? ",200,200)
	DrawText "Hello there, " + name$ + "!",220,220 
	Flip
	Delay 1000
Wend

End


Function InputText:String(prompt:String, x:Int, y:Int, wait:Int=True, clear:Int=True)
	Local vx:Int, vy:Int, vw:Int, vh:Int 
	Local char:Int, pl:Int = TextWidth(prompt), ph:Int = TextHeight(" ") 
	Global out:String
	
	GetViewport(vx, vy, vw, vh)
	
	If clear Then out = ""
	
	Repeat
		char = GetChar()
		Select True
			Case char = 8
				If out.Length > 0 Then out = out[..out.Length - 1]
				
			Case char = 13
				wait = False
			
			Case char > 31
				out :+ Chr(char)
		End Select
		
		SetViewport x, y, pl + TextWidth(out$ + "  "), ph
		Cls
		
		If (MilliSecs() Mod 750) < 375
			DrawText prompt + out, x, y
		Else
			DrawText prompt + out + "_", x, y
		EndIf
		
		Flip
	Until wait = False
	
	SetViewport vx, vy, vw, vh
	
	Return out
End Function


Agggghhhh...I tried for ages to get the same result.Tried grabbing images of the text area, drawing rectangles etc etc.
Got as far as looking up the viewport command but never took it any further.
Anyway, good stuff.

W00t !

Thanks Squatting Neville. This is exactly what I was looking for.

McFox

OMG :( just try the same code in Fullscreen...(Graphics 800,600,32)

Is there any way to remove the flicker :( ?
so bad :(...

Thanks

McFox

try some fiddling with the new sync settings, alltough it should normally revert to hardware sync I guess

The rect only seems to be copied to one buffer in fullscreen. It's silly but if you drawrect, flip, drawrect it's OK.
Seems to be connected to this...
Flickering

Thanks tonyg,
that's realy strange... is it a bug ? I can't find if it's a bug or not...

McFox