Ich habe den Gradient-Test weiter bearbeitet, man kann jetzt bis zu 8 Farben definieren.
mit "Pick Color" kann eine Farbe gewählt werden und mit dem senkrechten Schieberegler wird ihre "Position" eingestellt.
keine Bereichs- und sonstigen Überprüfungen durchgeführt, damit man sehen kann, wie Gradients auch mit "verrückten" Werten arbeiten.
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