Voiçi à quoi ressemble l'écran de veille. Sans l'aperçu pour le moment.
Le code est présent mais en commentaire.
Le code pour le screensaver est de Franco et le code pour les étoiles est de Pupil (Forum anglais). Merci à eux pour leurs bout de code.
Et j'ai ajouté des éléments et adapté le tout pour que ça fonctionne.
Code : Tout sélectionner
; (c) 2001 - Franco's template - absolutely freeware
; PureBasic screensaver
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Procédure de fonctionnement du Screensaver
; Ne pas modifier
Procedure OnlyOneSCRStart(Name$)
Shared OnlyOneStartMutex.l
OnlyOneStartMutex = CreateMutex_(0, 1, Name$)
OnlyOneStartError.l = GetLastError_()
If OnlyOneStartMutex <> 0 And OnlyOneStartError = 0
ProcedureReturn 1
Else
CloseHandle_(OnlyOneStartMutex)
End
EndIf
EndProcedure
Procedure OnlyOneSCRStop()
CloseHandle_(OnlyOneStartMutex)
EndProcedure
Procedure RunScreenSaver(ScreenSaverName$)
If InitSprite() = 0
MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
End
EndIf
If InitKeyboard() = 0
MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
End
EndIf
If OpenScreen(GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN), 32, ScreenSaverName$) = 0
MessageRequester("Error", "Can't open a screen !", 0)
EndIf
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Début du programme
Declare CreateINI(Fichier$, StarsMax.l, StarSize.l, StarSpeed.l, StarRotation.l)
Declare rnd(min.w, max.w)
Declare Setup_stars(MAX_STAR.l, STAR_SIZE.l, Largeur.l, Hauteur.l, OutputID)
Declare UpdateStar(MAX_STAR.l, STAR_SPEED.l, sens.l, Largeur.l, Hauteur.l)
; Declare HandleError(result, text.s)
; Declare PreviewCallback(hWnd, Message, wParam, lParam)
; Declare ExecutePreview()
ScreenSaverName$ = "Étoiles en rotation"
OnlyOneSCRStart(ScreenSaverName$)
; only the first 2 chars are interesting sometimes you have more as you see below
Parameter$ = Left(ProgramParameter(), 2)
; normal start of a screensaver
If Parameter$ = "/s"
; Le fichier ini n'existe pas, créer celui par défaut
If FileSize(ScreenSaverName$ + ".ini") = -1
CreateINI(ScreenSaverName$ + ".ini", 5000, 2, 5, 1)
EndIf
OpenPreferences(ScreenSaverName$ + ".ini")
Nb_max = ReadPreferenceLong("Nombre maximum d'étoiles", 5000)
Grosseur = ReadPreferenceLong("Grosseur des étoiles", 2)
Vitesse = ReadPreferenceLong("Vitesse des étoiles", 5)
Sens_rotation = ReadPreferenceLong("Sens de rotation des étoiles", 1)
ClosePreferences()
Dim star_x.l(Nb_max)
Dim star_y.l(Nb_max)
Dim star_z.l(Nb_max)
RunScreenSaver(ScreenSaverName$)
Run = 10
Setup_stars(Nb_max, Grosseur, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN), ScreenOutput())
While Run > 0
FlipBuffers()
ClearScreen(0, 0, 0)
UpdateStar(Nb_max, Vitesse, Sens_rotation, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN))
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; On vérifie si l'utilisateur touche au clavier ou à la souris
If GetInputState_()
Run = Run - 10
EndIf
If GetQueueStatus_(#QS_MOUSEMOVE)
Run = Run - 1
EndIf ; because of WinXp works under Win98 as well
; Delay(10)
Wend
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Fenètre pour le paramétrage
Enumeration
#Param_win
#Txt_MaxStars
#String_MaxStars
#Txt_SizeStars
#String_SizeStars
#Txt_SpeedStars
#String_SpeedStars
#Frame3D_RotationStar
#Option_CW
#Option_CCW
#Btn_Ok
#Btn_Cancel
EndEnumeration
If Parameter$ = "/c"
; Le fichier ini n'existe pas, créer celui par défaut
If FileSize(ScreenSaverName$ + ".ini") = -1
CreateINI(ScreenSaverName$ + ".ini", 5000, 2, 5, 1)
EndIf
OpenPreferences(ScreenSaverName$ + ".ini")
Nb_max = ReadPreferenceLong("Nombre maximum d'étoiles", 5000)
Grosseur = ReadPreferenceLong("Grosseur des étoiles", 2)
Vitesse = ReadPreferenceLong("Vitesse des étoiles", 5)
Sens_rotation = ReadPreferenceLong("Sens de rotation des étoiles", 1)
ClosePreferences()
If OpenWindow(#Param_win, 0, 0, 230, 170, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, ScreenSaverName$)
If CreateGadgetList(WindowID(#Param_win))
TextGadget(#Txt_MaxStars, 10, 10, 140, 20, "Nombre maximum d'étoiles :", #PB_Text_Center)
StringGadget(#String_MaxStars, 160, 10, 60, 20, Str(Nb_max))
TextGadget(#Txt_SizeStars, 10, 30, 140, 20, "Grosseur des étoiles :", #PB_Text_Center)
StringGadget(#String_SizeStars, 160, 30, 60, 20, Str(Grosseur))
TextGadget(#Txt_SpeedStars, 10, 50, 140, 20, "Vitesse des étoiles :", #PB_Text_Center)
StringGadget(#String_SpeedStars, 160, 50, 60, 20, Str(Vitesse))
Frame3DGadget(#Frame3D_RotationStar, 10, 80, 210, 50, "Sens de rotation des étoiles :")
OptionGadget(#Option_CW, 15, 100, 90, 20, "Sens Horaire")
OptionGadget(#Option_CCW, 110, 100, 105, 20, "Sens Anti-Horaire")
ButtonGadget(#Btn_Ok, 10, 140, 100, 20, "Ok")
ButtonGadget(#Btn_Cancel, 120, 140, 100, 20, "Annuler")
EndIf
EndIf
If Sens_rotation = 1
SetGadgetState(#Option_CW, 1)
Else
SetGadgetState(#Option_CCW, 1)
EndIf
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case #Btn_Ok
Nb_max = Val(GetGadgetText(#String_MaxStars))
Grosseur = Val(GetGadgetText(#String_SizeStars))
Vitesse = Val(GetGadgetText(#String_SpeedStars))
If GetGadgetState(#Option_CW) = 1
Sens_rotation = 1
Else
Sens_rotation = -1
EndIf
CreateINI(ScreenSaverName$ + ".ini", Nb_max, Grosseur, Vitesse, Sens_rotation)
EventID = #PB_EventCloseWindow
Case #Btn_Cancel
EventID = #PB_EventCloseWindow
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
EndIf
; "/p" when you mark the screensaver in the screensaver list
; and you have to show up something in the preview screen
; or if you leave the settings or the preview mode
If Parameter$ = "/p"
; ExecutePreview()
EndIf
OnlyOneSCRStop()
End
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Procédure pour l'affichage
Procedure CreateINI(Fichier$, StarsMax.l, StarSize.l, StarSpeed.l, StarRotation.l)
CreatePreferences(Fichier$)
WritePreferenceLong("Nombre maximum d'étoiles", StarsMax)
WritePreferenceLong("Grosseur des étoiles", StarSize)
WritePreferenceLong("Vitesse des étoiles", StarSpeed)
WritePreferenceLong("Sens de rotation des étoiles", StarRotation)
ClosePreferences()
EndProcedure
Procedure rnd(min.w, max.w)
a.w = max - Random (max - min)
ProcedureReturn a
EndProcedure
Procedure Setup_stars(MAX_STAR.l, STAR_SIZE.l, Largeur.l, Hauteur.l, OutputID)
For c.w = 0 To MAX_STAR
star_x(c) = Rnd(-Largeur / 2, Largeur / 2) << 6
star_y(c) = Rnd(-Hauteur / 2, Hauteur / 2) << 6
star_z(c) = Rnd(2, 255)
Next
StartDrawing(OutputID)
For i = 0 To 255
FrontColor(i, i, i)
Box(i * STAR_SIZE, 0, STAR_SIZE, STAR_SIZE)
Next
StopDrawing()
For i = 0 To 255
GrabSprite(i, i * STAR_SIZE, 0, STAR_SIZE, STAR_SIZE)
Next
EndProcedure
Procedure UpdateStar(MAX_STAR.l, STAR_SPEED.l, sens.l, Largeur.l, Hauteur.l)
cos.f = Cos(-sens * 0.025)
sin.f = Sin(-sens * 0.025)
For c = 0 To MAX_STAR
star_z(c) = star_z(c) - STAR_SPEED
x.l = star_x(c)
y.l = star_y(c)
star_y(c) = (y * cos - x * sin)
star_x(c) = (x * cos + y * sin)
If star_z(c) <= 2
star_z(c) = 255
EndIf
s_x.w = (star_x(c) / star_z(c)) + (Largeur / 2)
s_y.w = (star_y(c) / star_z(c)) + (Hauteur / 2)
col.w = 255 - star_z(c)
DisplaySprite(col, s_x, s_y)
Next
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Global previewFlag.l
; Global parameter.s
; Global prevWinHndlString.s
; Global prevWinHndl.l
; Global prevThreadID.l
;
; ; simple error checking
; Procedure HandleError(result, text.s)
; If result = 0 : MessageRequester("Error", text, #PB_MessageRequester_Ok) : End : EndIf
; EndProcedure
;
; ; preview window callback
; Procedure PreviewCallback(hWnd, Message, wParam, lParam)
; Select Message
; Case #WM_CLOSE
; UnregisterClass_("PreviewWindowClass", GetModuleHandle_(#NULL))
; DestroyWindow_(hWnd)
; End
; EndSelect
; Result = DefWindowProc_(hWnd, Message, wParam, lParam)
; ProcedureReturn Result
; EndProcedure
;
; ; execute the preview in the little mini monitor in 'Display Properties'
; Procedure ExecutePreview()
; PreviewWindowSize.RECT
; GetClientRect_(PrevWinHndl, @PreviewWindowSize)
; PreviewWindowClass.WNDCLASS
; Classname.s = "PreviewWindowClass"
; PreviewWindowClass\style = #CS_HREDRAW | #CS_VREDRAW
; PreviewWindowClass\lpfnWndProc = @PreviewCallback()
; PreviewWindowClass\cbClsExtra = 0
; PreviewWindowClass\cbWndExtra = 0
; PreviewWindowClass\hInstance = GetModuleHandle_(#NULL)
; PreviewWindowClass\hIcon = 0
; PreviewWindowClass\hCursor = 0
; PreviewWindowClass\hbrBackground = 0
; PreviewWindowClass\lpszMenuName = 0
; PreviewWindowClass\lpszClassName = @Classname
; RegisterClass_(PreviewWindowClass)
; hWnd.l = CreateWindowEx_(0, "PreviewWindowClass", "", #WS_CHILD | #WS_VISIBLE, 0, 0, PreviewWindowSize\right, PreviewWindowSize\bottom, PrevWinHndl, 0, GetModuleHandle_(#NULL), 0)
; If hWnd
;
; CreateImage(3, PreviewWindowSize\right, PreviewWindowSize\bottom)
; StartDrawing(ImageOutput())
; Box(0, 0, PreviewWindowSize\right, PreviewWindowSize\bottom, RGB(0, 250, 0))
; StopDrawing()
;
; HandleError(CreateGadgetList(hWnd), "Gadget list in preview window could not be created!")
; ImageGadget(1, 0, 0, PreviewWindowSize\right, PreviewWindowSize\bottom, UseImage(3))
; While GetMessage_(Message.MSG, 0, 0, 0)
; TranslateMessage_(Message)
; DispatchMessage_(Message)
; Wend
; EndIf
; EndProcedure