home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / 451-475 / apd453 / alert.amos / alert.amosSourceCode
AMOS Source Code  |  1993-01-08  |  4KB  |  146 lines

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