REM   * This program has a good routine for requestors in AmigaBASIC
REM   * so I included the basic code in the arc. Feel free to use this
REM   * requestor listing in your programs. The button gadgets do return 
REM   * a value of 1 or 2, for button 1 or button 2, to the main
REM   * program so they may be put to practical use.
REM   * Enjoy........Michael Fahrion


REM   * To run in AmigaBASIC you must have an output window. The small
REM   * window created here is lost in the upper left of the workbench.
REM   * There is no way to prevent basic from opening a full size window
REM   * when it is loaded.  I have deleteed the WINDOW line in the compiled
REM   * version so there is no window except the requestors. If you are 
REM   * using this requestor coding in your program just delete it.

 
WINDOW 1,"Click on box or press #1 or #2  ",(0,0)-(500,100),31,-1

REM  * These global arrays and variables should be initialized at
REM  * at the beginning of your program.

  RANDOMIZE TIMER
  DIM Work%(400)
  DIM ReqX1%(20),ReqY1%(20),ReqX2%(20),ReqY2%(20)

  ScrId=-1:WhichBox=0:BoxIndex=1:MaxLen=15
  ReqWindo=4' <- Requester WINDOW ID#
  ReqSide=320: ReqTop=80' <- Requester Top left corner position
  
  ON BREAK GOSUB Ender
  BREAK ON

REM  * This is the main loop. It sets up a random length pause of 5 to 10  
REM  * seconds and randomly picks a requestor to display.
REM  * Note the use of TIMER and a WHILE:WEND loop. This method of pausing
REM  * will always give you a specifed pause in seconds no matter if the
REM  * program is compiled, run with an excellerator board or not.

WhichOne:
wr=wr+1 
ON wr GOSUB 10,20,30,40,50,60,70,80,90,100,110,120,Ender

PRINT " Pressed box #";WhichBox;" "  

GOTO WhichOne


REM  * CALL calls the subroutine "ReQuest" and passes the variables to it.
REM  * Usage ("Message1","Message2","Button1","Button2",Variable returned)

10 :
CALL ReQuest("Insert Volumn XXI","in drive DF23:   ","CANCEL","RESUME",WhichBox)
RETURN

20 :
CALL ReQuest("Is it OK to explode","your Amiga now?    ","YES","NO",WhichBox)
RETURN

30 :
CALL ReQuest("Not that disk dummy","I want the blue one","CANCEL","RESUME",WhichBox)
RETURN

40 :
CALL ReQuest("Pick either button"," I won't do it anyway","CANCEL","RESUME",WhichBox)
RETURN

50 :
CALL ReQuest("Why did you do that","???????????","CANCEL","BECAUSE",WhichBox)
RETURN

60 :
CALL ReQuest("ROM is corrupted","Sorry about that","TRY","CRY",WhichBox) 
RETURN

70 :
CALL ReQuest("Not a DO$ disk   ","Use expensive type","CANCLE","RESUME",WhichBox)
RETURN

80 :
CALL ReQuest(" Disk write-protected"," Close little window ","OPEN","CLOSE",WhichBox)
RETURN

90 :
CALL ReQuest("Disk is full    ","        ","BURP","BELCH",WhichBox)
RETURN

100 :
CALL ReQuest("Object in use    ","You can't have it","NO-NO","NO-NO",WhichBox)
RETURN

110 :
CALL ReQuest("Object not found","Try the tan disk","MAYBE","BLUE?",WhichBox)
RETURN

120 :
CALL ReQuest("The only workbench","still with EDIT!  ","DELETE","DELETE",WhichBox)
RETURN

Ender:
  WINDOW CLOSE ReqWindo
  CLEAR,25000
  END


REM  *** This is the requestor sub program ***

