Scrollfelder und Endscheidungsfelder

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

sbrog

Betreff: Scrollfelder und Endscheidungsfelder

BeitragSo, Jul 04, 2004 11:01
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich hab mal ne Funktion geschrieben, mit der man eine Variable mittels klick auf Pfeile erhöht oder verringert und auf True und False stellen kann.

Als Anwendungsbeispiel habe ich das ganze habe ich in ein Rechteck umgesetzt, bei dem man mit diesen Feldern die Farbe verändern kann.

Eine schöne Aufgabe wäre es z.B , das texturerstellungsprogramm von Holzchopf mit diesen Funktionen zu schreiben.

BlitzBasic: [AUSKLAPPEN]

Graphics 1024,768
Global yesbutton1 = CreateImage(25,20)
Dim yes(24,19)
Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,1,1,0,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,1,1,0,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2

For y= 0 To 19
For x = 0 To 24
Read yes(x,y)
Next
Next

SetBuffer ImageBuffer(yesbutton1)
For y = 0 To 19
For x = 0 To 24
If yes(x,y) = 0 Then Color 255,255,255
If yes(x,y) = 1 Then Color 0,0,0
If yes(x,y) = 2 Then Color 255,0,0
Plot x,y
Next
Next
;-----------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------
Global yesbutton2 = CreateImage(25,30)
SetBuffer ImageBuffer(yesbutton2)
For y = 0 To 19
For x = 0 To 24
If yes(x,y) = 0 Then Color 0,0,0
If yes(x,y) = 1 Then Color 255,255,255
If yes(x,y) = 2 Then Color 255,0,0
Plot x,y
Next
Next

;---------------------------------------------------------------------------------------------------
Global nobutton1 = CreateImage(30,20)
Dim no(29,19)
Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2
Data 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,2,2,2,2,2,2,2

For y = 0 To 19
For x = 0 To 29
Read no(x,y)
Next
Next

SetBuffer ImageBuffer(nobutton1)
For y = 0 To 19
For x = 0 To 29
If no(x,y) = 0 Then Color 255,255,255
If no(x,y) = 1 Then Color 0,0,0
If no(x,y) = 2 Then Color 255,0,0
Plot x,y
Next
Next
;----------------------------------------------------------------------------------------------------
Global nobutton2 = CreateImage(30,20)
SetBuffer ImageBuffer(nobutton2)
For y = 0 To 19
For x = 0 To 29
If no(x,y) = 0 Then Color 0,0,0
If no(x,y) = 1 Then Color 255,255,255
If no(x,y) = 2 Then Color 255,0,0
Plot x,y
Next
Next

;----------------------------------------------------------------------------------------------------
Global scrolldown =CreateImage(20,20) ;Scrolldownbutton erstellen

MaskImage scrolldown,255,255,255

Dim scrolldownbutton(19,19) ; Die werte für den Scrolldownbutton, das Bild wird sozusagen gepixelt
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0
Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0
Data 0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0
Data 0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0
Data 0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,0
Data 0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,0
Data 0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0
Data 0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0
Data 0,0,0,0,0,1,2,2,2,2,2,2,2,2,1,0,0,0,0,0
Data 0,0,0,0,0,1,2,2,2,2,2,2,2,2,1,0,0,0,0,0
Data 0,0,0,0,0,0,1,2,2,2,2,2,2,1,0,0,0,0,0,0
Data 0,0,0,0,0,0,1,2,2,2,2,2,2,1,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,1,2,2,2,2,1,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,1,2,2,2,2,1,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,1,2,2,1,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,1,2,2,1,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0

For y= 0 To 19
For x= 0 To 19
Read scrolldownbutton(x,y) ;die werte des Buttons werden in ein array gespeichert
Next
Next


SetBuffer ImageBuffer(scrolldown) ;das bild wird in seinen buffer gezeichnet
For y = 0 To 19
For x = 0 To 19
If scrolldownbutton(x,y) = 0 Then Color 255,255,255
If scrolldownbutton(x,y) = 1 Then Color 255,255,255
If scrolldownbutton(x,y) = 2 Then Color 255,255,0
Plot x,y
Next
Next

;----------------------------------------------------------------------------------------------------
Global scrollup = CreateImage(20,20)

MaskImage scrollup,255,255,255

Dim scrollupbutton(19,19)
Data 0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,1,2,2,1,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,1,2,2,1,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,1,2,2,2,2,1,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,1,2,2,2,2,1,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,1,2,2,2,2,2,2,1,0,0,0,0,0,0
Data 0,0,0,0,0,0,1,2,2,2,2,2,2,1,0,0,0,0,0,0
Data 0,0,0,0,0,1,2,2,2,2,2,2,2,2,1,0,0,0,0,0
Data 0,0,0,0,0,1,2,2,2,2,2,2,2,2,1,0,0,0,0,0
Data 0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0
Data 0,0,0,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0
Data 0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,0
Data 0,0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,0
Data 0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0
Data 0,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0
Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0
Data 0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
Data 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1


