Re: création d'un editeur de boite de dialogue
Publié : sam. 19/févr./2011 17:33
Dayvid, tu m'as toujours pas dis ce qu'etait un gadget !
Forums PureBasic - Français
https://www.purebasic.fr/french/
Code : Tout sélectionner
; Exemple réaliser par Monsieur dieppedalle david
; le 20 février 2012
Enumeration
#Window_0
#Image_bouton
#bouton
#image_pour_bouton
EndEnumeration
Global NewList Liste_gadget()
#FONT_NORMAL = %00000000
#FONT_BOLD = %00000001
#FONT_ITALIC = %00000010
#FONT_UNDERLINE = %00000100
#FONT_STRIKEOUT = %00001000
#Clic_gauche_souris = 513
#Clic_gauche_relacher_souris = 514
#Clic_double_gauche_souris = 515
#Clic_droit_souris = 516
#Clic_droit_relacher_souris = 517
#Clic_double_droit_souris = 518
#Clic_centre_souris = 519
#Clic_centre_relacher_souris = 520
#Clic_double_centre_souris = 521
#Molette_souris = 522
; English forum: http://www.purebasic.fr/english/viewtopic.php?t=7042&highlight=
; Author: GPI
; Date: 28. July 2003
; OS: Windows
; Demo: No
; Some note: Windows send a #wm_mousemove, wenn the mouse is moved over one of
; your windows. (You can get this message with WaitWindowEvent())
Procedure.l IsMouseOverGadget(Gadget)
GetWindowRect_(GadgetID(Gadget),GadgetRect.RECT)
GetCursorPos_(mouse.POINT)
If mouse\x>=GadgetRect\Left And mouse\x<=GadgetRect\right And mouse\y>=GadgetRect\Top And mouse\y<=GadgetRect\bottom
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
; English forum: http://www.purebasic.fr/english/viewtopic.php?t=7603&highlight=
; Author: PB (updated for PB4.00 by blbltheworm)
; Date: 21. September 2003
; OS: Windows
; Demo: No
; Note: starting with PB v4 there is also a native command GadgetType() available
; Hinweis: seit PB v4 ist auch ein nativer Befehl GadgetType() verfügbar
Procedure.s GetGadgetType(gadget)
class$=Space(255) : GetClassName_(GadgetID(gadget),class$,255)
ProcedureReturn class$
EndProcedure
; pas de moi
Procedure CreateFont(Name$,Size,Style)
If (Style & #FONT_BOLD)
bold = 700
EndIf
If (Style & #FONT_ITALIC)
italic = 1
EndIf
If (Style & #FONT_UNDERLINE)
underline = 1
EndIf
If (Style & #FONT_STRIKEOUT)
strikeout = 1
EndIf
ProcedureReturn CreateFont_(Size,0,0,0,bold,italic,underline,strikeout,0,0,0,0,0,Name$)
EndProcedure
; pas de moi
Procedure.l MyLabeledImage(ImageNumber.l, Width.l, Height.l, Color.l, TColor.l, Label.s, Font.s, Bold.l, Italic.l, FontSize.l, Position_texte_X_surplus.l = 0, Position_texte_Y_surplus.l = 0)
Attributes = #FONT_NORMAL
If Bold
Attributes = Attributes | #FONT_BOLD
EndIf
If Italic
Attributes = Attributes | #FONT_ITALIC
EndIf
Normal = CreateFont(Font, FontSize, #FONT_NORMAL)
Bold = CreateFont(Font, FontSize, #FONT_BOLD)
Italic = CreateFont(Font, FontSize, #FONT_ITALIC)
Bold_Italic = CreateFont(Font, FontSize, #FONT_BOLD | #FONT_ITALIC)
Select Attributes
Case #FONT_NORMAL
FontToUse = Normal
Case #FONT_BOLD
FontToUse = Bold
Case #FONT_ITALIC
FontToUse = Italic
Case #FONT_BOLD | #FONT_ITALIC
FontToUse = Bold_Italic
Default
EndSelect
ImageID.l = CreateImage(ImageNumber, Width, Height)
StartDrawing(ImageOutput(ImageNumber))
Box(0, 0, Width, Height, Color)
FrontColor(RGB(Red(TColor),Green(TColor),Blue(TColor)))
DrawingFont(FontToUse)
DrawingMode(1)
If TextWidth(Label) < Width
XPos.l = (Width - TextWidth(Label)) / 2
Else
XPos.l = 4
EndIf
If TextWidth("M") < Height
YPos.l = (Height - TextWidth("M")) / 2 - 2
Else
YPos.l = 0
EndIf
DrawText(XPos + Position_texte_X_surplus, YPos + Position_texte_Y_surplus,Label)
StopDrawing()
ProcedureReturn ImageID
EndProcedure
; tous ça est de moi
Procedure Open_Window_0()
If OpenWindow(#Window_0, 523, 142, 600, 300, " Bouton Image Gadget fait maison", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
SmartWindowRefresh(#Window_0, 1)
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(200, 200, 200), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12))
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(255, 255, 255))
Line(149, 149, 1, 26, RGB(255, 255, 255))
Line(249, 149, 1, 26, RGB(160, 160, 160))
Line(149, 174, 100, 1, RGB(160, 160, 160))
StopDrawing()
EndIf
Repeat ; Start of the event loop
Event = WaitWindowEvent(1) ; This line waits until an event is received from Windows
WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadget() ; Is it a gadget event?
EventType = EventType() ; The event type
ButtonID = 0 ; The button ID Clicked
If IsMouseOverGadget(#Image_bouton) And interupteur_Image_bouton = 0 And clique_droit_sur_bouton = 1
If clique_gauche_sur_bouton = 0
clique_droit_sur_bouton = 0
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(255, 191, 0), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12))
interupteur_Image_bouton = 1
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(255, 255, 255))
Line(149, 149, 1, 26, RGB(255, 255, 255))
Line(249, 149, 1, 26, RGB(160, 160, 160))
Line(149, 174, 100, 1, RGB(160, 160, 160))
StopDrawing()
ElseIf clique_gauche_sur_bouton = 1
clique_droit_sur_bouton = 0
interupteur_Image_bouton = 1
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(255, 150, 0), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12, 1, 1))
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(160, 160, 160))
Line(149, 149, 1, 26, RGB(160, 160, 160))
Line(249, 149, 1, 26, RGB(255, 255, 255))
Line(149, 174, 100, 1, RGB(255, 255, 255))
StopDrawing()
EndIf
ElseIf IsMouseOverGadget(#Image_bouton) And interupteur_Image_bouton = 0 And clique_gauche_sur_fenetre = 0 And clique_gauche_sur_bouton = 1
interupteur_Image_bouton = 1
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(255, 150, 0), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12, 1, 1))
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(160, 160, 160))
Line(149, 149, 1, 26, RGB(160, 160, 160))
Line(249, 149, 1, 26, RGB(255, 255, 255))
Line(149, 174, 100, 1, RGB(255, 255, 255))
StopDrawing()
ElseIf IsMouseOverGadget(#Image_bouton) And interupteur_Image_bouton = 0 And clique_gauche_sur_fenetre = 0
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(255, 191, 0), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12))
interupteur_Image_bouton = 1
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(255, 255, 255))
Line(149, 149, 1, 26, RGB(255, 255, 255))
Line(249, 149, 1, 26, RGB(160, 160, 160))
Line(149, 174, 100, 1, RGB(160, 160, 160))
StopDrawing()
ElseIf IsMouseOverGadget(#Image_bouton) And interupteur_Image_bouton = 0 And clique_gauche_sur_fenetre = 1 And clique_droit_sur_bouton = 0
interupteur_Image_bouton = 1
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(255, 0, 0), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12))
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(255, 255, 255))
Line(149, 149, 1, 26, RGB(255, 255, 255))
Line(249, 149, 1, 26, RGB(160, 160, 160))
Line(149, 174, 100, 1, RGB(160, 160, 160))
StopDrawing()
EndIf
If Not IsMouseOverGadget(#Image_bouton) And interupteur_Image_bouton = 1
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(200, 200, 200), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12))
interupteur_Image_bouton = 0
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(255, 255, 255))
Line(149, 149, 1, 26, RGB(255, 255, 255))
Line(249, 149, 1, 26, RGB(160, 160, 160))
Line(149, 174, 100, 1, RGB(160, 160, 160))
StopDrawing()
EndIf
If Event = #PB_Event_Gadget
If GadgetID = #Image_bouton
If EventType = #PB_EventType_LeftClick
clique_gauche_sur_bouton = 1
interupteur_Image_bouton = 1
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(255, 150, 0), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12, 1, 1))
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(160, 160, 160))
Line(149, 149, 1, 26, RGB(160, 160, 160))
Line(249, 149, 1, 26, RGB(255, 255, 255))
Line(149, 174, 100, 1, RGB(255, 255, 255))
StopDrawing()
ElseIf EventType = #PB_EventType_RightClick
interupteur_Image_bouton = 1
If clique_gauche_sur_bouton = 0
Debug "clique droit sur le bouton"
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(255, 0, 255), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12))
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(255, 255, 255))
Line(149, 149, 1, 26, RGB(255, 255, 255))
Line(249, 149, 1, 26, RGB(160, 160, 160))
Line(149, 174, 100, 1, RGB(160, 160, 160))
StopDrawing()
ElseIf clique_gauche_sur_bouton = 1
Debug 77
ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(255, 150, 150), RGB(0, 0, 255), "Un bouton", "verdana", 0, 0, 12, 1, 1))
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(160, 160, 160))
Line(149, 149, 1, 26, RGB(160, 160, 160))
Line(249, 149, 1, 26, RGB(255, 255, 255))
Line(149, 174, 100, 1, RGB(255, 255, 255))
StopDrawing()
EndIf
ElseIf EventType = #PB_EventType_LeftDoubleClick
Debug 3
ElseIf EventType = #PB_EventType_RightDoubleClick
Debug 4
ElseIf EventType = #PB_EventType_DragStart
Debug 5
EndIf
Else
EndIf
ElseIf Event = #Clic_gauche_souris
clique_gauche_sur_fenetre = 1
Debug "clique gauche sur la fenêtre"
ElseIf Event = #Clic_gauche_relacher_souris
If IsMouseOverGadget(#Image_bouton) And interupteur_Image_bouton = 1 And clique_gauche_sur_bouton = 1 And clique_gauche_sur_fenetre = 0
interupteur_Image_bouton = 0
;ImageGadget(#Image_bouton, 150, 150, 100, 25, MyLabeledImage(#image_pour_bouton, 100, 25, RGB(200, 200, 200), RGB(255, 0, 0), "Un bouton", "verdana", 0, 0, 12))
StartDrawing(WindowOutput(#Window_0))
Line(150, 149, 100, 1, RGB(255, 255, 255))
Line(149, 149, 1, 26, RGB(255, 255, 255))
Line(249, 149, 1, 26, RGB(160, 160, 160))
Line(149, 174, 100, 1, RGB(160, 160, 160))
StopDrawing()
ButtonID = #Image_bouton
Else
Debug "clique gauche relacher"
EndIf
interupteur_Image_bouton = 0
clique_gauche_sur_bouton = 0
clique_gauche_sur_fenetre = 0
ElseIf Event = #Clic_droit_souris
Debug 99
ElseIf Event = #Clic_double_gauche_souris
Debug 8
ElseIf Event = #Clic_droit_relacher_souris
Debug 9
clique_droit_sur_bouton = 0
ElseIf Event = #Clic_double_droit_souris
Debug 11
ElseIf Event = #Clic_centre_souris
Debug 12
ElseIf Event = #Clic_centre_relacher_souris
Debug 13
ElseIf Event = #Clic_double_centre_souris
Debug 14
ElseIf Event = #Molette_souris
Debug 15
EndIf
If ButtonID = #Image_bouton
Debug "bouton appuiyer"
EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
EndProcedure
Open_Window_0()
Ton code est loin de faire ça !!! c'est du foutage de gueule et je trouve que ça devient récurant chez toi !!!dayvid a écrit : ...
ce que j'ai besoin:
une selection avec la souris sur la fenêtre
crée le gadget voulut
pouvoir déplacer le gadget crée
pouvoir modifier le gadget crée (taille, texte, image, etc)
je ne cherche pas a refaire un editeur visuelle car mon niveaux est
trop bas pour le momment et sa ne m'interesse pas en plus
j'ai juste besoin de ton aide si tu l'accepte pour divers petite chose
pour le reste je ferais je que je peut tous seulle
merci d'avence !!!
tu crois qu'il est idiot?c'est du foutage de gueule
Code : Tout sélectionner
; Exemple réaliser par Monsieur dieppedalle david
; le 20 février 2012
Lol merci Jojo sa ma fait rire et je suis 100% dacord avec toinan mais ca va pas la tete
si ca te plait pas tu tla ferme
il a passe du temps a le preparer, ne le jette pas comme ca
Code : Tout sélectionner
Procedure ButtonColorGadget(Gadget, x, y ,Width, Height ,Text$,fColor,bColor,Option=0, FontID=#PB_Font_Default)
Protected Img.i
Img=CreateImage(#PB_Any, Width, Height)
If StartDrawing(ImageOutput(Img))
DrawingFont(FontId)
Box(0, 0 ,Width, Height, bColor)
DrawText(Width/2 - TextWidth(Text$)/2, Height/2-TextHeight(Text$)/2,Text$,fColor,bColor)
StopDrawing()
ButtonImageGadget(Gadget, x, y, Width, height , ImageID(Img), Option)
EndIf
EndProcedure
OpenWindow(0,100,100,400,200,"Boutons Colorés - Quelques exemples",#PB_Window_SystemMenu)
ButtonColorGadget(#PB_Any,10,10,150,30,"Police par defaut",$9F9F9F, $B2FBE5,#PB_Button_Toggle)
ButtonColorGadget(#PB_Any,10,50,150,30,"Arial Italic",$DDDDDD, $494949,0,LoadFont(0,"Arial",12, #PB_Font_Italic))
ButtonColorGadget(#PB_Any,10,90,150,30,"En Rouge et Noir",$0611F9, $000000)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow