home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
451-475
/
apd453
/
alert.amos
/
alert.amosSourceCode
Wrap
AMOS Source Code
|
1993-01-08
|
4KB
|
146 lines
' An Intelligent Alert Routine.
' * Displays any number of text lines.
' * Auto-sizes Alert body, centres text.
' * XY addressable, with auto-centre on both axis.
' * 1 to 3 buttons.
' * Saves background & callers palette (has its own fixed palette)
' See Alert routine for parameter details.
' Robert Farnsworth.
' Jan. 1991.
Screen Open 0,640,256,16,Hires
Flash Off : Curs Off
Reserve Zone 3
T$="This is an intelligent Alert Routine.|It can display as many lines as you like.|"
T$=T$+"The body of the Alert will be made to fit.|"
T$=T$+"It can be placed anywhere on the screen,|"
T$=T$+"and it has an Auto-centering feature,|"
T$=T$+"so the Alert can be easily placed in the|"
T$=T$+"middle of the screen or along either axis.|"
T$=T$+"The Alert can have from one to three|"
T$=T$+"buttons."
ALERT[0,0,T$," OK |CANCEL",2,3]
Print At(0,0);"You pressed button number -";Param
ALERT[0,0,"|This is an|Alert with|three buttons.||"," 1 | 2 | 3 ",2,4]
Print At(0,0);"You pressed button number -";Param
ALERT[50,50,"Have a nice day.","Cheers!",3,5]
Print At(0,0);"You pressed button number -";Param
End
Procedure ALERT[X,Y,TITLE$,BUTTON$,FC,BC]
' X,Y - Coords of top left corner. Set either coord to 0 for
' auto centering on that axis.
' Title$ - Text for Title, seperated into lines by "|" chr.
' Button$ - Text for buttons, lines seperated by "|". Max 3 buttons.
' FC, BC - Foreground, background colours.
' RETURNS - The button that was pressed (1,2 or 3) starting from
' left hand button.
LINES=1
For I=1 To Len(TITLE$)
If Mid$(TITLE$,I,1)="|" Then Inc LINES
Next
Dim T$(LINES),B$(3)
MZ=Z
Reset Zone
Reserve Zone 3
' --- Save user palette
NCOLS=Screen Colour
Dim P(NCOLS)
For C=0 To NCOLS-1 : P(C)=Colour(C) : Next
' --- Setup our own palette
Palette ,,$FFF,$0,$F00,$F0,$F,$FF0,$F90,$C73,$3A3,$773,$DDD,$BBB,$377
' --- Check strings
If TITLE$="" Then Pop Proc
If BUTTON$="" Then Pop Proc
' --- Seperate the individual title lines
TITLES=0
FIRST=1
Repeat
SEPERATOR=Instr(TITLE$,"|",FIRST)
If SEPERATOR>0
T$(TITLES)=Mid$(TITLE$,FIRST,SEPERATOR-FIRST)
FIRST=SEPERATOR+1
Inc TITLES
Else
T$(TITLES)=Mid$(TITLE$,FIRST)
FIRST=Len(TITLE$)+1
Inc TITLES
End If
Until FIRST>Len(TITLE$) or TITLES=LINES
' --- Same for the buttons
BUTTONS=0
FIRST=1
Repeat
SEPERATOR=Instr(BUTTON$,"|",FIRST)
If SEPERATOR>0
B$(BUTTONS)=Mid$(BUTTON$,FIRST,SEPERATOR-FIRST)
FIRST=SEPERATOR+1
Inc BUTTONS
Else
B$(BUTTONS)=Mid$(BUTTON$,FIRST)
FIRST=Len(BUTTON$)+1
Inc BUTTONS
End If
Until FIRST>Len(BUTTON$) or BUTTONS=3
' --- calc height
HEIGHT=(TITLES)*8+4+14+5
' --- calc width
WIDTH=0
For I=0 To TITLES-1 : WIDTH=Max(WIDTH,Len(T$(I))*8) : Next
For I=0 To BUTTONS-1 : B=B+Len(B$(I))*8+16 : Next
WIDTH=Max(WIDTH,B)+12
' --- Auto centering
If X=0
X=Screen Width/2-WIDTH/2
End If
If Y=0
Y=Screen Height/2-HEIGHT/2
End If
X2=X+WIDTH : Y2=Y+HEIGHT
' --- Save the background
Get Cblock 1,X,Y,WIDTH+16,HEIGHT+16
' --- Draw the body
Ink BC
Bar X,Y To X2,Y2
Ink FC
Box X+2,Y+1 To X2-2,Y2-1
' --- Print titles
Ink FC,BC
TY=Y+8+3
For I=0 To TITLES-1
TX=X+WIDTH/2-(Len(T$(I))*8)/2
Text TX,TY,T$(I)
Add TY,8
Next
' --- Draw the buttons
BY=Y+HEIGHT-4 : Rem y for buttons baseline
Z=1
If BUTTONS=1
BX=X+WIDTH/2-((Len(B$(0))*8)+8)/2
ALERT_BUTTON[BX,BY,B$(0),Z]
End If
If BUTTONS=2
ALERT_BUTTON[X+8,BY,B$(0),Z]
ALERT_BUTTON[X2-8-((Len(B$(1))*8)+8),BY,B$(1),Z+1]
End If
If BUTTONS=3
BX=X+8
ALERT_BUTTON[BX,BY,B$(0),Z]
X3=BX+(Len(B$(0))*8)+8
X4=X2-8-((Len(B$(2))*8)+8)
ALERT_BUTTON[X4,BY,B$(2),Z+2]
X5=(X4-X3)/2-((Len(B$(1))*8+8)/2)
ALERT_BUTTON[X3+X5,BY,B$(1),Z+1]
End If
' --- Wait until user selects a button
Repeat
MZ=Mouse Zone
Until Mouse Key=1 and(MZ=>Z and MZ<=Z+BUTTONS)
' --- Restore user palette
For C=0 To NCOLS-1 : Colour C,P(C) : Next
Put Cblock 1,X,Y
End Proc[MZ-Z+1]
Procedure ALERT_BUTTON[X,Y,B$,Z]
L=Len(B$)*8
Box X,Y-12 To X+L+8,Y
Text X+4,Y-3,B$
Set Zone Z,X,Y-12 To X+L+8,Y
End Proc