March 05, 2021, 07:27:41 AM

Author Topic: [bb] Loading Screen with Progress Bar by Rogue Vector [ 1+ years ago ]  (Read 598 times)

Offline BlitzBot

Title : Loading Screen with Progress Bar
Author : Rogue Vector
Posted : 1+ years ago

Description :

This is a modular implementation of a Loading Screen program, which incorporates a progress bar.

It also demonstrates how you can implement a pseudo-object oriented class system. I've also included a small test program at the end of the main code.

The full zipped archive, with sound and background image is found at: <a href="http://www.octanedigitalstudios.com/downloads/Loadscreen.zip" target="_blank">http://www.OctaneDigitalStudios.com/downloads/Loadscreen.zip[/url]

The code and the resources are completely freeware.

Regards,

Rogue Vector
<a href="http://www.octanedigitalstudios.com/" target="_blank">http://www.OctaneDigitalStudios.com[/url]


Code :
Code: BlitzBasic
  1. .CLASS_LoadScreen
  2.  
  3.  
  4. .INFO
  5. ;<Graphics mode and buffer must be set before using this class>
  6. ;<Open Source Code>
  7. ;<By Rogue Vector 2004>
  8.  
  9.  
  10. .CONSTANTS
  11. Const LOADING_SCR=0
  12. Const SHUTDOWN_SCR=1
  13. Const FAILURE=0
  14. Const SUCCESS=1
  15.  
  16.  
  17. .PUBLIC
  18. ;<NONE>
  19.  
  20.  
  21. .PROTECTED
  22. Type TLoadScreen
  23.        
  24.         Field Protected_mImg%
  25.         Field Protected_mImgPosX#
  26.         Field Protected_mImgPosY#
  27.         Field Protected_mImgWidth#
  28.         Field Protected_mImgHeight#
  29.         Field Protected_mSnd%
  30.         Field Protected_mSndVol#
  31.         Field Protected_mSndChn%
  32.         Field Protected_mScrMidX#
  33.         Field Protected_mScrMidY#
  34.         Field Protected_mBarPosX#
  35.         Field Protected_mBarPosY#
  36.         Field Protected_mBarWidth#
  37.         Field Protected_mBarHeight#
  38.         Field Protected_mFrameWidth#
  39.         Field Protected_mFrameHeight#
  40.         Field Protected_mCurrentProgress%
  41.         Field Protected_mPercentage%
  42.         Field Protected_mFont%
  43.         Field Protected_mMaxObjects%
  44.         Field Protected_mBarMaxWidth#
  45.         Field Protected_mBarMaxHeight#
  46.         Field Protected_mBarVertOffset#
  47.         Field Protected_mTextVertOffset#
  48.         Field Protected_mTextHorizOffset#
  49.        
  50. End Type
  51.  
  52.  
  53. .CONSTRUCTORS
  54. Function LoadScreen_Create.TLoadScreen(v_maxobjects%, v_maxbarheight#, v_maxbarwidth#, v_barvertoffset#, v_textvertoffset#)
  55.  
  56.         Local l_object.TLoadScreen = New TLoadScreen
  57.        
  58.         l_objectProtected_mImg=0
  59.         l_objectProtected_mImgPosX=0.0
  60.         l_objectProtected_mImgPosY=0.0
  61.         l_objectProtected_mImgWidth#=0.0
  62.         l_objectProtected_mImgHeight#=0.0
  63.         l_objectProtected_mSnd=0
  64.         l_objectProtected_mSndVol=0.0
  65.         l_objectProtected_mSndChn=0
  66.         l_objectProtected_mScrMidX = Float(GraphicsWidth())  / 2
  67.         l_objectProtected_mScrMidY = Float(GraphicsHeight()) / 2
  68.         l_objectProtected_mBarPosX = l_objectProtected_mScrMidX - Float(v_maxbarwidth) / 2
  69.         l_objectProtected_mBarPosY = GraphicsHeight() - Float(GraphicsHeight() * v_barvertoffset)
  70.         l_objectProtected_mBarWidth   = v_maxbarwidth
  71.         l_objectProtected_mBarHeight  = v_maxbarheight
  72.         l_objectProtected_mFrameWidth = v_maxbarwidth  + 4
  73.         l_objectProtected_mFrameHeight= v_maxbarheight + 4
  74.         l_objectProtected_mCurrentProgress=0
  75.         l_objectProtected_mPercentage=0
  76.         l_objectProtected_mFont=0
  77.         l_objectProtected_mMaxObjects      = v_maxobjects
  78.         l_objectProtected_mBarMaxWidth     = v_maxbarwidth
  79.         l_objectProtected_mBarMaxHeight    = v_maxbarheight
  80.         l_objectProtected_mBarVertOffset   = Float( GraphicsHeight() * v_barvertoffset)
  81.         l_objectProtected_mTextVertOffset  = GraphicsHeight() - Float(GraphicsHeight() * v_textvertoffset)
  82.         l_objectProtected_mTextHorizOffset = Float(GraphicsWidth()/2)
  83.  
  84.        
  85.         Return l_object
  86.  
  87. End Function
  88.  
  89.  
  90. .DESTRUCTORS
  91. Function LoadScreen_Destroy(v_object.TLoadScreen)
  92.        
  93.         If (Handle v_object)
  94.        
  95.                 If (v_objectProtected_mImg)  Then FreeImage v_objectProtected_mImg
  96.                 If (v_objectProtected_mSnd)  Then FreeSound v_objectProtected_mSnd
  97.                 If (v_objectProtected_mFont) Then FreeFont  v_objectProtected_mFont
  98.                
  99.                 Delete v_object
  100.        
  101.                 Return SUCCESS
  102.                        
  103.         EndIf
  104.        
  105.         Return FAILURE
  106.  
  107. End Function
  108.  
  109.  
  110. Function LoadScreen_DestroyAll()
  111.        
  112.         Local l_tmp.TLoadScreen
  113.        
  114.         For l_tmp = Each TLoadScreen
  115.        
  116.                 If (l_tmpProtected_mImg)  Then FreeImage l_tmpProtected_mImg
  117.                 If (l_tmpProtected_mSnd)  Then FreeSound l_tmpProtected_mSnd
  118.                 If (l_tmpProtected_mFont) Then FreeFont  l_tmpProtected_mFont
  119.  
  120.                 Delete l_tmp
  121.  
  122.         Next
  123.  
  124.         Return SUCCESS
  125.  
  126. End Function
  127.  
  128.  
  129. .METHODS
  130. Function LoadScreen_SetImage(v_object.TLoadScreen, v_file$)
  131.  
  132.         If (Handle v_object)
  133.                        
  134.                 v_objectProtected_mImg       = LoadImage(v_file)
  135.                 v_objectProtected_mImgWidth  = ImageWidth(v_objectProtected_mImg)
  136.                 v_objectProtected_mImgHeight = ImageHeight(v_objectProtected_mImg)
  137.                 v_objectProtected_mImgPosX   = v_objectProtected_mScrMidX - v_objectProtected_mImgWidth  / 2
  138.                 v_objectProtected_mImgPosY   = v_objectProtected_mScrMidY - v_objectProtected_mImgHeight / 2
  139.                                
  140.                 Return SUCCESS
  141.        
  142.         EndIf
  143.        
  144.         Return FAILURE
  145.  
  146. End Function
  147.  
  148.  
  149. Function LoadScreen_Update(v_object.TLoadScreen, v_showPercentage%=False, v_red%=255, v_green%=255, v_blue%=255)
  150.  
  151.         If (Handle v_object)
  152.                
  153.                 Cls            
  154.                 DrawImage v_objectProtected_mImg, v_objectProtected_mImgPosX, v_objectProtected_mImgPosY
  155.                 v_objectProtected_mCurrentProgress = v_objectProtected_mCurrentProgress + 1
  156.                 v_objectProtected_mPercentage      = Int(v_objectProtected_mCurrentProgress*100 / v_objectProtected_mMaxObjects)
  157.                 v_objectProtected_mBarWidth        = Float(v_objectProtected_mBarMaxWidth * v_objectProtected_mPercentage) / 100  
  158.                 Color v_red, v_green, v_blue
  159.                 Rect v_objectProtected_mBarPosX-2, v_objectProtected_mBarPosY-2, v_objectProtected_mFrameWidth, v_objectProtected_mFrameHeight, 0
  160.                 Rect v_objectProtected_mBarPosX,   v_objectProtected_mBarPosY,   v_objectProtected_mBarWidth,   v_objectProtected_mBarHeight,   1
  161.  
  162.                 If (v_showPercentage) Text v_objectProtected_mTextHorizOffset, v_objectProtected_mTextVertOffset, Str(v_objectProtected_mPercentage) + "%", True
  163.  
  164.                 Flip
  165.  
  166.                 Return SUCCESS
  167.                
  168.         End If
  169.        
  170.         Return FAILURE
  171.  
  172. End Function
  173.        
  174.  
  175. Function LoadScreen_SetFont(v_object.TLoadScreen, v_TrueTypeFont$, v_height%, v_bold%=False, v_italic%=False, v_underline%=False)
  176.  
  177.         If (Handle v_object)
  178.  
  179.                 v_objectProtected_mFont = LoadFont(v_TrueTypeFont, v_height, v_bold, v_italic, v_underline)
  180.                 SetFont v_objectProtected_mFont
  181.  
  182.                 Return SUCCESS
  183.  
  184.         EndIf
  185.  
  186.         Return FAILURE
  187.  
  188. End Function
  189.  
  190.  
  191. Function LoadScreen_SetText(v_object.TLoadScreen, v_textvertoffset#, v_texthorizoffset#, v_default%=True)
  192.  
  193.         If (Handle v_object)
  194.        
  195.                 If (v_default)
  196.                
  197.                         v_objectProtected_mTextHorizOffset = Float(GraphicsWidth()/2)
  198.                
  199.                 Else
  200.                                        
  201.                         v_objectProtected_mTextVertOffset  = GraphicsHeight() - Float(GraphicsHeight() * v_textvertoffset)
  202.                         v_objectProtected_mTextHorizOffset = GraphicsWidth()  - Float(GraphicsWidth()  * v_texthorizoffset)
  203.                
  204.                 EndIf
  205.                        
  206.                 Return SUCCESS
  207.                
  208.         EndIf
  209.  
  210.         Return FAILURE
  211.        
  212. End Function
  213.  
  214.  
  215. Function LoadScreen_SetSound(v_object.TLoadScreen, v_file$="", v_vol#=0.3)
  216.  
  217.         If (Handle v_object) And (v_file<>"")
  218.  
  219.                 v_objectProtected_mSnd    = LoadSound(v_file)
  220.                 v_objectProtected_mSndVol = v_vol
  221.                 v_objectProtected_mSndChn = PlaySound(v_objectProtected_mSnd)
  222.                 ChannelVolume v_objectProtected_mSndChn, 0.0
  223.                 PauseChannel  v_objectProtected_mSndChn
  224.  
  225.                 Return SUCCESS
  226.  
  227.         EndIf
  228.  
  229.         Return FAILURE
  230.  
  231. End Function
  232.  
  233.  
  234. Function LoadScreen_PlaySound(v_object.TLoadScreen)
  235.  
  236.         If (Handle v_object) And (v_objectProtected_mSnd<>0)
  237.        
  238.                 ChannelVolume v_objectProtected_mSndChn, v_objectProtected_mSndVol
  239.                 ResumeChannel v_objectProtected_mSndChn
  240.                                
  241.                 Return SUCCESS
  242.        
  243.         EndIf
  244.        
  245.         Return FAILURE
  246.  
  247. End Function
  248.  
  249.  
  250.  
  251.  
  252. .ENDCLASS_LoadScreen
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259. ;Test program for the LoadScreen Class
  260. ;By Rogue Vector 2004
  261.  
  262. Graphics3D 800, 600, 16, 2
  263. SetBuffer BackBuffer()
  264.  
  265. Include "LoadScreen.bb"
  266.  
  267. ;Create a new load screen
  268. Global myLoadScreen.TLoadScreen = LoadScreen_Create(10, 8, 150, 0.38, 0.35 )
  269. If (LoadScreen_SetImage(myLoadScreen, "loading.jpg"))    Then DebugLog "LoadScreen_SetImage was a SUCCESS" Else DebugLog "LoadScreen_SetImage was a FAILURE"
  270. If (LoadScreen_SetFont(myLoadScreen, "Arial", 20, True)) Then DebugLog "LoadScreen_SetFont was a SUCCESS"  Else DebugLog "LoadScreen_SetFont was a FAILURE"
  271. If (LoadScreen_SetSound(myLoadScreen, "freewaresnd.mp3" )) Then DebugLog "LoadScreen_SetSound was a SUCCESS"  Else DebugLog "LoadScreen_SetSound was a FAILURE"
  272. If (LoadScreen_PlaySound(myLoadScreen)) Then DebugLog "LoadScreen_PlaySound was a SUCCESS"  Else DebugLog "LoadScreen_PlaySound was a FAILURE"
  273.  
  274. ;Simulate a loading sequence - Maximum of 10 objects to load
  275. LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;1
  276. Delay 1000 : LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;2
  277. Delay 1000 : LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;3
  278. Delay 1000 : LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;4
  279. Delay 1000 : LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;5
  280. Delay 1000 : LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;6
  281. Delay 1000 : LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;7
  282. Delay 1000 : LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;8
  283. Delay 1000 : LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;9
  284. Delay 1000 : LoadScreen_Update(myLoadScreen, True, 0, 98, 39) ;10      
  285.        
  286. Delay 1000
  287. Color 155,155,155
  288. Text GraphicsWidth()/2, GraphicsHeight() - 160, "Hit the <space> bar to continue",True : Flip
  289. While Not KeyHit(57) : Wend
  290.  
  291. If (LoadScreen_Destroy(myLoadScreen)) Then DebugLog "Load screen object was destroyed..."
  292. ;Delay 1000
  293.  
  294. EndGraphics
  295.  
  296. End


Comments :


chwaga(Posted 1+ years ago)

 nice work, very useful


CASO(Posted 1+ years ago)

 The link took me to <a href="http://landing.trafficz.com/index.php?domain=octanedigitalstudios.com" target="_blank">http://landing.trafficz.com/index.php?domain=octanedigitalstudios.com[/url]Something tells me that isn't supposed to happen.


Rabies(Posted 1+ years ago)

 Cool, works great.However CASO has a pointbad link.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal