home *** CD-ROM | disk | FTP | other *** search
/ Millennium Time Capsule / AC2000.BIN / disks / ac9_disk / tutorial.s / hbasic06.tut / routines / sharewar.txt < prev   
Encoding:
Text File  |  1998-03-29  |  4.9 KB  |  150 lines

  1.  
  2. Shareware delay box by Paul Jones for Atari Computing. Feel free to 
  3. add this code to your own programs if you have the need. However, if 
  4. you do add this code to your own program, you must announce this in 
  5. the program's documentation.
  6.  
  7. (c) Paul Jones and Renegade Publishing Ltd
  8.  
  9. Shareware dialogs... what's tha' then?
  10. --------------------------------------
  11.  
  12. You'd be forgiving for asking such a question, some people have never 
  13. seen one before since or if they have, call it by another name, or 
  14. nothing at all!
  15.  
  16. A shareware delay bar is just what it sounds like. It's a bar in a 
  17. dialog box which progresses to show how much time you've waited. Since 
  18. it's shareware, indicating the author wishes you to pay money to 
  19. "register" the software, he/she encourages you to do so by adding this. 
  20. While the bar is display, you can't click on anything, in effect, your 
  21. computer is frozen until the time is up... even on multitasking 
  22. systems. 
  23.  
  24. The code in the file SHAREWAR.BAS is an example of such a bar, with 
  25. source code and executable. The above is to be included in PDO (Print 
  26. Documents Out) to encourage people to register.
  27.  
  28. How does it work?
  29. -----------------
  30.  
  31. It's quite simple really. First you design a normal form dialog, with 
  32. two exceptions: 1) It doesn't have any exit buttons 2) It has a 
  33. SLIDERBAR.
  34.  
  35. A sliderbar is an object which can have it's size (width, height, x 
  36. and y co-ordinates etc) edited within a program. These are usually 
  37. boxes. There are actually two bars in a slide box, they are called the 
  38. background and the foreground. The background one isn't edited at all, 
  39. but used to find out the maximum size of the foreground sliderbar 
  40. (this is the white bar in our example). The foreground one is the bar 
  41. that moves (the blue one in our example).
  42.  
  43. Once the RSC has been loaded into memory, we have to find the maximum 
  44. width of the background bar since the foreground bar has it's width 
  45. set to a small width (this is so we can actually click on the thing in 
  46. the RSC editor, and also have access to the background bar too).
  47.  
  48. Using the system clock we can increment this bar whenever we like (I 
  49. use 100 milliseconds, which equals 0.1 second bursts). Instead of the 
  50. usuall form handling routines, we don't ask for any button selections, 
  51. so we come out of displaying the dialog instantly. We can then update 
  52. the dialog whenever it changes.
  53.  
  54. BASICally, it goes like this...
  55. -------------------------------
  56.  
  57. Here is how the most important routines work in the program:
  58.  
  59. SUB form_show (dial)
  60. STATIC junk,tree&,x,y,w,h,but,type_tree,treeno,tree&
  61.  
  62. junk=FNrsrc_gaddr(0,dial,tree&)
  63. form_center tree&,x,y,w,h
  64. form_dial FMD_START,0,0,0,0,x,y,w,h
  65. junk=FNobjc_draw(tree&,0,10,x,y,w,h)
  66. END SUB
  67.  
  68. This routine will first display the dialog box. It's a different model 
  69. of our normal dialog box displayer, because we don't ask GEM to wait 
  70. for a button to be pressed.
  71.  
  72. SUB form_show_part (dial, object)
  73. STATIC junk,tree&,x,y,w,h,but,type_tree,treeno,tree&
  74. STATIC x2,y2,w2,h2
  75.  
  76. junk=FNrsrc_gaddr(0,dial,tree&)
  77. form_center tree&,x,y,w,h
  78. SelectTree dial
  79.  
  80. form_dial FMD_START,0,0,0,0,x,y,w,h
  81.  
  82. junk=FNobjc_draw(tree&,object,0,x,y,w,h)
  83.  
  84. END SUB
  85.  
  86. This sub-routine can redraw parts of the dialog box for us. Notice the 
  87. objc_draw () which actually displays the sliderbar on the screen.
  88.  
  89. SUB GetSetObjects
  90. SHARED wwidth,swidth,spart
  91.  
  92. SelectTree sharedial
  93. wwidth=FNgetob_width (whiteback)
  94.  
  95. setob_width slidebar, 0
  96. swidth=0
  97.  
  98. spart=wwidth/100
  99.  
  100. END SUB
  101.  
  102. This is quite an important routine. It first finds out the width of 
  103. our background bar, then sets the foreground sliders width to 0. It 
  104. then calculates how much to add to the sliderbar each time the below 
  105. routine is called:
  106.  
  107. SUB do_timer
  108. SHARED swidth,wwidth,spart
  109. SHARED finished
  110.  
  111. swidth=swidth+spart
  112. IF swidth>wwidth THEN
  113.     finished=-1
  114. ELSE
  115.     setob_width slidebar,swidth
  116.     form_show_part sharedial, slidebar
  117. END IF
  118.  
  119. END SUB
  120.  
  121. This part is called every 100 milliseconds. It adds on part of the 
  122. slidebar to what already exists so gives the impression it's moving. 
  123. If the new width is over the size of the orginall, then the program 
  124. quits, otherwise the new size is implemented into the dialog and 
  125. redrawn.
  126.  
  127. DIM mess(16)
  128. StartProgram "SHAREWAR.RSC"
  129. GetSetObjects
  130.  
  131.     form_show (sharedial)
  132.  
  133. DO
  134.     e=FNevnt_multi(MU_TIMER,0,0,0,0,0,0,0,0,0,0,0,0,0,_
  135.                     VARPTR(mess(0)),100,0,0,0,0,k,0)
  136.  
  137.     IF e AND MU_TIMER THEN CALL do_timer
  138.  
  139. IF finished=-1 THEN CALL StopProgram
  140.  
  141. LOOP
  142.  
  143. The main loop. First it loads up the dialogs into memory (notice this 
  144. is different verion of StartProgram which we're used to). Then we set 
  145. the objects size.
  146.  
  147. The main evnt_multi contains another difference - instead of checking 
  148. for GEM messages and keyboard clicks, we're just looking for 
  149. MU_TIMERs. GEM will give us a signal whenever a certain amount of time 
  150. in milliseconds passes (notice the 100 in the parameters list?).