Splash screen with waiting thread

Share your advanced PureBasic knowledge/code with the community.
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Splash screen with waiting thread

Post by flaith »

For my needs (an application I'm working on), I made a splash screen with a waiting thread
Simple one, just to share it with you
The images and the source are in the zip file: SPLASH

Code: Select all

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

  ;Because of some issue with 64bits version, it's better to catch the image inside the thread
  ;Thanks to 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()
Last edited by flaith on Wed Oct 30, 2013 8:10 am, edited 1 time in total.
“Fear is a reaction. Courage is a decision.” - WC
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: Splash screen with waiting thread

Post by flaith »

Due to some issues with 64bits version, you must use the updated code above :wink:
“Fear is a reaction. Courage is a decision.” - WC
Post Reply