home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
turbopas
/
tppopups.arc
/
POPDEMO.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-08-25
|
9KB
|
369 lines
Program Popdemo;
(* Demonstration of POPUPS unit *)
USES crt, popups;
{* Define menuBar *}
CONST MainMenu : menuRec = (
row : 1; interval : 26; fore : White; back :Green);
MainmenuText : string [67] = 'Demos Run Thru';
{* Define pull-down menus *}
DemoMenu : popRec = (
left : 1; top : 3; right : 14; bottom : 7; style : 1;
normal : LightGray; hilite : LightGray;
normback : Blue; hiback : Magenta; border : Cyan);
DemoMenuText : string[33] =
'Show file Walk popup Graphics';
RunMenu : popRec =(
left : 28; top : 3; right : 40; bottom : 6; style : 1;
normal : Yellow; hilite : Yellow;
normback : Blue; hiback : Magenta; border : White);
RunMenuText : string [21] = 'All Demos Exit Menu';
QuitMenu : popRec =(
left : 53; top : 3; right : 70; bottom : 6; style : 2;
normal : LightGray; hilite: LightGray;
normback : Red; hiback : Cyan; border : White);
QuitMenuText : string [31] = 'Quit Program Exit This Menu';
{* Define windows for demos *}
FileWindow : popRec =(
left : 2; top : 5; right : 75; bottom : 25; style : 2;
normal : LightGray; hilite : LightGray;
normback : Magenta; hiback : 0; border :LightBlue);
Walker : popRec =(
left : 60; top : 1; right : 79; bottom : 6; style : 2;
normal : Red; hilite :0;
normback : Cyan; hiback : 0; border : Blue);
WalkerText : string [48] =
'This pop-up moves down by changing top, bottom';
SalesChart : popRec =(
left : 51; top : 9; right : 72; bottom : 22; style : 2;
normal : Cyan; hilite : 0;
normback : LightGray; hiback : 0; border : Blue);
{* -------------------------DEMO ROUTINES-------------------------- *}
PROCEDURE Showfile;
{ List the source of this program in FileWindow }
{ Leave the window open afterwards }
VAR ThisFile : TEXT;
Line : string [80];
BEGIN
popShow (FileWindow);
Assign (ThisFile, 'SAILING.TXT');
Reset (ThisFile);
WHILE NOT eof (ThisFile) DO BEGIN
Readln (ThisFile, line);
Writeln (Line);
END;
Close (ThisFile);
END;
{* -------------------------- *}
PROCEDURE WalkPopup;
{ Walk a pop-up down the right side of the display }
{ Moves by successively incrementing top and bottom }
VAR TopRow : INTEGER;
BEGIN
popShow (Walker);
FOR TopRow := 2 to 19 DO BEGIN
popErase (walker);
Walker.top := TopRow;
Walker.bottom := TopRow + 5;
popShow (Walker);
END;
END;
{* -------------------------- *}
PROCEDURE TextChart;
{ Simulate a sales results chart using simple text graphics }
CONST block = #219;
PROCEDURE DrawBar (column, height : INTEGER);
VAR y : INTEGER;
BEGIN
FOR y := 10 DOWNTO (10 - height) DO BEGIN
GotoXY (column, y);
Write (block);
END;
END;
BEGIN
popShow (SalesChart);
popCenter (SalesChart, 1, 'Sales Results');
TextColor (Green);
GotoXY (2,12); Write ('Projected');
DrawBar ( 2, 6);
DrawBar ( 7, 7);
DrawBar (12, 5);
DrawBar (17, 6);
TextColor (Red);
GotoXY (14, 12); Write ('Actual');
DrawBar ( 4, 5);
DrawBar ( 9, 6);
DrawBar (14, 7);
DrawBar (19, 8);
END;
{* ------------------------CONTROL ROUTINES------------------------ *}
FUNCTION DemoResult : CHAR;
{ Pull down and act on Demos Menu }
VAR key, wait : CHAR;
pick : INTEGER;
exiting : BOOLEAN;
BEGIN
pick := 1;
exiting := FALSE;
popShow (DemoMenu);
popHilite (DemoMenu, 1);
REPEAT
{ Get menu selection }
key := Keystroke;
popNormal (DemoMenu, pick); { remove hilite bar }
CASE key OF
'S' : pick := 1;
'W' : pick := 2;
'G' : pick := 3;
DownCursor : BEGIN
Inc (pick);
If pick > 3 THEN pick := 1; { wrap to top row }
END;
UpCursor : BEGIN
Dec (pick);
If pick = 0 THEN pick := 3;
END;
LeftCursor : exiting := TRUE;
RiteCursor : exiting := TRUE;
Enter : CASE pick OF { Selection by cursor + enter }
1 :key := 'S';
2 :key := 'W';
3 :key := 'G';
END;
ELSE exiting := TRUE; { Pass back keystroke }
END;
popHilite (DemoMenu, pick); { hilite new pick }
{ Do demo if selected }
IF key IN ['S', 'W', 'G'] THEN BEGIN
CASE key OF
'S' : BEGIN
ShowFile;
wait := ReadKey;
popErase (FileWindow);
END;
'W' : BEGIN
WalkPopup;
wait := ReadKey;
popErase (walker);
END;
'G' : BEGIN
TextChart;
wait := ReadKey;
popErase (SalesChart);
END;
END;
END;
UNTIL exiting;
popErase (DemoMenu);
DemoResult := key;
END;
{* -------------------------- *}
FUNCTION RunResult : CHAR;
{ Pull down and act on Run Menu }
VAR key, wait : CHAR;
pick : INTEGER;
exiting : BOOLEAN;
BEGIN
pick := 1;
exiting := FALSE;
popShow (RunMenu);
popHilite (RunMenu,1);
REPEAT
key := Keystroke; { remove hilite }
popNormal (RunMenu, pick);
CASE key OF
DownCursor : IF pick = 1 THEN pick := 2 ELSE pick := 1;
UpCursor : IF pick = 1 Then pick := 2 ELSE pick := 1;
'E' : exiting := TRUE;
LeftCursor : exiting := TRUE;
RiteCursor : exiting := TRUE;
Enter : IF pick = 1 THEN key := 'A'
ELSE BEGIN
exiting := TRUE;
key := 'E';
END;
ELSE exiting := TRUE; { pass back keystroke }
END;
popHilite (RunMenu, pick); { Hilite new pick }
IF key = 'A' THEN BEGIN { Do all demos on 'A' }
ShowFile;
TextChart;
WalkPopup;
wait := ReadKey; { Wait for a keystroke }
popErase (Walker); { Retreat through popups }
popErase (SalesChart);
popErase (FileWindow);
END;
UNTIL exiting;
popErase (RunMenu);
RunResult := key;
END;
{* -------------------------- *}
FUNCTION QuitResult : CHAR;
{ Pull down and act on Quit Menu }
VAR key : CHAR;
pick : INTEGER;
exiting : BOOLEAN;
BEGIN
pick := 1;
exiting := FALSE;
PopShow (QuitMenu);
popHilite (QuitMenu, 1);
REPEAT
key := Keystroke;
popNormal (QuitMenu, pick);
CASE key OF
DownCursor : IF pick = 1 THEN pick := 2 ELSE pick := 1;
UpCursor : IF pick = 1 THEN pick := 2 ELSE pick := 1;
'Q' : exiting := TRUE;
'E' : exiting := TRUE;
LeftCursor : exiting := TRUE;
RiteCursor : exiting := TRUE;
Enter : BEGIN
IF pick =1 THEN key := 'Q' ELSE key := 'E';
exiting := TRUE;
END;
ELSE exiting := TRUE; { Pass back keystroke }
END;
popHilite (QuitMenu, pick);
UNTIL exiting;
popErase (QuitMenu);
QuitResult := key;
END;
{* -------------------------- *}
PROCEDURE DoMainMenu;
{ Manages pull down menu selection }
TYPE MenuUp = ( Demos, Run, Thru);
VAR quitting : BOOLEAN;
MMsel : MenuUp;
UserKey : CHAR;
BEGIN
Quitting := FALSE;
MMsel := Demos;
REPEAT
UserKey := chr (0);
{ Act on selected pull down }
CASE MMsel OF
Demos : UserKey := DemoResult;
Run : UserKey := RunResult;
Thru : UserKey := QuitResult;
END;
{ Act on returned keystroke }
CASE UserKey OF
'E' : MMsel := Demos;
'D' : MMsel := Demos;
'R' : MMsel := Run;
'T' : MMsel := Thru;
'Q' : Quitting := TRUE;
LeftCursor : IF MMsel = Demos THEN
MMsel := Thru
ELSE
Dec (MMsel);
RiteCursor : IF MMSEL = Thru THEN
MMsel := Demos
ELSE
Inc (MMsel);
END;
UNTIL quitting;
END;
{* ----------------------------------------------------------------- *}
BEGIN { *** Main Program *** }
{ Initialize object text pointers }
MainMenu.choice := @MainMenuText;
DemoMenu.contents := @DemoMenuText;
RunMenu.contents := @RunMenuText;
QuitMenu.contents := @QuitMenuText;
Walker.contents := @WalkerText;
{ Set up screen and go }
ClrScr;
Cursoff;
showMenubar (MainMenu);
DoMainMenu;
{ Make sure cursor is on before quitting }
Curson;
ClrScr;
END.