{$X+}

Program So_easy_is_GAppI;

USES CRT,GRAPH,GAPPI;

Type MENUS=OBJECT(TMENU)
            PROCEDURE Men1;
           END;

Type DIALOGS=OBJECT(TDIALOG)
              FUNCTION ExDlg: Boolean;
              PROCEDURE Dlg1;
              PROCEDURE BMPDlg;
             END;

Var name: String[20];

PROCEDURE MENUS.Men1;
Const cmexit=101;
      cmdlg1=201;
      cmbmp =202;
      cmchk1=301;
      cmchk2=302;
Var ok,ex: Boolean;
    t,menu,element: Byte;
    d: DIALOGS;
    id: Integer;
BEGIN
 ex:=False;
 Setup(9,2); {Setup vga 640x480 + mouse driver}
 SetBkColor(Black);
 SetRGBPalette(5,57,57,57); {Because of the OK-button}
 ClearViewPort;
 Init(15,10); {Initialise the menu pointer variable}
 NewMenu('FILE'); {Make a menu called "File"}
 NewElem('Exit',cmexit,1); {Add the item "Exit" to the menu "File"}
 NewMenu('DIALOGS');
 NewElem('Dialog 1',cmdlg1,2);
 NewElem('BMP Dialog',cmbmp,2);
 ChkInit; {Initialises menu checkmarks}
 NewMenu('CHECKS');
 NewElem('Check me 1',cmchk1,3);
 SetState(false); {Tells GAPPI that this element can be checked and that
                   the initial state is not checked}
 NewElem('Check me 2',cmchk2,3);
 SetState(false);
 ShowMenu; {Draw the menu bar on screen}

 {Draws lines and text on the screen. This is done to show that a dialog
  box or a menu box does not delete the background on which it is placed:}
 SetColor(cyan);
 For t:=1 To 50 Do
  Line(30,30+t*5,610,30+t*5);
 SetColor(White);
 For t:=1 To 22 Do
  OutTextXY(200,40+t*10,'Don''t delete my background');

 Repeat {This part is the main program loop. It waits for the user to
         choose a menu item, then executes that part of the program, and
         then returns to the menu and awaits the users next choice}
  id:=Response; {Waits for the user to choose an item from the
             menu and returns the identifier.}
  If id=cmdlg1 {Dialogs, Dialog 1} Then d.Dlg1; {Execute Dialog 1}
  If id=cmbmp {Dialogs, BMP Dialog} Then d.BMPDlg;
  If id=cmexit {File, Exit} Then ex:=d.ExDlg; {Execute Exit Dialog}
  If ex Then Done; {If the user wishes to exit, shut down the menu}
 Until ex; {This loop continues until the users wishes to exit}
END;

PROCEDURE DIALOGS.Dlg1; {Dialog 1}
Const id_ok=2;
      id_up=4;
      id_down=6;
Var ok: Boolean;
    res: Integer;
BEGIN
 ok:=True;
 Init(170,100,470,280,ok); {Initialise the dialog frame with the specified
                            coordinates. When ok is set to True, the
                            background is saved.}
 StdDlg; {Draws a standard dialog frame on the screen}
 Caption('Dialog Box 1');
 Static(60,30,240,50,lightblue,'This is dialog 1',2,True);
   {Draw a text-box in the dialog, and place a text in it.
    The first 4 numbers are the coordinates. These are relative to the
    dialog frame. Then write the text in color lightblue. The text is
    centered in the text box (2). 1 means left justified, 3 means right
    justified}
 Static(65,65,130,79,lightgreen,'Name:',1,False);
 InitInput(1); {Initialise input line #1}
 With inp^[1] Do {Input line data:}
 BEGIN
  x:=65; y:=80; x1:=235; y1:=100; {The relative position}
  text:=name; {The text in the input line}
  color:=red; {The text color}
  cha:=20; {The maximum number of characters in the input line}
 END;
 DrawInput; {Draw the input line}
 ChkInit; {Initialise check boxes}
 chk^[1]:=False; {set initial state of check box 1 (not checked)}
 chk^[2]:=True;
 NewChk(175,110); {Relative position of check box 1}
 NewChk(175,125);
 RadInit; {Initialise radio buttons}
 rad^[1]:=True; {Initial state of radio button 1}
 rad^[2]:=False;
 NewRadGrp; {Make a new group of radio buttons}
 NewRad(125,110); {Relative position of radio button 1}
 NewRad(125,125);
 SetColor(0);
 DlgRectangle(124,109,137,135); {Draw a black frame around the radio buttons}
 Button(120,150,180,170,'Ok',id_ok); {Place push button in dialog box}
 Button(200,150,260,170,'Up',id_up);
 Button(40,150,100,170,'Down',id_down);
 DefBtn(id_ok); {Ok button is default = can be pressed by pressing 'enter'}
 Repeat
  res:=Response; {Which pushbutton has been pressed?}
  If res=id_up Then {If it is pushbutton "Up":}
  BEGIN
   Delay(50);
   RedrawBtn(id_up); {Draw the "Up" button again. It can now be pushed again}
  END;
 Until res=id_ok; {Repeat until user push "Ok" button}
 name:=inp^[1].text; {Get the current text in the Inputline}
 Close;
END;

PROCEDURE DIALOGS.BMPDlg;
Const id_ok=1;
Var ok:  Boolean;
    res: Integer;
BEGIN
 ok:=True;
 Init(170,100,470,280,ok);
 StdDlg;
 Caption('Bitmap Dialog');
 DlgBitmap(45,30,'gappi.lgo'); {Show a bitmap in the dialog box}
 BMPButton(120,130,'ok_up.btn','ok_dn.btn',id_ok); {Place a bitmap button}
 DefBtn(id_ok); {DefBtn and RedrawBtn works with bitmap buttons too}
 res:=Response;
 Close;
END;

FUNCTION DIALOGS.ExDlg: Boolean;
Var ok: Boolean;
    r: Integer;
BEGIN
 ok:=True;
 Init(100,100,300,200,ok);
 StdDlg;
 Static(30,30,170,50,lightblue,'End Program?',2,true);
 Button(30,70,90,90,'Yes',1);
 Button(110,70,170,90,'No',2);
 r:=Response;
 Close;
 If r=1 Then ExDlg:=True
 Else ExDlg:=False;
END;

Var m:       MENUS;
    foer,nu: LongInt;

BEGIN
 name:='This is an inputline';
 m.Men1;
 CloseGraph;
 ClrScr;
END.


