Page 1 of 1

Splash Screen

Posted: Mon Jun 01, 2009 4:02 am
by Hot Pockets
Could someone please show me how to make a splash screen using a bmp image file. The examples show drawing an image but I have a great image I want to use for a 1024 x 768 splash screen.

Posted: Mon Jun 01, 2009 4:20 am
by netmaestro
If you're wanting a splash screen to fade in against the desktop background before your DX screen opens, a borderless layered window with your bmp as a background brush (or image gadget) would work fine. There should be examples of this on the forums.

Simple demo:

Code: Select all

UseJPEGImageDecoder()
LoadImage(0,#PB_Compiler_Home+"examples\sources\data\r2skin.jpg")

OpenWindow(0,0,0,512,512,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW)
hBrush = CreatePatternBrush_(ImageID(0))
SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hBrush)
InvalidateRect_(WindowID(0),0,1)
HideWindow(0,0)

alpha=0
Repeat
  ev=WindowEvent()
  If ev=#PB_Event_CloseWindow:End:EndIf
  SetLayeredWindowAttributes_(WindowID(0),0,alpha,#LWA_ALPHA)
  alpha+1
  Delay(20)
Until alpha=255 Or GetAsyncKeyState_(#VK_SPACE)&32768

t=ElapsedMilliseconds()
Repeat
  ev=WindowEvent()
  If ev=#PB_Event_CloseWindow:End:EndIf
 Until ElapsedMilliseconds()-t>=2000 Or GetAsyncKeyState_(#VK_SPACE)&32768

CloseWindow(0)
DeleteObject_(hBrush)

; Open screen and go on

Posted: Mon Jun 01, 2009 4:28 am
by Mistrel

Re: Splash Screen

Posted: Fri May 24, 2013 3:01 am
by Blankname
netmaestro wrote:If you're wanting a splash screen to fade in against the desktop background before your DX screen opens, a borderless layered window with your bmp as a background brush (or image gadget) would work fine. There should be examples of this on the forums.

Simple demo:

Code: Select all

UseJPEGImageDecoder()
LoadImage(0,#PB_Compiler_Home+"examples\sources\data\r2skin.jpg")

OpenWindow(0,0,0,512,512,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW)
hBrush = CreatePatternBrush_(ImageID(0))
SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hBrush)
InvalidateRect_(WindowID(0),0,1)
HideWindow(0,0)

alpha=0
Repeat
  ev=WindowEvent()
  If ev=#PB_Event_CloseWindow:End:EndIf
  SetLayeredWindowAttributes_(WindowID(0),0,alpha,#LWA_ALPHA)
  alpha+1
  Delay(20)
Until alpha=255 Or GetAsyncKeyState_(#VK_SPACE)&32768

t=ElapsedMilliseconds()
Repeat
  ev=WindowEvent()
  If ev=#PB_Event_CloseWindow:End:EndIf
 Until ElapsedMilliseconds()-t>=2000 Or GetAsyncKeyState_(#VK_SPACE)&32768

CloseWindow(0)
DeleteObject_(hBrush)

; Open screen and go on
Not bad, thanks for example code. Here is a updated version of it.

Code: Select all

LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\PureBasicLogo.bmp")

If OpenWindow(0, 0, 0, 381, 68, "", #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_Invisible)
  SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_LAYERED | #WS_EX_TOOLWINDOW)
  hBrush = CreatePatternBrush_(ImageID(0))
  SetClassLong_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
  InvalidateRect_(WindowID(0), 0, 1)
  HideWindow(0, 0)
  
  For alpha = 0 To 255
    WindowEvent()
    SetLayeredWindowAttributes_(WindowID(0), 0, alpha, #LWA_ALPHA)
    Delay(5)
  Next
  
  Timer = ElapsedMilliseconds()
  Repeat
    WindowEvent()
    Delay(1)
  Until ElapsedMilliseconds()-Timer >= 3000
  
  CloseWindow(0)
  DeleteObject_(hBrush)
EndIf

Re: Splash Screen

Posted: Fri May 24, 2013 6:05 am
by TI-994A
Hello guys! Great implementations of splash screens, especially the fader. However, for a simple cross-platform solution, this works too:

Code: Select all

EnableExplicit
InitNetwork()

Enumeration
  #MainWindow
  #splashWindow  
  #splashImage
  #splashPicture
EndEnumeration

Define.i wFlags, iWidth, iHeight, tWidth, displayTime, mainFlag, splashFont, splashText.s

If ReceiveHTTPFile("https://www.dropbox.com/s/9is77u0d7xzhvjy/rainbow.bmp?dl=1",
                   GetTemporaryDirectory() + "splash.bmp")
  If LoadImage(#splashPicture, GetTemporaryDirectory() + "splash.bmp")
    iWidth = ImageWidth(#splashPicture)
    iHeight = ImageHeight(#splashPicture)    
    splashFont = FontID(LoadFont(#PB_Any, "Arial", 9))
    splashText = "Splash Screen Example - Copyright (c) TI-994A"
    StartDrawing(ImageOutput(#splashPicture))      
      DrawingFont(splashFont)
      DrawingMode(#PB_2DDrawing_Transparent)
      tWidth = TextWidth(splashText)
      DrawText((iWidth - tWidth) / 2, iHeight - 30, splashText, #Black)
    StopDrawing()
    wFlags = #PB_Window_BorderLess | #PB_Window_ScreenCentered
    If OpenWindow(#splashWindow, #PB_Any, #PB_Any, iWidth, iHeight, "", wFlags)
      ImageGadget(#splashImage, 0, 0, iWidth, iHeight, ImageID(#splashPicture))
      StickyWindow(#splashWindow, 1)
      displayTime = ElapsedMilliseconds()
      While ElapsedMilliseconds() - displayTime < 5000
        WaitWindowEvent(100) 
        If ElapsedMilliseconds() - displayTime > 3000 And Not mainFlag
          wFlags = #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget
          OpenWindow(#MainWindow, #PB_Any, #PB_Any, 640, 480, "Main Program", wFlags)
          mainFlag = 1
        EndIf
      Wend
      CloseWindow(#splashWindow)
    EndIf
  EndIf
EndIf

If Not mainFlag: End: EndIf
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
The InitNetwork() function is only required because the example uses an image from my DropBox folder. You can remove it if you're using your own local image. And remember to add the relevant image decoders (UseJPEGImageDecoder, UsePNGImageDecoder, etc.) if required. Also, the main program window is initialised in the timer loop to simulate a concurrent threaded process. Otherwise, it could just be opened after the splash window closes.
EDITS wrote:18th February 2019: updated download links

Re: Splash Screen

Posted: Fri May 24, 2013 10:59 am
by Little John
TI-994A wrote:a simple cross-platform solution
Nice, thank you!

Re: Splash Screen

Posted: Fri Jul 12, 2013 12:18 pm
by em_uk
Cross platform version doesn't as intended on Win7 x64 PB5.20b5 x86.

The rainbow image is shown immediately and then after the loop the surround window appears.