Color_button

Share your advanced PureBasic knowledge/code with the community.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Color_button

Post by dobro »

another color button for fun :)

Code: Select all



;***********************************************
;Titre  :*set_bouton_color
;Auteur  : Zorro
;Date  :27/06/2016
;Heure  :22:38:29
;Version Purebasic :  PureBasic 5.42 LTS (Windows - x86)
;Version de l'editeur :EPB V2.64 (en test )
; Libairies necessaire : Aucune 
; colorize un bouton APRES sa creation ....
;***********************************************

Declare Create_Z_Button(Id_gadget, x,  y, Larg, Haut,coul_ecriture, coul_fond, txt.s,type_fonte.s, taille_fonte.i)
Declare Set_Z_button(Id_gadget)	
; Structure Obligatoire, c'est la dedans que ce trouve tout les details de chaque bouton Gadget
; ça permet d'avoir les infos necessaire pour recuperer les valeurs d'un gadgets, ou modifier les valeurs du gadget
; via les procedures Get et Set
; **************************************************
Structure gadgetZ
			x.i
			y.i
			Larg.i
			Haut.i
			Coul_ecriture.l
			coul_fond.l
			txt.s
			type_fonte.s
			taille_fonte.i
EndStructure
Global Dim gadgetZ.gadgetZ(1) ; ici dimentionner en fonction du nombre de gadget Z_button 
#bouton=1
; **************************************************





