home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
001-099
/
ff094.lzh
/
ModulaTools
/
Examples
/
BigTest.mod
< prev
next >
Wrap
Text File
|
1987-08-23
|
12KB
|
350 lines
(******************************************************************************)
(* *)
(* I originally intended for this test to be another simple demonstration *)
(* of some of the features of ModulaTools. However, the versatility of the *)
(* module got the best of me, and I kept adding capabilities as I thought of *)
(* them. As a result, this may not seem as simple a demo as the others. *)
(* Even so, an examination of the procedures below should illustrate the *)
(* ease in which new features may be added to your program. Trying to achieve *)
(* the same functionality without ModulaTools would easily require several *)
(* times as much code as shown below, and it wouldn't include the protection *)
(* against illegal inputs that ModulaTools does. It's your choice... *)
(* *)
(******************************************************************************)
MODULE Test;
FROM DiskFontLibrary IMPORT AvailFontsHeader, AvailFontsHeaderPtr, AvailFont,
OpenDiskFont;
FROM GraphicsLibrary IMPORT Jam1, DrawingModes, DrawingModeSet;
FROM InOut IMPORT Read, Write, WriteInt, WriteString, WriteLn;
FROM Intuition IMPORT ScreenPtr, MenuFlags, MenuFlagSet, Menu,
MenuPtr, MenuItem, MenuItemPtr, IntuiMessagePtr,
IDCMPFlags, IDCMPFlagSet, WindowPtr, WindowFlags,
WindowFlagSet, IntuitionText, IntuitionTextPtr;
FROM Menus IMPORT SetMenuStrip, HighComp;
FROM Screens IMPORT CloseScreen;
FROM Storage IMPORT DestroyHeap;
FROM Strings IMPORT String;
FROM SYSTEM IMPORT ADR, BYTE, NULL;
FROM Text IMPORT TextAttr, TextAttrPtr, TextFontPtr,
RemFont, CloseFont;
FROM Views IMPORT Modes, ModeSet;
FROM Windows IMPORT CloseWindow;
FROM ModulaTools IMPORT OpenGraphics, CloseGraphics, CreateScreen,
CreateWindow, InitializeMenuStrip, DestroyMenuStrip,
AddMenu, AddItem, AddSubItem, FirstMenu, SelectText,
ChoiceType, GotMessage, GetMenuChoice, ViewFeatures,
ItemOn, NoKey, RightJustify, TextDrawMode, TextPen,
HiResScreen, NewItemColumn, CurrentItem, Checkable,
FillPen, FrontTextPen, BackTextPen, AutoIndent,
WindowFeatures, CurrentFont, VerPixPerChar, Left,
GetAndSortAllFonts, ReturnFontResourcesToSystem;
CONST
MaxFonts = 6; (* MaxFonts+1 = maximum number of fonts to open *)
VAR
UserScreen : ScreenPtr;
UserWindow : WindowPtr;
IMessage : IntuiMessagePtr;
finished : BOOLEAN; (* logical variable for event loop. (What??) *)
WindowTitle : String;
ScreenTitle : String;
MenuChoice : ChoiceType;
FontBuffer : AvailFontsHeaderPtr;
AttrStore : ARRAY[0..MaxFonts] OF TextAttrPtr; (* storage space for *)
FontStore : ARRAY[0..MaxFonts] OF TextFontPtr; (* font information *)
TotalFonts : CARDINAL;
i : CARDINAL;
PROCEDURE CreateMenuWindow;
BEGIN
INCL(ViewFeatures, Hires); (* High-resolution Screen *)
ScreenTitle := "MenuScreen";
UserScreen := CreateScreen (0, 0, 640, 200, 3, ScreenTitle);
WindowTitle := "Push down the little menu-button on the mouse, please...";
FillPen := TextPen; (* pen used to draw border *)
TextPen := 2; (* pen used to draw text *)
EXCL(WindowFeatures, WindowClose); (* no close gadget *)
EXCL(WindowFeatures, WindowDrag); (* no drag gadget *)
EXCL(WindowFeatures, WindowDepth); (* no depth gadget *)
UserWindow := CreateWindow (0, 0, 640, 200, WindowTitle, UserScreen);
END CreateMenuWindow;
PROCEDURE CreateDrawingModesMenu;
BEGIN
AddMenu("Drawing Modes");
TextDrawMode := DrawingModeSet{Jam2};
SelectText := "Replace ";
AddItem("DrawingModeSet{Jam2}", NoKey, ItemOn, 0);
TextDrawMode := Jam1;
SelectText := "OverwriteOverwriteOverwrite";
AddItem("Jam1", NoKey, ItemOn, 0);
TextDrawMode := DrawingModeSet{Complement};
AddItem("DrawingModeSet{Complement}", NoKey, ItemOn, 0);
TextDrawMode := DrawingModeSet{InverseVid};
SelectText := "OverwriteOverwriteOverwrite";
AddItem("DrawingModeSet{InverseVid}", NoKey, ItemOn, 0);
INCL(TextDrawMode, Jam2);
SelectText := "Replace ";
AddItem("DrawingModeSet{Jam2, InverseVid}", NoKey, ItemOn, 0);
END CreateDrawingModesMenu;
PROCEDURE CreateColorsMenu;
(* This procedure changes the color of the alternate text in a MenuItem *)
PROCEDURE NewSelectColor(NewTextPen : INTEGER);
VAR
dummyIText : IntuitionTextPtr;
BEGIN
dummyIText := IntuitionTextPtr(CurrentItem^.SelectFill);
dummyIText^.FrontPen := BYTE(NewTextPen);
END NewSelectColor;
BEGIN
TextDrawMode := DrawingModeSet{Jam2};
AutoIndent := TRUE; (* Align second Item with other two. *)
AddMenu("Colors");
SelectText := "Pen #4 ";
FrontTextPen := 1;
AddItem("Pen #1 ", "1", ItemOn+Checkable, 4);
NewSelectColor(4);
SelectText := "Pen #5 ";
FrontTextPen := 2;
AddItem("Pen #2 ", "2", ItemOn, 0);
NewSelectColor(5);
SelectText := "Pen #6 ";
FrontTextPen := 3;
AddItem("Pen #3 ", "3", ItemOn+Checkable, 1);
NewSelectColor(6);
END CreateColorsMenu;
PROCEDURE CreateIntuitionBugMenu;
BEGIN
FrontTextPen := TextPen; (* same as before Colors Menu *)
AutoIndent := FALSE; (* checkable Items are indented anyway... *)
RightJustify := FALSE; (* don't align Items with Menu right-edge *)
AddMenu("Intuition bug? (Select an Item...)");
Left := -50; (* optional *)
AddItem("#1", "a", ItemOn+Checkable, 0);
AddItem("#2", "b", ItemOn+Checkable, 0);
AddItem("#3", "c", ItemOn+Checkable, 0);
AddItem("#4", "d", ItemOn+Checkable, 0);
AddItem("#5", "e", ItemOn+Checkable, 0);
AddItem("#6", "f", ItemOn+Checkable, 0);
AddItem("#7", "g", ItemOn+Checkable, 0);
AddItem("#8", "h", ItemOn+Checkable, 0);
NewItemColumn := TRUE;
AddItem("#9", "i", ItemOn+Checkable, 0);
AddItem("#10", "j", ItemOn+Checkable, 0);
AddItem("#11", "k", ItemOn+Checkable, 0);
AddItem("#12", "l", ItemOn+Checkable, 0);
AddItem("#13", "m", ItemOn+Checkable, 0);
AddItem("#14", "n", ItemOn+Checkable, 0);
AddItem("#15", "o", ItemOn+Checkable, 0);
AddItem("#16", "p", ItemOn+Checkable, 0);
NewItemColumn := TRUE;
AddItem("#17", "q", ItemOn+Checkable, 0);
AddItem("#18", "r", ItemOn+Checkable, 0);
AddItem("#19", "s", ItemOn+Checkable, 0);
AddItem("#20", "t", ItemOn+Checkable, 0);
AddItem("#21", "u", ItemOn+Checkable, 0);
AddItem("#22", "v", ItemOn+Checkable, 0);
AddItem("#23", "w", ItemOn+Checkable, 0);
AddItem("#24", "x", ItemOn+Checkable, 0);
NewItemColumn := TRUE;
AddItem("#25", "y", ItemOn+Checkable, 0);
AddItem("#26", "z", ItemOn+Checkable, 0);
END CreateIntuitionBugMenu;
PROCEDURE CreateSartreMenu;
BEGIN
RightJustify := TRUE; (* Item select-box same size as Menu's *)
AddMenu("Screw Sartre...");
FOR i := 0 TO TotalFonts DO
CurrentFont := AttrStore[i]; (* font for Item text *)
VerPixPerChar := AttrStore[i]^.taYSize; (* font height *)
AddItem("Exit", NoKey, ItemOn, 0);
END; (* FOR i *)
END CreateSartreMenu;
(* This procedure waits for the user to choose an Item from the Sartre Menu *)
PROCEDURE ProcessIntuitionMessages;
CONST
SartreMenu = 3;
BEGIN
finished := FALSE;
WHILE NOT (finished) DO
IF (GotMessage (IMessage, UserWindow)) THEN
IF (MenuPick IN IMessage^.Class) THEN
GetMenuChoice (IMessage^.Code, FirstMenu, MenuChoice);
IF (MenuChoice.MenuChosen = SartreMenu) THEN
finished := TRUE;
END; (* WITH MenuChoice^ *)
END; (* IF MenuPick *)
END; (* IF GotMessage *)
END; (* WHILE NOT finished *)
END ProcessIntuitionMessages;
(* This procedure opens several fonts for use in the "Screw Sartre..." Menu *)
PROCEDURE GimmeNewFonts () : BOOLEAN;
BEGIN
(* $T- Compiler thinks afhAvailFonts has one element *)
IF (GetAndSortAllFonts(FontBuffer)) THEN (* get new fonts: *)
WITH FontBuffer^ DO (* still painful *)
TotalFonts := afhNumEntries DIV 2; (* avoid duplicate fonts *)
IF (TotalFonts > MaxFonts) THEN TotalFonts := MaxFonts; END;
FOR i := 0 TO TotalFonts DO
AttrStore[i] := ADR( afhAvailFonts[2*i].afAttr );
FontStore[i] := OpenDiskFont (AttrStore[i]^);
END; (* FOR i *)
END; (* FontBuffer^ *)
RETURN TRUE;
ELSE
RETURN FALSE;
END; (* IF GetAndSortAllFonts *)
(* $T+ turn range checking back on *)
END GimmeNewFonts;
(* This little piggy closes the fonts opened above. If no other process is *)
(* accessing them, the fonts will be removed from the system-font list. *)
PROCEDURE GetRidOfFonts;
VAR
WhoCares : LONGINT;
BEGIN
FOR i := 0 TO TotalFonts DO
CloseFont (FontStore[i]^);
WhoCares := RemFont (FontStore[i]^);
END; (* FOR i *)
ReturnFontResourcesToSystem (FontBuffer);
END GetRidOfFonts;
BEGIN
WriteLn;
WriteString("Looking for Fonts...are you there, Fonts?");
WriteLn; WriteLn;
IF GimmeNewFonts() THEN (* identify all available fonts *)
WriteString("Apparently so...");
ELSE
WriteString("Apparently not...");
END; (* IF GimmeNewFonts *)
WriteLn; WriteLn;
IF OpenGraphics() THEN (* open libraries and initialize needed variables *)
CreateMenuWindow;
IF (UserWindow <> NULL) THEN
InitializeMenuStrip; (* initialize more needed variables *)
HiResScreen := TRUE; (* The Menu routines need to know this. *)
FrontTextPen := TextPen;
BackTextPen := FillPen; (* make (Sub)Item background invisible; *)
CreateDrawingModesMenu;
CreateColorsMenu; (* link menus into current MenuStrip *)
CreateIntuitionBugMenu;
CreateSartreMenu;
SetMenuStrip(UserWindow, FirstMenu^);
ProcessIntuitionMessages; (* ...until user chooses to exit *)
GetRidOfFonts; (* free memory allotted to fonts *)
DestroyMenuStrip(UserWindow); (* free memory allotted to MenuStrip *)
CloseWindow (UserWindow);
ELSE
WriteString ("No Window allocated..."); WriteLn;
END; (* IF UserWindow *)
IF (UserScreen <> NULL) THEN
CloseScreen (UserScreen);
ELSE
WriteString ("No Screen allocated..."); WriteLn;
END; (* IF UserScreen *)
CloseGraphics (); (* close appropriate libraries *)
ELSE
WriteString ("Graphics didn't open properly...");
END; (* IF OpenGraphics *)
DestroyHeap; (* ensure that all memory allocated is deallocated *)
END Test.