For y = 0 To 19
For x = 0 To 19
Read scrollupbutton(x,y)
Next
Next

SetBuffer ImageBuffer(scrollup)
For y = 0 To 19
For x = 0 To 19
If scrollupbutton(x,y) = 0 Then Color 255,255,255
If scrollupbutton(x,y) = 1 Then Color 255,255,255
If scrollupbutton(x,y) = 2 Then Color 255,255,0
Plot x,y
Next
Next

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

Global mausbutton = CreateImage(20,20)
SetBuffer ImageBuffer (mausbutton)
Line 10,0,10,20
Line 0,10,20,10

;------------------------------------------------------------------------------------------------
;DIe Variablen, die als scrollfelder erscheinen

Global rot = 200
Global blau =200
Global gruen = 200

Global rahmen_rot = 255
Global rahmen_gruen
Global rahmen_blau

;die variablen, die als Ja-Nein-entscheidungsfelder erscheinen
Global rahmen = True
;-----------------------------------------------------------------------------------------------
Global mausx
Global mausy

x= 100:y= 100
;--------------------------------------------------------------------------------------------------
SetBuffer BackBuffer()

Repeat
Cls

mausx = MouseX() ;die mauskoordinaten werden an eine Variable übergeben
mausy = MouseY()
DrawImage mausbutton,Mausx,Mausy ;die maus wird gezeichnet

rot = scrollfeld(800,20,rot,0,255,"Rot")
gruen = scrollfeld(875,20,gruen,0,255,"Grün")
blau = scrollfeld(950,20,blau,0,255,"Blau")

rahmen_rot = scrollfeld(800,200,rahmen_rot,0,255,"Rot")
rahmen_gruen = scrollfeld(875,200,rahmen_gruen,0,255,"Grün")
rahmen_blau = scrollfeld(950,200,rahmen_blau,0,255,"Blau")

rahmen = janeinfeld(800,150,rahmen,"Rahmen")
texturmalen()

Flip
Until KeyHit(1)
;--------------------------------------------------------------------------------------------------
Function scrollfeld(x,y,variable,min,max,ueberschrift$) ;zeichnet ein scrollfeld an x,y,der wert wird an die variable übergeben

DrawImage scrollup,x+15,y ;der Hochpfeil wird gezeihcnet
DrawImage scrolldown,x+15,y+50 ;der runterpfeil wird gezeichnet
Color 255,255,255
Rect x,y+25,50,20 ;das eingabefeld wird gezeichnet

Color 155,155,155
If MouseDown(1)
If ImagesCollide(mausbutton,mausx,mausy,0,scrollup,x+15,y,0) Then variable = variable +1 ;wenn auf den oberen pfeil geklickt wird, wird die variable erhöht
If ImagesCollide(mausbutton,mausx,mausy,0,scrolldown,x+15,y+50,0) Then variable = variable -1 ;auf dem unteren pfeil verringert
EndIf

If variable > max Then variable = min ;wenn die variable zu groß für ihren zweck ist, dann fängt sie wieder bei 0 an
If variable < min Then variable = max

Text x,y-15,ueberschrift ; die überschrift des Scrollfelds wird gemalt
Text x,y+25,variable ;die variable wird zur information ins scrollfeld geschrieben
Return variable ;die Variable wird an die jeweilige zurückgegeben
End Function
;----------------------------------------------------------------------------------------------------
Function janeinfeld(x,y,variable,ueberschrift$)



If variable = True
DrawImage yesbutton2,x,y+15
DrawImage nobutton1,x+45,y+15
If ImagesCollide(mausbutton,mausx,mausy,0,nobutton1,x+45,y+15,0) And MouseHit(1) Then variable = False
EndIf

If variable = False
DrawImage yesbutton1,x,y+15
DrawImage nobutton2,x+45,y+15
If ImagesCollide(mausbutton,mausx,mausy,0,yesbutton1,x,y+15,0) And MouseHit(1) Then variable = True
EndIf
Text x,y,ueberschrift
Return variable
End Function
;----------------------------------------------------------------------------------------------------


Function texturmalen()
Color rot,gruen,blau
Rect 448,320,128,128

If rahmen = True
Color rahmen_rot,rahmen_gruen,rahmen_blau
Rect 448,320,128,128,0
Rect 447,319,130,130,0
EndIf

End Function

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group