Eingabefelder

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

 

Hi

Betreff: Eingabefelder

BeitragDo, Apr 03, 2008 22:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich stell den Quellcode für ein Eingabefelder mal rein bin in letzter Zeit kaum daran am arbeiten
vllt kann es ja einer brauchen
Die Eingaberoutine ist unvollständig und ich hab iwo noch was vergssen weiss aber nicht mehr wo genau das war

Code: [AUSKLAPPEN]

;--------------------------------------------Inputfield Type (Nötig)---------------------------------------------
Type inputfield
  Field xstart
  Field ystart
  Field width
  Field heigth
  Field fieldnumber
  Field over
  Field down
  Field keyuse
  Field pos
  Field posinmsg
  Field cursorstate
  Field signs
  Field avgsnwd ;average sign width
  Field msg$
  Field tempmsg$
End Type
;-------------------------------------------------------------------------------------------------------------------------------



;--------------------------------------------Globale Variablen (Nötig)----------------------------------------------
Global theinput.inputfield
;-------------------------------------------------------------------------------------------------------------------------------



;--------------------------------------------Funktionen für die Inputfelder (Nötig)-------------------------------

Function createinputfield(xstart,ystart,width,heigth,fieldnumber)
theinput=New inputfield

theinput\xstart=xstart
theinput\ystart=ystart
theinput\width=width
theinput\heigth=heigth
theinput\fieldnumber=fieldnumber
theinput\avgsnwd#=(Float(StringWidth("Test String 1")/Float((Len("Test String 1")))))
theinput\signs=Int(width/theinput\avgsnwd#)-1
End Function

;----------------------------------------------------------------------------------------------------------------------------

Function drawinputfields()

For theinput.inputfield = Each inputfield

 Color 255,255,255
 Rect theinput\xstart,theinput\ystart,theinput\width,theinput\heigth,1

 Color 0,0,0
 Rect theinput\xstart,theinput\ystart,theinput\width,theinput\heigth,0

 If theinput\down=True Then

  If theinput\keyuse=True Then

   Color 0,0,0

  Else

   theinput\cursorstate=theinput\cursorstate+1
   If theinput\cursorstate =101 Then theinput\cursorstate=0

   If theinput\cursorstate => 0 And theinput\cursorstate < 50 Then
    Color 0,0,0
   EndIf
   If theinput\cursorstate > 49 And theinput\cursorstate < 101 Then
    Color 255,255,255
   EndIf

  EndIf

  Rect theinput\xstart+3+(theinput\pos)*theinput\avgsnwd,theinput\ystart+2,1,theinput\heigth-4

 EndIf

 Color 0,0,0
  Text theinput\xstart+3,theinput\ystart-7+theinput\heigth/2,theinput\tempmsg
 Color 255,255,255

Next

End Function

;--------------------------------------------------------------------------------------------------------------------------------

Function checkinputmsg()

For theinput.inputfield = Each inputfield

 If theinput\down=True Then

 tempmsg$=""


;----------------------------select-key-----------------------------------------
 key=GetKey()

  Select key
   Case 0

   Case 8
   

   Case 13
   Case 1
   Case 2
   Case 3
   Case 4
   Case 5
   Case 6
   Case 9
   Case 27
   Case 28
   Case 29

   Case 30
    If theinput\signs < Len(theinput\msg$) Then
     If theinput\pos=theinput\signs And theinput\posinmsg < Len(theinput\msg$)
      theinput\posinmsg=theinput\posinmsg+1
     EndIf
     theinput\pos=theinput\pos+1
    Else
     If theinput\pos=Len(theinput\msg$) Then
      theinput\posinmsg=theinput\posinmsg+1
     EndIf
     theinput\pos=theinput\pos+1
    EndIf

   Case 31
    If theinput\pos=0 And theinput\posinmsg > 0 Then
     theinput\posinmsg=theinput\posinmsg-1
    EndIf
    theinput\pos=theinput\pos-1

   Default
    If theinput\posinmsg=Len(theinput\msg$) And (theinput\pos=theinput\signs Or theinput\pos=Len(theinput\msg$)) Then
     theinput\msg$=theinput\msg$+Chr(key)
     theinput\posinmsg=theinput\posinmsg+1
    ElseIf theinput\pos=0 Then
     theinput\msg$=Chr(key)+theinput\msg$
    Else
     If Len(theinput\msg$) >= theinput\signs Then
      If theinput\posinmsg < theinput\signs Then
       theinput\msg$=Left(theinput\msg$,theinput\pos)+Chr(key)+Right(theinput\msg$,Len(theinput\msg$)-theinput\pos)
      Else
       theinput\msg$=Left(theinput\msg$,theinput\posinmsg-(theinput\signs-theinput\pos))+Chr(key)+Right(theinput\msg$,Len(theinput\msg$)-(theinput\posinmsg-(theinput\signs-theinput\pos)))
      EndIf
     Else
      If theinput\posinmsg < theinput\signs Then
       theinput\msg$=Left(theinput\msg$,theinput\pos)+Chr(key)+Right(theinput\msg$,Len(theinput\msg$)-theinput\pos)
      Else
       theinput\msg$=Left(theinput\msg$,theinput\posinmsg-(Len(theinput\msg$)-theinput\pos))+Chr(key)+Right(theinput\msg$,Len(theinput\msg$)-(theinput\posinmsg-(Len(theinput\msg$)-theinput\pos)))
      EndIf
     EndIf
     If theinput\pos=theinput\signs Then theinput\posinmsg=theinput\posinmsg+1
    EndIf
    theinput\pos=theinput\pos+1

  End Select
;-----------------------------------------------------------------------------------


;--------------------pos-overflow-pos-underflow-------------------------------------
 If theinput\posinmsg > Len(theinput\msg$) Then theinput\posinmsg=Len(theinput\msg$)
 If theinput\posinmsg < 0 Then theinput\posinmsg=0

 If theinput\pos > theinput\signs Then theinput\pos=theinput\signs
 If theinput\pos < 0 Then theinput\pos=0
 If theinput\pos > Len(theinput\msg$) Then theinput\pos=Len(theinput\msg$)
;-----------------------------------------------------------------------------------


;--------------------------------------tempmsg--------------------------------------
 If theinput\posinmsg=>theinput\signs Then
  theinput\tempmsg$=Mid(theinput\msg$,theinput\posinmsg-(theinput\signs-1),theinput\signs)
 Else
  theinput\tempmsg$=Left(theinput\msg$,theinput\signs)
 EndIf
;-----------------------------------------------------------------------------------

 EndIf

Next

FlushKeys()
End Function

;--------------------------------------------------------------------------------------------------------------------------------

Function checkinputfields(mx,my)

For theinput.inputfield = Each inputfield

 If mx>theinput\xstart And mx<(theinput\xstart+theinput\width) And my>theinput\ystart And my<(theinput\ystart+theinput\heigth) Then
  theinput\over=True
 Else
  theinput\over=False
 EndIf

 If theinput\down=True Then
  If theinput\over=False And MouseDown(1) Then theinput\down=False
 Else
  If theinput\over=True And MouseDown(1) Then
   theinput\down=True
   Exit
  EndIf
 EndIf

Next

End Function

;--------------------------------------------------------------------------------------------------------------------------------

Function getinput$(fieldnumber)
theinput.inputfield=First inputfield

For i = 1 To fieldnumber-1
 theinput=After theinput
Next

Return theinput\msg$
End Function

;--------------------------------------------------------------------------------------------------------------------------------

Function currentcursor(defaultcursor,overcursor)
 For theinput.inputfield = Each inputfield
  If theinput\over=True Then Return overcursor
 Next

 Return defaultcursor
End Function

;--------------------------------------------------------------------------------------------------------------------------------



und hier noch das beispielprogramm

Code: [AUSKLAPPEN]

;--------------------------------------------Grafikinitialisierung------------------------------------------------------------
Graphics 1280,1024,32,1
SetBuffer BackBuffer()
EnableDirectInput 1
;--------------------------------------------------------------------------------------------------------------------------------



;--------------------------------------------Gui Include------------------------------------------------------------
Include "Eingabefelder.bb"
;--------------------------------------------------------------------------------------------------------------------------------



;--------------------------------------------Mauscursor setzen------------------------------------------------------
cursor=LoadAnimImage("..\Images\Cursor.cur",20,20,0,1)
MaskImage cursor,255,0,255
;--------------------------------------------------------------------------------------------------------------------------------
overcursor=LoadAnimImage("..\Images\Cursor.cur",20,20,2,1)
HandleImage overcursor,12,9
MaskImage overcursor,255,0,255
;--------------------------------------------------------------------------------------------------------------------------------



;--------------------------------------------Inputfelder erstellen-------------------------------------------------
createinputfield(100,50,100,20,1)
createinputfield(100,80,100,20,2)
createinputfield(100,110,100,20,3)
createinputfield(100,140,100,20,4)
createinputfield(100,170,100,20,5)
createinputfield(100,200,100,20,6)
createinputfield(100,230,100,20,7)
createinputfield(100,260,100,20,8)
createinputfield(100,290,100,20,9)
createinputfield(100,320,100,20,10)
createinputfield(100,350,100,20,11)
createinputfield(100,380,100,20,12)
createinputfield(100,410,100,20,13)
createinputfield(100,440,100,20,14)
createinputfield(100,470,100,20,15)
createinputfield(100,500,100,20,16)
createinputfield(100,530,100,20,17)
createinputfield(100,560,100,20,18)
createinputfield(100,590,100,20,19)
createinputfield(100,620,100,20,20)
;--------------------------------------------------------------------------------------------------------------------------------


;--------------------------------------------Hauptschleife-------------------------------------------------------------------
Repeat
ClsColor 255,255,255
Cls

mx=MouseX()
my=MouseY()

checkinputmsg()
checkinputfields(mx,my)
drawinputfields()

Color 0,0,0

theinput.inputfield=First inputfield
Text 600,142,"Gesamter Text: "+theinput\msg
Text 600,156,"Textabschnitt: "+theinput\tempmsg

Text 600,184,theinput\pos
Text 600,198,theinput\posinmsg

Text 600,212,(Len(theinput\msg))
Text 600,226,theinput\signs

Text 100,670,"Geben sie in ein Feld exit ein um das Programm zu beenden"


If KeyDown(28) Then

For theinput.inputfield=Each inputfield
If theinput\down=True Then msg$=theinput\msg$
Next

RuntimeError("Ihre Eingabe:  "+Chr(34)+msg$+Chr(34))

EndIf


For i = 1 To 20
 a$=getinput$(i)
 If Trim(Lower(a$)) = "exit" Then RuntimeError("Sie haben Exit eingegeben um das Programm zu beenden")
 If Trim(Lower(a$)) = "hallo" Then Text 210,50+(i-1)*30,"Hi"
Next

Color 255,255,255

DrawImage currentcursor(cursor,overcursor),mx,my

Flip
Until KeyDown(1)
End
;--------------------------------------------------------------------------------------------------------------------------------


und noch die cursorimages

user posted image

TimBo

BeitragFr, Apr 04, 2008 0:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi,

cooles Ding,
aber bei mir gehts Backspace und Entfernen nicht. Confused

Viele Grüße
TimBo
mfg Tim Borowski // CPU: Ryzen 2700x GPU: Nvidia RTX 2070 OC (Gigabyte) Ram: 16GB DDR4 @ 3000MHz OS: Windows 10
Stolzer Gewinner des BCC 25 & BCC 31
hat einen ersten Preis in der 1. Runde beim BWInf 2010/2011 & 2011/12 mit BlitzBasic erreicht.

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group