Splash Screen
Posted: Mon Jun 01, 2009 4:02 am
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.
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.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
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)
EndIfCode: 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 : WendEDITS wrote:18th February 2019: updated download links
Nice, thank you!TI-994A wrote:a simple cross-platform solution