home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / 501-525 / apd520 / asstd_programs / alert.amos / alert.amosSourceCode
AMOS Source Code  |  1991-01-18  |  5KB  |  160 lines

  1. '----------------- 
  2. ' Alert Routine  
  3. '----------------- 
  4. '
  5. ' An Intelligent Alert Routine.
  6. '
  7. ' * Displays any number of text lines. 
  8. ' * Auto-sizes Alert body, centres text. 
  9. ' * XY addressable, with auto-centre on both axis. 
  10. ' * 1 to 3 buttons.
  11. ' * Saves background & callers palette (has its own fixed palette)   
  12. '
  13. ' See Alert routine for parameter details. 
  14. '
  15. ' Robert Farnsworth. 
  16. ' Jan. 1991. 
  17. '
  18. Screen Open 0,640,256,16,Hires
  19. Flash Off : Curs Off 
  20. Reserve Zone 3
  21. '
  22. T$="This is an intelligent Alert Routine.|It can display as many lines as you like.|"
  23. T$=T$+"The body of the Alert will be made to fit.|"
  24. T$=T$+"It can be placed anywhere on the screen,|"
  25. T$=T$+"and it has an Auto-centering feature,|"
  26. T$=T$+"so the Alert can be easily placed in the|"
  27. T$=T$+"middle of the screen or along either axis.|"
  28. T$=T$+"The Alert can have from one to three|"
  29. T$=T$+"buttons."
  30. ALERT[0,0,T$," OK |CANCEL",2,3]
  31. Print At(0,0);"You pressed button number -";Param
  32. ALERT[0,0,"|This is an|Alert with|three buttons.||"," 1 | 2 | 3 ",2,4]
  33. Print At(0,0);"You pressed button number -";Param
  34. ALERT[50,50,"Have a nice day.","Cheers!",3,5]
  35. Print At(0,0);"You pressed button number -";Param
  36. End 
  37. '------------- My Alert Routine -------------------- 
  38. '
  39. Procedure ALERT[X,Y,TITLE$,BUTTON$,FC,BC]
  40.    '
  41.    '     X,Y - Coords of top left corner. Set either coord to 0 for 
  42.    '           auto centering on that axis. 
  43.    '  Title$ - Text for Title, seperated into lines by "|" chr.     
  44.    ' Button$ - Text for buttons, lines seperated by "|".  Max 3 buttons.  
  45.    '  FC, BC - Foreground, background colours.  
  46.    ' RETURNS - The button that was pressed (1,2 or 3) starting from 
  47.    '           left hand button.
  48.    '
  49.    LINES=1
  50.    For I=1 To Len(TITLE$)
  51.       If Mid$(TITLE$,I,1)="|" Then Inc LINES
  52.    Next 
  53.    Dim T$(LINES),B$(3)
  54.    MZ=Z
  55.    Reset Zone 
  56.    Reserve Zone 3
  57.    ' --- Save user palette
  58.    NCOLS=Screen Colour
  59.    Dim P(NCOLS)
  60.    For C=0 To NCOLS-1 : P(C)=Colour(C) : Next 
  61.    ' --- Setup our own palette
  62.    Palette ,,$FFF,$0,$F00,$F0,$F,$FF0,$F90,$C73,$3A3,$773,$DDD,$BBB,$377
  63.    ' --- Check strings
  64.    If TITLE$="" Then Pop Proc
  65.    If BUTTON$="" Then Pop Proc
  66.    ' --- Seperate the individual title lines  
  67.    TITLES=0
  68.    FIRST=1
  69.    Repeat 
  70.       SEPERATOR=Instr(TITLE$,"|",FIRST)
  71.       If SEPERATOR>0
  72.          T$(TITLES)=Mid$(TITLE$,FIRST,SEPERATOR-FIRST)
  73.          FIRST=SEPERATOR+1
  74.          Inc TITLES
  75.       Else 
  76.          T$(TITLES)=Mid$(TITLE$,FIRST)
  77.          FIRST=Len(TITLE$)+1
  78.          Inc TITLES
  79.       End If 
  80.    Until FIRST>Len(TITLE$) or TITLES=LINES
  81.    ' --- Same for the buttons 
  82.    BUTTONS=0
  83.    FIRST=1
  84.    Repeat 
  85.       SEPERATOR=Instr(BUTTON$,"|",FIRST)
  86.       If SEPERATOR>0
  87.          B$(BUTTONS)=Mid$(BUTTON$,FIRST,SEPERATOR-FIRST)
  88.          FIRST=SEPERATOR+1
  89.          Inc BUTTONS
  90.       Else 
  91.          B$(BUTTONS)=Mid$(BUTTON$,FIRST)
  92.          FIRST=Len(BUTTON$)+1
  93.          Inc BUTTONS
  94.       End If 
  95.    Until FIRST>Len(BUTTON$) or BUTTONS=3
  96.    ' --- calc height
  97.    HEIGHT=(TITLES)*8+4+14+5
  98.    ' --- calc width 
  99.    WIDTH=0
  100.    For I=0 To TITLES-1 : WIDTH=Max(WIDTH,Len(T$(I))*8) : Next 
  101.    For I=0 To BUTTONS-1 : B=B+Len(B$(I))*8+16 : Next 
  102.    WIDTH=Max(WIDTH,B)+12
  103.    ' --- Auto centering 
  104.    If X=0
  105.       X=Screen Width/2-WIDTH/2
  106.    End If 
  107.    If Y=0
  108.       Y=Screen Height/2-HEIGHT/2
  109.    End If 
  110.    X2=X+WIDTH : Y2=Y+HEIGHT
  111.    ' --- Save the background
  112.    Get Cblock 1,X,Y,WIDTH+16,HEIGHT+16
  113.    ' --- Draw the body
  114.    Ink BC
  115.    Bar X,Y To X2,Y2
  116.    Ink FC
  117.    Box X+2,Y+1 To X2-2,Y2-1
  118.    ' --- Print titles 
  119.    Ink FC,BC
  120.    TY=Y+8+3
  121.    For I=0 To TITLES-1
  122.       TX=X+WIDTH/2-(Len(T$(I))*8)/2
  123.       Text TX,TY,T$(I)
  124.       Add TY,8
  125.    Next 
  126.    ' --- Draw the buttons 
  127.    BY=Y+HEIGHT-4 : Rem y for buttons baseline 
  128.    Z=1
  129.    If BUTTONS=1
  130.       BX=X+WIDTH/2-((Len(B$(0))*8)+8)/2
  131.       ALERT_BUTTON[BX,BY,B$(0),Z]
  132.    End If 
  133.    If BUTTONS=2
  134.       ALERT_BUTTON[X+8,BY,B$(0),Z]
  135.       ALERT_BUTTON[X2-8-((Len(B$(1))*8)+8),BY,B$(1),Z+1]
  136.    End If 
  137.    If BUTTONS=3
  138.       BX=X+8
  139.       ALERT_BUTTON[BX,BY,B$(0),Z]
  140.       X3=BX+(Len(B$(0))*8)+8
  141.       X4=X2-8-((Len(B$(2))*8)+8)
  142.       ALERT_BUTTON[X4,BY,B$(2),Z+2]
  143.       X5=(X4-X3)/2-((Len(B$(1))*8+8)/2)
  144.       ALERT_BUTTON[X3+X5,BY,B$(1),Z+1]
  145.    End If 
  146.    ' --- Wait until user selects a button 
  147.    Repeat 
  148.       MZ=Mouse Zone
  149.    Until Mouse Key=1 and(MZ=>Z and MZ<=Z+BUTTONS)
  150.    ' --- Restore user palette 
  151.    For C=0 To NCOLS-1 : Colour C,P(C) : Next 
  152.    Put Cblock 1,X,Y
  153. End Proc[MZ-Z+1]
  154. '
  155. Procedure ALERT_BUTTON[X,Y,B$,Z]
  156.    L=Len(B$)*8
  157.    Box X,Y-12 To X+L+8,Y
  158.    Text X+4,Y-3,B$
  159.    Set Zone Z,X,Y-12 To X+L+8,Y
  160. End Proc