Splash Screen
-
- User
- Posts: 51
- Joined: Mon Jun 01, 2009 3:56 am
Splash Screen
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.
- netmaestro
- PureBasic Bullfrog
- Posts: 8433
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
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:
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
Last edited by netmaestro on Mon Jun 01, 2009 4:50 am, edited 1 time in total.
BERESHEIT
Re: Splash Screen
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)
EndIf
Re: Splash Screen
Hello guys! Great implementations of splash screens, especially the fader. However, for a simple cross-platform solution, this works too: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.
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
EDITS wrote:18th February 2019: updated download links
Last edited by TI-994A on Mon Feb 18, 2019 5:35 am, edited 2 times in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Splash Screen
Nice, thank you!TI-994A wrote:a simple cross-platform solution
Re: Splash Screen
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.
The rainbow image is shown immediately and then after the loop the surround window appears.
----
R Tape loading error, 0:1
R Tape loading error, 0:1