Bien sur, c'est très facile, regarde
Code : Tout sélectionner
; Auteur : Le Soldat Inconnu
; Version de PB : 4
;
; Explication du programme :
; Pour faire des programmes de test rapidement, il ne reste qu'a rajouter les gadgets et la gestion des évènements.
Enumeration
#Fond
#Fond_Decoupe_H
#Fond_Decoupe_B
#Fond_Decoupe_D
#Fond_Decoupe_G
#Bouton
#Bouton_Survol
EndEnumeration
; Création de la fenêtre et de la GadgetList
If OpenWindow(0, 0, 0, 300, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget) = 0
End
EndIf
; le fond
CreateImage(#Fond, 300, 300)
StartDrawing(ImageOutput(#Fond))
For n = 0 To 299
Line(0, n, 300, 0, RGB(170 + 80 * n / 300, 170 + 80 * n / 300, 170 + 80 * n / 300))
Next
StopDrawing()
; le bouton
CreateImage(#Bouton, 100, 25)
StartDrawing(ImageOutput(#Bouton))
Box(1, 1, 98, 23, $FFFFFF)
DrawingMode(#PB_2DDrawing_Transparent)
Texte.s = "Bonjour"
DrawText((100 - TextWidth(Texte)) / 2, (25 - TextHeight(Texte)) / 2, Texte, $000000)
StopDrawing()
CreateImage(#Bouton_Survol, 100, 25)
StartDrawing(ImageOutput(#Bouton_Survol))
Box(1, 1, 98, 23, $00FF00)
DrawingMode(#PB_2DDrawing_Transparent)
Texte.s = "Au revoir"
DrawText((100 - TextWidth(Texte)) / 2, (25 - TextHeight(Texte)) / 2, Texte, $000000)
StopDrawing()
; Affichage
; On découpe le fond pour faire un trou pour le bouton
GrabImage(#Fond, #Fond_Decoupe_H, 0, 0, 300, 200)
GrabImage(#Fond, #Fond_Decoupe_B, 0, 225, 300, 75)
GrabImage(#Fond, #Fond_Decoupe_G, 0, 200, 100, 25)
GrabImage(#Fond, #Fond_Decoupe_D, 200, 200, 100, 25)
; Fond
ImageGadget(#Fond_Decoupe_H, 0, 0, 300, 200, ImageID(#Fond_Decoupe_H))
ImageGadget(#Fond_Decoupe_B, 0, 225, 300, 75, ImageID(#Fond_Decoupe_B))
ImageGadget(#Fond_Decoupe_G, 0, 200, 100, 25, ImageID(#Fond_Decoupe_G))
ImageGadget(#Fond_Decoupe_D, 200, 200, 100, 25, ImageID(#Fond_Decoupe_D))
; Bouton
ImageGadget(#Bouton, 100, 200, 100, 25, ImageID(#Bouton))
Repeat
Event = WaitWindowEvent()
Select Event
Case #WM_MOUSEMOVE
x = WindowMouseX(0)
y = WindowMouseY(0)
If x >= GadgetX(#Bouton) And x < GadgetX(#Bouton) + GadgetWidth(#Bouton) And y >= GadgetY(#Bouton) And y < GadgetY(#Bouton) + GadgetHeight(#Bouton)
If Bouton_Actif = 0
Bouton_Actif = 1
SetGadgetState(#Bouton, ImageID(#Bouton_Survol))
EndIf
ElseIf Bouton_Actif
Bouton_Actif = 0
SetGadgetState(#Bouton, ImageID(#Bouton))
EndIf
Case #PB_Event_Menu
Select EventMenu() ; Menus
EndSelect
Case #PB_Event_Gadget
Select EventGadget() ; Gadgets
Case #Bouton
Select EventType()
Case #PB_EventType_LeftClick
Debug "Clic gauche sur le bouton"
EndSelect
Case #Fond_Decoupe_H, #Fond_Decoupe_B, #Fond_Decoupe_D, #Fond_Decoupe_G
Select EventType()
Case #PB_EventType_LeftClick
Debug "Clic gauche sur le fond"
Case #PB_EventType_RightClick
Debug "Clic droit sur le fond"
EndSelect
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
après, il manque juste l'event #wm_mousemove qui n'est pas portable pour le moment.
donc totalement portable, je ferais comme cela
Code : Tout sélectionner
; Auteur : Le Soldat Inconnu
; Version de PB : 4
;
; Explication du programme :
; Pour faire des programmes de test rapidement, il ne reste qu'a rajouter les gadgets et la gestion des évènements.
Enumeration
#Fond
#Fond_Decoupe_H
#Fond_Decoupe_B
#Fond_Decoupe_D
#Fond_Decoupe_G
#Bouton
#Bouton_Survol
EndEnumeration
; Création de la fenêtre et de la GadgetList
If OpenWindow(0, 0, 0, 300, 300, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget) = 0
End
EndIf
; le fond
CreateImage(#Fond, 300, 300)
StartDrawing(ImageOutput(#Fond))
For n = 0 To 299
Line(0, n, 300, 0, RGB(170 + 80 * n / 300, 170 + 80 * n / 300, 170 + 80 * n / 300))
Next
StopDrawing()
; le bouton
CreateImage(#Bouton, 100, 25)
StartDrawing(ImageOutput(#Bouton))
Box(1, 1, 98, 23, $FFFFFF)
DrawingMode(#PB_2DDrawing_Transparent)
Texte.s = "Bonjour"
DrawText((100 - TextWidth(Texte)) / 2, (25 - TextHeight(Texte)) / 2, Texte, $000000)
StopDrawing()
CreateImage(#Bouton_Survol, 100, 25)
StartDrawing(ImageOutput(#Bouton_Survol))
Box(1, 1, 98, 23, $00FF00)
DrawingMode(#PB_2DDrawing_Transparent)
Texte.s = "Au revoir"
DrawText((100 - TextWidth(Texte)) / 2, (25 - TextHeight(Texte)) / 2, Texte, $000000)
StopDrawing()
; Affichage
; On découpe le fond pour faire un trou pour le bouton
GrabImage(#Fond, #Fond_Decoupe_H, 0, 0, 300, 200)
GrabImage(#Fond, #Fond_Decoupe_B, 0, 225, 300, 75)
GrabImage(#Fond, #Fond_Decoupe_G, 0, 200, 100, 25)
GrabImage(#Fond, #Fond_Decoupe_D, 200, 200, 100, 25)
; Fond
ImageGadget(#Fond_Decoupe_H, 0, 0, 300, 200, ImageID(#Fond_Decoupe_H))
ImageGadget(#Fond_Decoupe_B, 0, 225, 300, 75, ImageID(#Fond_Decoupe_B))
ImageGadget(#Fond_Decoupe_G, 0, 200, 100, 25, ImageID(#Fond_Decoupe_G))
ImageGadget(#Fond_Decoupe_D, 200, 200, 100, 25, ImageID(#Fond_Decoupe_D))
; Bouton
ImageGadget(#Bouton, 100, 200, 100, 25, ImageID(#Bouton))
Repeat
Event = WaitWindowEvent(50)
If Souris_X <> WindowMouseX(0) Or Souris_Y <> WindowMouseY(0)
Souris_X = WindowMouseX(0)
Souris_Y = WindowMouseY(0)
If Souris_X >= GadgetX(#Bouton) And Souris_X < GadgetX(#Bouton) + GadgetWidth(#Bouton) And Souris_Y >= GadgetY(#Bouton) And Souris_Y < GadgetY(#Bouton) + GadgetHeight(#Bouton)
If Bouton_Actif = 0
Bouton_Actif = 1
SetGadgetState(#Bouton, ImageID(#Bouton_Survol))
EndIf
ElseIf Bouton_Actif
Bouton_Actif = 0
SetGadgetState(#Bouton, ImageID(#Bouton))
EndIf
EndIf
Select Event
Case #PB_Event_Gadget
Select EventGadget() ; Gadgets
Case #Bouton
Select EventType()
Case #PB_EventType_LeftClick
Debug "Clic gauche sur le bouton"
EndSelect
Case #Fond_Decoupe_H, #Fond_Decoupe_B, #Fond_Decoupe_D, #Fond_Decoupe_G
Select EventType()
Case #PB_EventType_LeftClick
Debug "Clic gauche sur le fond"
Case #PB_EventType_RightClick
Debug "Clic droit sur le fond"
EndSelect
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
après, il suffit de mettre tous les gadgets dans un container pour pouvoir les afficher ou les masquer d'un coup comme ce qui était demandé au début.
Je passe comme ça car le problème du fond avec un skin, c'est que les textgadget, bouton et autre ne le supporte pas bien.