Une Horloge analogique

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Une Horloge analogique

Message par Le Soldat Inconnu »

Je mets ma pierre à l'édifice :)

Code : Tout sélectionner

CompilerIf Defined(AlphaImageWindow, #PB_Function) = 0
	ProcedureDLL SetLayeredWindow(WindowID) ; Set #WS_EX_LAYERED window attribute
		SetWindowLong_(WindowID, #GWL_EXSTYLE, GetWindowLong_(WindowID, #GWL_EXSTYLE) | #WS_EX_LAYERED) ; Mettre l'attribut WS_EX_LAYERED à la fenêtre
	EndProcedure
	ProcedureDLL AlphaImageWindow(WindowID, ImageID) ; Set image as window background (32bits image support)
		Protected Image_HDC, Image_Bitmap.BITMAP, ContextOffset.POINT, Blend.BLENDFUNCTION, Image
		
		; Dimension de l'image
		GetObject_(ImageID, SizeOf(BITMAP), @Image_Bitmap)
		
		Image = CreateImage(#PB_Any, Image_Bitmap\bmWidth, Image_Bitmap\bmHeight, 32)
		StartDrawing(ImageOutput(Image))
			DrawingMode(#PB_2DDrawing_AlphaBlend)
			DrawAlphaImage(ImageID, 0, 0)
			DrawingMode(#PB_2DDrawing_AlphaChannel)
			DrawAlphaImage(ImageID, 0, 0)
		StopDrawing()
		
		; Chargement du HDC
		Image_HDC = CreateCompatibleDC_(#Null)
		Image_Ancienne = SelectObject_(Image_HDC, ImageID(Image))
		
		; L'image est mise en skin de la fenêtre
		Blend\SourceConstantAlpha = 255 ; niveau de transparence
		Blend\AlphaFormat = 1 ; Support de la couche alpha
		Blend\BlendOp = 0
		Blend\BlendFlags = 0
		UpdateLayeredWindow_(WindowID, 0, 0, @Image_Bitmap + 4, Image_HDC, @ContextOffset, 0, @Blend, 2)
		
		; Fermeture du HDC
		SelectObject_(Image_HDC, Image_Ancienne)
		DeleteDC_(Image_HDC)
		
		; Supression de l'image
		FreeImage(Image)
		
	EndProcedure
CompilerEndIf

Procedure CircleAA(x, y, Radius, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
	Protected N, nn, Distance.f, Application.f, Couleur_Fond.l
	If Mode & #PB_2DDrawing_Outlined ; Cercle vide
		; on dessine 1/4 du cercle et on duplique pour le reste
		For N = 0 To Radius
			For nn = 0 To Radius
				Distance.f = Sqr(N * N + nn * nn)
				If Distance <= Radius And Distance > Radius - 1
					Application.f = 1 - Abs(Radius - 1 - Distance)
					Alpha = Alpha(Color) * Application
					Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
				ElseIf Distance <= Radius - Thickness And Distance > Radius - Thickness - 1
					Application.f = 1 - Abs(Radius - Thickness - Distance)
					Alpha = Alpha(Color) * Application
					Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
				ElseIf Distance <= Radius - 1 And Distance > Radius - Thickness
					Plot(x + N, y + nn, Color)
					If N <> 0
						Plot(x - N, y + nn, Color)
					EndIf
					If nn <> 0
						Plot(x + N, y - nn, Color)
					EndIf
					If N <> 0 And nn <> 0
						Plot(x - N, y - nn, Color)
					EndIf
				EndIf
			Next
		Next
	Else ; Cercle plein
		; on dessine 1/4 du cercle et on duplique pour le reste
		For N = 0 To Radius
			For nn = 0 To Radius
				Distance.f = Sqr(N * N + nn * nn)
				If Distance <= Radius And Distance > Radius - 1
					Application.f = (Radius - Distance)
					Alpha = Alpha(Color) * Application
					Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
				ElseIf Distance <= Radius - 1
					Plot(x + N, y + nn, Color)
					If N <> 0
						Plot(x - N, y + nn, Color)
					EndIf
					If nn <> 0
						Plot(x + N, y - nn, Color)
					EndIf
					If N <> 0 And nn <> 0
						Plot(x - N, y - nn, Color)
					EndIf
				EndIf
			Next
		Next
	EndIf
EndProcedure

Procedure EllipseAA(x, y, RadiusX, RadiusY, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
	Protected N, nn, Distance.f, Application.f, Couleur_Fond.l, Ellispse_Rayon.f, Ellipse_E.f
	; Précacul de l'équation de l'ellipse
	If RadiusX > RadiusY
		Ellipse_E = Sqr(RadiusX * RadiusX - RadiusY * RadiusY) / RadiusX
	Else
		Ellipse_E = Sqr(RadiusY * RadiusY - RadiusX * RadiusX) / RadiusY
	EndIf
	Ellipse_E * Ellipse_E
	If Mode & #PB_2DDrawing_Outlined ; ellipse vide
		; on dessine 1/4 de l'ellipse et on duplique pour le reste
		For N = 0 To RadiusX
			For nn = 0 To RadiusY
				Distance.f = Sqr(N * N + nn * nn)
				If RadiusX > RadiusY
					If N
						Ellipse_CosAngle.f = N / Distance
						Ellispse_Rayon = Sqr(RadiusY * RadiusY / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
					Else
						Ellispse_Rayon = RadiusY
					EndIf
				Else
					If nn
						Ellipse_CosAngle.f = nn / Distance
						Ellispse_Rayon = Sqr(RadiusX * RadiusX / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
					Else
						Ellispse_Rayon = RadiusX
					EndIf
				EndIf
				If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1
					Application.f = 1 - Abs(Ellispse_Rayon - 1 - Distance)
					Alpha = Alpha(Color) * Application
					Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
				ElseIf Distance <= Ellispse_Rayon - Thickness And Distance > Ellispse_Rayon - Thickness - 1
					Application.f = 1 - Abs(Ellispse_Rayon - Thickness - Distance)
					Alpha = Alpha(Color) * Application
					Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
				ElseIf Distance <= Ellispse_Rayon - 1 And Distance > Ellispse_Rayon - Thickness
					Plot(x + N, y + nn, Color)
					If N <> 0
						Plot(x - N, y + nn, Color)
					EndIf
					If nn <> 0
						Plot(x + N, y - nn, Color)
					EndIf
					If N <> 0 And nn <> 0
						Plot(x - N, y - nn, Color)
					EndIf
				EndIf
			Next
		Next
	Else ; ellipse pleine
		; on dessine 1/4 de l'ellipse et on duplique pour le reste
		For N = 0 To RadiusX
			For nn = 0 To RadiusY
				Distance.f = Sqr(N * N + nn * nn)
				If RadiusX > RadiusY
					If N
						Ellipse_CosAngle.f = N / Distance
						Ellispse_Rayon = Sqr(RadiusY * RadiusY / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
					Else
						Ellispse_Rayon = RadiusY
					EndIf
				Else
					If nn
						Ellipse_CosAngle.f = nn / Distance
						Ellispse_Rayon = Sqr(RadiusX * RadiusX / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
					Else
						Ellispse_Rayon = RadiusX
					EndIf
				EndIf
				If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1
					Application.f = (Ellispse_Rayon - Distance)
					Alpha = Alpha(Color) * Application
					Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
					Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
				ElseIf Distance <= Ellispse_Rayon - 1
					Plot(x + N, y + nn, Color)
					If N <> 0
						Plot(x - N, y + nn, Color)
					EndIf
					If nn <> 0
						Plot(x + N, y - nn, Color)
					EndIf
					If N <> 0 And nn <> 0
						Plot(x - N, y - nn, Color)
					EndIf
				EndIf
			Next
		Next
	EndIf
EndProcedure

Procedure LineAA(x, y, Width, Hight, Color, Thickness = 1)
	Protected SensX, SensY, N, nn, Epaisseur.f, x2.f, y2.f, Couleur_Fond.l, Application.f, Distance.f
	; On mets la droite toujours dans le même sens pour l'analyse
	; La sauvegarde du sens permettra de dessiner la droite ensuite dans le bon sens
	If Width >= 0
		SensX = 1
	Else
		SensX = -1
		Width = -Width
	EndIf
	If Hight >= 0
		SensY = 1
	Else
		SensY = -1
		Hight = -Hight
	EndIf
	
	
	; Demi épaisseur de la ligne
	Epaisseur.f = Thickness / 2
	
	; calcul pour le changement de repère qui permet de connaitre l'épaisseur du trait et de gérer l'AA
	Distance.f = Sqr(Width * Width + Hight * Hight)
	CosAngle.f = Width / Distance
	SinAngle.f = -Sin(ACos(CosAngle))
	
	; Dessin de la ligne
	For N = -Thickness To Width + Thickness
		For nn = -Thickness To Hight + Thickness
			
			; changement de base
			; les y représentent l'épaisseur de la ligne
			x2 = N * CosAngle - nn * SinAngle
			y2 = Abs(N * SinAngle + nn * CosAngle)
			
			If y2 <= Epaisseur + 0.5
				Application = 0.5 + Epaisseur - y2
				If Application > 1
					Application = 1
				EndIf
				If x2 > -1 And x2 < Distance + 1
					If x2 < 0
						Application * (1 + x2)
					ElseIf x2 > Distance
						Application * (1 - x2 + Distance)
					EndIf
				Else
					Application = 0
				EndIf
				If Application > 0
					If Application < 1
						Alpha = Alpha(Color) * Application
						Plot(x + N * SensX, y + nn * SensY, $00FFFFFF & Color | Alpha << 24)
					Else
						Plot(x + N * SensX, y + nn * SensY, Color)
					EndIf
				EndIf
			EndIf
			
		Next
	Next
	
EndProcedure

Procedure TriangleAA(x1, y1, x2, y2, x3, y3, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
	Protected Epaisseur.f, Zone_G, Zone_D, Zone_H, Zone_B, Couleur_Fond, Application.f
	Protected Width12.l, Hight12.l, Distance12.f, CosAngle12.f, SinAngle12.f, Sens12.l, y1_r2.f, Application1.f, Interieur1
	Protected Width23.l, Hight23.l, Distance23.f, CosAngle23.f, SinAngle23.f, Sens23.l, y2_r2.f, Application2.f, Interieur2
	Protected Width31.l, Hight31.l, Distance31.f, CosAngle31.f, SinAngle31.f, Sens31.l, y3_r2.f, Application3.f, Interieur3
	
	; Demi épaisseur de la ligne
	Epaisseur.f = Thickness / 2
	
	; calcul pour le changement de repère qui permet de connaitre l'épaisseur du trait et de gérer l'AA
	; Pour la ligne 12
	; Le point de départ du repère est le point x1, y1
	Width12.l = x2 - x1
	Hight12.l = y2 - y1
	Distance12.f = Sqr(Width12 * Width12 + Hight12 * Hight12)
	CosAngle12.f = Width12 / Distance12
	SinAngle12.f = Sin(ACos(CosAngle12))
	If Hight12 > 0
		SinAngle12 = -SinAngle12
	EndIf
	; changement de base
	y3_r2 = (x3 - x1) * SinAngle12 + (y3 - y1) * CosAngle12
	; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
	If y3_r2 > 0
		Sens12 = 1
	Else
		Sens12 = -1
	EndIf
	; Pour la ligne 23
	; Le point de départ du repère est le point x2, y2
	Width23.l = x3 - x2
	Hight23.l = y3 - y2
	Distance23.f = Sqr(Width23 * Width23 + Hight23 * Hight23)
	CosAngle23.f = Width23 / Distance23
	SinAngle23.f = Sin(ACos(CosAngle23))
	If Hight23 > 0
		SinAngle23 = -SinAngle23
	EndIf
	; changement de base
	y1_r2 = (x1 - x2) * SinAngle23 + (y1 - y2) * CosAngle23
	; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
	If y1_r2 > 0
		Sens23 = 1
	Else
		Sens23 = -1
	EndIf
	; Pour la ligne 31
	; Le point de départ du repère est le point x3, y3
	Width31.l = x1 - x3
	Hight31.l = y1 - y3
	Distance31.f = Sqr(Width31 * Width31 + Hight31 * Hight31)
	CosAngle31.f = Width31 / Distance31
	SinAngle31.f = Sin(ACos(CosAngle31))
	If Hight31 > 0
		SinAngle31 = -SinAngle31
	EndIf
	; changement de base
	y2_r2 = (x2 - x3) * SinAngle31 + (y2 - y3) * CosAngle31
	; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
	If y2_r2 > 0
		Sens31 = 1
	Else
		Sens31 = -1
	EndIf
	
	; Détermination de la zone de dessin
	Zone_G = x1
	Zone_D = x1
	Zone_B = y1
	Zone_H = y1
	If x2 < Zone_G
		Zone_G = x2
	EndIf
	If x3 < Zone_G
		Zone_G = x3
	EndIf
	If x2 > Zone_D
		Zone_D = x2
	EndIf
	If x3 > Zone_D
		Zone_D = x3
	EndIf
	If y2 < Zone_B
		Zone_B = y2
	EndIf
	If y3 < Zone_B
		Zone_B = y3
	EndIf
	If y2 > Zone_H
		Zone_H = y2
	EndIf
	If y3 > Zone_H
		Zone_H = y3
	EndIf
	Zone_B - Thickness
	Zone_H + Thickness
	Zone_G - Thickness
	Zone_D + Thickness
	
	; Dessin du triangle
	If Mode & #PB_2DDrawing_Outlined ; Triangle vide
		For N = Zone_G To Zone_D
			For nn = Zone_B To Zone_H
				
				y1_r2 = (N - x1) * SinAngle12 + (nn - y1) * CosAngle12
				y1_r2 * Sens12
				If y1_r2 >= -0.5 - Epaisseur
					
					Application1.f = 0.5 + Epaisseur + y1_r2
					If Application1 > 1
						Application1 = 1 + 0.5 + Epaisseur - Application1
						If Application1 < 0
							Application1 = 0
						EndIf
						Interieur1 = 1
					Else
						Interieur1 = 0
					EndIf
					
					y2_r2 = (N - x2) * SinAngle23 + (nn - y2) * CosAngle23
					y2_r2 * Sens23
					If y2_r2 >= -0.5 - Epaisseur
						
						Application2.f = 0.5 + Epaisseur + y2_r2
						If Application2 > 1
							Application2 = 1 + 0.5 + Epaisseur - Application2
							If Application2 < 0
								Application2 = 0
							EndIf
							Interieur2 = 1
						Else
							Interieur2 = 0
						EndIf
						
						y3_r2 = (N - x3) * SinAngle31 + (nn - y3) * CosAngle31
						y3_r2 * Sens31
						If y3_r2 >= -0.5 - Epaisseur
							
							Application3.f = 0.5 + Epaisseur + y3_r2
							If Application3 > 1
								Application3 = 1 + 0.5 + Epaisseur - Application3
								If Application3 < 0
									Application3 = 0
								EndIf
								Interieur3 = 1
							Else
								Interieur3 = 0
							EndIf
							
							
							If Interieur1 And Interieur2 And Interieur3
								Application = Application1 + Application2 + Application3
							Else
								Application = 1
								If Interieur1 = 0
									Application * Application1
								EndIf
								If Interieur2 = 0
									Application * Application2
								EndIf
								If Interieur3 = 0
									Application * Application3
								EndIf
							EndIf
							If Application > 0
								If Application < 1
									; Couleur_Fond = Point(n, nn)
									; Plot(n, nn, ColorBlending(Color, Couleur_Fond, Application))
									Alpha = Alpha(Color) * Application
									Plot(N, nn, $00FFFFFF & Color | Alpha << 24)
								Else
									Plot(N, nn, Color)
								EndIf
							EndIf
							
						EndIf
					EndIf
				EndIf
				
			Next
		Next
	Else ; Triangle plein
		For N = Zone_G To Zone_D
			For nn = Zone_B To Zone_H
				
				y1_r2 = (N - x1) * SinAngle12 + (nn - y1) * CosAngle12
				y1_r2 * Sens12
				If y1_r2 >= -0.5 - Epaisseur
					
					Application1.f = 0.5 + Epaisseur + y1_r2
					If Application1 > 1
						Application1 = 1
					EndIf
					
					y2_r2 = (N - x2) * SinAngle23 + (nn - y2) * CosAngle23
					y2_r2 * Sens23
					If y2_r2 >= -0.5 - Epaisseur
						
						Application2.f = 0.5 + Epaisseur + y2_r2
						If Application2 > 1
							Application2 = 1
						EndIf
						
						y3_r2 = (N - x3) * SinAngle31 + (nn - y3) * CosAngle31
						y3_r2 * Sens31
						If y3_r2 >= -0.5 - Epaisseur
							
							Application3.f = 0.5 + Epaisseur + y3_r2
							If Application3 > 1
								Application3 = 1
							EndIf
							
							Application = Application1 * Application2 * Application3
							If Application < 1
								Alpha = Alpha(Color) * Application
								Plot(N, nn, $00FFFFFF & Color | Alpha << 24)
							Else
								Plot(N, nn, Color)
							EndIf
							
						EndIf
					EndIf
				EndIf
				
			Next
		Next
	EndIf
	
EndProcedure




OpenWindow(0, 0, 0, 101, 101, "Horloge", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
StickyWindow(0, 1)
SetLayeredWindow(WindowID(0))

CreateImage(0, 101, 101, 32 | #PB_Image_Transparent)

AddWindowTimer(0, 1, 1000)


Repeat
	Event = WaitWindowEvent()
	
	Select Event
		Case #PB_Event_Timer
			Select EventTimer()
				Case 1
					Date = Date()
					Seconde.d = Second(Date) * 2 * #PI / 60
					Minute.d = Minute(Date) * 2 * #PI / 60
					Heure.d = Hour(Date) * 2 * #PI / 12
					
					StartDrawing(ImageOutput(0))
						DrawingMode(#PB_2DDrawing_AlphaChannel)
						Box(0, 0, 101, 101, 0) ; Efface
						DrawingMode(#PB_2DDrawing_AlphaBlend)
						; Fond
						CircleAA(50, 50, 50, $80000000)
						; Bordure
						CircleAA(50, 50, 50, $C0000000, 2, #PB_2DDrawing_Outlined)
						; Aiguille heure
						x1 = 50 + 35 * Sin(Heure)
						y1 = 50 - 35 * Cos(Heure)
						x2 = 50 + 5 * Sin(Heure - #PI * 2 / 3)
						y2 = 50 - 5 * Cos(Heure - #PI * 2 / 3)
						x3 = 50 + 5 * Sin(Heure + #PI * 2 / 3)
						y3 = 50 - 5 * Cos(Heure + #PI * 2 / 3)
						TriangleAA(x1, y1, x2, y2, x3, y3, $80FFFFFF)
						; Aiguille minute
						x1 = 50 + 45 * Sin(Minute)
						y1 = 50 - 45 * Cos(Minute)
						x2 = 50 + 3 * Sin(Minute - #PI * 2 / 3)
						y2 = 50 - 3 * Cos(Minute - #PI * 2 / 3)
						x3 = 50 + 3 * Sin(Minute + #PI * 2 / 3)
						y3 = 50 - 3 * Cos(Minute + #PI * 2 / 3)
						TriangleAA(x1, y1, x2, y2, x3, y3, $C0FFFFFF)
						; Aiguille seconde
						x1 = 50 + 45 * Sin(Seconde)
						y1 = 50 - 45 * Cos(Seconde)
						x2 = 50 + 8 * Sin(Seconde - #PI)
						y2 = 50 - 8 * Cos(Seconde - #PI)
						LineAA(x1, y1, x2 - x1 + 1, y2 - y1 + 1, $FFFFFFFF, 1)
						
					StopDrawing()
					AlphaImageWindow(WindowID(0), ImageID(0))
					
			EndSelect
	EndSelect
	
	
Until Event = #PB_Event_CloseWindow
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Une Horloge analogique

Message par Ar-S »

Très propre ;)
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
microdevweb
Messages : 1802
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: Une Horloge analogique

Message par microdevweb »

Bonjour le soldat inconnu,

Pas mal du tout...
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: Une Horloge analogique

Message par Backup »

elle n'est pas déplaçable ?

il y en avait une de tres belle , cetait celle de Denis dans les exemples ,de GDI+ :)
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Une Horloge analogique

Message par Le Soldat Inconnu »

elle n'est pas déplaçable ?
Tu ne sais pas faire :mrgreen:
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Une Horloge analogique

Message par Ar-S »

version de LSI déplaçable :wink:

Code : Tout sélectionner

CompilerIf Defined(AlphaImageWindow, #PB_Function) = 0
  ProcedureDLL SetLayeredWindow(WindowID) ; Set #WS_EX_LAYERED window attribute
    SetWindowLong_(WindowID, #GWL_EXSTYLE, GetWindowLong_(WindowID, #GWL_EXSTYLE) | #WS_EX_LAYERED) ; Mettre l'attribut WS_EX_LAYERED à la fenêtre
  EndProcedure
  ProcedureDLL AlphaImageWindow(WindowID, ImageID) ; Set image as window background (32bits image support)
    Protected Image_HDC, Image_Bitmap.BITMAP, ContextOffset.POINT, Blend.BLENDFUNCTION, Image
    
    ; Dimension de l'image
    GetObject_(ImageID, SizeOf(BITMAP), @Image_Bitmap)
    
    Image = CreateImage(#PB_Any, Image_Bitmap\bmWidth, Image_Bitmap\bmHeight, 32)
    StartDrawing(ImageOutput(Image))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      DrawAlphaImage(ImageID, 0, 0)
      DrawingMode(#PB_2DDrawing_AlphaChannel)
      DrawAlphaImage(ImageID, 0, 0)
    StopDrawing()
    
    ; Chargement du HDC
    Image_HDC = CreateCompatibleDC_(#Null)
    Image_Ancienne = SelectObject_(Image_HDC, ImageID(Image))
    
    ; L'image est mise en skin de la fenêtre
    Blend\SourceConstantAlpha = 255 ; niveau de transparence
    Blend\AlphaFormat = 1 ; Support de la couche alpha
    Blend\BlendOp = 0
    Blend\BlendFlags = 0
    UpdateLayeredWindow_(WindowID, 0, 0, @Image_Bitmap + 4, Image_HDC, @ContextOffset, 0, @Blend, 2)
    
    ; Fermeture du HDC
    SelectObject_(Image_HDC, Image_Ancienne)
    DeleteDC_(Image_HDC)
    
    ; Supression de l'image
    FreeImage(Image)
    
  EndProcedure
CompilerEndIf

Procedure CircleAA(x, y, Radius, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
  Protected N, nn, Distance.f, Application.f, Couleur_Fond.l
  If Mode & #PB_2DDrawing_Outlined ; Cercle vide
    ; on dessine 1/4 du cercle et on duplique pour le reste
    For N = 0 To Radius
      For nn = 0 To Radius
        Distance.f = Sqr(N * N + nn * nn)
        If Distance <= Radius And Distance > Radius - 1
          Application.f = 1 - Abs(Radius - 1 - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Radius - Thickness And Distance > Radius - Thickness - 1
          Application.f = 1 - Abs(Radius - Thickness - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Radius - 1 And Distance > Radius - Thickness
          Plot(x + N, y + nn, Color)
          If N <> 0
            Plot(x - N, y + nn, Color)
          EndIf
          If nn <> 0
            Plot(x + N, y - nn, Color)
          EndIf
          If N <> 0 And nn <> 0
            Plot(x - N, y - nn, Color)
          EndIf
        EndIf
      Next
    Next
  Else ; Cercle plein
    ; on dessine 1/4 du cercle et on duplique pour le reste
    For N = 0 To Radius
      For nn = 0 To Radius
        Distance.f = Sqr(N * N + nn * nn)
        If Distance <= Radius And Distance > Radius - 1
          Application.f = (Radius - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Radius - 1
          Plot(x + N, y + nn, Color)
          If N <> 0
            Plot(x - N, y + nn, Color)
          EndIf
          If nn <> 0
            Plot(x + N, y - nn, Color)
          EndIf
          If N <> 0 And nn <> 0
            Plot(x - N, y - nn, Color)
          EndIf
        EndIf
      Next
    Next
  EndIf
EndProcedure

Procedure EllipseAA(x, y, RadiusX, RadiusY, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
  Protected N, nn, Distance.f, Application.f, Couleur_Fond.l, Ellispse_Rayon.f, Ellipse_E.f
  ; Précacul de l'équation de l'ellipse
  If RadiusX > RadiusY
    Ellipse_E = Sqr(RadiusX * RadiusX - RadiusY * RadiusY) / RadiusX
  Else
    Ellipse_E = Sqr(RadiusY * RadiusY - RadiusX * RadiusX) / RadiusY
  EndIf
  Ellipse_E * Ellipse_E
  If Mode & #PB_2DDrawing_Outlined ; ellipse vide
    ; on dessine 1/4 de l'ellipse et on duplique pour le reste
    For N = 0 To RadiusX
      For nn = 0 To RadiusY
        Distance.f = Sqr(N * N + nn * nn)
        If RadiusX > RadiusY
          If N
            Ellipse_CosAngle.f = N / Distance
            Ellispse_Rayon = Sqr(RadiusY * RadiusY / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
          Else
            Ellispse_Rayon = RadiusY
          EndIf
        Else
          If nn
            Ellipse_CosAngle.f = nn / Distance
            Ellispse_Rayon = Sqr(RadiusX * RadiusX / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
          Else
            Ellispse_Rayon = RadiusX
          EndIf
        EndIf
        If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1
          Application.f = 1 - Abs(Ellispse_Rayon - 1 - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Ellispse_Rayon - Thickness And Distance > Ellispse_Rayon - Thickness - 1
          Application.f = 1 - Abs(Ellispse_Rayon - Thickness - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Ellispse_Rayon - 1 And Distance > Ellispse_Rayon - Thickness
          Plot(x + N, y + nn, Color)
          If N <> 0
            Plot(x - N, y + nn, Color)
          EndIf
          If nn <> 0
            Plot(x + N, y - nn, Color)
          EndIf
          If N <> 0 And nn <> 0
            Plot(x - N, y - nn, Color)
          EndIf
        EndIf
      Next
    Next
  Else ; ellipse pleine
    ; on dessine 1/4 de l'ellipse et on duplique pour le reste
    For N = 0 To RadiusX
      For nn = 0 To RadiusY
        Distance.f = Sqr(N * N + nn * nn)
        If RadiusX > RadiusY
          If N
            Ellipse_CosAngle.f = N / Distance
            Ellispse_Rayon = Sqr(RadiusY * RadiusY / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
          Else
            Ellispse_Rayon = RadiusY
          EndIf
        Else
          If nn
            Ellipse_CosAngle.f = nn / Distance
            Ellispse_Rayon = Sqr(RadiusX * RadiusX / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
          Else
            Ellispse_Rayon = RadiusX
          EndIf
        EndIf
        If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1
          Application.f = (Ellispse_Rayon - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Ellispse_Rayon - 1
          Plot(x + N, y + nn, Color)
          If N <> 0
            Plot(x - N, y + nn, Color)
          EndIf
          If nn <> 0
            Plot(x + N, y - nn, Color)
          EndIf
          If N <> 0 And nn <> 0
            Plot(x - N, y - nn, Color)
          EndIf
        EndIf
      Next
    Next
  EndIf
EndProcedure

Procedure LineAA(x, y, Width, Hight, Color, Thickness = 1)
  Protected SensX, SensY, N, nn, Epaisseur.f, x2.f, y2.f, Couleur_Fond.l, Application.f, Distance.f
  ; On mets la droite toujours dans le même sens pour l'analyse
  ; La sauvegarde du sens permettra de dessiner la droite ensuite dans le bon sens
  If Width >= 0
    SensX = 1
  Else
    SensX = -1
    Width = -Width
  EndIf
  If Hight >= 0
    SensY = 1
  Else
    SensY = -1
    Hight = -Hight
  EndIf
  
  
  ; Demi épaisseur de la ligne
  Epaisseur.f = Thickness / 2
  
  ; calcul pour le changement de repère qui permet de connaitre l'épaisseur du trait et de gérer l'AA
  Distance.f = Sqr(Width * Width + Hight * Hight)
  CosAngle.f = Width / Distance
  SinAngle.f = -Sin(ACos(CosAngle))
  
  ; Dessin de la ligne
  For N = -Thickness To Width + Thickness
    For nn = -Thickness To Hight + Thickness
      
      ; changement de base
      ; les y représentent l'épaisseur de la ligne
      x2 = N * CosAngle - nn * SinAngle
      y2 = Abs(N * SinAngle + nn * CosAngle)
      
      If y2 <= Epaisseur + 0.5
        Application = 0.5 + Epaisseur - y2
        If Application > 1
          Application = 1
        EndIf
        If x2 > -1 And x2 < Distance + 1
          If x2 < 0
            Application * (1 + x2)
          ElseIf x2 > Distance
            Application * (1 - x2 + Distance)
          EndIf
        Else
          Application = 0
        EndIf
        If Application > 0
          If Application < 1
            Alpha = Alpha(Color) * Application
            Plot(x + N * SensX, y + nn * SensY, $00FFFFFF & Color | Alpha << 24)
          Else
            Plot(x + N * SensX, y + nn * SensY, Color)
          EndIf
        EndIf
      EndIf
      
    Next
  Next
  
EndProcedure

Procedure TriangleAA(x1, y1, x2, y2, x3, y3, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
  Protected Epaisseur.f, Zone_G, Zone_D, Zone_H, Zone_B, Couleur_Fond, Application.f
  Protected Width12.l, Hight12.l, Distance12.f, CosAngle12.f, SinAngle12.f, Sens12.l, y1_r2.f, Application1.f, Interieur1
  Protected Width23.l, Hight23.l, Distance23.f, CosAngle23.f, SinAngle23.f, Sens23.l, y2_r2.f, Application2.f, Interieur2
  Protected Width31.l, Hight31.l, Distance31.f, CosAngle31.f, SinAngle31.f, Sens31.l, y3_r2.f, Application3.f, Interieur3
  
  ; Demi épaisseur de la ligne
  Epaisseur.f = Thickness / 2
  
  ; calcul pour le changement de repère qui permet de connaitre l'épaisseur du trait et de gérer l'AA
  ; Pour la ligne 12
  ; Le point de départ du repère est le point x1, y1
  Width12.l = x2 - x1
  Hight12.l = y2 - y1
  Distance12.f = Sqr(Width12 * Width12 + Hight12 * Hight12)
  CosAngle12.f = Width12 / Distance12
  SinAngle12.f = Sin(ACos(CosAngle12))
  If Hight12 > 0
    SinAngle12 = -SinAngle12
  EndIf
  ; changement de base
  y3_r2 = (x3 - x1) * SinAngle12 + (y3 - y1) * CosAngle12
  ; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
  If y3_r2 > 0
    Sens12 = 1
  Else
    Sens12 = -1
  EndIf
  ; Pour la ligne 23
  ; Le point de départ du repère est le point x2, y2
  Width23.l = x3 - x2
  Hight23.l = y3 - y2
  Distance23.f = Sqr(Width23 * Width23 + Hight23 * Hight23)
  CosAngle23.f = Width23 / Distance23
  SinAngle23.f = Sin(ACos(CosAngle23))
  If Hight23 > 0
    SinAngle23 = -SinAngle23
  EndIf
  ; changement de base
  y1_r2 = (x1 - x2) * SinAngle23 + (y1 - y2) * CosAngle23
  ; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
  If y1_r2 > 0
    Sens23 = 1
  Else
    Sens23 = -1
  EndIf
  ; Pour la ligne 31
  ; Le point de départ du repère est le point x3, y3
  Width31.l = x1 - x3
  Hight31.l = y1 - y3
  Distance31.f = Sqr(Width31 * Width31 + Hight31 * Hight31)
  CosAngle31.f = Width31 / Distance31
  SinAngle31.f = Sin(ACos(CosAngle31))
  If Hight31 > 0
    SinAngle31 = -SinAngle31
  EndIf
  ; changement de base
  y2_r2 = (x2 - x3) * SinAngle31 + (y2 - y3) * CosAngle31
  ; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
  If y2_r2 > 0
    Sens31 = 1
  Else
    Sens31 = -1
  EndIf
  
  ; Détermination de la zone de dessin
  Zone_G = x1
  Zone_D = x1
  Zone_B = y1
  Zone_H = y1
  If x2 < Zone_G
    Zone_G = x2
  EndIf
  If x3 < Zone_G
    Zone_G = x3
  EndIf
  If x2 > Zone_D
    Zone_D = x2
  EndIf
  If x3 > Zone_D
    Zone_D = x3
  EndIf
  If y2 < Zone_B
    Zone_B = y2
  EndIf
  If y3 < Zone_B
    Zone_B = y3
  EndIf
  If y2 > Zone_H
    Zone_H = y2
  EndIf
  If y3 > Zone_H
    Zone_H = y3
  EndIf
  Zone_B - Thickness
  Zone_H + Thickness
  Zone_G - Thickness
  Zone_D + Thickness
  
  ; Dessin du triangle
  If Mode & #PB_2DDrawing_Outlined ; Triangle vide
    For N = Zone_G To Zone_D
      For nn = Zone_B To Zone_H
        
        y1_r2 = (N - x1) * SinAngle12 + (nn - y1) * CosAngle12
        y1_r2 * Sens12
        If y1_r2 >= -0.5 - Epaisseur
          
          Application1.f = 0.5 + Epaisseur + y1_r2
          If Application1 > 1
            Application1 = 1 + 0.5 + Epaisseur - Application1
            If Application1 < 0
              Application1 = 0
            EndIf
            Interieur1 = 1
          Else
            Interieur1 = 0
          EndIf
          
          y2_r2 = (N - x2) * SinAngle23 + (nn - y2) * CosAngle23
          y2_r2 * Sens23
          If y2_r2 >= -0.5 - Epaisseur
            
            Application2.f = 0.5 + Epaisseur + y2_r2
            If Application2 > 1
              Application2 = 1 + 0.5 + Epaisseur - Application2
              If Application2 < 0
                Application2 = 0
              EndIf
              Interieur2 = 1
            Else
              Interieur2 = 0
            EndIf
            
            y3_r2 = (N - x3) * SinAngle31 + (nn - y3) * CosAngle31
            y3_r2 * Sens31
            If y3_r2 >= -0.5 - Epaisseur
              
              Application3.f = 0.5 + Epaisseur + y3_r2
              If Application3 > 1
                Application3 = 1 + 0.5 + Epaisseur - Application3
                If Application3 < 0
                  Application3 = 0
                EndIf
                Interieur3 = 1
              Else
                Interieur3 = 0
              EndIf
              
              
              If Interieur1 And Interieur2 And Interieur3
                Application = Application1 + Application2 + Application3
              Else
                Application = 1
                If Interieur1 = 0
                  Application * Application1
                EndIf
                If Interieur2 = 0
                  Application * Application2
                EndIf
                If Interieur3 = 0
                  Application * Application3
                EndIf
              EndIf
              If Application > 0
                If Application < 1
                  ; Couleur_Fond = Point(n, nn)
                  ; Plot(n, nn, ColorBlending(Color, Couleur_Fond, Application))
                  Alpha = Alpha(Color) * Application
                  Plot(N, nn, $00FFFFFF & Color | Alpha << 24)
                Else
                  Plot(N, nn, Color)
                EndIf
              EndIf
              
            EndIf
          EndIf
        EndIf
        
      Next
    Next
  Else ; Triangle plein
    For N = Zone_G To Zone_D
      For nn = Zone_B To Zone_H
        
        y1_r2 = (N - x1) * SinAngle12 + (nn - y1) * CosAngle12
        y1_r2 * Sens12
        If y1_r2 >= -0.5 - Epaisseur
          
          Application1.f = 0.5 + Epaisseur + y1_r2
          If Application1 > 1
            Application1 = 1
          EndIf
          
          y2_r2 = (N - x2) * SinAngle23 + (nn - y2) * CosAngle23
          y2_r2 * Sens23
          If y2_r2 >= -0.5 - Epaisseur
            
            Application2.f = 0.5 + Epaisseur + y2_r2
            If Application2 > 1
              Application2 = 1
            EndIf
            
            y3_r2 = (N - x3) * SinAngle31 + (nn - y3) * CosAngle31
            y3_r2 * Sens31
            If y3_r2 >= -0.5 - Epaisseur
              
              Application3.f = 0.5 + Epaisseur + y3_r2
              If Application3 > 1
                Application3 = 1
              EndIf
              
              Application = Application1 * Application2 * Application3
              If Application < 1
                Alpha = Alpha(Color) * Application
                Plot(N, nn, $00FFFFFF & Color | Alpha << 24)
              Else
                Plot(N, nn, Color)
              EndIf
              
            EndIf
          EndIf
        EndIf
        
      Next
    Next
  EndIf
  
EndProcedure




hwnd=OpenWindow(0, 0, 0, 101, 101, "Horloge", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
StickyWindow(0, 1)
SetLayeredWindow(WindowID(0))

CreateImage(0, 101, 101, 32 | #PB_Image_Transparent)

AddWindowTimer(0, 1, 1000)


Repeat
  Event = WaitWindowEvent()
  
  Select Event
      
    Case #WM_LBUTTONDOWN
      SendMessage_(hwnd, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
      
    Case #PB_Event_Timer
      Select EventTimer()
        Case 1
          Date = Date()
          Seconde.d = Second(Date) * 2 * #PI / 60
          Minute.d = Minute(Date) * 2 * #PI / 60
          Heure.d = Hour(Date) * 2 * #PI / 12
          
          StartDrawing(ImageOutput(0))
            DrawingMode(#PB_2DDrawing_AlphaChannel)
            Box(0, 0, 101, 101, 0) ; Efface
            DrawingMode(#PB_2DDrawing_AlphaBlend)
            ; Fond
            CircleAA(50, 50, 50, $80000000)
            ; Bordure
            CircleAA(50, 50, 50, $C0000000, 2, #PB_2DDrawing_Outlined)
            ; Aiguille heure
            x1 = 50 + 35 * Sin(Heure)
            y1 = 50 - 35 * Cos(Heure)
            x2 = 50 + 5 * Sin(Heure - #PI * 2 / 3)
            y2 = 50 - 5 * Cos(Heure - #PI * 2 / 3)
            x3 = 50 + 5 * Sin(Heure + #PI * 2 / 3)
            y3 = 50 - 5 * Cos(Heure + #PI * 2 / 3)
            TriangleAA(x1, y1, x2, y2, x3, y3, $80FFFFFF)
            ; Aiguille minute
            x1 = 50 + 45 * Sin(Minute)
            y1 = 50 - 45 * Cos(Minute)
            x2 = 50 + 3 * Sin(Minute - #PI * 2 / 3)
            y2 = 50 - 3 * Cos(Minute - #PI * 2 / 3)
            x3 = 50 + 3 * Sin(Minute + #PI * 2 / 3)
            y3 = 50 - 3 * Cos(Minute + #PI * 2 / 3)
            TriangleAA(x1, y1, x2, y2, x3, y3, $C0FFFFFF)
            ; Aiguille seconde
            x1 = 50 + 45 * Sin(Seconde)
            y1 = 50 - 45 * Cos(Seconde)
            x2 = 50 + 8 * Sin(Seconde - #PI)
            y2 = 50 - 8 * Cos(Seconde - #PI)
            LineAA(x1, y1, x2 - x1 + 1, y2 - y1 + 1, $FFFFFFFF, 1)
            
          StopDrawing()
          AlphaImageWindow(WindowID(0), ImageID(0))
          
      EndSelect
  EndSelect
  
  
Until Event = #PB_Event_CloseWindow
Pour ceux que ça intéresse et qui ne sont pas habitués aux API (moi le premier mais j'me soigne :D).

On récupère le handle de la fenêtre :

Code : Tout sélectionner

hwnd = OpenWindow(0, 0, 0, 101, 101, "Horloge", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
avant on avait simplement :

Code : Tout sélectionner

OpenWindow(0, 0, 0, 101, 101, "Horloge", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
et ajout de l'Event #WM_LBUTTONDOWN

Code : Tout sélectionner

Case #WM_LBUTTONDOWN
      SendMessage_(hwnd, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: Une Horloge analogique

Message par Backup »

on peut pas la quitter ? :mrgreen:
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Une Horloge analogique

Message par Ar-S »

Vieille rave :!: :mrgreen: :mrgreen:

Allez pour ne pas avoir à fermer le prog comme un veau.

ajout de la fermeture au clique droit.

Code : Tout sélectionner

CompilerIf Defined(AlphaImageWindow, #PB_Function) = 0
  ProcedureDLL SetLayeredWindow(WindowID) ; Set #WS_EX_LAYERED window attribute
    SetWindowLong_(WindowID, #GWL_EXSTYLE, GetWindowLong_(WindowID, #GWL_EXSTYLE) | #WS_EX_LAYERED) ; Mettre l'attribut WS_EX_LAYERED à la fenêtre
  EndProcedure
  ProcedureDLL AlphaImageWindow(WindowID, ImageID) ; Set image as window background (32bits image support)
    Protected Image_HDC, Image_Bitmap.BITMAP, ContextOffset.POINT, Blend.BLENDFUNCTION, Image
    
    ; Dimension de l'image
    GetObject_(ImageID, SizeOf(BITMAP), @Image_Bitmap)
    
    Image = CreateImage(#PB_Any, Image_Bitmap\bmWidth, Image_Bitmap\bmHeight, 32)
    StartDrawing(ImageOutput(Image))
      DrawingMode(#PB_2DDrawing_AlphaBlend)
      DrawAlphaImage(ImageID, 0, 0)
      DrawingMode(#PB_2DDrawing_AlphaChannel)
      DrawAlphaImage(ImageID, 0, 0)
    StopDrawing()
    
    ; Chargement du HDC
    Image_HDC = CreateCompatibleDC_(#Null)
    Image_Ancienne = SelectObject_(Image_HDC, ImageID(Image))
    
    ; L'image est mise en skin de la fenêtre
    Blend\SourceConstantAlpha = 255 ; niveau de transparence
    Blend\AlphaFormat = 1 ; Support de la couche alpha
    Blend\BlendOp = 0
    Blend\BlendFlags = 0
    UpdateLayeredWindow_(WindowID, 0, 0, @Image_Bitmap + 4, Image_HDC, @ContextOffset, 0, @Blend, 2)
    
    ; Fermeture du HDC
    SelectObject_(Image_HDC, Image_Ancienne)
    DeleteDC_(Image_HDC)
    
    ; Supression de l'image
    FreeImage(Image)
    
  EndProcedure
CompilerEndIf

Procedure CircleAA(x, y, Radius, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
  Protected N, nn, Distance.f, Application.f, Couleur_Fond.l
  If Mode & #PB_2DDrawing_Outlined ; Cercle vide
    ; on dessine 1/4 du cercle et on duplique pour le reste
    For N = 0 To Radius
      For nn = 0 To Radius
        Distance.f = Sqr(N * N + nn * nn)
        If Distance <= Radius And Distance > Radius - 1
          Application.f = 1 - Abs(Radius - 1 - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Radius - Thickness And Distance > Radius - Thickness - 1
          Application.f = 1 - Abs(Radius - Thickness - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Radius - 1 And Distance > Radius - Thickness
          Plot(x + N, y + nn, Color)
          If N <> 0
            Plot(x - N, y + nn, Color)
          EndIf
          If nn <> 0
            Plot(x + N, y - nn, Color)
          EndIf
          If N <> 0 And nn <> 0
            Plot(x - N, y - nn, Color)
          EndIf
        EndIf
      Next
    Next
  Else ; Cercle plein
    ; on dessine 1/4 du cercle et on duplique pour le reste
    For N = 0 To Radius
      For nn = 0 To Radius
        Distance.f = Sqr(N * N + nn * nn)
        If Distance <= Radius And Distance > Radius - 1
          Application.f = (Radius - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Radius - 1
          Plot(x + N, y + nn, Color)
          If N <> 0
            Plot(x - N, y + nn, Color)
          EndIf
          If nn <> 0
            Plot(x + N, y - nn, Color)
          EndIf
          If N <> 0 And nn <> 0
            Plot(x - N, y - nn, Color)
          EndIf
        EndIf
      Next
    Next
  EndIf
EndProcedure

Procedure EllipseAA(x, y, RadiusX, RadiusY, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
  Protected N, nn, Distance.f, Application.f, Couleur_Fond.l, Ellispse_Rayon.f, Ellipse_E.f
  ; Précacul de l'équation de l'ellipse
  If RadiusX > RadiusY
    Ellipse_E = Sqr(RadiusX * RadiusX - RadiusY * RadiusY) / RadiusX
  Else
    Ellipse_E = Sqr(RadiusY * RadiusY - RadiusX * RadiusX) / RadiusY
  EndIf
  Ellipse_E * Ellipse_E
  If Mode & #PB_2DDrawing_Outlined ; ellipse vide
    ; on dessine 1/4 de l'ellipse et on duplique pour le reste
    For N = 0 To RadiusX
      For nn = 0 To RadiusY
        Distance.f = Sqr(N * N + nn * nn)
        If RadiusX > RadiusY
          If N
            Ellipse_CosAngle.f = N / Distance
            Ellispse_Rayon = Sqr(RadiusY * RadiusY / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
          Else
            Ellispse_Rayon = RadiusY
          EndIf
        Else
          If nn
            Ellipse_CosAngle.f = nn / Distance
            Ellispse_Rayon = Sqr(RadiusX * RadiusX / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
          Else
            Ellispse_Rayon = RadiusX
          EndIf
        EndIf
        If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1
          Application.f = 1 - Abs(Ellispse_Rayon - 1 - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Ellispse_Rayon - Thickness And Distance > Ellispse_Rayon - Thickness - 1
          Application.f = 1 - Abs(Ellispse_Rayon - Thickness - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Ellispse_Rayon - 1 And Distance > Ellispse_Rayon - Thickness
          Plot(x + N, y + nn, Color)
          If N <> 0
            Plot(x - N, y + nn, Color)
          EndIf
          If nn <> 0
            Plot(x + N, y - nn, Color)
          EndIf
          If N <> 0 And nn <> 0
            Plot(x - N, y - nn, Color)
          EndIf
        EndIf
      Next
    Next
  Else ; ellipse pleine
    ; on dessine 1/4 de l'ellipse et on duplique pour le reste
    For N = 0 To RadiusX
      For nn = 0 To RadiusY
        Distance.f = Sqr(N * N + nn * nn)
        If RadiusX > RadiusY
          If N
            Ellipse_CosAngle.f = N / Distance
            Ellispse_Rayon = Sqr(RadiusY * RadiusY / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
          Else
            Ellispse_Rayon = RadiusY
          EndIf
        Else
          If nn
            Ellipse_CosAngle.f = nn / Distance
            Ellispse_Rayon = Sqr(RadiusX * RadiusX / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
          Else
            Ellispse_Rayon = RadiusX
          EndIf
        EndIf
        If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1
          Application.f = (Ellispse_Rayon - Distance)
          Alpha = Alpha(Color) * Application
          Plot(x + N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y + nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x + N, y - nn, $00FFFFFF & Color | Alpha << 24)
          Plot(x - N, y - nn, $00FFFFFF & Color | Alpha << 24)
        ElseIf Distance <= Ellispse_Rayon - 1
          Plot(x + N, y + nn, Color)
          If N <> 0
            Plot(x - N, y + nn, Color)
          EndIf
          If nn <> 0
            Plot(x + N, y - nn, Color)
          EndIf
          If N <> 0 And nn <> 0
            Plot(x - N, y - nn, Color)
          EndIf
        EndIf
      Next
    Next
  EndIf
EndProcedure

Procedure LineAA(x, y, Width, Hight, Color, Thickness = 1)
  Protected SensX, SensY, N, nn, Epaisseur.f, x2.f, y2.f, Couleur_Fond.l, Application.f, Distance.f
  ; On mets la droite toujours dans le même sens pour l'analyse
  ; La sauvegarde du sens permettra de dessiner la droite ensuite dans le bon sens
  If Width >= 0
    SensX = 1
  Else
    SensX = -1
    Width = -Width
  EndIf
  If Hight >= 0
    SensY = 1
  Else
    SensY = -1
    Hight = -Hight
  EndIf
  
  
  ; Demi épaisseur de la ligne
  Epaisseur.f = Thickness / 2
  
  ; calcul pour le changement de repère qui permet de connaitre l'épaisseur du trait et de gérer l'AA
  Distance.f = Sqr(Width * Width + Hight * Hight)
  CosAngle.f = Width / Distance
  SinAngle.f = -Sin(ACos(CosAngle))
  
  ; Dessin de la ligne
  For N = -Thickness To Width + Thickness
    For nn = -Thickness To Hight + Thickness
      
      ; changement de base
      ; les y représentent l'épaisseur de la ligne
      x2 = N * CosAngle - nn * SinAngle
      y2 = Abs(N * SinAngle + nn * CosAngle)
      
      If y2 <= Epaisseur + 0.5
        Application = 0.5 + Epaisseur - y2
        If Application > 1
          Application = 1
        EndIf
        If x2 > -1 And x2 < Distance + 1
          If x2 < 0
            Application * (1 + x2)
          ElseIf x2 > Distance
            Application * (1 - x2 + Distance)
          EndIf
        Else
          Application = 0
        EndIf
        If Application > 0
          If Application < 1
            Alpha = Alpha(Color) * Application
            Plot(x + N * SensX, y + nn * SensY, $00FFFFFF & Color | Alpha << 24)
          Else
            Plot(x + N * SensX, y + nn * SensY, Color)
          EndIf
        EndIf
      EndIf
      
    Next
  Next
  
EndProcedure

Procedure TriangleAA(x1, y1, x2, y2, x3, y3, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
  Protected Epaisseur.f, Zone_G, Zone_D, Zone_H, Zone_B, Couleur_Fond, Application.f
  Protected Width12.l, Hight12.l, Distance12.f, CosAngle12.f, SinAngle12.f, Sens12.l, y1_r2.f, Application1.f, Interieur1
  Protected Width23.l, Hight23.l, Distance23.f, CosAngle23.f, SinAngle23.f, Sens23.l, y2_r2.f, Application2.f, Interieur2
  Protected Width31.l, Hight31.l, Distance31.f, CosAngle31.f, SinAngle31.f, Sens31.l, y3_r2.f, Application3.f, Interieur3
  
  ; Demi épaisseur de la ligne
  Epaisseur.f = Thickness / 2
  
  ; calcul pour le changement de repère qui permet de connaitre l'épaisseur du trait et de gérer l'AA
  ; Pour la ligne 12
  ; Le point de départ du repère est le point x1, y1
  Width12.l = x2 - x1
  Hight12.l = y2 - y1
  Distance12.f = Sqr(Width12 * Width12 + Hight12 * Hight12)
  CosAngle12.f = Width12 / Distance12
  SinAngle12.f = Sin(ACos(CosAngle12))
  If Hight12 > 0
    SinAngle12 = -SinAngle12
  EndIf
  ; changement de base
  y3_r2 = (x3 - x1) * SinAngle12 + (y3 - y1) * CosAngle12
  ; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
  If y3_r2 > 0
    Sens12 = 1
  Else
    Sens12 = -1
  EndIf
  ; Pour la ligne 23
  ; Le point de départ du repère est le point x2, y2
  Width23.l = x3 - x2
  Hight23.l = y3 - y2
  Distance23.f = Sqr(Width23 * Width23 + Hight23 * Hight23)
  CosAngle23.f = Width23 / Distance23
  SinAngle23.f = Sin(ACos(CosAngle23))
  If Hight23 > 0
    SinAngle23 = -SinAngle23
  EndIf
  ; changement de base
  y1_r2 = (x1 - x2) * SinAngle23 + (y1 - y2) * CosAngle23
  ; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
  If y1_r2 > 0
    Sens23 = 1
  Else
    Sens23 = -1
  EndIf
  ; Pour la ligne 31
  ; Le point de départ du repère est le point x3, y3
  Width31.l = x1 - x3
  Hight31.l = y1 - y3
  Distance31.f = Sqr(Width31 * Width31 + Hight31 * Hight31)
  CosAngle31.f = Width31 / Distance31
  SinAngle31.f = Sin(ACos(CosAngle31))
  If Hight31 > 0
    SinAngle31 = -SinAngle31
  EndIf
  ; changement de base
  y2_r2 = (x2 - x3) * SinAngle31 + (y2 - y3) * CosAngle31
  ; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
  If y2_r2 > 0
    Sens31 = 1
  Else
    Sens31 = -1
  EndIf
  
  ; Détermination de la zone de dessin
  Zone_G = x1
  Zone_D = x1
  Zone_B = y1
  Zone_H = y1
  If x2 < Zone_G
    Zone_G = x2
  EndIf
  If x3 < Zone_G
    Zone_G = x3
  EndIf
  If x2 > Zone_D
    Zone_D = x2
  EndIf
  If x3 > Zone_D
    Zone_D = x3
  EndIf
  If y2 < Zone_B
    Zone_B = y2
  EndIf
  If y3 < Zone_B
    Zone_B = y3
  EndIf
  If y2 > Zone_H
    Zone_H = y2
  EndIf
  If y3 > Zone_H
    Zone_H = y3
  EndIf
  Zone_B - Thickness
  Zone_H + Thickness
  Zone_G - Thickness
  Zone_D + Thickness
  
  ; Dessin du triangle
  If Mode & #PB_2DDrawing_Outlined ; Triangle vide
    For N = Zone_G To Zone_D
      For nn = Zone_B To Zone_H
        
        y1_r2 = (N - x1) * SinAngle12 + (nn - y1) * CosAngle12
        y1_r2 * Sens12
        If y1_r2 >= -0.5 - Epaisseur
          
          Application1.f = 0.5 + Epaisseur + y1_r2
          If Application1 > 1
            Application1 = 1 + 0.5 + Epaisseur - Application1
            If Application1 < 0
              Application1 = 0
            EndIf
            Interieur1 = 1
          Else
            Interieur1 = 0
          EndIf
          
          y2_r2 = (N - x2) * SinAngle23 + (nn - y2) * CosAngle23
          y2_r2 * Sens23
          If y2_r2 >= -0.5 - Epaisseur
            
            Application2.f = 0.5 + Epaisseur + y2_r2
            If Application2 > 1
              Application2 = 1 + 0.5 + Epaisseur - Application2
              If Application2 < 0
                Application2 = 0
              EndIf
              Interieur2 = 1
            Else
              Interieur2 = 0
            EndIf
            
            y3_r2 = (N - x3) * SinAngle31 + (nn - y3) * CosAngle31
            y3_r2 * Sens31
            If y3_r2 >= -0.5 - Epaisseur
              
              Application3.f = 0.5 + Epaisseur + y3_r2
              If Application3 > 1
                Application3 = 1 + 0.5 + Epaisseur - Application3
                If Application3 < 0
                  Application3 = 0
                EndIf
                Interieur3 = 1
              Else
                Interieur3 = 0
              EndIf
              
              
              If Interieur1 And Interieur2 And Interieur3
                Application = Application1 + Application2 + Application3
              Else
                Application = 1
                If Interieur1 = 0
                  Application * Application1
                EndIf
                If Interieur2 = 0
                  Application * Application2
                EndIf
                If Interieur3 = 0
                  Application * Application3
                EndIf
              EndIf
              If Application > 0
                If Application < 1
                  ; Couleur_Fond = Point(n, nn)
                  ; Plot(n, nn, ColorBlending(Color, Couleur_Fond, Application))
                  Alpha = Alpha(Color) * Application
                  Plot(N, nn, $00FFFFFF & Color | Alpha << 24)
                Else
                  Plot(N, nn, Color)
                EndIf
              EndIf
              
            EndIf
          EndIf
        EndIf
        
      Next
    Next
  Else ; Triangle plein
    For N = Zone_G To Zone_D
      For nn = Zone_B To Zone_H
        
        y1_r2 = (N - x1) * SinAngle12 + (nn - y1) * CosAngle12
        y1_r2 * Sens12
        If y1_r2 >= -0.5 - Epaisseur
          
          Application1.f = 0.5 + Epaisseur + y1_r2
          If Application1 > 1
            Application1 = 1
          EndIf
          
          y2_r2 = (N - x2) * SinAngle23 + (nn - y2) * CosAngle23
          y2_r2 * Sens23
          If y2_r2 >= -0.5 - Epaisseur
            
            Application2.f = 0.5 + Epaisseur + y2_r2
            If Application2 > 1
              Application2 = 1
            EndIf
            
            y3_r2 = (N - x3) * SinAngle31 + (nn - y3) * CosAngle31
            y3_r2 * Sens31
            If y3_r2 >= -0.5 - Epaisseur
              
              Application3.f = 0.5 + Epaisseur + y3_r2
              If Application3 > 1
                Application3 = 1
              EndIf
              
              Application = Application1 * Application2 * Application3
              If Application < 1
                Alpha = Alpha(Color) * Application
                Plot(N, nn, $00FFFFFF & Color | Alpha << 24)
              Else
                Plot(N, nn, Color)
              EndIf
              
            EndIf
          EndIf
        EndIf
        
      Next
    Next
  EndIf
  
EndProcedure




hwnd=OpenWindow(0, 0, 0, 101, 101, "Horloge", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
StickyWindow(0, 1)
SetLayeredWindow(WindowID(0))

; SetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE,GetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE) | #WS_EX_LAYERED)
; SetLayeredWindowAttributes_(WindowID(0), 0, (255 * 60) / 100, #LWA_ALPHA)

CreateImage(0, 101, 101, 32 | #PB_Image_Transparent)

AddWindowTimer(0, 1, 1000)


Repeat
  Event = WaitWindowEvent()
  
  Select Event
      
    Case #WM_RBUTTONDOWN
      quite = 1
      
    Case #WM_LBUTTONDOWN
      SendMessage_(hwnd, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
      
    Case #PB_Event_Timer
      Select EventTimer()
        Case 1
          Date = Date()
          Seconde.d = Second(Date) * 2 * #PI / 60
          Minute.d = Minute(Date) * 2 * #PI / 60
          Heure.d = Hour(Date) * 2 * #PI / 12
          
          StartDrawing(ImageOutput(0))
            DrawingMode(#PB_2DDrawing_AlphaChannel)
            Box(0, 0, 101, 101, 0) ; Efface
            DrawingMode(#PB_2DDrawing_AlphaBlend)
            ; Fond
            CircleAA(50, 50, 50, $80000000)
            ; Bordure
            CircleAA(50, 50, 50, $C0000000, 2, #PB_2DDrawing_Outlined)
            ; Aiguille heure
            x1 = 50 + 35 * Sin(Heure)
            y1 = 50 - 35 * Cos(Heure)
            x2 = 50 + 5 * Sin(Heure - #PI * 2 / 3)
            y2 = 50 - 5 * Cos(Heure - #PI * 2 / 3)
            x3 = 50 + 5 * Sin(Heure + #PI * 2 / 3)
            y3 = 50 - 5 * Cos(Heure + #PI * 2 / 3)
            TriangleAA(x1, y1, x2, y2, x3, y3, $80FFFFFF)
            ; Aiguille minute
            x1 = 50 + 45 * Sin(Minute)
            y1 = 50 - 45 * Cos(Minute)
            x2 = 50 + 3 * Sin(Minute - #PI * 2 / 3)
            y2 = 50 - 3 * Cos(Minute - #PI * 2 / 3)
            x3 = 50 + 3 * Sin(Minute + #PI * 2 / 3)
            y3 = 50 - 3 * Cos(Minute + #PI * 2 / 3)
            TriangleAA(x1, y1, x2, y2, x3, y3, $C0FFFFFF)
            ; Aiguille seconde
            x1 = 50 + 45 * Sin(Seconde)
            y1 = 50 - 45 * Cos(Seconde)
            x2 = 50 + 8 * Sin(Seconde - #PI)
            y2 = 50 - 8 * Cos(Seconde - #PI)
            LineAA(x1, y1, x2 - x1 + 1, y2 - y1 + 1, $FFFFFFFF, 1)
            
          StopDrawing()
          AlphaImageWindow(WindowID(0), ImageID(0))
          
      EndSelect
  EndSelect
  
  
Until quite = 1
End

~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: Une Horloge analogique

Message par Backup »

Merci :)

Le soldat , nous fait du boulot de chinois.... a moitié fini :roll: :mrgreen:
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Une Horloge analogique

Message par Ar-S »

et oui ma pauvre Lucette, les vraies valeurs se perdent :mrgreen: :mrgreen:
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: Une Horloge analogique

Message par Le Soldat Inconnu »

pfff, ce qu'il ne faut pas entendre.

Tiens, la version widget (toujours en arrière plan sur le bureau), avec déplacement et accrochage sur les bords de l'écran. Et fermeture par menu sur clic droit

Code : Tout sélectionner

CompilerIf Defined(AlphaImageWindow, #PB_Function) = 0
	ProcedureDLL SetLayeredWindow(WindowID) ; Set #WS_EX_LAYERED window attribute
		SetWindowLong_(WindowID, #GWL_EXSTYLE, GetWindowLong_(WindowID, #GWL_EXSTYLE) | #WS_EX_LAYERED) ; Mettre l'attribut WS_EX_LAYERED à la fenêtre
	EndProcedure
	ProcedureDLL AlphaImageWindow(WindowID, ImageID) ; Set image as window background (32bits image support)
		Protected Image_HDC, Image_Bitmap.BITMAP, ContextOffset.POINT, Blend.BLENDFUNCTION, Image
		
		; Dimension de l'image
		GetObject_(ImageID, SizeOf(BITMAP), @Image_Bitmap)
		
		Image = CreateImage(#PB_Any, Image_Bitmap\bmWidth, Image_Bitmap\bmHeight, 32)
		StartDrawing(ImageOutput(Image))
			DrawingMode(#PB_2DDrawing_AlphaBlend)
			DrawAlphaImage(ImageID, 0, 0)
			DrawingMode(#PB_2DDrawing_AlphaChannel)
			DrawAlphaImage(ImageID, 0, 0)
		StopDrawing()
		
		; Chargement du HDC
		Image_HDC = CreateCompatibleDC_(#Null)
		Image_Ancienne = SelectObject_(Image_HDC, ImageID(Image))
		
		; L'image est mise en skin de la fenêtre
		Blend\SourceConstantAlpha = 255 ; niveau de transparence
		Blend\AlphaFormat = 1 ; Support de la couche alpha
		Blend\BlendOp = 0
		Blend\BlendFlags = 0
		UpdateLayeredWindow_(WindowID, 0, 0, @Image_Bitmap + 4, Image_HDC, @ContextOffset, 0, @Blend, 2)
		
		; Fermeture du HDC
		SelectObject_(Image_HDC, Image_Ancienne)
		DeleteDC_(Image_HDC)
		
		; Supression de l'image
		FreeImage(Image)
		
	EndProcedure
CompilerEndIf


Procedure CircleAA(x, y, Radius, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
	Protected n, nn, Distance.f, Application.f, Color_Alpha.l, Color_Normal.l, Alpha.l, x1, x2, y1, y2
	Color_Alpha = Alpha(Color)
	Color_Normal = Color & $00FFFFFF
	If Mode & #PB_2DDrawing_Outlined ; Cercle vide
		; on dessine 1/4 du cercle et on duplique pour le reste
		For n = 0 To Radius
			For nn = 0 To Radius
				Distance.f = Sqr(n * n + nn * nn)
				If Distance <= Radius And Distance > Radius - 1
					Application.f = 1 - Abs(Radius - 1 - Distance)
					Alpha = Color_Alpha * Application
					Alpha = Color_Normal | Alpha << 24
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Alpha)
					Plot(x2, y1, Alpha)
					Plot(x1, y2, Alpha)
					Plot(x2, y2, Alpha)
				ElseIf Distance <= Radius - Thickness And Distance > Radius - Thickness - 1
					Application.f = 1 - Abs(Radius - Thickness - Distance)
					Alpha = Color_Alpha * Application
					Alpha = Color_Normal | Alpha << 24
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Alpha)
					Plot(x2, y1, Alpha)
					Plot(x1, y2, Alpha)
					Plot(x2, y2, Alpha)
				ElseIf Distance <= Radius - 1 And Distance > Radius - Thickness
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Color)
					If n <> 0
						Plot(x2, y1, Color)
					EndIf
					If nn <> 0
						Plot(x1, y2, Color)
					EndIf
					If n <> 0 And nn <> 0
						Plot(x2, y2, Color)
					EndIf
				EndIf
			Next
		Next
	Else ; Cercle plein
		; on dessine 1/4 du cercle et on duplique pour le reste
		For n = 0 To Radius
			For nn = 0 To Radius
				Distance.f = Sqr(n * n + nn * nn)
				If Distance <= Radius And Distance > Radius - 1
					Application.f = (Radius - Distance)
					Alpha = Alpha(Color) * Application
					Alpha = Color_Normal | Alpha << 24
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Alpha)
					Plot(x2, y1, Alpha)
					Plot(x1, y2, Alpha)
					Plot(x2, y2, Alpha)
				ElseIf Distance <= Radius - 1
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Color)
					If n <> 0
						Plot(x2, y1, Color)
					EndIf
					If nn <> 0
						Plot(x1, y2, Color)
					EndIf
					If n <> 0 And nn <> 0
						Plot(x2, y2, Color)
					EndIf
				EndIf
			Next
		Next
	EndIf
EndProcedure

Procedure EllipseAA(x, y, RadiusX, RadiusY, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
	Protected n, nn, Distance.f, Application.f, Ellispse_Rayon.f, Ellipse_CosAngle.f, Ellipse_E.f, Color_Alpha.l, Color_Normal.l, Alpha.l, x1, x2, y1, y2
	Color_Alpha = Alpha(Color)
	Color_Normal = Color & $00FFFFFF
	; Précacul de l'équation de l'ellipse
	If RadiusX > RadiusY
		Ellipse_E = (RadiusX * RadiusX - RadiusY * RadiusY) / (RadiusX * RadiusX)
	Else
		Ellipse_E = (RadiusY * RadiusY - RadiusX * RadiusX) / (RadiusY * RadiusY)
	EndIf
	If Mode & #PB_2DDrawing_Outlined ; ellipse vide
		; on dessine 1/4 de l'ellipse et on duplique pour le reste
		For n = 0 To RadiusX
			For nn = 0 To RadiusY
				Distance.f = Sqr(n * n + nn * nn)
				If RadiusX > RadiusY
					If n
						Ellipse_CosAngle.f = n / Distance
						Ellispse_Rayon = Sqr(RadiusY * RadiusY / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
					Else
						Ellispse_Rayon = RadiusY
					EndIf
				Else
					If nn
						Ellipse_CosAngle.f = nn / Distance
						Ellispse_Rayon = Sqr(RadiusX * RadiusX / (1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle))
					Else
						Ellispse_Rayon = RadiusX
					EndIf
				EndIf
				If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1
					Application.f = 1 - Abs(Ellispse_Rayon - 1 - Distance)
					Alpha = Alpha(Color) * Application
					Alpha = Color_Normal | Alpha << 24
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Alpha)
					Plot(x2, y1, Alpha)
					Plot(x1, y2, Alpha)
					Plot(x2, y2, Alpha)
				ElseIf Distance <= Ellispse_Rayon - Thickness And Distance > Ellispse_Rayon - Thickness - 1
					Application.f = 1 - Abs(Ellispse_Rayon - Thickness - Distance)
					Alpha = Alpha(Color) * Application
					Alpha = Color_Normal | Alpha << 24
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Alpha)
					Plot(x2, y1, Alpha)
					Plot(x1, y2, Alpha)
					Plot(x2, y2, Alpha)
				ElseIf Distance <= Ellispse_Rayon - 1 And Distance > Ellispse_Rayon - Thickness
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Color)
					If n <> 0
						Plot(x2, y1, Color)
					EndIf
					If nn <> 0
						Plot(x1, y2, Color)
					EndIf
					If n <> 0 And nn <> 0
						Plot(x2, y2, Color)
					EndIf
				EndIf
			Next
		Next
	Else ; ellipse pleine
		; on dessine 1/4 de l'ellipse et on duplique pour le reste
		For n = 0 To RadiusX
			For nn = 0 To RadiusY
				Distance.f = Sqr(n * n + nn * nn)
				If RadiusX > RadiusY
					If n
						Ellipse_CosAngle.f = n / Distance
						Ellispse_Rayon = RadiusY / Sqr(1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle)
					Else
						Ellispse_Rayon = RadiusY
					EndIf
				Else
					If nn
						Ellipse_CosAngle.f = nn / Distance
						Ellispse_Rayon = RadiusX / Sqr(1 - Ellipse_E * Ellipse_CosAngle * Ellipse_CosAngle)
					Else
						Ellispse_Rayon = RadiusX
					EndIf
				EndIf
				If Distance <= Ellispse_Rayon And Distance > Ellispse_Rayon - 1
					Application.f = (Ellispse_Rayon - Distance)
					Alpha = Alpha(Color) * Application
					Alpha = Color_Normal | Alpha << 24
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Alpha)
					Plot(x2, y1, Alpha)
					Plot(x1, y2, Alpha)
					Plot(x2, y2, Alpha)
				ElseIf Distance <= Ellispse_Rayon - 1
					x1 = x + n
					x2 = x - n
					y1 = y + nn
					y2 = y - nn
					Plot(x1, y1, Color)
					If n <> 0
						Plot(x2, y1, Color)
					EndIf
					If nn <> 0
						Plot(x1, y2, Color)
					EndIf
					If n <> 0 And nn <> 0
						Plot(x2, y2, Color)
					EndIf
				EndIf
			Next
		Next
	EndIf
EndProcedure

Procedure LineAA(x, y, Width, Hight, Color, Thickness = 1)
	Protected SensX, SensY, n, nn, Epaisseur.f, x2.f, y2.f, Application.f, Distance.f, CosAngle.f, SinAngle.f, Color_Alpha.l, Color_Normal.l, Alpha.l
	Color_Alpha = Alpha(Color)
	Color_Normal = Color & $00FFFFFF
	; On mets la droite toujours dans le même sens pour l'analyse
	; La sauvegarde du sens permettra de dessiner la droite ensuite dans le bon sens
	If Width >= 0
		SensX = 1
	Else
		SensX = -1
		Width = -Width
	EndIf
	If Hight >= 0
		SensY = 1
	Else
		SensY = -1
		Hight = -Hight
	EndIf
	
	
	; Demi épaisseur de la ligne
	Epaisseur.f = Thickness / 2
	
	; calcul pour le changement de repère qui permet de connaitre l'épaisseur du trait et de gérer l'AA
	Distance.f = Sqr(Width * Width + Hight * Hight)
	CosAngle.f = Width / Distance
	SinAngle.f = -Sin(ACos(CosAngle))
	
	; Dessin de la ligne
	For n = -Thickness To Width + Thickness
		For nn = -Thickness To Hight + Thickness
			
			; changement de base
			; les y représentent l'épaisseur de la ligne
			x2 = n * CosAngle - nn * SinAngle
			y2 = Abs(n * SinAngle + nn * CosAngle)
			
			If y2 <= Epaisseur + 0.5
				Application = 0.5 + Epaisseur - y2
				If Application > 1
					Application = 1
				EndIf
				If x2 > -1 And x2 < Distance + 1
					If x2 < 0
						Application * (1 + x2)
					ElseIf x2 > Distance
						Application * (1 - x2 + Distance)
					EndIf
				Else
					Application = 0
				EndIf
				If Application > 0
					If Application < 1
						Alpha = Color_Alpha * Application
						Alpha = Color_Normal | Alpha << 24
						Plot(x + n * SensX, y + nn * SensY, Alpha)
					Else
						Plot(x + n * SensX, y + nn * SensY, Color)
					EndIf
				EndIf
			EndIf
			
		Next
	Next
	
EndProcedure

Procedure TriangleAA(x1, y1, x2, y2, x3, y3, Color, Thickness = 1, Mode = #PB_2DDrawing_Default)
	Protected n, nn, Epaisseur.f, Zone_G, Zone_D, Zone_H, Zone_B, Application.f, Color_Alpha.l, Color_Normal.l, Alpha.l
	Color_Alpha = Alpha(Color)
	Color_Normal = Color & $00FFFFFF
	Protected Width12.l, Hight12.l, Distance12.f, CosAngle12.f, SinAngle12.f, Sens12.l, y1_r2.f, Application1.f, Interieur1
	Protected Width23.l, Hight23.l, Distance23.f, CosAngle23.f, SinAngle23.f, Sens23.l, y2_r2.f, Application2.f, Interieur2
	Protected Width31.l, Hight31.l, Distance31.f, CosAngle31.f, SinAngle31.f, Sens31.l, y3_r2.f, Application3.f, Interieur3
	
	; Demi épaisseur de la ligne
	Epaisseur.f = Thickness / 2
	
	; calcul pour le changement de repère qui permet de connaitre l'épaisseur du trait et de gérer l'AA
	; Pour la ligne 12
	; Le point de départ du repère est le point x1, y1
	Width12.l = x2 - x1
	Hight12.l = y2 - y1
	Distance12.f = Sqr(Width12 * Width12 + Hight12 * Hight12)
	CosAngle12.f = Width12 / Distance12
	SinAngle12.f = Sin(ACos(CosAngle12))
	If Hight12 > 0
		SinAngle12 = -SinAngle12
	EndIf
	; changement de base
	y3_r2 = (x3 - x1) * SinAngle12 + (y3 - y1) * CosAngle12
	; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
	If y3_r2 > 0
		Sens12 = 1
	Else
		Sens12 = -1
	EndIf
	; Pour la ligne 23
	; Le point de départ du repère est le point x2, y2
	Width23.l = x3 - x2
	Hight23.l = y3 - y2
	Distance23.f = Sqr(Width23 * Width23 + Hight23 * Hight23)
	CosAngle23.f = Width23 / Distance23
	SinAngle23.f = Sin(ACos(CosAngle23))
	If Hight23 > 0
		SinAngle23 = -SinAngle23
	EndIf
	; changement de base
	y1_r2 = (x1 - x2) * SinAngle23 + (y1 - y2) * CosAngle23
	; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
	If y1_r2 > 0
		Sens23 = 1
	Else
		Sens23 = -1
	EndIf
	; Pour la ligne 31
	; Le point de départ du repère est le point x3, y3
	Width31.l = x1 - x3
	Hight31.l = y1 - y3
	Distance31.f = Sqr(Width31 * Width31 + Hight31 * Hight31)
	CosAngle31.f = Width31 / Distance31
	SinAngle31.f = Sin(ACos(CosAngle31))
	If Hight31 > 0
		SinAngle31 = -SinAngle31
	EndIf
	; changement de base
	y2_r2 = (x2 - x3) * SinAngle31 + (y2 - y3) * CosAngle31
	; on regarde de quel coté de la ligne se trouve le triangle en regardant la position du point 3
	If y2_r2 > 0
		Sens31 = 1
	Else
		Sens31 = -1
	EndIf
	
	; Détermination de la zone de dessin
	Zone_G = x1
	Zone_D = x1
	Zone_B = y1
	Zone_H = y1
	If x2 < Zone_G
		Zone_G = x2
	EndIf
	If x3 < Zone_G
		Zone_G = x3
	EndIf
	If x2 > Zone_D
		Zone_D = x2
	EndIf
	If x3 > Zone_D
		Zone_D = x3
	EndIf
	If y2 < Zone_B
		Zone_B = y2
	EndIf
	If y3 < Zone_B
		Zone_B = y3
	EndIf
	If y2 > Zone_H
		Zone_H = y2
	EndIf
	If y3 > Zone_H
		Zone_H = y3
	EndIf
	Zone_B - Thickness
	Zone_H + Thickness
	Zone_G - Thickness
	Zone_D + Thickness
	
	; Dessin du triangle
	If Mode & #PB_2DDrawing_Outlined ; Triangle vide
		For n = Zone_G To Zone_D
			For nn = Zone_B To Zone_H
				
				y1_r2 = (n - x1) * SinAngle12 + (nn - y1) * CosAngle12
				y1_r2 * Sens12
				If y1_r2 >= -0.5 - Epaisseur
					
					Application1.f = 0.5 + Epaisseur + y1_r2
					If Application1 > 1
						Application1 = 1 + 0.5 + Epaisseur - Application1
						If Application1 < 0
							Application1 = 0
						EndIf
						Interieur1 = 1
					Else
						Interieur1 = 0
					EndIf
					
					y2_r2 = (n - x2) * SinAngle23 + (nn - y2) * CosAngle23
					y2_r2 * Sens23
					If y2_r2 >= -0.5 - Epaisseur
						
						Application2.f = 0.5 + Epaisseur + y2_r2
						If Application2 > 1
							Application2 = 1 + 0.5 + Epaisseur - Application2
							If Application2 < 0
								Application2 = 0
							EndIf
							Interieur2 = 1
						Else
							Interieur2 = 0
						EndIf
						
						y3_r2 = (n - x3) * SinAngle31 + (nn - y3) * CosAngle31
						y3_r2 * Sens31
						If y3_r2 >= -0.5 - Epaisseur
							
							Application3.f = 0.5 + Epaisseur + y3_r2
							If Application3 > 1
								Application3 = 1 + 0.5 + Epaisseur - Application3
								If Application3 < 0
									Application3 = 0
								EndIf
								Interieur3 = 1
							Else
								Interieur3 = 0
							EndIf
							
							
							If Interieur1 And Interieur2 And Interieur3
								Application = Application1 + Application2 + Application3
							Else
								Application = 1
								If Interieur1 = 0
									Application * Application1
								EndIf
								If Interieur2 = 0
									Application * Application2
								EndIf
								If Interieur3 = 0
									Application * Application3
								EndIf
							EndIf
							If Application > 0
								If Application < 1
									Alpha = Color_Alpha * Application
									Alpha = Color_Normal | Alpha << 24
									Plot(n, nn, Alpha)
								Else
									Plot(n, nn, Color)
								EndIf
							EndIf
							
						EndIf
					EndIf
				EndIf
				
			Next
		Next
	Else ; Triangle plein
		For n = Zone_G To Zone_D
			For nn = Zone_B To Zone_H
				
				y1_r2 = (n - x1) * SinAngle12 + (nn - y1) * CosAngle12
				y1_r2 * Sens12
				If y1_r2 >= -0.5 - Epaisseur
					
					Application1.f = 0.5 + Epaisseur + y1_r2
					If Application1 > 1
						Application1 = 1
					EndIf
					
					y2_r2 = (n - x2) * SinAngle23 + (nn - y2) * CosAngle23
					y2_r2 * Sens23
					If y2_r2 >= -0.5 - Epaisseur
						
						Application2.f = 0.5 + Epaisseur + y2_r2
						If Application2 > 1
							Application2 = 1
						EndIf
						
						y3_r2 = (n - x3) * SinAngle31 + (nn - y3) * CosAngle31
						y3_r2 * Sens31
						If y3_r2 >= -0.5 - Epaisseur
							
							Application3.f = 0.5 + Epaisseur + y3_r2
							If Application3 > 1
								Application3 = 1
							EndIf
							
							Application = Application1 * Application2 * Application3
							If Application < 1
								Alpha = Color_Alpha * Application
								Alpha = Color_Normal | Alpha << 24
								Plot(n, nn, Alpha)
							Else
								Plot(n, nn, Color)
							EndIf
							
						EndIf
					EndIf
				EndIf
				
			Next
		Next
	EndIf
	
EndProcedure

Global NewList MoveWindowList.i()
Procedure MoveWindow_ChildWindowSearch(hwnd.l, lParam.l)
	Protected hWnd_Class.s, hWnd_ProcessID.i, Class.s
	Class.s = Space(50)
	GetClassName_(hwnd, @hWnd_Class, 50)
	If Left(hWnd_Class, 12) = "WindowClass_" ; Nom de l'objet rechercher
		GetWindowThreadProcessId_(hwnd, @hWnd_ProcessID)
		If hWnd_ProcessID = lParam And GetWindowLong_(hwnd, #GWL_STYLE) & #WS_VISIBLE = #WS_VISIBLE ; pour lister que les fenêtres visibles
			AddElement(MoveWindowList()) : MoveWindowList() = hwnd
		EndIf
	EndIf
	ProcedureReturn #True
EndProcedure
Procedure MoveWindow(Window.i, Magnetic.b = 1, CenterMouse.b = 1) ; Déplace une fenêtre sans bordure
	#MoveWindow_Magnetic_Screen = 6
	#MoveWindow_Magnetic_Window = 8
	#MoveWindow_Magnetic_Step = 4
	Protected Fenetre.RECT, AutreFenetre.RECT, Numero_Ecran.l, NbEcran.l, Ecran.RECT, Deplacement_X, Deplacement_Y, Event, FenetreX, FenetreY, ProcessID, hwnd, hWnd_ProcessID, FenetreL, FenetreH
	
	; Point de départ
	GetWindowRect_(WindowID(Window), @Fenetre) ; Taille de la fenêtre totale, bordure comprise
	ClientToScreen_(WindowID(Window), @AutreFenetre) ; Taille de la zone de travail
	FenetreL = Fenetre\right - Fenetre\left
	FenetreH = Fenetre\bottom - Fenetre\top
	
	; Point de départ
	Deplacement_X = WindowMouseX(Window)
	Deplacement_Y = WindowMouseY(Window)
	If CenterMouse
		CenterMouse = 4
	EndIf
	
	Deplacement_X + AutreFenetre\left - Fenetre\left
	Deplacement_Y + AutreFenetre\top - Fenetre\top
	
	If Magnetic
		; Recherche de toute les fenêtres visibles du programme
		GetWindowThreadProcessId_(WindowID(Window), @ProcessID) ; Handle du process
		hwnd = FindWindow_(0, 0)
		While hwnd <> 0
			GetWindowThreadProcessId_(hwnd, @hWnd_ProcessID)
			If hWnd_ProcessID = ProcessID And GetWindowLong_(hwnd, #GWL_STYLE) & #WS_VISIBLE = #WS_VISIBLE ; pour lister que les fenêtres visibles
				AddElement(MoveWindowList()) : MoveWindowList() = hwnd
			EndIf
			EnumChildWindows_(hwnd, @MoveWindow_ChildWindowSearch(), ProcessID) ; On recherche sur les fenêtres enfants
			hwnd = GetWindow_(hwnd, #GW_HWNDNEXT)
		Wend
		
		; Dimension de l'écran
		NbEcran = ExamineDesktops()
		NbEcran - 1
	EndIf
	
	Repeat
		
		Event = WaitWindowEvent(20)
		
		ForEach MoveWindowList() ; On actualise l'affichage de toute les fenêtres
			UpdateWindow_(MoveWindowList())
		Next
		
		If CenterMouse And Event = #WM_MOUSEMOVE ; On prend le centre la fenêtre
			CenterMouse - 1
			If CenterMouse = 0
				Deplacement_X = WindowWidth(Window) / 2
				Deplacement_Y = WindowHeight(Window) / 2
			EndIf
		EndIf
		
		; Position de la fenêtre
		FenetreX = DesktopMouseX() - Deplacement_X
		FenetreY = DesktopMouseY() - Deplacement_Y
		
		If Magnetic
			
			; Dimension de la fenêtre avec prise en comptes des bords
			Fenetre\left = FenetreX
			Fenetre\right = FenetreX + FenetreL
			Fenetre\top = FenetreY
			Fenetre\bottom = FenetreY + FenetreH
			
			For Numero_Ecran = 0 To NbEcran
				; Taille de l'écran
				Ecran\left = DesktopX(Numero_Ecran)
				Ecran\right = DesktopX(Numero_Ecran) + DesktopWidth(Numero_Ecran)
				Ecran\top = DesktopY(Numero_Ecran)
				Ecran\bottom = DesktopY(Numero_Ecran) + DesktopHeight(Numero_Ecran)
				; Accrochage sur les bords de l'écran
				If Fenetre\left - Ecran\left < (#MoveWindow_Magnetic_Step * #MoveWindow_Magnetic_Screen + #MoveWindow_Magnetic_Screen / 2) And Fenetre\left >= Ecran\left - (#MoveWindow_Magnetic_Screen / 2)
					FenetreX = (Fenetre\left - Ecran\left + (#MoveWindow_Magnetic_Screen / 2)) / #MoveWindow_Magnetic_Screen
					FenetreX * #MoveWindow_Magnetic_Screen
				ElseIf Ecran\right - Fenetre\right < (#MoveWindow_Magnetic_Step * #MoveWindow_Magnetic_Screen + #MoveWindow_Magnetic_Screen / 2) And Fenetre\right <= Ecran\right + (#MoveWindow_Magnetic_Screen / 2)
					FenetreX = (Ecran\right - Fenetre\right + #MoveWindow_Magnetic_Screen / 2) / #MoveWindow_Magnetic_Screen
					FenetreX * #MoveWindow_Magnetic_Screen
					FenetreX = Ecran\right + Fenetre\left - Fenetre\right - FenetreX
				EndIf
				If Fenetre\top - Ecran\top < (#MoveWindow_Magnetic_Step * #MoveWindow_Magnetic_Screen + #MoveWindow_Magnetic_Screen / 2) And Fenetre\top >= Ecran\top - (#MoveWindow_Magnetic_Screen / 2)
					FenetreY = (Fenetre\top - Ecran\top + (#MoveWindow_Magnetic_Screen / 2)) / #MoveWindow_Magnetic_Screen
					FenetreY * #MoveWindow_Magnetic_Screen
				ElseIf Ecran\bottom - Fenetre\bottom < (#MoveWindow_Magnetic_Step * #MoveWindow_Magnetic_Screen + #MoveWindow_Magnetic_Screen / 2) And Fenetre\bottom <= Ecran\bottom + (#MoveWindow_Magnetic_Screen / 2)
					FenetreY = (Ecran\bottom - Fenetre\bottom + (#MoveWindow_Magnetic_Screen / 2)) / #MoveWindow_Magnetic_Screen
					FenetreY * #MoveWindow_Magnetic_Screen
					FenetreY = Ecran\bottom + Fenetre\top - Fenetre\bottom - FenetreY
				EndIf
				; Accrochage sur le milieu de l'écran
				If Abs((Fenetre\right + Fenetre\left) - (Ecran\right + Ecran\left)) < (#MoveWindow_Magnetic_Window * 2)
					FenetreX = (Ecran\right + Ecran\left) / 2 - (Fenetre\right - Fenetre\left) / 2
				EndIf
				If Abs((Fenetre\bottom + Fenetre\top) - (Ecran\bottom + Ecran\top)) < (#MoveWindow_Magnetic_Window * 2)
					FenetreY = (Ecran\bottom + Ecran\top) / 2 - (Fenetre\bottom - Fenetre\top) / 2
				EndIf
			Next
			; Accrochage sur les autres fenêtres
			ForEach MoveWindowList()
				If MoveWindowList() <> WindowID(Window)
					GetWindowRect_(MoveWindowList(), @AutreFenetre.RECT) ; On récupère la positon de la fenêtre
					
					; Bord gauche et droit
					If (Fenetre\top >= AutreFenetre\top - #MoveWindow_Magnetic_Window And Fenetre\top <= AutreFenetre\bottom + #MoveWindow_Magnetic_Window) Or (Fenetre\bottom >= AutreFenetre\top - #MoveWindow_Magnetic_Window And Fenetre\bottom <= AutreFenetre\bottom + #MoveWindow_Magnetic_Window) Or (Fenetre\top <= AutreFenetre\top And Fenetre\bottom >= AutreFenetre\bottom)
						; Bord gauche de l'autre fenêtre
						If Abs(Fenetre\right - AutreFenetre\left) < #MoveWindow_Magnetic_Window
							FenetreX = AutreFenetre\left - (Fenetre\right - Fenetre\left)
						ElseIf Abs(Fenetre\left - AutreFenetre\left) < #MoveWindow_Magnetic_Window
							FenetreX = AutreFenetre\left
						EndIf
						; Bord droit de l'autre fenêtre
						If Abs(Fenetre\right - AutreFenetre\right) < #MoveWindow_Magnetic_Window
							FenetreX = AutreFenetre\right - (Fenetre\right - Fenetre\left)
						ElseIf Abs(Fenetre\left - AutreFenetre\right) < #MoveWindow_Magnetic_Window
							FenetreX = AutreFenetre\right
						EndIf
					EndIf
					; Bord haut et bas
					If (Fenetre\left >= AutreFenetre\left - #MoveWindow_Magnetic_Window And Fenetre\left <= AutreFenetre\right + #MoveWindow_Magnetic_Window) Or (Fenetre\right >= AutreFenetre\left - #MoveWindow_Magnetic_Window And Fenetre\right <= AutreFenetre\right + #MoveWindow_Magnetic_Window) Or (Fenetre\left <= AutreFenetre\left And Fenetre\right >= AutreFenetre\right)
						; Bord haut de l'autre fenêtre
						If Abs(Fenetre\bottom - AutreFenetre\top) < #MoveWindow_Magnetic_Window
							FenetreY = AutreFenetre\top - (Fenetre\bottom - Fenetre\top)
						ElseIf Abs(Fenetre\top - AutreFenetre\top) < #MoveWindow_Magnetic_Window
							FenetreY = AutreFenetre\top
						EndIf
						; Bord bas de l'autre fenêtre
						If Abs(Fenetre\bottom - AutreFenetre\bottom) < #MoveWindow_Magnetic_Window
							FenetreY = AutreFenetre\bottom - (Fenetre\bottom - Fenetre\top)
						ElseIf Abs(Fenetre\top - AutreFenetre\bottom) < #MoveWindow_Magnetic_Window
							FenetreY = AutreFenetre\bottom
						EndIf
					EndIf
					
				EndIf
			Next
			
		EndIf
		
		; On déplace la fenêtre
		ResizeWindow(Window, FenetreX, FenetreY, #PB_Ignore, #PB_Ignore)
		
	Until Event = #WM_LBUTTONUP Or Event = #WM_NCLBUTTONUP
	
	ClearList(MoveWindowList())
	
EndProcedure

Procedure Callback(WindowID, message, wParam, lParam)
	Protected *WindowPos.WINDOWPOS
	Result = #PB_ProcessPureBasicEvents
	
	If message = #WM_WINDOWPOSCHANGING ; Window position is about to change !
		*WindowPos = lParam
		*WindowPos\hwndInsertAfter = #HWND_BOTTOM ; <-- Forces the window to stay in the background
	EndIf
	
	ProcedureReturn Result
EndProcedure


If OpenWindow(0, 0, 0, 101, 101, "Horloge", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
	
	If CreatePopupMenu(0)
		MenuItem(0, "Quitter")
		
		
		SetLayeredWindow(WindowID(0))
		
		CreateImage(0, 101, 101, 32 | #PB_Image_Transparent)
		
		AddWindowTimer(0, 1, 1000)
		
		SetWindowCallback(@Callback(), 0)
		
		
		Repeat
			Event = WaitWindowEvent()
			
			Select Event
				Case #PB_Event_Timer
					Select EventTimer()
						Case 1
							Date = Date()
							Seconde.d = Second(Date) * 2 * #PI / 60
							Minute.d = Minute(Date) * 2 * #PI / 60
							Heure.d = Hour(Date) * 2 * #PI / 12
							
							StartDrawing(ImageOutput(0))
								DrawingMode(#PB_2DDrawing_AlphaChannel)
								Box(0, 0, 101, 101, 0) ; Efface
								DrawingMode(#PB_2DDrawing_AlphaBlend)
								; Fond
								CircleAA(50, 50, 50, $80000000)
								; Bordure
								CircleAA(50, 50, 50, $C0000000, 2, #PB_2DDrawing_Outlined)
								; Aiguille heure
								x1 = 50 + 35 * Sin(Heure)
								y1 = 50 - 35 * Cos(Heure)
								x2 = 50 + 5 * Sin(Heure - #PI * 2 / 3)
								y2 = 50 - 5 * Cos(Heure - #PI * 2 / 3)
								x3 = 50 + 5 * Sin(Heure + #PI * 2 / 3)
								y3 = 50 - 5 * Cos(Heure + #PI * 2 / 3)
								TriangleAA(x1, y1, x2, y2, x3, y3, $80FFFFFF, 2)
								; Aiguille minute
								x1 = 50 + 45 * Sin(Minute)
								y1 = 50 - 45 * Cos(Minute)
								x2 = 50 + 10 * Sin(Minute - #PI * 5 / 6)
								y2 = 50 - 10 * Cos(Minute - #PI * 5 / 6)
								x3 = 50 + 10 * Sin(Minute + #PI * 5 / 6)
								y3 = 50 - 10 * Cos(Minute + #PI * 5 / 6)
								TriangleAA(x1, y1, x2, y2, x3, y3, $C0FFFFFF, 2)
								; Aiguille seconde
								x1 = 50 + 45 * Sin(Seconde)
								y1 = 50 - 45 * Cos(Seconde)
								x2 = 50 + 15 * Sin(Seconde - #PI)
								y2 = 50 - 15 * Cos(Seconde - #PI)
								LineAA(x1, y1, x2 - x1 + 1, y2 - y1 + 1, $FFFFFFFF, 2)
							StopDrawing()
							AlphaImageWindow(WindowID(0), ImageID(0))
							
					EndSelect
					
				Case #WM_LBUTTONDOWN
					MoveWindow(0, 1, 1) ; Déplacement de la fenêtre
					
				Case #WM_RBUTTONUP
					DisplayPopupMenu(0, WindowID(0))
					
				Case #PB_Event_Menu
					Select EventMenu()
						Case 0 ; Quitte
							Event = #PB_Event_CloseWindow
					EndSelect
			EndSelect
			
			
		Until Event = #PB_Event_CloseWindow
	EndIf
EndIf
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Golfy
Messages : 423
Inscription : mer. 25/août/2004 15:14
Localisation : Grenoble
Contact :

Re: Une Horloge analogique

Message par Golfy »

On est toujours dans le forum débutant ? 8O

bon alors, j'ajoute ma suggestion :
Dommage qu'on ne puisse pas la mettre "Always on top" :roll: .................. :mrgreen: :mrgreen: :mrgreen:
*je sors*
Purebasic 5.30 full sous Windows XP (x86) et Win7 (64 bits), Linux Debian. Orientation réseaux, domotique
http://golfy.olympe.in/Teo-Tea/
Avatar de l’utilisateur
microdevweb
Messages : 1802
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: Une Horloge analogique

Message par microdevweb »

Hummm très joli code et résultat
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
david
Messages : 208
Inscription : jeu. 03/févr./2005 21:10

Re: Une Horloge analogique

Message par david »

Golfy a écrit :bon alors, j'ajoute ma suggestion :
Dommage qu'on ne puisse pas la mettre "Always on top" :roll: .................. :mrgreen: :mrgreen: :mrgreen:

après la ligne 729

Code : Tout sélectionner

If OpenWindow(0, 0, 0, 101, 101, "Horloge", #PB_Window_BorderLess | #PB_Window_ScreenCentered)

j'ai rajouté:

Code : Tout sélectionner

  SetWindowPos_(WindowID(0), -1, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE) ;fenetre premier plan********
touvé dans les forums purebasic
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Re: Une Horloge analogique

Message par Backup »

@david

un simple

Code : Tout sélectionner

StickyWindow(#Fenetre, Etat) 
aurai suffit ....

je pense que Golfy a poussé la "blague" histoire d'en rejouter :)

parcequ'ici , tout le monde , je suppose connaissait la réponse avec StickyWindow()
Répondre