pour ce code j'ai remercié Arctic Fox et c4s du forum anglais.
mais j'avais oublié que j'avais déjà vu un code identique réalisé par le soldat inconnu ici :
donc je lui adresse aussi un merci.. pour son talent.
le post du forum anglais à remis le sujet au gout du jour et comme maintenant il y de nouvelles commandes "gradient"
je n'ai pas eu de mal à adapter cette fonction sur les boutons.
faire des images de bouton 3D sympa et ainsi skinner nos boutons.
bien sur, il y a d'autres programmes dans le même genre mais il sont pas gratuit..
Code : Tout sélectionner
Enumeration
#windows
#ButtonGadget1
#ButtonGadget2
#TextGadget1
#TextGadget2
#TextGadget3
#TextGadget4
#StringGadget1
#StringGadget2
#StringGadget3
#StringGadget4
#StringGadget5
#StringGadget6
#StringGadget7
#StringGadget8
EndEnumeration
Global cb.l,cf.l,TextColor.l,Textshadow.l,passe.l
Procedure.f GradientCallback(x, y)
ProcedureReturn Sin(x * 0.1) - Cos(y * 0.1) ; will be between 0 and 1
EndProcedure
Procedure ColoredButtonGadget(GadgetNr,X,Y,Width,Height,Text.s,TextFontID,TextColor,Textshadow)
Protected ImageNr
If GadgetNr = #PB_Any : ProcedureReturn -1 : EndIf
ImageNr = CreateImage(#PB_Any,Width,Height,32 );| #PB_Image_Transparent
If ImageNr
StartDrawing(ImageOutput(ImageNr))
DrawingMode(#PB_2DDrawing_Gradient)
If passe=0
cb=BackColor(RGB(Random(255),Random(255),Random(255)))
cf=FrontColor(RGB(Random(255),Random(255),Random(255)))
Else
BackColor(cb)
FrontColor(cf)
EndIf
Debug "Back=RGB("+Str(Red(cb))+","+Str(Green(cb))+","+Str(Blue(cb))+") : Front=RGB("+Str(Red(cf))+","+Str(Green(cf))+","+Str(Blue(cf))+")"
Debug "TextColor=RGB("+Str(Red(TextColor))+","+Str(Green(TextColor))+","+Str(Blue(TextColor))+") : Textshadow=RGB("+Str(Red(Textshadow))+","+Str(Green(Textshadow))+","+Str(Blue(Textshadow))+")"
; EllipticalGradient(Width/2,Height/2,Width/2,Height/3)
BoxedGradient(0,0,Width,Height)
Box(0,0,Width,Height)
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
DrawingFont(TextFontID)
DrawText((Width - TextWidth(Text)) / 2+1,(Height - TextHeight(Text)) / 2-1,Text,Textshadow | $FF000000)
DrawText((Width - TextWidth(Text)) / 2,(Height - TextHeight(Text)) / 2,Text,TextColor | $FF000000)
StopDrawing()
ButtonImageGadget(GadgetNr,X,Y,Width,Height,ImageID(ImageNr))
EndIf
ProcedureReturn ImageNr
EndProcedure
CreateImage(21, 200, 300)
OpenWindow (#windows,#PB_Ignore,#PB_Ignore,200,300,"Button with text color!",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Text.s="Thanks"
LoadFont(0,"Arial",8)
StartDrawing(ImageOutput(21))
DrawingMode(#PB_2DDrawing_Gradient)
BackColor(RGB(Random(255),Random(255),Random(255)))
FrontColor(RGB(Random(255),Random(255),Random(255)))
;BoxedGradient(0,0,200,300)
;CustomGradient(@GradientCallback())
LinearGradient(0,0,200,300)
Box(0, 0, 200,300)
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
DrawingFont(FontID(0))
DrawText(20,20,"Text RGB:",RGB(0,0,0) | $FF000000)
DrawText(20,43,"ShadeTx RGB:",RGB(0,0,0) | $FF000000)
DrawText(20,242,"Back:",RGB(0,0,0) | $FF000000)
DrawText(20,267,"Front:",RGB(0,0,0) | $FF000000)
StopDrawing()
ImageGadget(20, 0, 0,200,300, ImageID(21))
DisableGadget(20, 1)
StringGadget(#StringGadget1,95,15,25,20,"180",#PB_String_Numeric)
StringGadget(#StringGadget2,125,15,25,20,"128",#PB_String_Numeric)
StringGadget(#StringGadget3,155,15,25,20,"0",#PB_String_Numeric)
StringGadget(#StringGadget4,95,40,25,20,"50",#PB_String_Numeric)
StringGadget(#StringGadget5,125,40,25,20,"50",#PB_String_Numeric)
StringGadget(#StringGadget6,155,40,25,20,"50",#PB_String_Numeric)
StringGadget(#StringGadget7,60,240,120,20,"RGB("+Str(Red(cb))+","+Str(Green(cb))+","+Str(Blue(cb))+")",#PB_String_ReadOnly )
StringGadget(#StringGadget8,60,265,120,20,"RGB("+Str(Red(cf))+","+Str(Green(cf))+","+Str(Blue(cf))+")",#PB_String_ReadOnly )
TextColor=RGB(Val(GetGadgetText(#StringGadget1)),Val(GetGadgetText(#StringGadget2)),Val(GetGadgetText(#StringGadget3)))
Textshadow=RGB(Val(GetGadgetText(#StringGadget4)),Val(GetGadgetText(#StringGadget5)),Val(GetGadgetText(#StringGadget6)))
ColoredButtonGadget(#ButtonGadget1,20,70,160,160,Text,LoadFont(1,"Arial",26,#PB_Font_Bold),TextColor,Textshadow) ; Returns ImageNr
ButtonGadget(#ButtonGadget2,72,15,20,20,"?")
Repeat
event= WaitWindowEvent()
Select EventGadget()
Case #ButtonGadget1
passe=0
If Text="Thanks":Text="Merci":Else:Text="Thanks":EndIf
TextColor=RGB(Val(GetGadgetText(#StringGadget1)),Val(GetGadgetText(#StringGadget2)),Val(GetGadgetText(#StringGadget3)))
Textshadow=RGB(Val(GetGadgetText(#StringGadget4)),Val(GetGadgetText(#StringGadget5)),Val(GetGadgetText(#StringGadget6)))
ColoredButtonGadget(#ButtonGadget1,20,70,160,160,Text,LoadFont(1,"Arial",26,#PB_Font_Bold),TextColor,Textshadow)
SetGadgetText(#StringGadget7,"RGB("+Str(Red(cb))+","+Str(Green(cb))+","+Str(Blue(cb))+")")
SetGadgetText(#StringGadget8,"RGB("+Str(Red(cf))+","+Str(Green(cf))+","+Str(Blue(cf))+")")
Case #ButtonGadget2
passe=1
If Text="Thanks":Text="Merci":Else:Text="Thanks":EndIf
TextColor=RGB(Val(GetGadgetText(#StringGadget1)),Val(GetGadgetText(#StringGadget2)),Val(GetGadgetText(#StringGadget3)))
Textshadow=RGB(Val(GetGadgetText(#StringGadget4)),Val(GetGadgetText(#StringGadget5)),Val(GetGadgetText(#StringGadget6)))
ColoredButtonGadget(#ButtonGadget1,20,70,160,160,Text,LoadFont(1,"Arial",26,#PB_Font_Bold),TextColor,Textshadow)
SetGadgetText(#StringGadget7,"RGB("+Str(Red(cb))+","+Str(Green(cb))+","+Str(Blue(cb))+")")
SetGadgetText(#StringGadget8,"RGB("+Str(Red(cf))+","+Str(Green(cf))+","+Str(Blue(cf))+")")
EndSelect
Until event= #PB_Event_CloseWindow
;#;new procedure ........
;#Procedure ColoredButtonGadget(GadgetNr,X,Y,Width,Height,Text.s,TextFontID,cf,cb,TextColor,Textshadow)
;#Protected ImageNr
;#
;# If GadgetNr = #PB_Any : ProcedureReturn -1 : EndIf
;#
;# ImageNr = CreateImage(#PB_Any,Width,Height,32 );| #PB_Image_Transparent
;# If ImageNr
;# StartDrawing(ImageOutput(ImageNr))
;# DrawingMode(#PB_2DDrawing_Gradient)
;# BackColor(cb)
;# FrontColor(cf)
;# BoxedGradient(0,0,Width,Height)
;# Box(0,0,Width,Height)
;# DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
;# DrawingFont(TextFontID)
;# DrawText((Width - TextWidth(Text)) / 2+1,(Height - TextHeight(Text)) / 2-1,Text,Textshadow | $FF000000)
;# DrawText((Width - TextWidth(Text)) / 2,(Height - TextHeight(Text)) / 2,Text,TextColor | $FF000000)
;# StopDrawing()
;#
;# ButtonImageGadget(GadgetNr,X,Y,Width,Height,ImageID(ImageNr))
;# EndIf
;#
;#ProcedureReturn ImageNr
;#EndProcedure
;#Global cb.l,cf.l,TextColor.l,Textshadow.l,front.l,back.l
;#OpenWindow (0,#PB_Ignore,#PB_Ignore,200,200,"Button with text color!",#PB_Window_SystemMenu | #PB_Window_ScreenCentered);#
;#
;#; copy 2 lines debugger:
;#Back=RGB(78,89,221) : Front=RGB(185,211,38)
;#TextColor=RGB(180,128,0) : Textshadow=RGB(50,50,50)
;#;-----------------------------------------------------
;#
;#ColoredButtonGadget(1,20,20,160,160,"CANCEL",LoadFont(1,"Arial",26,#PB_Font_Bold),front,back,TextColor,Textshadow)
;#Repeat
;# event= WaitWindowEvent()
;# Select EventGadget()
;# Case 1
;# EndSelect
;#Until event= #PB_Event_CloseWindow