Splash screen avec thread

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Splash screen avec thread

Message par flaith »

Bonjour,

voici un simple programme affichant un splash screen avec une animation pendant le chargement
Les images et le programme sont dans le zip: SPLASH

Code : Tout sélectionner

Enumeration
  ;-## SPLASH SCREEN ##
  #SPLASH_WIN
  #SPLASH_IMG
  #SPLASH_GADGET_IMG
  #SPLASH_WAIT_FRAME_1
  #SPLASH_WAIT_FRAME_2
  #SPLASH_WAIT_FRAME_3
  #SPLASH_WAIT_FRAME_4
  #SPLASH_WAIT_FRAME_5
  #SPLASH_WAIT_FRAME_6
  #SPLASH_WAIT_FRAME_7
  #SPLASH_WAIT_FRAME_8  
EndEnumeration

DataSection
  SPLASH_IMAGE_LOADING:          : IncludeBinary "Images/Loading_40hrs_2.png"
  SPLASH_WAIT_FRAME_1:           : IncludeBinary "Images/Wait_Frame_1.png"
  SPLASH_WAIT_FRAME_2:           : IncludeBinary "Images/Wait_Frame_2.png"
  SPLASH_WAIT_FRAME_3:           : IncludeBinary "Images/Wait_Frame_3.png"
  SPLASH_WAIT_FRAME_4:           : IncludeBinary "Images/Wait_Frame_4.png"
  SPLASH_WAIT_FRAME_5:           : IncludeBinary "Images/Wait_Frame_5.png"
  SPLASH_WAIT_FRAME_6:           : IncludeBinary "Images/Wait_Frame_6.png"
  SPLASH_WAIT_FRAME_7:           : IncludeBinary "Images/Wait_Frame_7.png"
  SPLASH_WAIT_FRAME_8:           : IncludeBinary "Images/Wait_Frame_8.png"
EndDataSection

Global.i SPLASH_WAIT = #False
Global.i Dim Wait_IMG(8)
Global.i WAIT_IMG_LOADING

Procedure ShowSplashScreen(*Value)
  Protected.i _Frame = 0

  ;Plantage sous x64 si les images sont chargées dans la procedure OpenSplashScreen()
  ;Chargement des images dans le thread, merci G-Rom ;-)

  WAIT_IMG_LOADING = CatchImage(#PB_Any, ?SPLASH_IMAGE_LOADING)
  Wait_IMG(0) = CatchImage(#PB_Any, ?SPLASH_WAIT_FRAME_1)
  Wait_IMG(1) = CatchImage(#PB_Any, ?SPLASH_WAIT_FRAME_2)
  Wait_IMG(2) = CatchImage(#PB_Any, ?SPLASH_WAIT_FRAME_3)
  Wait_IMG(3) = CatchImage(#PB_Any, ?SPLASH_WAIT_FRAME_4)
  Wait_IMG(4) = CatchImage(#PB_Any, ?SPLASH_WAIT_FRAME_5)
  Wait_IMG(5) = CatchImage(#PB_Any, ?SPLASH_WAIT_FRAME_6)
  Wait_IMG(6) = CatchImage(#PB_Any, ?SPLASH_WAIT_FRAME_7)
  Wait_IMG(7) = CatchImage(#PB_Any, ?SPLASH_WAIT_FRAME_8)  

  Repeat
    If StartDrawing(CanvasOutput(#SPLASH_GADGET_IMG))
      Box(0, 0, 300, 150, $FFFFFF)
      DrawAlphaImage(ImageID(WAIT_IMG_LOADING), 0, 0)
      DrawAlphaImage(ImageID(Wait_IMG(_Frame)), 300-50-25, 150-50-10)
      StopDrawing()
    EndIf

    Delay(*Value)
    _Frame + 1
    If _Frame > 7 : _Frame = 0 : EndIf
    If SPLASH_WAIT = #True : Break : EndIf
  ForEver

  Delay(250)
EndProcedure

Procedure OpenSplashScreen()
  If OpenWindow(#SPLASH_WIN, 0, 0, 300, 150, "DAC40: Loading...", #PB_Window_ScreenCentered | #PB_Window_BorderLess | #WS_POPUP)
    CanvasGadget(#SPLASH_GADGET_IMG, 0, 0, 300, 150)

    CreateThread(@ShowSplashScreen(), 100)
    Repeat
      While Random(20) = 10
        SPLASH_WAIT = #True
      Wend
      Delay(1000)
    Until SPLASH_WAIT
  EndIf
EndProcedure

UsePNGImageDecoder()
OpenSplashScreen()
Dernière modification par flaith le mer. 30/oct./2013 3:11, modifié 1 fois.
Avatar de l’utilisateur
Ar-S
Messages : 9472
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Splash screen avec thread

Message par Ar-S »

Sympa ce petit exemple merci flaith
~~~~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
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Splash screen avec thread

Message par flaith »

Merci Ar-S :mrgreen:
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Splash screen avec thread

Message par falsam »

Joli Flaith. Merci pour ce partage :)
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Splash screen avec thread

Message par Kwai chang caine »

Super beau avec ses couleurs pastels, on dirait un panneau d'attente de site moderne (Style flash ou JAVA) 8O
Comme quoi...notre bon PB et son mode procedural est pas si "ringue" que ça :D

Merci pour le partage 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
G-Rom
Messages : 3626
Inscription : dim. 10/janv./2010 5:29

Re: Splash screen avec thread

Message par G-Rom »

plantage sous seven x64.
Il faut chargé les images dans le threads.
Sympa sinon ;)
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Splash screen avec thread

Message par flaith »

Merci à vous tous :D
Code modifié, merci G-Rom :wink:
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Re: Splash screen avec thread

Message par flaith »

Sinon, pour les couleurs, ce sont celles utilisées par la société, donc pas trop le choix :mrgreen:
Répondre