mywin= OpenWindow (0,0,0,218,68, "bouton coloré, By Zorro" , #PB_Window_SystemMenu|#PB_Window_ScreenCentered )



If mywin	
			coul_fond=RGB(255,255,0)								   ;Fond jaune
			coul_ecriture=RGB(0,0,125)								   ; couleur ecriture
			txt.s="Bouton standard"
			type_fonte.s="Arial"
			taille_fonte.i=8
			Create_Z_Button(#bouton, 10,  10, 200, 30,coul_ecriture, coul_fond, txt.s,type_fonte.s, taille_fonte.i) ; on creer un bouton image normal +couleur ecriture+couleur fond+text.... 
			
			; on peut acceder au parametre de chaque bouton ainsi :
			Debug "la couleur d'ecriture est :"+Str( gadgetZ(#bouton)\Coul_ecriture.l	)
			Debug "le text de ce bouton est :"+gadgetz(#bouton)\txt.s
			;
			Repeat 
						Event=WaitWindowEvent()
						Select Event
										
							Case #PB_Event_Gadget											
										Select EventGadget()														
											Case #bouton
														
														;	Create_Z_Button(#bouton, 10,  10, 200, 30, coul_ecriture, coul_fond,txt.s,type_fonte.s, taille_fonte.i) 
														; JE modifie  seulement la couleur de fond et d'ecriture , ainsi que le text du bouton et son type de fonte et sa taille de texte:
														gadgetZ(#bouton)\txt.s ="Bouton standard Changé "
														gadgetZ(#bouton)\type_fonte.s="Comic sans Ms"
														gadgetZ(#bouton)\coul_fond.l=RGB(255,0,255) ;Fond Rose
														gadgetZ(#bouton)\Coul_ecriture.l=RGB(0,0,0) ; couleur ecriture noir
														gadgetZ(#bouton)\taille_fonte.i=12
														; on active les changements
														Set_Z_button(#bouton)	
														
														; on peut acceder au parametre de chaque bouton ainsi :
														Debug "la couleur d'ecriture est :"+Str( gadgetZ(#bouton)\Coul_ecriture.l	)
														Debug "le text de ce bouton est :"+gadgetz(#bouton)\txt.s
														
										EndSelect
						EndSelect
			Until Event= #PB_Event_CloseWindow
EndIf

; *********************** Librairie de fonctions pour gerer un Z_button **********************************************

Procedure Set_Z_button(Id_gadget)	
			; By Zorro
			; permet d'activer les changements apporté dans la structure d'un Z_button
			Shared Id
			Id=Id_gadget
		
			
			x=gadgetz(Id)\x
			y=gadgetz(Id)\y
			larg=gadgetz(Id)\Larg
			Haut=gadgetz(Id)\Haut
			coul_ecriture=gadgetz(Id)\coul_ecriture
			coul_fond=gadgetz(Id)\coul_fond
			txt.s=gadgetz(Id)\txt.s
			type_fonte.s=gadgetz(Id)\type_fonte.s
			taille_fonte.i=gadgetz(Id)\taille_fonte.i
				If Larg<=0:Larg=8:EndIf
				If Haut<=0:Haut=8:EndIf
			If Isimage
						FreeImage(Id)
			EndIf
			If IsFont
						FreeFont(Id)
			EndIf
			If type_fonte.s="" : type_fonte.s="Arial":EndIf
			If  taille_fonte.i=0: taille_fonte.i=8:EndIf
			If LoadFont(Id, type_fonte.s, taille_fonte.i) 
						If CreateImage(Id, larg, haut)								
									StartDrawing(ImageOutput(Id))
												DrawingMode(#PB_2DDrawing_Transparent)						
												Box(0, 0,larg, haut, coul_fond)
												DrawingFont(FontID(Id))
												FrontColor(coul_ecriture)							
												DrawText((Larg-TextWidth(txt))/2,(Haut-TextHeight(txt))/2,Txt.s)  					
									StopDrawing()
						EndIf		
			EndIf		
			If IsGadget(Id)
						SetGadgetAttribute(Id, #PB_Button_Image, ImageID( Id))
			EndIf
			
EndProcedure

Procedure create_Z_Button(Id_gadget, x,  y, Larg, Haut,coul_ecriture, coul_fond, txt.s,type_fonte.s, taille_fonte.i)
			; by Zorro
			; cree un bouton image avec couleur fond+ couleur ecriture +texte
			; Id servira a donner le numero du gadget, le numero de l'image, et le numero de la fonte !!
			; si le bouton existe deja, il est effacé , puis recrée ! 
			
			If Larg<=0:Larg=8:EndIf
			If Haut<=0:Haut=8:EndIf
			
			gadgetz(Id_gadget)\x=x
			gadgetz(Id_gadget)\y=y
			gadgetz(Id_gadget)\Larg=larg
			gadgetz(Id_gadget)\Haut=Haut
			gadgetz(Id_gadget)\coul_ecriture=coul_ecriture
			gadgetz(Id_gadget)\coul_fond=coul_fond
			gadgetz(Id_gadget)\txt.s=txt.s
			gadgetz(Id_gadget)\type_fonte.s=type_fonte.s
			gadgetz(Id_gadget)\taille_fonte.i=taille_fonte.i
			
			Shared Id
			Id=Id_gadget
			If IsFont(Id)
						FreeFont(Id)
			EndIf
			If IsImage(Id)
						FreeImage(Id)
			EndIf
			If IsGadget(Id)
						FreeGadget(Id)
			EndIf
			
			If type_fonte.s="" : type_fonte.s="Arial":EndIf
			If  taille_fonte.i=0: taille_fonte.i=8:EndIf
			If LoadFont(Id, type_fonte.s, taille_fonte.i) 
						If CreateImage(Id, larg, haut)								
									StartDrawing(ImageOutput(Id))
												DrawingMode(#PB_2DDrawing_Transparent)						
												Box(0, 0,larg, haut, coul_fond)
												DrawingFont(FontID(Id))
												FrontColor(coul_ecriture)							
												DrawText((Larg-TextWidth(txt))/2,(Haut-TextHeight(txt))/2,Txt.s)  					
									StopDrawing()
						EndIf		
			EndIf
			
			ButtonImageGadget(Id,x,y,larg,Haut,ImageID( Id))		
			
			ProcedureReturn #True
EndProcedure

Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Color_button

Post by dobro »

hum .... little Fix , sorry :)
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Post Reply