Seite 1 von 1

Beispiele zu neuen Funktionen in PB 4.40

Verfasst: 30.08.2009 15:14
von ts-soft
Ich habe diesen Thread mal eröffnet, um Tipps und Tricks, Beispiele usw.
speziell zu neuen Funktionen in PB 4.40 an einem zentralem Punkt zu sammeln.

Alle Beispiele sollten sofort lauffähig, alle Variablen deklariert und Einsteigerfreundlich sein.
Sie sollten sich auf Map(), Gradient, Timer usw. beziehen, aber eher nicht
auf die neue Projektverwaltung oder anderer IDE Features.

Wäre Nett, wenn ein Mod diesen Thread klebrig macht, bis ein neuer Thread
zu PB 4.50 erforderlich ist :wink:

Bei Fragen zu den Beispielen bitte genau Angeben, welches Beispiel von
welchem Autor gemeint ist, sonst gibts Kuddelmuddel und Mißverständnisse.

Gruß

Thomas

Edit by NicTheQuick:
Thread ist nun klebrig.

Verfasst: 30.08.2009 15:16
von ts-soft
Fang ich mal an :wink:

StatusBarProgress() und Timertest

Code: Alles auswählen

EnableExplicit

Define i, t1, t2, t3

OpenWindow(0, #PB_Ignore, #PB_Ignore, 630, 20, "timerdemo", #PB_Window_SystemMenu)

If CreateStatusBar(0, WindowID(0))
  For i = 1 To 3
    AddStatusBarField(210)
    StatusBarProgress(0, i - 1, 0, #PB_ProgressBar_Smooth, 0, 100)
    AddWindowTimer(0, i, 100 * i)
  Next
EndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
     
    Case #PB_Event_Timer
      Select EventTimer()
        Case 1
          t1 + 1
          If t1 > 100 : t1 = 0 : EndIf
          StatusBarProgress(0, 0, t1)
         
        Case 2
          t2 + 1
          If t2 > 100 : t2 = 0 : EndIf
          StatusBarProgress(0, 1, t2)
         
        Case 3
          t3 + 1
          If t3 > 100 : t3 = 0 : EndIf
          StatusBarProgress(0, 2, t3)       
      EndSelect
   
  EndSelect
ForEver

Gradienttest

Verfasst: 30.08.2009 17:23
von bizzl
Okay, dann auch noch mal hier:

Werde das Programm noch etwas ausbauen, z.B. mit Farbauswahl, und besser strukturieren und kommentieren.
Weiß aber nicht wann, da ich ab morgen wieder arbeiten muss.

Code: Alles auswählen

;Gradient-Test written 30.08.2009 by "bizzl"
EnableExplicit

Define event.l

Structure LinearGradient
  top.l
  bottom.l
  left.l
  right.l
  gad.l[14]
EndStructure

Structure BoxedGradient
  x.l
  y.l
  width.l
  height.l
  gad.l[14]
EndStructure

Structure EllipticalGradient
  x.l
  y.l
  xrad.l
  yrad.l
  gad.l[14]
EndStructure

Structure ConicalGradient
  x.l
  y.l
  angle.f
  gad.l[11]
EndStructure

Global lg.LinearGradient,bg.BoxedGradient,eg.EllipticalGradient,cg.ConicalGradient

Procedure Draw()
  If StartDrawing(ImageOutput(0))
    DrawingMode(#PB_2DDrawing_Gradient)
    LinearGradient(lg\left,lg\top,lg\right,lg\bottom)
    GradientColor(0.0,RGB(243, 16, 0))
    GradientColor(0.25,RGB(19, 16, 236))
    GradientColor(0.50,RGB(123, 169, 56))
    GradientColor(0.75,RGB(252, 250, 52))
    GradientColor(1.0,RGB(243, 16, 0))
    Box(0,0,100,100)
    StopDrawing()
  EndIf 
  If StartDrawing(ImageOutput(1))
    DrawingMode(#PB_2DDrawing_Gradient)
    LinearGradient(lg\left,lg\top,lg\right,lg\bottom)
    GradientColor(0.0,RGB(243, 16, 0))
    GradientColor(0.25,RGB(19, 16, 236))
    GradientColor(0.50,RGB(123, 169, 56))
    GradientColor(0.75,RGB(252, 250, 52))
    GradientColor(1.0,RGB(243, 16, 0))
    Circle(50,50,50)
    StopDrawing()
  EndIf 
  If StartDrawing(ImageOutput(2))
    DrawingMode(#PB_2DDrawing_Gradient)
    BoxedGradient(bg\x,bg\y,bg\width,bg\height)
    GradientColor(0.0,RGB(243, 16, 0))
    GradientColor(0.25,RGB(19, 16, 236))
    GradientColor(0.50,RGB(123, 169, 56))
    GradientColor(0.75,RGB(252, 250, 52))
    GradientColor(1.0,RGB(243, 16, 0))
    Box(0,0,100,100)
    StopDrawing()
  EndIf         
  If StartDrawing(ImageOutput(3))
    DrawingMode(#PB_2DDrawing_Gradient)
    BoxedGradient(bg\x,bg\y,bg\width,bg\height)
    GradientColor(0.0,RGB(243, 16, 0))
    GradientColor(0.25,RGB(19, 16, 236))
    GradientColor(0.50,RGB(123, 169, 56))
    GradientColor(0.75,RGB(252, 250, 52))
    GradientColor(1.0,RGB(243, 16, 0))
    Circle(50,50,50)
    StopDrawing()
  EndIf 
  If StartDrawing(ImageOutput(4))
    DrawingMode(#PB_2DDrawing_Gradient)
    EllipticalGradient(eg\x,eg\y,eg\xrad,eg\yrad)
    GradientColor(0.0,RGB(243, 16, 0))
    GradientColor(0.25,RGB(19, 16, 236))
    GradientColor(0.50,RGB(123, 169, 56))
    GradientColor(0.75,RGB(252, 250, 52))
    GradientColor(1.0,RGB(243, 16, 0))
    Box(0,0,100,100)
    StopDrawing()
  EndIf         
  If StartDrawing(ImageOutput(5))
    DrawingMode(#PB_2DDrawing_Gradient)
    EllipticalGradient(eg\x,eg\y,eg\xrad,eg\yrad)
    GradientColor(0.0,RGB(243, 16, 0))
    GradientColor(0.25,RGB(19, 16, 236))
    GradientColor(0.50,RGB(123, 169, 56))
    GradientColor(0.75,RGB(252, 250, 52))
    GradientColor(1.0,RGB(243, 16, 0))
    Circle(50,50,50)
    StopDrawing()
  EndIf  
  If StartDrawing(ImageOutput(6))
    DrawingMode(#PB_2DDrawing_Gradient)
    ConicalGradient(cg\x,cg\y,cg\angle)
    GradientColor(0.0,RGB(243, 16, 0))
    GradientColor(0.25,RGB(19, 16, 236))
    GradientColor(0.50,RGB(123, 169, 56))
    GradientColor(0.75,RGB(252, 250, 52))
    GradientColor(1.0,RGB(243, 16, 0))
    Box(0,0,100,100)
    StopDrawing()
  EndIf         
  If StartDrawing(ImageOutput(7))
    DrawingMode(#PB_2DDrawing_Gradient)
    ConicalGradient(cg\x,cg\y,cg\angle)
    GradientColor(0.0,RGB(243, 16, 0))
    GradientColor(0.25,RGB(19, 16, 236))
    GradientColor(0.50,RGB(123, 169, 56))
    GradientColor(0.75,RGB(252, 250, 52))
    GradientColor(1.0,RGB(243, 16, 0))
    Circle(50,50,50)
    StopDrawing()
  EndIf         
EndProcedure

Procedure Init()
  Protected x
  For x=0 To 7
    If CreateImage(x,100,100)=0:ProcedureReturn #False:EndIf
  Next x
  lg\gad[0]=ContainerGadget(#PB_Any,10,10,200,400,#PB_Container_Raised)
  lg\gad[1]=TextGadget(#PB_Any,0,10,200,20,"LinearGradient",#PB_Text_Center )
  lg\gad[2]=TextGadget(#PB_Any,10,30,50,20,"Top:")
  lg\gad[3]=TrackBarGadget(#PB_Any,50,30,100,20,0,100)
  lg\gad[4]=TextGadget(#PB_Any,10,60,50,20,"Left:")
  lg\gad[5]=TrackBarGadget(#PB_Any,50,60,100,20,0,100)
  lg\gad[6]=TextGadget(#PB_Any,10,90,50,20,"Right:")
  lg\gad[7]=TrackBarGadget(#PB_Any,50,90,100,20,0,100):SetGadgetState(lg\gad[7],100)
  lg\gad[8]=TextGadget(#PB_Any,10,120,50,20,"Bottom:")
  lg\gad[9]=TrackBarGadget(#PB_Any,50,120,100,20,0,100):SetGadgetState(lg\gad[9],100)
  lg\gad[10]=TextGadget(#PB_Any,160,30,20,20,"0")
  lg\gad[11]=TextGadget(#PB_Any,160,60,20,20,"0")
  lg\gad[12]=TextGadget(#PB_Any,160,90,20,20,"100")
  lg\gad[13]=TextGadget(#PB_Any,160,120,20,20,"100")
  CloseGadgetList()
  lg\top=0
  lg\left=0
  lg\right=100
  lg\bottom=100
  bg\gad[0]=ContainerGadget(#PB_Any,240,10,200,400,#PB_Container_Raised)
  bg\gad[1]=TextGadget(#PB_Any,0,10,200,20,"BoxedGradient",#PB_Text_Center )
  bg\gad[2]=TextGadget(#PB_Any,10,30,50,20,"X:")
  bg\gad[3]=TrackBarGadget(#PB_Any,50,30,100,20,0,100)
  bg\gad[4]=TextGadget(#PB_Any,10,60,50,20,"Y:")
  bg\gad[5]=TrackBarGadget(#PB_Any,50,60,100,20,0,100)
  bg\gad[6]=TextGadget(#PB_Any,10,90,50,20,"Width:")
  bg\gad[7]=TrackBarGadget(#PB_Any,50,90,100,20,0,100):SetGadgetState(bg\gad[7],100)
  bg\gad[8]=TextGadget(#PB_Any,10,120,50,20,"Height:")
  bg\gad[9]=TrackBarGadget(#PB_Any,50,120,100,20,0,100):SetGadgetState(bg\gad[9],100)
  bg\gad[10]=TextGadget(#PB_Any,160,30,20,20,"0")
  bg\gad[11]=TextGadget(#PB_Any,160,60,20,20,"0")
  bg\gad[12]=TextGadget(#PB_Any,160,90,20,20,"100")
  bg\gad[13]=TextGadget(#PB_Any,160,120,20,20,"100")
  CloseGadgetList()
  bg\x=0
  bg\y=0
  bg\width=100
  bg\height=100
  eg\gad[0]=ContainerGadget(#PB_Any,450,10,200,400,#PB_Container_Raised)
  eg\gad[1]=TextGadget(#PB_Any,0,10,200,20,"Circular/EllipticalGradient",#PB_Text_Center )
  eg\gad[2]=TextGadget(#PB_Any,10,30,50,20,"X:")
  eg\gad[3]=TrackBarGadget(#PB_Any,50,30,100,20,0,100):SetGadgetState(eg\gad[3],50)
  eg\gad[4]=TextGadget(#PB_Any,10,60,50,20,"Y:")
  eg\gad[5]=TrackBarGadget(#PB_Any,50,60,100,20,0,100):SetGadgetState(eg\gad[5],50)
  eg\gad[6]=TextGadget(#PB_Any,10,90,50,20,"RadiusX:")
  eg\gad[7]=TrackBarGadget(#PB_Any,50,90,100,20,0,100):SetGadgetState(eg\gad[7],50)
  eg\gad[8]=TextGadget(#PB_Any,10,120,50,20,"RadiusY:")
  eg\gad[9]=TrackBarGadget(#PB_Any,50,120,100,20,0,100):SetGadgetState(eg\gad[9],50)
  eg\gad[10]=TextGadget(#PB_Any,160,30,20,20,"50")
  eg\gad[11]=TextGadget(#PB_Any,160,60,20,20,"50")
  eg\gad[12]=TextGadget(#PB_Any,160,90,20,20,"50")
  eg\gad[13]=TextGadget(#PB_Any,160,120,20,20,"50")
  CloseGadgetList() 
  eg\x=50
  eg\y=50
  eg\xrad=50
  eg\yrad=50
  cg\gad[0]=ContainerGadget(#PB_Any,660,10,200,400,#PB_Container_Raised)
  cg\gad[1]=TextGadget(#PB_Any,0,10,200,20,"ConicalGradient",#PB_Text_Center )
  cg\gad[2]=TextGadget(#PB_Any,10,30,50,20,"X:")
  cg\gad[3]=TrackBarGadget(#PB_Any,50,30,100,20,0,100):SetGadgetState(cg\gad[3],50)
  cg\gad[4]=TextGadget(#PB_Any,10,60,50,20,"Y:")
  cg\gad[5]=TrackBarGadget(#PB_Any,50,60,100,20,0,100):SetGadgetState(cg\gad[5],50)
  cg\gad[6]=TextGadget(#PB_Any,10,90,50,20,"Angle:")
  cg\gad[7]=TrackBarGadget(#PB_Any,50,90,100,20,0,359):SetGadgetState(cg\gad[7],0)
  cg\gad[8]=TextGadget(#PB_Any,160,30,20,20,"50")
  cg\gad[9]=TextGadget(#PB_Any,160,60,20,20,"50")
  cg\gad[10]=TextGadget(#PB_Any,160,90,20,20,"0")
  CloseGadgetList()
  cg\x=50
  cg\y=50
  cg\angle=0.0 
  ProcedureReturn #True 
EndProcedure

If OpenWindow(0,0,100,1024,600,"Gradient-Test",#PB_Window_SystemMenu|#PB_Window_Normal)
  If Init()
    Repeat
      If StartDrawing(WindowOutput(0))
        DrawImage(ImageID(0),60,170)
        DrawImage(ImageID(1),60,280)
        DrawImage(ImageID(2),290,170)
        DrawImage(ImageID(3),290,280)
        DrawImage(ImageID(4),500,170)
        DrawImage(ImageID(5),500,280)
        DrawImage(ImageID(6),710,170)
        DrawImage(ImageID(7),710,280)
        StopDrawing()
      EndIf
      event=WaitWindowEvent()
      If event=#PB_Event_Gadget
        Select EventGadget()
          Case lg\gad[3]:lg\top=GetGadgetState(lg\gad[3]):SetGadgetText(lg\gad[10],Str(lg\top))
          Case lg\gad[5]:lg\left=GetGadgetState(lg\gad[5]):SetGadgetText(lg\gad[11],Str(lg\left))
          Case lg\gad[7]:lg\right=GetGadgetState(lg\gad[7]):SetGadgetText(lg\gad[12],Str(lg\right))
          Case lg\gad[9]:lg\bottom=GetGadgetState(lg\gad[9]):SetGadgetText(lg\gad[13],Str(lg\bottom))        
          Case bg\gad[3]:bg\x=GetGadgetState(bg\gad[3]):SetGadgetText(bg\gad[10],Str(bg\x))
          Case bg\gad[5]:bg\y=GetGadgetState(bg\gad[5]):SetGadgetText(bg\gad[11],Str(bg\y))
          Case bg\gad[7]:bg\width=GetGadgetState(bg\gad[7]):SetGadgetText(bg\gad[12],Str(bg\width))
          Case bg\gad[9]:bg\height=GetGadgetState(bg\gad[9]):SetGadgetText(bg\gad[13],Str(bg\height))        
          Case eg\gad[3]:eg\x=GetGadgetState(eg\gad[3]):SetGadgetText(eg\gad[10],Str(eg\x))
          Case eg\gad[5]:eg\y=GetGadgetState(eg\gad[5]):SetGadgetText(eg\gad[11],Str(eg\y))
          Case eg\gad[7]:eg\xrad=GetGadgetState(eg\gad[7]):SetGadgetText(eg\gad[12],Str(eg\xrad))
          Case eg\gad[9]:eg\yrad=GetGadgetState(eg\gad[9]):SetGadgetText(eg\gad[13],Str(eg\yrad))        
          Case cg\gad[3]:cg\x=GetGadgetState(cg\gad[3]):SetGadgetText(cg\gad[8],Str(cg\x))
          Case cg\gad[5]:cg\y=GetGadgetState(cg\gad[5]):SetGadgetText(cg\gad[9],Str(cg\y))
          Case cg\gad[7]:cg\angle=GetGadgetState(cg\gad[7]):SetGadgetText(cg\gad[10],Str(cg\angle))
        EndSelect
      EndIf
      Draw()
    Until event=#PB_Event_CloseWindow
  EndIf
EndIf

Verfasst: 30.08.2009 18:44
von Kiffi
die Nutzung von PostgreSQL wurde hier erläutert:

http://www.purebasic.fr/german/viewtopic.php?t=20740

(an dieser Stelle noch mal Danke an - chris -)

Grüße ... Kiffi

Verfasst: 30.08.2009 19:21
von milan1612

Code: Alles auswählen

Structure Test
  string.s
  answer.i
EndStructure

*Ptr.Test = AllocateMemory(SizeOf(Test))
*Ptr\string = "Hallo Welt!"
*Ptr\answer = 42

ClearStructure(*Ptr, Test)

Debug *Ptr\string
Debug *Ptr\answer

FreeMemory(*Ptr)
ClearStructure ist im Zusammenhang mit Strukturen welche Strings enthalten besonders
nützlich - der von den Strings belegte Speicher wird dabei nämlich ebenfalls korrekt freigegeben...

CheckBox inbetween

Verfasst: 30.08.2009 21:18
von ts-soft
CheckBox inbetween

Code: Alles auswählen

If OpenWindow(0, 0, 0, 270, 130, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CheckBoxGadget(0, 10,  10, 250, 20, "CheckBox standard")
  CheckBoxGadget(1, 10,  40, 250, 20, "CheckBox checked")
  SetGadgetState(1, #PB_Checkbox_Checked)
  CheckBoxGadget(2, 10,  70, 250, 20, "CheckBox inbetween", #PB_CheckBox_ThreeState)
  SetGadgetState(2, #PB_Checkbox_Inbetween)
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf



Verfasst: 30.08.2009 23:11
von ts-soft
Die Nutzung von Map wird hier gut erläutert:
http://www.purebasic.fr/english/viewtop ... 539#295539
leider in englisch, hier nochmal der Code von eddy

Code: Alles auswählen

NewMap PB_Versions.s()
PB_Versions("430") = "PB 4.30"
PB_Versions("440") = "PB 4.40b1"
Debug MapSize(PB_Versions())

FindMapElement(PB_Versions(), "430")
Debug "Result Found = " + PB_Versions()

Procedure TestMap(Map ThisMap.s())
   
   ResetMap(ThisMap())
   While NextMapElement(ThisMap())
      Debug MapKey(ThisMap()) + " => " + ThisMap()
   Wend
   
   ForEach ThisMap()
      Debug MapKey(ThisMap()) + " => "  +ThisMap()
   Next
   
EndProcedure

TestMap(PB_Versions())
ClearMap(PB_Versions())

Beispiel für Maps

Verfasst: 31.08.2009 08:01
von Little John
Ein anderes Beispiel für Maps.

Code: Alles auswählen

; PB 4.40 final

EnableExplicit

Define n, k

;-- Testdaten
n = 10

Dim people$(n-1)
people$(0) = "Fred"
people$(1) = "Timo"
people$(2) = "Lisa"
people$(3) = "Paul"
people$(4) = "Lisa"
people$(5) = "Mary"
people$(6) = "Anna"
people$(7) = "Timo"
people$(8) = "Lisa"
people$(9) = "Fred"

;-- Liste der unterschiedlichen Namen aufbauen und deren Vorkommen zählen
NewMap nameCount()

For k = 0 To n-1
   If FindMapElement(nameCount(), people$(k))
      nameCount() + 1
   Else
      AddMapElement(nameCount(), people$(k), #PB_Map_NoElementCheck)
      nameCount() = 1
   EndIf
Next

;-- Ausgabe
ForEach nameCount()
   Debug MapKey(nameCount()) + ": " + Str(nameCount())
Next
//edit: Das Programm ist jetzt schneller durch Verwendung von #PB_Map_NoElementCheck (das in der Beta-Version, mit der ich diesen Code zuvor schrieb, noch nicht zur Verfügung stand).

Gruß, Little John

GradientTest neue Version

Verfasst: 06.09.2009 14:16
von bizzl
Ich habe den Gradient-Test weiter bearbeitet, man kann jetzt bis zu 8 Farben definieren.
Mit "Active" wird die jeweilige Farbe ein- oder ausgeschaltet,
mit "Pick Color" kann eine Farbe gewählt werden und mit dem senkrechten Schieberegler wird ihre "Position" eingestellt.
Ich habe mit Absicht keine Bereichs- und sonstigen Überprüfungen durchgeführt, damit man sehen kann, wie Gradients auch mit "verrückten" Werten arbeiten.

Bitte um Feedback.

Code: Alles auswählen

;Gradient-Test V0.2, written 06.09.2009 by "bizzl"
EnableExplicit

Define event.l,egad.l

Structure LinearGradient
  top.l
  bottom.l
  left.l
  right.l
  gad.l[14]
EndStructure

Structure BoxedGradient
  x.l
  y.l
  width.l
  height.l
  gad.l[14]
EndStructure

Structure EllipticalGradient
  x.l
  y.l
  xrad.l
  yrad.l
  gad.l[14]
EndStructure

Structure ConicalGradient
  x.l
  y.l
  angle.f
  gad.l[11]
EndStructure

Structure GradientColors
  percent.f
  value.l
  active.l
  gad.l[5]
EndStructure

Global lg.LinearGradient,bg.BoxedGradient,eg.EllipticalGradient,cg.ConicalGradient
Global NewList colors.GradientColors()

Procedure SetGradientColors()
  ResetGradientColors()
  ForEach colors()
    If colors()\active=#True:GradientColor(colors()\percent,colors()\value):EndIf 
  Next 
EndProcedure

Procedure Draw()
  If StartDrawing(ImageOutput(0))
    DrawingMode(#PB_2DDrawing_Gradient)
    LinearGradient(lg\left,lg\top,lg\right,lg\bottom)
    SetGradientColors()
    Box(0,0,100,100)
    StopDrawing()
  EndIf 
  If StartDrawing(ImageOutput(1))
    DrawingMode(#PB_2DDrawing_Gradient)
    LinearGradient(lg\left,lg\top,lg\right,lg\bottom)
    SetGradientColors()
    Circle(50,50,50)
    StopDrawing()
  EndIf 
  If StartDrawing(ImageOutput(2))
    DrawingMode(#PB_2DDrawing_Gradient)
    BoxedGradient(bg\x,bg\y,bg\width,bg\height)
    SetGradientColors()
    Box(0,0,100,100)
    StopDrawing()
  EndIf         
  If StartDrawing(ImageOutput(3))
    DrawingMode(#PB_2DDrawing_Gradient)
    BoxedGradient(bg\x,bg\y,bg\width,bg\height)
    SetGradientColors()
    Circle(50,50,50)
    StopDrawing()
  EndIf 
  If StartDrawing(ImageOutput(4))
    DrawingMode(#PB_2DDrawing_Gradient)
    EllipticalGradient(eg\x,eg\y,eg\xrad,eg\yrad)
    SetGradientColors()
    Box(0,0,100,100)
    StopDrawing()
  EndIf         
  If StartDrawing(ImageOutput(5))
    DrawingMode(#PB_2DDrawing_Gradient)
    EllipticalGradient(eg\x,eg\y,eg\xrad,eg\yrad)
    SetGradientColors()
    Circle(50,50,50)
    StopDrawing()
  EndIf  
  If StartDrawing(ImageOutput(6))
    DrawingMode(#PB_2DDrawing_Gradient)
    ConicalGradient(cg\x,cg\y,cg\angle)
    SetGradientColors()
    Box(0,0,100,100)
    StopDrawing()
  EndIf         
  If StartDrawing(ImageOutput(7))
    DrawingMode(#PB_2DDrawing_Gradient)
    ConicalGradient(cg\x,cg\y,cg\angle)
    SetGradientColors()
    Circle(50,50,50)
    StopDrawing()
  EndIf         
EndProcedure

Procedure Init()
  Protected x,cgad=110
  AddElement(colors())
  colors()\percent=0.0
  colors()\value=RGB(243, 16, 0)
  colors()\active=#True 
  colors()\gad[0]=ContainerGadget(#PB_Any,10,414,80,180,#PB_Container_Raised)
  SetGadgetColor(colors()\gad[0],#PB_Gadget_BackColor,colors()\value)
  colors()\gad[1]=ButtonGadget(#PB_Any,10,10,60,20,"Active",#PB_Button_Toggle)
  SetGadgetState(colors()\gad[1],1)
  colors()\gad[2]=ButtonGadget(#PB_Any,10,40,60,20,"Pick Color")
  colors()\gad[3]=TrackBarGadget(#PB_Any,10,70,20,100,0,100,#PB_TrackBar_Vertical) 
  SetGadgetState(colors()\gad[3],colors()\percent*100)
  colors()\gad[4]=TextGadget(#PB_Any,40,110,30,14,Str(colors()\percent*100),#PB_Text_Center )
  CloseGadgetList()
  AddElement(colors())
  colors()\percent=0.25
  colors()\value=RGB(19, 16, 236)
  colors()\active=#True 
  colors()\gad[0]=ContainerGadget(#PB_Any,10+cgad,414,80,180,#PB_Container_Raised)
  SetGadgetColor(colors()\gad[0],#PB_Gadget_BackColor,colors()\value)
  colors()\gad[1]=ButtonGadget(#PB_Any,10,10,60,20,"Active",#PB_Button_Toggle)
  SetGadgetState(colors()\gad[1],1)
  colors()\gad[2]=ButtonGadget(#PB_Any,10,40,60,20,"Pick Color")
  colors()\gad[3]=TrackBarGadget(#PB_Any,10,70,20,100,0,100,#PB_TrackBar_Vertical)
  SetGadgetState(colors()\gad[3],colors()\percent*100)
  colors()\gad[4]=TextGadget(#PB_Any,40,110,30,14,Str(colors()\percent*100),#PB_Text_Center )
  CloseGadgetList()
  AddElement(colors())
  colors()\percent=0.50
  colors()\value=RGB(123, 169, 56)
  colors()\active=#True 
  colors()\gad[0]=ContainerGadget(#PB_Any,10+cgad*2,414,80,180,#PB_Container_Raised)
  SetGadgetColor(colors()\gad[0],#PB_Gadget_BackColor,colors()\value)
  colors()\gad[1]=ButtonGadget(#PB_Any,10,10,60,20,"Active",#PB_Button_Toggle)
  SetGadgetState(colors()\gad[1],1)
  colors()\gad[2]=ButtonGadget(#PB_Any,10,40,60,20,"Pick Color")
  colors()\gad[3]=TrackBarGadget(#PB_Any,10,70,20,100,0,100,#PB_TrackBar_Vertical)
  SetGadgetState(colors()\gad[3],colors()\percent*100) 
  colors()\gad[4]=TextGadget(#PB_Any,40,110,30,14,Str(colors()\percent*100),#PB_Text_Center )
  CloseGadgetList()
  AddElement(colors())
  colors()\percent=0.75
  colors()\value=RGB(252, 250, 52)
  colors()\active=#True 
  colors()\gad[0]=ContainerGadget(#PB_Any,10+cgad*3,414,80,180,#PB_Container_Raised)
  SetGadgetColor(colors()\gad[0],#PB_Gadget_BackColor,colors()\value)
  colors()\gad[1]=ButtonGadget(#PB_Any,10,10,60,20,"Active",#PB_Button_Toggle)
  SetGadgetState(colors()\gad[1],1)
  colors()\gad[2]=ButtonGadget(#PB_Any,10,40,60,20,"Pick Color")
  colors()\gad[3]=TrackBarGadget(#PB_Any,10,70,20,100,0,100,#PB_TrackBar_Vertical)
  SetGadgetState(colors()\gad[3],colors()\percent*100) 
  colors()\gad[4]=TextGadget(#PB_Any,40,110,30,14,Str(colors()\percent*100),#PB_Text_Center )
  CloseGadgetList()
  AddElement(colors())
  colors()\percent=1.0
  colors()\value=RGB(243, 16, 0)
  colors()\active=#True 
  colors()\gad[0]=ContainerGadget(#PB_Any,10+cgad*4,414,80,180,#PB_Container_Raised)
  SetGadgetColor(colors()\gad[0],#PB_Gadget_BackColor,colors()\value)
  colors()\gad[1]=ButtonGadget(#PB_Any,10,10,60,20,"Active",#PB_Button_Toggle)
  SetGadgetState(colors()\gad[1],1)
  colors()\gad[2]=ButtonGadget(#PB_Any,10,40,60,20,"Pick Color")
  colors()\gad[3]=TrackBarGadget(#PB_Any,10,70,20,100,0,100,#PB_TrackBar_Vertical) 
  SetGadgetState(colors()\gad[3],colors()\percent*100)
  colors()\gad[4]=TextGadget(#PB_Any,40,110,30,14,Str(colors()\percent*100),#PB_Text_Center )
  CloseGadgetList()
  AddElement(colors())
  colors()\percent=0.0
  colors()\value=0
  colors()\active=#False
  colors()\gad[0]=ContainerGadget(#PB_Any,10+cgad*5,414,80,180,#PB_Container_Raised)
  SetGadgetColor(colors()\gad[0],#PB_Gadget_BackColor,colors()\value)
  colors()\gad[1]=ButtonGadget(#PB_Any,10,10,60,20,"Active",#PB_Button_Toggle)
  colors()\gad[2]=ButtonGadget(#PB_Any,10,40,60,20,"Pick Color")
  colors()\gad[3]=TrackBarGadget(#PB_Any,10,70,20,100,0,100,#PB_TrackBar_Vertical) 
  colors()\gad[4]=TextGadget(#PB_Any,40,110,30,14,Str(colors()\percent*100),#PB_Text_Center )
  CloseGadgetList()   
  AddElement(colors())
  colors()\percent=0.0
  colors()\value=0
  colors()\active=#False
  colors()\gad[0]=ContainerGadget(#PB_Any,10+cgad*6,414,80,180,#PB_Container_Raised)
  SetGadgetColor(colors()\gad[0],#PB_Gadget_BackColor,colors()\value)
  colors()\gad[1]=ButtonGadget(#PB_Any,10,10,60,20,"Active",#PB_Button_Toggle)
  colors()\gad[2]=ButtonGadget(#PB_Any,10,40,60,20,"Pick Color")
  colors()\gad[3]=TrackBarGadget(#PB_Any,10,70,20,100,0,100,#PB_TrackBar_Vertical) 
  colors()\gad[4]=TextGadget(#PB_Any,40,110,30,14,Str(colors()\percent*100),#PB_Text_Center )
  CloseGadgetList() 
  AddElement(colors())
  colors()\percent=0.0
  colors()\value=0
  colors()\active=#False
  colors()\gad[0]=ContainerGadget(#PB_Any,10+cgad*7,414,80,180,#PB_Container_Raised)
  SetGadgetColor(colors()\gad[0],#PB_Gadget_BackColor,colors()\value)
  colors()\gad[1]=ButtonGadget(#PB_Any,10,10,60,20,"Active",#PB_Button_Toggle)
  colors()\gad[2]=ButtonGadget(#PB_Any,10,40,60,20,"Pick Color")
  colors()\gad[3]=TrackBarGadget(#PB_Any,10,70,20,100,0,100,#PB_TrackBar_Vertical) 
  colors()\gad[4]=TextGadget(#PB_Any,40,110,30,14,Str(colors()\percent*100),#PB_Text_Center )
  CloseGadgetList()     
  For x=0 To 7
    If CreateImage(x,100,100)=0:ProcedureReturn #False:EndIf
  Next x
  lg\gad[0]=ContainerGadget(#PB_Any,10,10,200,400,#PB_Container_Raised)
  lg\gad[1]=TextGadget(#PB_Any,0,10,200,20,"LinearGradient",#PB_Text_Center)
  lg\gad[2]=TextGadget(#PB_Any,10,30,50,20,"Top:")
  lg\gad[3]=TrackBarGadget(#PB_Any,50,30,100,20,0,100)
  lg\gad[4]=TextGadget(#PB_Any,10,60,50,20,"Left:")
  lg\gad[5]=TrackBarGadget(#PB_Any,50,60,100,20,0,100)
  lg\gad[6]=TextGadget(#PB_Any,10,90,50,20,"Right:")
  lg\gad[7]=TrackBarGadget(#PB_Any,50,90,100,20,0,100):SetGadgetState(lg\gad[7],100)
  lg\gad[8]=TextGadget(#PB_Any,10,120,50,20,"Bottom:")
  lg\gad[9]=TrackBarGadget(#PB_Any,50,120,100,20,0,100):SetGadgetState(lg\gad[9],100)
  lg\gad[10]=TextGadget(#PB_Any,160,30,20,20,"0")
  lg\gad[11]=TextGadget(#PB_Any,160,60,20,20,"0")
  lg\gad[12]=TextGadget(#PB_Any,160,90,20,20,"100")
  lg\gad[13]=TextGadget(#PB_Any,160,120,20,20,"100")
  CloseGadgetList()
  lg\top=0
  lg\left=0
  lg\right=100
  lg\bottom=100
  bg\gad[0]=ContainerGadget(#PB_Any,240,10,200,400,#PB_Container_Raised)
  bg\gad[1]=TextGadget(#PB_Any,0,10,200,20,"BoxedGradient",#PB_Text_Center )
  bg\gad[2]=TextGadget(#PB_Any,10,30,50,20,"X:")
  bg\gad[3]=TrackBarGadget(#PB_Any,50,30,100,20,0,100)
  bg\gad[4]=TextGadget(#PB_Any,10,60,50,20,"Y:")
  bg\gad[5]=TrackBarGadget(#PB_Any,50,60,100,20,0,100)
  bg\gad[6]=TextGadget(#PB_Any,10,90,50,20,"Width:")
  bg\gad[7]=TrackBarGadget(#PB_Any,50,90,100,20,0,100):SetGadgetState(bg\gad[7],100)
  bg\gad[8]=TextGadget(#PB_Any,10,120,50,20,"Height:")
  bg\gad[9]=TrackBarGadget(#PB_Any,50,120,100,20,0,100):SetGadgetState(bg\gad[9],100)
  bg\gad[10]=TextGadget(#PB_Any,160,30,20,20,"0")
  bg\gad[11]=TextGadget(#PB_Any,160,60,20,20,"0")
  bg\gad[12]=TextGadget(#PB_Any,160,90,20,20,"100")
  bg\gad[13]=TextGadget(#PB_Any,160,120,20,20,"100")
  CloseGadgetList()
  bg\x=0
  bg\y=0
  bg\width=100
  bg\height=100
  eg\gad[0]=ContainerGadget(#PB_Any,450,10,200,400,#PB_Container_Raised)
  eg\gad[1]=TextGadget(#PB_Any,0,10,200,20,"Circular/EllipticalGradient",#PB_Text_Center )
  eg\gad[2]=TextGadget(#PB_Any,10,30,50,20,"X:")
  eg\gad[3]=TrackBarGadget(#PB_Any,50,30,100,20,0,100):SetGadgetState(eg\gad[3],50)
  eg\gad[4]=TextGadget(#PB_Any,10,60,50,20,"Y:")
  eg\gad[5]=TrackBarGadget(#PB_Any,50,60,100,20,0,100):SetGadgetState(eg\gad[5],50)
  eg\gad[6]=TextGadget(#PB_Any,10,90,50,20,"RadiusX:")
  eg\gad[7]=TrackBarGadget(#PB_Any,50,90,100,20,0,100):SetGadgetState(eg\gad[7],50)
  eg\gad[8]=TextGadget(#PB_Any,10,120,50,20,"RadiusY:")
  eg\gad[9]=TrackBarGadget(#PB_Any,50,120,100,20,0,100):SetGadgetState(eg\gad[9],50)
  eg\gad[10]=TextGadget(#PB_Any,160,30,20,20,"50")
  eg\gad[11]=TextGadget(#PB_Any,160,60,20,20,"50")
  eg\gad[12]=TextGadget(#PB_Any,160,90,20,20,"50")
  eg\gad[13]=TextGadget(#PB_Any,160,120,20,20,"50")
  CloseGadgetList() 
  eg\x=50
  eg\y=50
  eg\xrad=50
  eg\yrad=50
  cg\gad[0]=ContainerGadget(#PB_Any,660,10,200,400,#PB_Container_Raised)
  cg\gad[1]=TextGadget(#PB_Any,0,10,200,20,"ConicalGradient",#PB_Text_Center )
  cg\gad[2]=TextGadget(#PB_Any,10,30,50,20,"X:")
  cg\gad[3]=TrackBarGadget(#PB_Any,50,30,100,20,0,100):SetGadgetState(cg\gad[3],50)
  cg\gad[4]=TextGadget(#PB_Any,10,60,50,20,"Y:")
  cg\gad[5]=TrackBarGadget(#PB_Any,50,60,100,20,0,100):SetGadgetState(cg\gad[5],50)
  cg\gad[6]=TextGadget(#PB_Any,10,90,50,20,"Angle:")
  cg\gad[7]=TrackBarGadget(#PB_Any,50,90,100,20,0,359):SetGadgetState(cg\gad[7],0)
  cg\gad[8]=TextGadget(#PB_Any,160,30,20,20,"50")
  cg\gad[9]=TextGadget(#PB_Any,160,60,20,20,"50")
  cg\gad[10]=TextGadget(#PB_Any,160,90,20,20,"0")
  CloseGadgetList()
  cg\x=50
  cg\y=50
  cg\angle=0.0 
  ProcedureReturn #True 
EndProcedure

Procedure CheckColorGadgets(g)
  With colors()
  ForEach colors()
    If g=\gad[1]
      If GetGadgetState(\gad[1])=0
        \active=#False 
       Else 
        \active=#True
      EndIf 
    EndIf
    If g=\gad[2]
      \value=ColorRequester(\value)
      SetGadgetColor(\gad[0],#PB_Gadget_BackColor,\value)
      SetGadgetState(colors()\gad[1],1)
      \active=#True
    EndIf 
    If g=\gad[3]
      \percent=GetGadgetState(\gad[3])/100
      SetGadgetText(\gad[4],Str(\percent*100))
    EndIf 
  Next
  EndWith
EndProcedure

If OpenWindow(0,40,100,880,600,"Gradient-Test",#PB_Window_SystemMenu|#PB_Window_Normal)
  If Init()
    Repeat
      If StartDrawing(WindowOutput(0))
        DrawImage(ImageID(0),60,170)
        DrawImage(ImageID(1),60,280)
        DrawImage(ImageID(2),290,170)
        DrawImage(ImageID(3),290,280)
        DrawImage(ImageID(4),500,170)
        DrawImage(ImageID(5),500,280)
        DrawImage(ImageID(6),710,170)
        DrawImage(ImageID(7),710,280)
        StopDrawing()
      EndIf
      event=WaitWindowEvent()
      If event=#PB_Event_Gadget
        egad=EventGadget()
        Select egad
          Case lg\gad[3]:lg\top=GetGadgetState(lg\gad[3]):SetGadgetText(lg\gad[10],Str(lg\top))
          Case lg\gad[5]:lg\left=GetGadgetState(lg\gad[5]):SetGadgetText(lg\gad[11],Str(lg\left))
          Case lg\gad[7]:lg\right=GetGadgetState(lg\gad[7]):SetGadgetText(lg\gad[12],Str(lg\right))
          Case lg\gad[9]:lg\bottom=GetGadgetState(lg\gad[9]):SetGadgetText(lg\gad[13],Str(lg\bottom))        
          Case bg\gad[3]:bg\x=GetGadgetState(bg\gad[3]):SetGadgetText(bg\gad[10],Str(bg\x))
          Case bg\gad[5]:bg\y=GetGadgetState(bg\gad[5]):SetGadgetText(bg\gad[11],Str(bg\y))
          Case bg\gad[7]:bg\width=GetGadgetState(bg\gad[7]):SetGadgetText(bg\gad[12],Str(bg\width))
          Case bg\gad[9]:bg\height=GetGadgetState(bg\gad[9]):SetGadgetText(bg\gad[13],Str(bg\height))        
          Case eg\gad[3]:eg\x=GetGadgetState(eg\gad[3]):SetGadgetText(eg\gad[10],Str(eg\x))
          Case eg\gad[5]:eg\y=GetGadgetState(eg\gad[5]):SetGadgetText(eg\gad[11],Str(eg\y))
          Case eg\gad[7]:eg\xrad=GetGadgetState(eg\gad[7]):SetGadgetText(eg\gad[12],Str(eg\xrad))
          Case eg\gad[9]:eg\yrad=GetGadgetState(eg\gad[9]):SetGadgetText(eg\gad[13],Str(eg\yrad))        
          Case cg\gad[3]:cg\x=GetGadgetState(cg\gad[3]):SetGadgetText(cg\gad[8],Str(cg\x))
          Case cg\gad[5]:cg\y=GetGadgetState(cg\gad[5]):SetGadgetText(cg\gad[9],Str(cg\y))
          Case cg\gad[7]:cg\angle=GetGadgetState(cg\gad[7]):SetGadgetText(cg\gad[10],Str(cg\angle))
          Default:CheckColorGadgets(egad)
        EndSelect
      EndIf
      Draw()
    Until event=#PB_Event_CloseWindow
  EndIf
EndIf

Re: Beispiele zu neuen Funktionen in PB 4.40

Verfasst: 10.11.2009 19:40
von legion
SUPER Beispiele ! Danke fürs Teilen !

Lg. Legion