Einfaches Input-Modul

Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Neue Antwort erstellen

Justus

Betreff: Einfaches Input-Modul

BeitragDo, Apr 06, 2006 19:50
Antworten mit Zitat
Benutzer-Profile anzeigen
Vielleicht erspart es ja jemandem 5 Minuten Schreibarbeit: Einfaches Input-Modul

Code: [AUSKLAPPEN]

'---------------------------------------------------------------
' BlitzMax Input Module
'---------------------------------------------------------------
Import BRL.Retro
Import BRL.Max2D
Module justus.input

Type TInput
   
   Field x:Int               'The input's X-Coordinate
   Field y:Int               'The input's Y-Coordinate
   Field font:TImageFont         'The font used to display the input
   Field currentContent:String      'Content that has already been input
   Field blinktime:Int         'In milliseconds; 500-0: display cursor; 0-(-500) do not display cursor
   
EndType

Rem
bbdoc:   Erstellt ein Eingabefeld
returns: Ein TInput - Objekt
End Rem
Function CreateInput:TInput(x:Int,y:Int,font:TImageFont)
   Local tempInput:TInput = New TInput
   tempInput.x = x
   tempInput.y = y
   tempInput.font = font
   Return tempInput
EndFunction

Rem
bbdoc:   Aktualisiert ein Eingabefeld
returns: Nichts
about:   Sowohl die Anzeige als auch die grafische Ausgabe wird hiermit geregelt
End Rem
Function UpdateInput(tempInput:TInput)
   Local char:Int = GetChar()
   If char <> Null Then
      Select char
         Case KEY_BACKSPACE tempInput.currentContent = Mid(tempInput.currentContent,1,Len(tempInput.currentContent)-1)
         Default tempInput.currentContent = tempInput.currentContent + Chr(char)
      EndSelect
   EndIf
   SetImageFont tempInput.font
   DrawText tempInput.currentContent,tempInput.x,tempInput.y
   If tempInput.blinktime + 500 > MilliSecs() Then
      DrawText "|",tempInput.x + TextWidth(tempInput.currentContent),tempInput.y
   EndIf
   If tempInput.blinktime + 1000 < MilliSecs() Then tempInput.blinktime = MilliSecs()
EndFunction

Rem
bbdoc:   Liefert den Inhalt eines Eingabefeldes
returns: Den aktuellen Inhalt des Eingabefelds als Zeichenkette
End Rem
Function GetInputContent:String(tempInput:TInput)
   Return tempInput.currentContent
EndFunction

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group