Einfach zu benutzende Input-Rotine

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

BtbN

Betreff: Einfach zu benutzende Input-Rotine

BeitragSa, Okt 08, 2005 13:56
Antworten mit Zitat
Benutzer-Profile anzeigen
Code: [AUSKLAPPEN]
Global coursorpos,coursortyp,blink=1,blinktimer=MilliSecs(),textout$,backdowntime,backfirst
Global BlitzPlus = 0 ;Ob du blitzPlus hast, wenn nein, muss der NumBlock anders benutzt werden!

Function CreateInput(xpos,ypos,maxwidth=-1,maxletters=-1,blinken=0,showtext=1)
 Local vortext$
 Local nachtext$
 Local toadd$
 Local gotkey = GetKey()
 If (((gotkey > 31 And gotkey < 138 And gotkey <> 127) Or (gotkey >= 196 And gotkey <= 255)) Or (gotkey >= 158 And gotkey <= 191)) And (StringWidth(textout$+Chr(gotkey)) <= maxwidth Or maxwidth = -1) And (Len(textout$+Chr(gotkey)) <= maxletters Or maxletters = -1) Then
  If coursortyp = 0 Then
   vortext$ = Left(textout$,coursorpos)
   nachtext$ = Mid(textout$,coursorpos+1)
   textout$ = vortext$+Chr(gotkey)+nachtext$
  Else
   vortext$ = Left(textout$,coursorpos)
   nachtext$ = Mid(textout$,coursorpos+2)
   textout$ = vortext$+Chr(gotkey)+nachtext$
  EndIf
  coursorpos = coursorpos + 1
 EndIf
 If gotkey = 8 And textout$ <> "" Then
  vortext$ = Left(textout$,coursorpos-1)
  nachtext$ = Mid(textout$,coursorpos+1)
  textout$ = vortext$+nachtext$
  coursorpos = coursorpos - 1
 EndIf
 If (gotkey = $F728 Or gotkey = 4) Then
  vortext$ = Left(textout$,coursorpos)
  nachtext$ = Mid(textout$,coursorpos+2)
  textout$ = vortext$+nachtext$
  If KeyDown(157) Then textout$ = "":coursorpos = 0
 EndIf
 If BlitzPlus = 0 Then
  If KeyHit(82) Then toadd$ = "0"
  If KeyHit(79) Then toadd$ = toadd$ + "1"
  If KeyHit(80) Then toadd$ = toadd$ + "2"
  If KeyHit(81) Then toadd$ = toadd$ + "3"
  If KeyHit(75) Then toadd$ = toadd$ + "4"
  If KeyHit(76) Then toadd$ = toadd$ + "5"
  If KeyHit(77) Then toadd$ = toadd$ + "6"
  If KeyHit(71) Then toadd$ = toadd$ + "7"
  If KeyHit(72) Then toadd$ = toadd$ + "8"
  If KeyHit(73) Then toadd$ = toadd$ + "9"
  If KeyHit(83) Then toadd$ = toadd$ + ","
  If coursortyp = 0 Then
   vortext$ = Left(textout$,coursorpos)
   nachtext$ = Mid(textout$,coursorpos+1)
   textout$ = vortext$+toadd$+nachtext$
  Else
   vortext$ = Left(textout$,coursorpos)
   nachtext$ = Mid(textout$,coursorpos+2)
   textout$ = vortext$+toadd$+nachtext$
  EndIf
  coursorpos = coursorpos + Len(toadd$)
  If KeyDown(14) And Len(textout$) > 0 Then
   If backfirst = 0 Then
    backfirst = 1
    backdowntime = MilliSecs()
   ElseIf MilliSecs()-backdowntime >= 450 Then
    vortext$ = Left(textout$,coursorpos-1)
    nachtext$ = Mid(textout$,coursorpos+1)
    textout$ = vortext$+nachtext$
    coursorpos = coursorpos - 1
   EndIf
  Else
   backfirst = 0
  EndIf
 EndIf
 If (gotkey = $F702 Or gotkey = 31) And coursorpos > 0 Then
  coursorpos = coursorpos - 1
 EndIf
 If (gotkey = $F703 Or gotkey = 30) And coursorpos < Len(textout$) Then
  coursorpos = coursorpos + 1
 EndIf
 If (gotkey = $F727 Or gotkey = 3) Then
  coursortyp = 1-coursortyp
 EndIf
 If (gotkey = $F72A Or gotkey = 1) Then
  coursorpos = 0
 EndIf
 If (gotkey = $F72B Or gotkey = 2) Then
  coursorpos = Len(textout$)
 EndIf
 If MilliSecs() - blinktimer >= 750 Then blink=1-blink:blinktimer=MilliSecs()
 If showtext = 1 Then Text xpos,ypos,textout$
 If (blink = 1 Or blinken = 0) And showtext = 1 Then
  If coursortyp = 1 Then
   If coursorpos > 0 Then
    Rect xpos+StringWidth(Left(textout$,coursorpos)),ypos+StringHeight(Mid(textout$,coursorpos,1)),StringWidth(Mid(textout$,coursorpos,1)),2
   Else
    If Len(textout$) > 0 Then
     Rect xpos,ypos+FontHeight(),StringWidth(Mid(textout,1,1)),2
    Else
     Rect xpos,ypos+FontHeight(),8,2
    EndIf
   EndIf
  Else
   Rect xpos+StringWidth(Left(textout$,coursorpos)),ypos,2,FontHeight()
  EndIf
 EndIf
End Function


Parameter:
xpos: Die X-Position, wo das Input-Feld anfangen soll
ypos: Die Y-Position
maxwidth: Maximale breite des eingabe-Feldes in Pixeln(-1 = Unbegrenzt)
maxletters: Maximale länge des Textes in Buchstaben(-1 = Unbegrenzt)
blinken: Ob der Coursor blinken soll
showtext: Ob die Eingabe angezeigt werden soll

Die Funktion CreateInput MUSS in der Hauptschleife aufgerufen werden, und zwar in jedem Durchgang. Den Font kann man setzen wie man will, die Funktion passt sich an. Den Text kann man aus der Variable textout$ lesen.

HINWEIS: Wie mir scheint, funktioniert in B3D der NumBlock nicht richtig und in B3D läuft die Rotine im allgemeinen schlechter, als in B+. Bei B+ funktioniert dieser jedoch einwandfrei. Ist also für B+ konzipiert ^^

ACHTUNG: Teilweise sind die Zeilen zu lang für das Forum. Deshalb hab ich es nochmal hochgeladen:
http://nameless-home.de/dl.php?f=InputLib.bb
Es ist auch noch direkt ein Beispiel dabei.

BORNtobeNAMELESS
Ps.: Bitte um KONSTRUKTIVE kritik!
  • Zuletzt bearbeitet von BtbN am Sa, Okt 08, 2005 17:40, insgesamt 2-mal bearbeitet

bloxx01

BeitragSa, Okt 08, 2005 16:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Ist ganz in Ordnung, jedoch sollte bei gedrückter backspace Taste der String gekürzt werden, und ich finde die Funktion sollte den Text returnen.
Space Threat - der kostenlose 3D Multiplayer Spaceshooter
www.SpaceThreat.de

BtbN

BeitragSa, Okt 08, 2005 17:21
Antworten mit Zitat
Benutzer-Profile anzeigen
In BlitzPlus funktioniert das, mit gedrückter Rücktaste!
Is nen Bug von B3D, da is die GetKey-Funktion leicht abgedreht!
Aber ich guck ma, was sich machen läßt!

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group