home *** CD-ROM | disk | FTP | other *** search
- program Truchet;
- {Demonstrates TRUCHET Tilings. Based on A.K. Dewdney's 7/89 Computer Recreations column in Scientific American.}
- {Quickly written by: Jon Benton. Thanks to: THINK Technology, TML, and the guys in GEnie's MACPRO section.}
- {This is Freeware, enjoy it!}
- uses
- PrintTraps, Quickdraw, Picker, Palettes, Globs, DLOGStuff, WindowStuff, prefsUnit, Truchet;
-
-
- {======================================================================================= }
- procedure Panic;
- begin
- ExitToShell;
- end;
-
- {== ================================ }
- procedure ClickInGoAway;
- var
- topWindow: WindowPtr;
- begin
- topWindow := FrontWindow;
-
- if TrackGoAway(topWindow, MainEvent.where) then
- begin
- if topWindow = MainWindPtr then
- begin
- CloseWindow(MainWindPtr);
- gdh^^.done := TRUE;
- end;
- end;
-
- end;
-
- {======================================================================================= }
- procedure ClickInDA (theWindow: WindowPtr);
- begin
- SystemClick(MainEvent, theWindow);
- end;{ClickInDA}
-
- {======================================================================================= }
- procedure ClickAppleMenu (TheItem: integer);
- var
- SavedPort: GrafPtr;
- TheName: Str255;
- Dummy: integer;
- begin
- case theItem of
- MenuAbout:
- begin
- ObscureCursor;
- DoAbout;
- end;
- otherwise
- begin
- GetPort(SavedPort); {get current port, just in case the DA is uncooperative sort…}
- GetItem(myMenus[AppleMenuID], TheItem, TheName); {identify which DA}
- Dummy := OpenDeskAcc(TheName); {kick off DA}
- SetPort(SavedPort); {set back to original port}
- end; {otherwise}
- end;{case}
- end;{ClickAppleMenu}
-
- {======================================================================================= }
- procedure ClickFileMenu (TheItem: integer);
- var
- Dummy: boolean;
- begin
- case TheItem of
- MenuQuit:
- gdh^^.Done := TRUE;
- otherwise
- ;
- end; {case}
- end;{ClickFileMenu}
-
- {======================================================================================= }
- procedure ClickEditMenu (TheItem: integer);
- begin
- if not SystemEdit(TheItem - 1) then {okay, it's us, not a DA}
- case theItem of
- MenuUndo:
- ; {this pgm doesn't handle any of the cases}
- MenuCopy:
- ;
- MenuCut:
- ;
- MenuPaste:
- ;
- MenuClear:
- ;
- otherwise
- ;
- end;{case}
- {• if (TheItem = MenuCut) or (TheItem = MenuCopy) then•}
- {• gdh^^.ClipChanged := true;•}
- end;{ClickEditMenu}
-
- {======================================================================================= }
- procedure ClickTileMenu (TheItem: integer);
- begin
- case theItem of
- MenuDrawEm:
- begin
- GetDateTime(aLong); {make sure the numbers are randomized}
- gdh^^.seedRand := aLong - TickCount; {store it away…}
- DoTruchet;
- FakeGrowIcon(mainWindPtr);
- end;
- MenuPrefs:
- begin
- DoPrefs;
- DoTruchet;
- ValidRect(mainWindPtr^.portRect);
- end;
- otherwise
- ;
- end;{case}
- end;{ClickTileMenu}
-
- {======================================================================================= }
- procedure ClickInMenu;
- var
- Selection: longint;
- begin
- Selection := MenuSelect(MainEvent.where);
- case HiWord(Selection) of
- AppleMenuID:
- ClickAppleMenu(LoWord(Selection));
- FileMenuID:
- ClickFileMenu(LoWord(Selection));
- EditMenuID:
- ClickEditMenu(LoWord(Selection));
- TileMenuID:
- ClickTileMenu(LoWord(Selection));
- otherwise
- ;
- end;
- HiliteMenu(0); {turns off menu after action has taken place}
- end;{ClickInMenu}
-
- {======================================================================================= }
- procedure AClick; {someone clicked somewhere…}
- var
- where: integer;
- theWindow: WindowPtr;
- begin
-
- where := FindWindow(MainEvent.where, theWindow); {where on DeskTop did they click?}
-
- case where of
- inDesk:
- SysBeep(1);
- inMenuBar:
- ClickInMenu;
- inSysWindow:
- ClickInDA(theWindow);
- inContent:
- begin
- if FrontWindow = MainWindPtr then
- ClickInContent;
- end;
- inDrag:
- begin
- aRect := gdh^^.DragRect;
- DragWindow(theWindow, MainEvent.where, aRect);
- end;
- inGrow:
- ClickInGrow;
- inGoAway:
- ClickInGoAway;
- inZoomIn:
- ClickInZoom(inZoomIn);
- inZoomOut:
- ClickInZoom(inZoomOut);
- end;
-
- end;
-
- {======================================================================================= }
- procedure CommandKey (TheKey: char); {handle Command Keys…}
- var
- Selection: longint;
- begin
- Selection := MenuKey(TheKey);
- case HiWord(Selection) of
- AppleMenuID:
- ClickAppleMenu(LoWord(Selection));
- FileMenuID:
- ClickFileMenu(LoWord(Selection));
- EditMenuID:
- ClickEditMenu(LoWord(Selection));
- TileMenuID:
- ClickTileMenu(LoWord(Selection));
- otherwise
- ;
- end;
- HiliteMenu(0);
- end;{CommandKey}
-
- {======================================================================================= }
- procedure AKey; {user hit key(s) on keyboard…}
- var
- TheCode: integer;
- TheChar: char;
- begin
- TheCode := BitAnd(MainEvent.message, charCodeMask);
- TheChar := chr(TheCode);
-
- if BitAnd(MainEvent.modifiers, cmdKey) <> 0 then
- CommandKey(TheChar)
- end;{AKey}
-
- {======================================================================================= }
- procedure MainLoop; {EventLoop…not MultiFinder friendly…}
- var
- Dummy: boolean;
- whichDialog: DialogPtr;
- whichItem: integer;
- begin
-
- gdh^^.Done := FALSE; {initialize global 'Quit-and-Get-Out' flag…}
- repeat
- SystemTask;
- Dummy := GetNextEvent(everyEvent, MainEvent);
- if Dummy then
- begin
- case MainEvent.what of
- mouseDown:
- AClick;
- mouseUp:
- ;
- keyDown:
- AKey;
- keyUp:
- ;
- autoKey:
- AKey;
- updateEvt:
- AnUpDate;
- DiskEvt:
- HandleDiskEvt;
- activateEvt:
- AnActivate;
- otherwise
- ;
- end; {case}
- end;
- until gdh^^.Done;
-
- end;
-
- {======================================================================================= }
- {MAIN}
-
- begin
- InitMac;
- gdh := GlobalDataHDL(NewHandle(SizeOf(GlobalDataRec))); {allocate handle for our global data}
- if sysCheck then
- begin
- InitGlobs;
- MakeMenus;
- PutUpWind('Truchet Tiles');
- ShowWindow(MainWindPtr);
- MainLoop;
- end;
- end. {TRUCHET program}