SUB ReQuest(msg1$,msg2$,B1$,B2$,WhichBox) STATIC
  SHARED BoxIndex,ScrId 
  SHARED ReqX1%(),ReqY1%(),ReqX2%(),ReqY2%()
  SHARED ReqWindo,ReqSide,ReqTop 
  BoxIndex=1: Height=PEEKW(WINDOW(8)+58)
  WinWidth=20*(8-2*(Height=9))+35
  WINDOW ReqWindo,"System Request    ",(ReqSide,ReqTop)-(ReqSide+WinWidth,ReqTop+50),6,ScrId

  LINE(0,0)-(WinWidth,50),1,bf:COLOR 0,1
  PRINT :PRINT TAB(11-LEN(msg1$)/2);msg1$
  PRINT TAB(11-LEN(msg2$)/2);msg2$:PRINT 
  LOCATE ,2: TxBox B1$
  PRINT TAB(20-LEN(B2$));:TxBox B2$:WhichBox=0
  CALL WaitBox(WhichBox)
  CALL FlashRelease(WhichBox)
  WINDOW CLOSE ReqWindo
 END SUB


REM  * Another sub program to make gadget buttons to fit text

SUB TxBox(msg$) STATIC       
  SHARED ReqX1%(),ReqY1%(),ReqX2%(),ReqY2%()
  SHARED BoxIndex
  
  ReqX1=WINDOW(4):ReqY1=WINDOW(5)-10
  PRINT  " ";msg$;" ";
  ReqX2=WINDOW(4):ReqY2=ReqY1+14
  CALL Box(BoxIndex,ReqX1,ReqY1,ReqX2,ReqY2)
  BoxIndex=BoxIndex+1
  PRINT SPC(1);
 END SUB


REM  * Draws boxes around gadgets

SUB Box(I,ReqX1,ReqY1,ReqX2,ReqY2) STATIC      
  SHARED ReqX1%(),ReqY1%(),ReqX2%(),ReqY2%()
  IF ReqX2<ReqX1 THEN SWAP ReqX1,ReqX2
  LINE (ReqX1,ReqY1)-(ReqX2,ReqY2),1-(WINDOW(6)>1),B
  LINE (ReqX1-2,ReqY1-2)-(ReqX2+2,ReqY2+2),3,B 
  LINE (ReqX1-3,ReqY1-2)-(ReqX2+3,ReqY2+2),3,B
  ReqX1%(I)=ReqX1:ReqY1%(I)=ReqY1:ReqX2%(I)=ReqX2:ReqY2%(I)=ReqY2
 END SUB


REM  * Wait routine till a button is clicked

SUB WaitBox(WhichBox) STATIC    
  WhichBox=0
  WHILE WhichBox=0
    Key$=INKEY$
    IF Key$="1" THEN WhichBox=1
    IF Key$="2" THEN WhichBox=2
    CALL WhatBox(WhichBox)
  WEND
  EXIT SUB
 RETURN
 END SUB


REM  * Flashes the selected gadget

SUB FlashRelease(WhichBox) STATIC       
  SHARED ReqX1%(),ReqY1%(),ReqX2%(),ReqY2%(),Work%()
  SHARED RelVerify
  GET (ReqX1%(WhichBox),ReqY1%(WhichBox))-(ReqX2%(WhichBox),ReqY2%(WhichBox)),Work%
  PUT (ReqX1%(WhichBox),ReqY1%(WhichBox)),Work%,PRESET
  iX=MOUSE(1):iY=MOUSE(2):RelVerify=-1
  WHILE MOUSE(0)<>0
    IF MOUSE(1)<>iX OR MOUSE(2)<>iY THEN RelVerify=0
  WEND
  PUT (ReqX1%(WhichBox),ReqY1%(WhichBox)),Work%,PSET
 END SUB


REM  * Sets value of variable for which button clicked

SUB WhatBox(WhichBox) STATIC           
  SHARED ReqX1%(),ReqY1%(),ReqX2%(),ReqY2%(),BoxIndex
  IF MOUSE(0)=0 THEN EXIT SUB
  x=MOUSE(1):y=MOUSE(2):I=1
  WHILE I < BoxIndex AND NOT (x>ReqX1%(I) AND x<ReqX2%(I) AND y>ReqY1%(I) AND y<ReqY2%(I))
    I=I+1
  WEND
  WhichBox=I:IF I=BoxIndex THEN WhichBox=0
 END SUB
  

