[B2d] Buttons

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

pixelshooter

Betreff: [B2d] Buttons

BeitragFr, Apr 21, 2006 17:13
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich hab mal ne function programmiert, mit der Man Buttons als Objekte generieren und abfragen kann, weil ich sowas auch in bb3d haben wollte, in B+ gibts das ja schon:

Code: [AUSKLAPPEN]
Function alphaImage (x,y,image,maxx,maxy,transparenz = 50)
   For a = x To x + maxx
      For b = y To y + maxy
         GetColor(a,b)
         red      (a,b) = ColorRed()
         green   (a,b) = ColorGreen()
         blue   (a,b) = ColorBlue()
      Next
   Next
   DrawImage image,x,y
   For a = x To x + maxx
      For b = y To y + maxy
         GetColor(a,b)
         red2   (a,b) = ColorRed()
         green2   (a,b) = ColorGreen()
         blue2   (a,b) = ColorBlue()
      Next
   Next
   
   For a = x To x + maxx
      For b = y To y + maxy
         red3    = ((red(a,b)    * transparenz) + (Red2(a,b)    * (100 - transparenz))) / 100
         green3   = ((green(a,b)   * transparenz) + (Green2(a,b)  * (100 - transparenz))) / 100
         blue3   = ((blue(a,b)    * transparenz) + (Blue2(a,b)   * (100 - transparenz))) / 100
   
         Color red3,green3,blue3
         Plot a,b
      Next
   Next
End Function

Function button (x,y,inhalt$,image,nr,font,transparenz = 0,image2 = 1)
   If transparenz <> 0 Then
      alphaImage (x,y,image,ImageWidth(image)+100,ImageHeight(image)+100,transparenz)
   Else DrawImage image,x,y
   EndIf
   SetFont font
   Color 0,0,0
   Text x + ((ImageWidth(image) + StringWidth(inhalt$)) / 2 - StringWidth(inhalt$)),y + ((ImageHeight(image) + StringHeight(inhalt$)) / 2 - StringHeight(inhalt$)),inhalt$
   If Not nr = 99
      buttons (nr,1) = x
      buttons (nr,2) = y
      buttons (nr,3) = ImageWidth(image) + x
      buttons (nr,4) = ImageHeight(image) + y
      buttons (nr,5) = image
      buttons (nr,6) = image2
      buttons (nr,7) = font
      buttons2$(nr)  = inhalt$
   EndIf
End Function
   
Function IfButton(buttonid)
   If MouseX()>buttons(buttonid,1)And MouseX()<buttons(buttonid,3)And MouseY()>buttons(buttonid,2)And MouseY()<buttons(buttonid,4) And pointed(buttonid)=0
      pointed(buttonid) = 1
      button(buttons(buttonid,1) + 2,buttons(buttonid,2),buttons2$(buttonid),buttons(buttonid,6),99,buttons(buttonid,7))
   EndIf   
   If  Not (MouseX()>buttons(buttonid,1)And MouseX()<buttons(buttonid,3)And MouseY()>buttons(buttonid,2)And MouseY()<buttons(buttonid,4))
      If pointed(buttonid) = 1
         pointed(buttonid) = 0
         button(buttons(buttonid,1),buttons(buttonid,2),buttons2$(buttonid),buttons(buttonid,5),99,buttons(buttonid,7))
      EndIf
   EndIf
   If MouseX()>buttons(buttonid,1)And MouseX()<buttons(buttonid,3)And MouseY()>buttons(buttonid,2)And MouseY()<buttons(buttonid,4)
      If MouseHit(1)
         Return True
      ElseIf MouseHit(2)
         butinfo(buttonid,MouseX(),MouseY())
         geinfod = 1
      EndIf
   EndIf
End Function


Weil ich deswegen schonmal kritisert worden bin, Die func alphaImage is nur provisorisch und ungeeignet, weil se zu langsam ist. Wenn jemand eine in Echtzeit zu gebrauchende Lösung hat, würde ich mich freuen, wenn er sie mir schicken würde.

Und so funzt der Kram:
Am anfang erst mal die Variablen belegen:

Code: [AUSKLAPPEN]
global buttondown = <deinbild>
global buttonup = <deinbild2>
global buttonfont = <deinfont>
dim buttons(100,7)
dim buttons2$(100)
dim red(graphicswidth(),graphicsheight())
dim green(graphicswidth(),graphicsheight())
dim blue(graphicswidth(),graphicsheight())
dim red2(graphicswidth(),graphicsheight())
dim green2(graphicswidth(),graphicsheight())
dim blue2(graphicswidth(),graphicsheight())


so, und jetzt machen wir dir nen button:

Code: [AUSKLAPPEN]
button(100,100,"dein Button",buttonup,1,bottonfont,0,buttondown)

repeat
  delay 100
  if ifbutton(1) then print "hello world"
forever


ich geb euch noch'n tipp: keinen Button mit der id 99 belegen, wird sicher lustig...
>> Musikerstellung, Grafik und Design: http://www.pixelshooter.net.tc

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group