PROGRAM GEM_Demo;

CONST
  {$I GEMCONST.PAS}

TYPE
  {$I GEMTYPE.PAS}

VAR MPtr: Menu_Ptr;


  {$I GEMSUBS.PAS}


PROCEDURE Make_Menu (VAR MPtr: Menu_Ptr);
VAR MItem, MTitl1, MTitl2: INTEGER;
BEGIN
  MPtr   := New_Menu (10,' kleine Demo I ');
  MTitl1 := Add_MTitle (MPtr, ' Funktion ');
  MTitl2 := Add_MTitle (MPtr, ' Programmende ');
  MItem  := Add_MItem (MPtr, MTitl1,' Growbox    G ');
  MItem  := Add_MItem (MPtr, MTitl1,' Rubberbox  R ');
  MItem  := Add_MItem (MPtr, MTitl2,' Ende        E ');
END;

PROCEDURE Info;
VAR was: INTEGER;
BEGIN
  was := Do_Alert (Concat ('[0][Ich bin ein kleines Demo-|',
                           'Programm.| |Ich hoffe, daž Sie',
                           ' durch mich |einiges besser ver',
                           'stehen!][Na sch”n]'),1);
END;


PROCEDURE Do_Rubberbox;
VAR was, x, y, b, h, dummy: INTEGER;
    Nachricht: Message_Buffer;
BEGIN
  was := Get_Event (E_Button,1,1,1,0,FALSE,0,0,0,0,FALSE,0,0,0,0,
                    Nachricht,dummy,dummy,dummy,x,y,dummy);
  Rubberbox (x, y, 8, 16, b, h);
  Paint_Color (White);
  Hide_Mouse;
  Paint_Rect (x, y, b, h);
  Show_Mouse;
END;

PROCEDURE Control;
VAR was, dummy, Taste : INTEGER;
    Nachricht : Message_Buffer;
    Ende      : BOOLEAN;
    y         : CHAR;
BEGIN
  Ende := FALSE;
  REPEAT
    was := Get_Event (E_Message | E_Keyboard, 0,0,0,0,FALSE,0,0,0,0,FALSE,0,0,0,0,
                      Nachricht, Taste, dummy,dummy,dummy,dummy,dummy);
        IF was = was&E_Keyboard THEN BEGIN
           y := CHR(Taste MOD 256);
        CASE y OF
          'I','i' : Info;
          'G','g' : GrowBox (150,30,10,10,100,100,100,100);
          'R','r' : Do_Rubberbox;
          'E','e' : Ende := TRUE;
       OTHERWISE: WriteLn (Taste, CHR(Taste MOD 256));
       END;
    END
    ELSE BEGIN
      CASE Nachricht[4] OF
          8: Info;
         18: GrowBox (150,30,10,10,100,100,100,100);
         19: Do_Rubberbox;
         20: Ende := TRUE;
      OTHERWISE : WriteLn (Nachricht[4],'#');
      END;
      Menu_Normal (MPtr, Nachricht[3]);
    END;
  UNTIL Ende;
END;

BEGIN
 IF Init_Gem >= 0 THEN BEGIN
    Make_Menu (MPtr);
    Draw_Menu (MPtr);
    Control;
    Erase_Menu (MPtr);
    Delete_Menu (MPtr);
    Exit_Gem;
  END;
END.
