home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / authors / chris_evans / graphicalwindows.amos / graphicalwindows.amosSourceCode
AMOS Source Code  |  1986-08-03  |  9KB  |  267 lines

  1. '---------------------------   
  2. '  GRAPHICAL WINDOW TUTORIAL         
  3. '       by                   
  4. '  Chris Evans             
  5. '  44 Shady Lane - RR7     
  6. '  St. Thomas, ONT             
  7. '  Canada  N5P 3T2        (letters welcome)            
  8. '--------------------------- 
  9. '
  10. ' Windowing gives programs a professional look, but coders 
  11. ' often don't use WIND OPEN because it creates windows 
  12. ' that are short on beauty, and long on problems if you
  13. ' use the CLS command.  In the program below, a WINOPEN
  14. ' procedure was created to avoid both the above.  The
  15. ' result is a window that has an Intuition-style 
  16. ' rectangular title bar, and better graphical style
  17. ' borders which are both created in REDRAW.
  18. '
  19. ' Two screens are used so that when the rubber band
  20. ' (perimeter) line is displayed, one screen can hold an
  21. ' untouched image of the window which can be copied back 
  22. ' onto the screen containing the unwanted lines after the
  23. ' user moves the mouse.  In this way no lines are ever 
  24. ' left on the screen that are not necessary, so there is 
  25. ' no "garbage".  The command WIND SAVE allows the window 
  26. ' to be moved without corrupting the underlying screen.
  27. '
  28. Global XONE,YONE,XTWO,YTWO
  29. Screen Open 1,640,200,4,Hires
  30. Curs Off 
  31. Flash Off 
  32. Cls 0
  33. Palette 0,$FFF,$F00,$F
  34. Screen Open 0,640,200,4,Hires
  35. Curs Off 
  36. Flash Off 
  37. Cls 0
  38. Palette 0,$FFF,$F00,$F
  39. '
  40. '------------------------------------- 
  41. ' Wind Save allows the window(s) to    
  42. '  be moved without corrupting the     
  43. '        underlying screen.            
  44. '------------------------------------- 
  45. '
  46. Wind Save 
  47. WINOPEN[128,33,47,7,"TOTALLY AMOS"]
  48. WINTEXT[0,0,"Devoted to totally interesting information",1]
  49. WINTEXT[0,1,"about AMOS programming.  Try dragging the",1]
  50. WINTEXT[0,2,"title bar.  When you click the close",1]
  51. WINTEXT[0,3,"gadget the window will disappear and the",1]
  52. WINTEXT[0,4,"program will end.",1]
  53. Screen Copy 0 To 1
  54. Do 
  55.    If Mouse Key=1
  56.       CHECK
  57.    End If 
  58. Loop 
  59. '
  60. '------------------------------------- 
  61. '   The procedure WINOPEN opens a      
  62. '  window and calls the procedure      
  63. '              REDRAW.                 
  64. '------------------------------------- 
  65. '
  66. Procedure WINOPEN[XO,YO,XT,YT,TITLE$]
  67. '    
  68.    '----------------------------------------------------------------
  69.    '  The parameters for WINOPEN are:                               
  70.    '                                                                
  71.    '  1)  XO = The X Graphic co-ordinate for the top left corner.   
  72.    '  2)  YO = The Y Graphic co-ordinate for the top left corner.   
  73.    '  3)  XT = The number of characters wide                      
  74.    '  4)  YT = The number of characters high                        
  75.    '  5)  TITLE$ = Contains the title for the top bar               
  76.    '                                                                
  77.    '         WINOPEN assumes you want to create Window 1.           
  78.    '----------------------------------------------------------------
  79. '    
  80.    Wind Open 1,XO,YO,XT,YT
  81.    Window 1
  82.    REDRAW[XO,YO,XT,YT,TITLE$]
  83.    XONE=XO : XTWO=XT : YONE=YO : YTWO=YT
  84. End Proc
  85. '
  86. '------------------------------------- 
  87. '    The procedure REDRAW draws        
  88. '   graphics on Window 1 making it     
  89. '   look like an Intuition window.     
  90. '------------------------------------- 
  91. '
  92. Procedure REDRAW[XO,YO,XT,YT,TITLE$]
  93.    Window 1
  94.    Ink 3
  95.    Bar XO,YO To XO+(XT*8)-8,YO+(YT*8)-1
  96.    Ink 2
  97.    Box XO,YO To XO+(XT*8)-8,YO+(YT*8)-1
  98.    Bar XO,YO To XO+(XT*8)-8,YO+8
  99.    Ink 0
  100.    Gr Writing 0
  101.    Text XO+24,YO+7,TITLE$
  102.    DRA_CLOSE[XO,YO]
  103. End Proc
  104. '
  105. '------------------------------------- 
  106. ' The procedure WINTEXT allows you     
  107. '   to put text inside the window      
  108. '      using the Text feature.         
  109. '-------------------------------------   
  110. '
  111. Procedure WINTEXT[X,Y,TXT$,C0L]
  112. '    
  113.    '--------------------------------------------------- 
  114.    '  The parameters of WINTEXT are:                      
  115.    '                                                      
  116.    '  1)  X = The X position (similar to Locate)          
  117.    '  2)  Y = The Y position (similar to Locate)          
  118.    '  3)  TXT$ = What is put at X,Y                       
  119.    '  4)  C0L = The ink colour of the text                
  120.    '                                                      
  121.    '  WINTEXT uses Gr Writing 0.  Don't change this     
  122.    '  or it could corrupt the blue window area.         
  123.    '----------------------------------------------------  
  124. '    
  125.    Ink 1
  126.    Gr Writing 0
  127.    Text XONE+5+(X*8),YONE+(Y*8)+17,TXT$
  128. End Proc
  129. '
  130. '--------------------------------------  
  131. ' The procedure DRA_CLOSE draws the      
  132. ' Intuition style close gadget.  A       
  133. ' re-sizer gadget is omitted because   
  134. ' it serves no purpose in the Amos     
  135. ' environment; the coder will draw     
  136. ' the window to fit the information.     
  137. '--------------------------------------
  138. '
  139. Procedure DRA_CLOSE[X,Y]
  140.    Ink 2
  141.    Box X+0,Y+0 To X+9,Y+8
  142.    Box X+1,Y+1 To X+8,Y+7
  143.    Ink 0
  144.    Box X+2,Y+2 To X+7,Y+6
  145.    Ink 1
  146.    Bar X+3,Y+3 To X+6,Y+5
  147. End Proc
  148. '
  149. '------------------------------------- 
  150. '   The procedure CHECK is called      
  151. ' whenever the left mouse button is    
  152. ' pressed (look at the main loop).     
  153. '   If the mouse cursor is on the      
  154. '  close gadget then the window is     
  155. ' closed and the program ends.  (If    
  156. ' you want to change that, put what    
  157. '  you want in place of line 168..       
  158. '   If the mouse cursor is on the      
  159. ' title bar, the procedure MOVEBAR     
  160. '            is called.                
  161. '--------------------------------------  
  162. '
  163. Procedure CHECK
  164.    XM=X Screen(X Mouse)
  165.    YM=Y Screen(Y Mouse)
  166.    If XM>XONE-3 and XM<XONE+9
  167.       If YM>YONE-1 and YM<YONE+9
  168.          Window 1
  169.          Wind Close 
  170.          End 
  171.       End If 
  172.    End If 
  173.    If XM>XONE+9 and XM<XONE+(XTWO*8)-10
  174.       If YM>YONE-1 and YM<YONE+9
  175.          MOVEBAR
  176.       End If 
  177.    End If 
  178. End Proc
  179. '
  180. Procedure MOVEBAR
  181.    Screen To Front 1 : Rem Remember that the user is seeing Screen 1
  182.    Screen 1
  183. '    
  184.    '--------------------------------------------- 
  185.    ' Here, the position of the mouse cursor is    
  186.    ' found, and the difference between the        
  187.    ' mouse cursor location and the top left       
  188.    ' corner is found.  This is done so that       
  189.    ' the box doesn't jump to somewhere else on    
  190.    ' the screen.                                  
  191.    '--------------------------------------------- 
  192. '    
  193.    XM=X Screen(X Mouse)
  194.    YM=Y Screen(Y Mouse)
  195.    XD=XM-XONE
  196.    YD=YM-YONE
  197. '    
  198.    'The following Repeat and Until statements wait for the
  199.    'user to let go of the left mouse button.
  200. '    
  201.    Repeat 
  202. '      
  203.       'Here, the placement of the mouse cursor is found
  204.       'again.  
  205. '      
  206.       XM=X Screen(X Mouse)
  207.       YM=Y Screen(Y Mouse)
  208. '      
  209.       'The rubber band line is drawn to show where the 
  210.       'window will move to.
  211. '      
  212.       Box XM-XD,YM-YD To XM-XD-1+(XTWO*8-7),YM-YD+(YTWO*8-1)
  213. '      
  214.       '------------------------------------------
  215.       ' The following 5 lines wait for the       
  216.       ' user to either:                          
  217.       '                                          
  218.       ' 1)  Move the mouse.                      
  219.       ' 2)  Let go of the left mouse button.     
  220.       '------------------------------------------
  221. '      
  222.       Do 
  223.          Exit If X Screen(X Mouse)<>XM
  224.          Exit If Y Screen(Y Mouse)<>YM
  225.          Exit If Mouse Key<>1
  226.       Loop 
  227. '      
  228.       'The next line copies the display of Screen 0 to Screen 1. 
  229. '      
  230.       Screen Copy 0 To 1
  231. '      
  232.    Until Mouse Key<>1
  233. '    
  234.    Screen To Front 0 : Rem The user is now seeing Screen 0
  235.    Screen 0
  236.    Window 1 : Rem Close  
  237.    Wind Close : Rem     window 1 
  238. '    
  239.    'The next four lines figure out where the new window 
  240.    'will appear.
  241. '    
  242.    FINALXONE=XM-XD
  243.    FINALYONE=YM-YD
  244.    DIFFERENCEX=FINALXONE mod 16
  245.    FINALXONE=FINALXONE-DIFFERENCEX
  246. '    
  247.    '------------------------------------------------------
  248.    'The next five lines re-open window 1 in its new 
  249.    'position and put the text on top of it again.  You
  250.    'will notice that the position isn't exactly where you 
  251.    'left the mouse cursor.  The position was pushed back
  252.    'to the nearest multiple of 16.  This is done because
  253.    'AMOS won't accept boundaries that aren't multiples
  254.    'of 16 since the blitter chip is used for these windows. 
  255.    '------------------------------------------------------- 
  256. '    
  257.    WINOPEN[FINALXONE,FINALYONE,XTWO,YTWO,"TOTALLY AMOS"]
  258.    WINTEXT[0,0,"Devoted to totally interesting information",1]
  259.    WINTEXT[0,1,"about AMOS programming.  Try dragging the",1]
  260.    WINTEXT[0,2,"title bar.  When you click the close",1]
  261.    WINTEXT[0,3,"gadget the window will disappear and the",1]
  262.    WINTEXT[0,4,"program will end.",1]
  263. '    
  264.    Screen Copy 0 To 1 : Rem The newly created screen is now
  265.    '                        copied back to screen 1.
  266. '    
  267. End Proc