home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-15 | 93.2 KB | 3,557 lines | [TEXT/PJMM] |
- program SplatMaster2;
-
- uses
- Quickdraw, Picker, Palettes, sane;
-
- const
- drawBtnName = 'Draw Frame';
- clearBtnName = 'Clear Splats';
- fillBtnName = 'Draw Filled';
- OK_ALRT_ID = 1005;
- YN_ALRT_ID = 1006;
- YNC_ALRT_ID = 1007;
-
- MacroDLOG_ID = 400;
-
- rad1_Start_ET = 16;
- rad1_End_ET = 17;
- rad2_Start_ET = 18;
- rad2_End_ET = 19;
- theta_ET = 20;
- divs_ET = 21;
- iterations_ET = 23;
-
- k_MoveToSentinel = $5000; { = 20480}
- k_Sentinel = k_MoveToSentinel + $1000; { = 20480 + 4096 = 24576}
-
- {MacDraw PicComment values follow}
- PicDwgBeg = 130;
- PicDwgEnd = 131;
- PicGrpBeg = 140;
- PicGrpEnd = 141;
- StringBegin = 152;
- StringEnd = 153;
-
- {constants for the NewSplat dialog}
- NewBlnDLOG_ID = 401;
- okay = 1;
- cancel = 2;
- innerRad_ET = 3;
- outerRad_ET = 4;
- divisions_ET = 5;
- name_ET = 6;
- autoDraw_Chk = 14;
- groBox_Chk = 15;
- statsBox_Chk = 16;
- polyBox_Chk = 17;
-
- k_PrefsResID = 128;
- k_PrefsResType = 'prf1';
-
- MainWindID = 1000;
-
- AppleMenuID = 1000;
- MenuAbout = 1;
- MenuHelp = 2;
-
- FileMenuID = 1001;
- MenuNew = 1;
- MenuQuit = 3;
-
- EditMenuID = 1002;
- MenuUndo = 1;
- MenuCut = 3;
- MenuCopy = 4;
- MenuPaste = 5;
- MenuClear = 6;
- MenuPrefs = 8;
-
- GoodiesMenuID = 1003;
- MenuMultiSplat = 1;
- MenuClearSplats = 2;
- MenuHidePalette = 3;
- DoIt4 = 4;
-
- k_SaveAlrtID = 1001;
- k_okALRTID = 1005;
- k_ynALRTID = 1006; { Yes No type alert }
- k_yncALRTID = 1007; { Yes, No, Cancel type alert }
-
- k_crossCurs = 1;
- k_arrowCurs = 2;
- k_watchCurs = 3;
-
- {keyboard equivalents}
- k_UpArrow = 30;
- k_DownArrow = 31;
- k_LeftArrow = 28;
- k_RightArrow = 29;
- k_PgUp = 11;
- k_PgDown = 12;
- k_HelpKey = 5;
- k_HomeKey = 1;
- k_EndKey = 4;
- k_Enter = 3;
- k_CR = 13;
- k_Comma = 44;
- k_Period = 46;
- k_Tab = 9;
- k_BS = 8;
- k_EscClr = 27;
-
-
- {• Low-memory globals:•}
- ROM85 = $28E;
- MBarHeight = $BAA;
-
- {our constants}
- kNumCtls = 2;
-
- kArraySiz = 1001;
- twoPi = 6.283185307;
-
- type
- WordPtr = ^INTEGER;
-
- BigArray = array[0..0] of Point;
- BigArrayPtr = ^BigArray;
- BigArrayHdl = ^BigArrayPtr;
-
- PrefRec = record
- def_alwaysDraw: Boolean; {default value}
- def_alwaysGrowBox: Boolean;
- def_alwaysStatBox: Boolean;
- def_alwaysPolyBox: Boolean;
- end;
- PrefPtr = ^PrefRec;
- PrefHdl = ^PrefPtr;
-
- {balloon info}
- SplatRec = record
- name: Str63;
- blnMiddle: Point;
- innerRadius, outerRadius: integer;
- rad1Start, rad1End, rad2Start, rad2End: integer;
- theta, thetaEndDegrees: real;
- iterations, divisions: integer;
- myBigArray: BigArrayHdl;
- maxPtsAllowed, numPtsSoFar: integer;
- autoRedraw, autoFill: Boolean;
- statsBox: rect;
- numSplats: integer;
- statsFont: integer;
- end;
-
- type
- TopicSet = record
- textRsrc, stylRsrc: Integer;
- end;
- HelpListHdl = ^HelpListPtr;
- HelpListPtr = ^HelpList;
- HelpList = record
- numTopics: Integer;
- topicSets: array[0..0] of TopicSet;
- end;
-
- var
- HasColorQD: boolean; { can we use color? }
- HasCoProcessor: boolean; { are we fast? }
-
- DrawWindPtr: WindowPtr;
- mainWindowStorage: WindowRecord;
- mainWindPalette: PaletteHandle;
- GrowIconRect: Rect; { for pseudo grow-icon }
- clippingRect: Rect;
-
- toolWindPtr: WindowPtr;
- toolWindowStorage: WindowRecord;
-
- paletteWindPtr: WindowPtr;
- paletteWindowStorage: WindowRecord;
-
- hueWindPtr: WindowPtr;
- hueWindowStorage: WindowRecord;
-
- myMenus: array[AppleMenuID..GoodiesMenuID] of MenuHandle; {all of the normal menus}
-
- gIBeam: CursHandle;
- gWatch: CursHandle;
- gCrossHairs: CursHandle;
- cursorIs: integer;
-
- quitting, finished, errorFlag, refreshMenus, gWNEImplemented: Boolean;
- currMenuHeight, savedMenuHeight: integer;
-
- MainEvent: EventRecord;
-
- poly: PolyHandle;
- innerRadScrl, outerRadScrl, divsScrl: ControlHandle;
- redScroll, greenScroll, blueScroll: ControlHandle;
- drawBtnRect, clearBtnRect, fillBtnRect: Rect;
- autoDrawChkBox: Rect;
- autoFillChkBox: Rect;
- showToolWind: Boolean;
- showPaletteWind: Boolean;
- graphPICHdl: PicHandle;
-
- curSplat: SplatRec;
- prefs: PrefRec;
- appResFileRef: integer; {for prefs resource}
- tempSplat: SplatRec; {make this global, just to make life easier}
-
- myDialog: DialogPtr;
- myHelpListH: HelpListHdl;
- theList: ListHandle;
- pagesize, numTopics: Integer;
- textRes, numTopicsH: Handle;
- sBar: ControlHandle;
- theText: TEHandle;
-
- {$S One}
- procedure CreateList;
- var
- i, iType: Integer;
- topicStr: Str255;
- iRect, dataBounds: Rect;
- cSize, theCell: Cell;
- iHandle: Handle;
- begin
- GetDItem(myDialog, 3, iType, iHandle, iRect);
- FrameRect(iRect);
- InsetRect(iRect, 1, 1);
- SetPt(cSize, iRect.right - iRect.left, 17);
- SetRect(dataBounds, 0, 0, 1, numTopics);
- theList := LNew(iRect, dataBounds, cSize, 0, myDialog, False, False, False, True);
- for i := 1 to numTopics do {drawIt, hasGrow, hScroll, vScroll}
- begin
- GetIndString(topicStr, 256, i);
- SetPt(theCell, 0, i - 1);
- LSetCell(Pointer(Ord(@topicStr) + 1), Length(topicStr), theCell, theList);
- end;
- theList^^.selFlags := lOnlyOne;
- SetPt(theCell, 0, 0);
- LSetSelect(true, theCell, theList);
- LDoDraw(True, theList); {set drawing to True now that list is built}
- end;
-
- procedure ScrAction (theCtl: ControlHandle; partCode: Integer);
- var
- delta, oldValue: Integer;
- begin
- case partCode of
- inUpButton:
- delta := -10;
- inDownButton:
- delta := 10;
- inPageUp:
- delta := -pagesize;
- inPageDown:
- delta := pagesize;
- otherwise
- end;
- if partCode <> 0 then
- begin
- oldValue := GetCtlValue(theCtl);
- SetCtlValue(theCtl, oldValue + delta);
- TEScroll(0, oldValue - GetCtlValue(theCtl), theText);
- end;
- end;
-
- procedure WindowScroll (thePt: Point; theWindow: WindowPtr);
- var
- theCtl: ControlHandle;
- part, oldValue: Integer;
- begin
- GlobalToLocal(thePt);
- case FindControl(thePt, theWindow, theCtl) of
- inUpButton..inPageDown:
- part := TrackControl(theCtl, thePt, @ScrAction);
- inThumb:
- begin
- with theText^^ do
- oldValue := viewRect.top - destRect.top;
- if TrackControl(theCtl, thePt, nil) <> 0 then
- TEScroll(0, oldValue - GetCtlValue(theCtl), theText);
- end;
- otherwise
- end;
- end;
-
- procedure LoadText (item: Integer);
- const
- inactive = 255;
- var
- max, textNum, stylNum: Integer;
- textRes, stylRes: Handle;
- begin
- TEDeactivate(theText);
- TESetSelect(0, 32767, theText);
- TEDelete(theText);
- theText^^.destRect := theText^^.viewRect;
- textNum := myHelpListH^^.topicSets[item].textRsrc;
- stylNum := myHelpListH^^.topicSets[item].stylRsrc;
- if (textNum <> 0) & (stylNum <> 0) then
- begin
- textRes := GetResource('TEXT', textNum);
- stylRes := GetResource('styl', stylNum);
- HLock(textRes);
- HLock(stylRes);
- TEStylInsert(textRes^, SizeResource(textRes), StScrpHandle(stylRes), theText);
- HUnlock(stylRes);
- HUnlock(textRes);
- end;
- max := TEGetHeight(theText^^.nLines, 0, theText) - pagesize;
- if max > 0 then
- HiliteControl(sBar, activeFlag)
- else
- HiliteControl(sBar, inactive);
- SetCtlValue(sBar, 0);
- SetCtlMax(sBar, max);
- TEActivate(theText);
- end;
-
- function MyFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: Integer): Boolean;
- var
- iType, part: Integer;
- iBox: Rect;
- iHdl: Handle;
- thePt: Point;
- theCtl: ControlHandle;
- ignore: Boolean;
- newCell: Cell;
- begin
- MyFilter := False;
- case theEvent.what of
- keyDown, autoKey: {close if enter or return is keyed}
- if BitAnd(theEvent.message, charCodeMask) in [3, 13] then
- begin
- MyFilter := True;
- GetDItem(theDialog, 1, iType, iHdl, iBox);
- InvertRoundRect(iBox, 10, 10);
- itemHit := 1;
- end;
- mouseDown:
- begin
- thePt := theEvent.where;
- GlobalToLocal(thePt);
- part := FindControl(thePt, myDialog, theCtl);
- if theCtl = sBar then
- WindowScroll(theEvent.where, myDialog)
- else if theCtl = theList^^.vScroll then
- ignore := LClick(thePt, theEvent.modifiers, theList)
- else if PtInRect(thePt, theList^^.rView) then
- begin
- ignore := LClick(thePt, theEvent.modifiers, theList);
- SetPt(newCell, 0, 0);
- ignore := LGetSelect(True, newCell, theList);
- LoadText(newCell.v);
- end;
- end;
- updateEvt:
- begin
- TEUpdate(theText^^.viewRect, theText);
- LUpdate(myDialog^.visRgn, theList);
- end;
- otherwise
- end;
- end;
-
- procedure Help (strRsrcNum, hlpRsrcNum: Integer);
- type
- IntHdl = ^IntPtr;
- IntPtr = ^Integer;
- var
- savePort: GrafPtr;
- iBox, tBox: Rect;
- iType, itemHit: Integer;
- iHdl: Handle;
- begin
- GetPort(savePort);
- myDialog := GetNewDialog(1001, nil, Pointer(-1));
- SetPort(myDialog);
- ShowWindow(myDialog);
- TextFont(Geneva);
- TextSize(12);
- numTopics := IntHdl(GetResource('STR#', strRsrcNum))^^;
- myHelpListH := HelpListHdl(GetResource('HLP#', hlpRsrcNum));
- HLock(Handle(myHelpListH));
- CreateList;
- GetDItem(myDialog, 2, iType, iHdl, tBox);
- FrameRect(tBox);
- InsetRect(tBox, 4, 2);
- pagesize := tBox.bottom - tBox.top;
- theText := TEStylNew(tBox, tBox);
- HLock(Handle(theText));
- GetDItem(myDialog, 6, iType, iHdl, iBox);
- sBar := ControlHandle(iHdl);
- GetDItem(myDialog, 1, iType, iHdl, iBox);
- InsetRect(iBox, -4, -4);
- PenSize(3, 3);
- FrameRoundRect(iBox, 16, 16);
- PenSize(1, 1);
- LoadText(0);
- repeat
- ModalDialog(@MyFilter, itemHit);
- until itemHit = 1;
- HUnlock(Handle(theText));
- LDispose(theList);
- DisposDialog(myDialog);
- SetPort(savePort);
- end;
-
- {-------------------Draw Fake Grow Icon-------------------}
- {The following procedure will put a graphic growbox in the lower right corner}
- procedure FakeGrowIcon (WPtr: WindowPtr; visible: boolean);
- var
- bot, rght: integer;
- R: rect;
- pState: PenState;
- begin
- bot := WPtr^.portRect.bottom;
- rght := WPtr^.PortRect.right;
- SetRect(growIconRect, rght - 15, bot - 15, rght + 1, bot + 1);
- if visible then
- begin
- GetPenState(pState);
- EraseRect(growIconRect);
- FrameRect(growIconRect);
- SetRect(R, rght - 10, bot - 10, rght - 1, bot - 1);
- FrameRect(R);
- SetRect(R, rght - 12, bot - 12, rght - 5, bot - 5);
- EraseRect(R);
- FrameRect(R);
- SetPenState(pState);
- end;{if visible}
- end;
-
- {===========================================================================}
- procedure SetUpPalette;
- const
- numColors = 256; {256 - 2; 2 spots reserved for black & white}
- colorsAvail = 254;
- var
- i: integer;
- num: real;
- anRGB: RGBColor;
- begin
- mainWindPalette := NewPalette(256, nil, pmCourteous, $5000);
- {mainWindPalette := GetPalette(mainWindowPtr);}
-
- anRGB.red := 2 * maxInt;
- anRGB.blue := 2 * maxInt;
- anRGB.green := 2 * maxInt;
- SetEntryColor(mainWindPalette, 0, anRGB); {first Entry is white}
- anRGB.red := 0;
- anRGB.blue := 0;
- anRGB.green := 0;
- SetEntryColor(mainWindPalette, 255, anRGB); {last entry is black}
-
- for i := 1 to numColors - 1 do {defaults to grays}
- begin
- num := 1 - i / (colorsAvail);
- anRGB.red := 2 * (round(num * maxint));
- anRGB.blue := 2 * (round(num * maxint));
- anRGB.green := 2 * (round(num * maxint));
- SetEntryColor(mainWindPalette, i + 1, anRGB);
- end;
-
- for i := 1 to numColors do
- ProtectEntry(i, TRUE);
- end;
-
- {===========================================================================}
- procedure PutUpDrawingWIND;
- var
- Screen: Rect;
- offSet: point;
- begin
- if hasColorQD then
- begin
- DrawWindPtr := GetNewCWindow(1000, @mainWindowStorage, pointer(-1));
- SetUpPalette;
- SetPalette(DrawWindPtr, mainWindPalette, TRUE);
- ActivatePalette(DrawWindPtr);
- end
- else
- DrawWindPtr := GetNewWindow(1000, @mainWindowStorage, WindowPtr(-1));
-
- SetPort(DrawWindPtr);
-
- offSet.h := (ScreenBits.bounds.right - DrawWindPtr^.portRect.right) div 2 + 20;
- offSet.v := 26 + (ScreenBits.bounds.bottom - DrawWindPtr^.portRect.bottom) div 3;
- {not calculating currMenuHeight yet}
- {offSet.v := currMenuHeight + (ScreenBits.bounds.bottom - DrawWindPtr^.portRect.bottom) div 3;}
- MoveWindow(DrawWindPtr, offSet.h, offSet.v, TRUE);
-
- clippingRect := DrawWindPtr^.portRect;
- InsetRect(clippingRect, 1, 1);
- ClipRect(clippingRect);
-
- SetWTitle(DrawWindPtr, 'SplatMaster');
- ShowWindow(DrawWindPtr);
- FakeGrowIcon(DrawWindPtr, prefs.def_alwaysGrowBox);
- end;
-
-
- {===========================================================================}
- procedure CloseDrawingWIND;
- begin
- CloseWindow(DrawWindPtr);
- end;
-
-
- {===========================================================================}
- procedure CenterWindow (theWindow: WindowPtr);
-
- const
- MBarHeight = $BAA;
- type
- WordPtr = ^INTEGER;
- var
- theX, theY: INTEGER;
- scrnNoMB: Rect; (* Rectangle of the screen without Menu Bar. *)
- begin
- with WindowPeek(theWindow)^.port do
- begin
- with screenBits do
- begin
- theX := ((bounds.right - bounds.left) - (portRect.right - portRect.left)) div 2;
- theY := ((bounds.bottom - bounds.top) - (portRect.bottom - portRect.top)) div 3;
- end
- end;
- theY := theY + WordPtr(MBarHeight)^;
- MoveWindow(theWindow, theX, theY, FALSE);
- end;
-
-
- {===========================================================================}
- procedure DoDrag (theWindow: WindowPtr);
- begin
- {this allows the user to drag a window around in the rectangle defined by}
- {ScreenBits.bounds.}
- DragWindow(theWindow, MainEvent.where, ScreenBits.bounds);
- end;
-
- {===========================================================================}
- procedure DoGrow (theWindow: WindowPtr);
- var
- Wptr, oldPort: Windowptr;
- sizeRect: rect;
- newSize: longint;
- newWidth, newHeight: integer;
- r: rect;
- bot, rght: integer;
-
- begin
- GetPort(oldPort);
- SetPort(theWindow);
- if theWindow <> FrontWindow then
- SelectWindow(theWindow);
- {the minimum size that this particular window can be resized is}
- {100 pixels wide, 100 pixels tall. The maximum size is}
- {screenBits.right,screenBits.bottom - 37 tall.}
- SetRect(sizeRect, 100, 100, screenBits.bounds.right, screenBits.bounds.bottom - 37);
- newSize := GrowWindow(theWindow, MainEvent.where, sizeRect);
- if newSize <> 0 then
- begin
- bot := WPtr^.portRect.bottom;
- rght := WPtr^.PortRect.right;
- EraseRect(theWindow^.portRect);
- newWidth := LoWord(newSize);
- newHeight := HiWord(newSize);
- SizeWindow(theWindow, newWidth, newHeight, TRUE);
- ClipRect(theWindow^.portRect);
- InvalRect(theWindow^.portRect);
- FakeGrowIcon(theWindow, prefs.def_alwaysGrowBox);
- clippingRect := DrawWindPtr^.portRect;
- InsetRect(clippingRect, 1, 1);
- ClipRect(clippingRect);
- end;
- SetPort(oldPort);
- end;{DoGrow}
-
- {===========================================================================}
- {• procedure HandleWClose; {(whichWindow : WindowPtr; where : point);•]}
- {• begin•}
- {• Quitting := TRUE;•}
- {• if whichWindow <> FrontWindow then•}
- {• SelectWindow(whichWindow)•}
- {• else•}
- {• begin•}
- {• if TrackGoAway(whichWindow, where) then•}
- {• begin•}
- {• {•]}
- {•{ if anything in the window needs to be saved to•]}
- {•{ disk, now is the time to do it!!!!!•]}
- {•{ •]}
- {• HideWindow(whichWindow);•}
- {• disposeWindow(whichWindow);•}
- {• end;•}
- {• end;•}
- {• end;{HandleWClose•]}
-
- {======================================================================================= }
- procedure DoMessage (mes0: str255; mes1: str255; mes2: str255; mes3: str255);
- const
- MessageDialog = 258;
- var
- dialogP: DialogPtr;
- item: integer;
- oldPort: grafPtr;
- begin
- GetPort(oldPort);
- ParamText(mes0, mes1, mes2, mes3);
- dialogP := GetNewDialog(MessageDialog, nil, pointer(-1));
- if dialogP = nil then
- begin
- SysBeep(5);
- end
- else
- begin
- CenterWindow(dialogP);
- ShowWindow(dialogP);
- InitCursor;
- ModalDialog(nil, item);
- DisposDialog(dialogP);
- end;
- SetPort(oldPort);
- end; {DoMessage}
-
-
- {======================================================================================= }
- procedure DoOneLiner (mes0: Str255);
- begin
- DoMessage(mes0, '', '', '');
- end; {DoOneLiner}
-
-
- {======================================================================================= }
- {Make sure your message has already been prepared using ParamText}
- procedure Do_OK_ALRT;
- var
- oldPort: GrafPtr;
- dummy: integer;
- begin
- GetPort(oldPort);
- dummy := StopAlert(OK_ALRT_ID, nil);
- SetPort(oldPort);
- end; {Do_OK_ALRT}
-
-
- {======================================================================================= }
- {Make sure your message has already been prepared using ParamText}
- function Do_YN_ALRT: Boolean;
- var
- oldPort: GrafPtr;
- begin
- GetPort(oldPort);
- if (Alert(YN_ALRT_ID, nil) = 1) then
- Do_YN_ALRT := TRUE
- else
- Do_YN_ALRT := FALSE;
- SetPort(oldPort);
- end; {Do_YN_ALRT}
-
-
-
- {======================================================================================= }
- {Make sure your message has already been prepared using ParamText}
- function Do_YNC_Alrt: integer;
- var
- oldPort: GrafPtr;
- begin
- GetPort(oldPort);
- Do_YNC_Alrt := Alert(YNC_ALRT_ID, nil);
- SetPort(oldPort);
- end; {Do_YNC_Alrt}
-
-
- {======================================================================================= }
- {This is a routine used to add strings to an existing list}
- procedure Add_List_String (theString: Str255; theList: ListHandle);
- var
- theRow: integer; {The Row that we are adding}
- aStr: str255;
- aPt: point;
- begin
- if (theList <> nil) then
- begin
- aPt.h := 0; {Point to the correct column}
- theRow := LAddRow(1, 200, theList); {Add another row at the end of the list}
- aPt.v := theRow; {Point to the row just added}
- aStr := theString;{Get the string to add}
- LSetCell(Pointer(ord(@aStr) + 1), length(aStr), aPt, theList);{Place string in row just created}
- LDraw(aPt, theList); {Draw the new string}
- end;
- end;
-
-
- {======================================================================================= }
- {--------------------Scan Event Queue for Cmd-Period---------------------}
-
- {example of code that might call CheckForStop }
- { itsAnEvent := EventAvail(keyDownMask, myEvent);}
- { if itsAnEvent then}
- { begin}
- { if CheckForStop(myEvent) then}
- { goto 99;}
- { end;}
-
- function CheckForStop (theEvent: EventRecord): boolean;
- type
- Trick = packed record
- case boolean of
- true: (
- long: Longint
- );
- false: (
- chr3, chr2, chr1, chr0: char
- )
- end;
- var
- CharCode: char;
- TrickVar: Trick;
- stop: boolean;
- periodKey: char;
- begin
- stop := FALSE;
- periodKey := chr(46);
- TrickVar.long := theEvent.message;
- CharCode := TrickVar.chr0;
- if BitAnd(theEvent.modifiers, CmdKey) = CmdKey then
- if CharCode = periodKey then
- stop := TRUE;
- CheckForStop := stop;
- end;
-
- {--------------------Check/Uncheck CheckBoxes in DLOGs---------------------}
- procedure CheckABox (theDlog: dialogPtr; ItemNum: integer; HighLite: boolean);
- var
- itemtype: integer; {the dialog items type}
- itemhandle: handle; {the dialog items handle}
- itemrect: rect; {the dialog items rect}
- itemcntlhand: controlhandle; {we convert the items handle to a cntl handle}
-
- begin
- GetDItem(theDlog, ItemNum, itemtype, itemhandle, itemrect); {get the handle}
- itemcntlhand := controlhandle(itemhandle); {convert it to a cntl handle}
- if HighLite then
- begin
- SetCtlValue(itemcntlhand, 1); {hilite the control}
- end
- else
- begin
- SetCtlValue(itemcntlhand, 0); {unlilite the control}
- end;
- end;
-
- {-----------------Track User's Use of Scrollbar---------------}
-
- procedure TrackScroll (theControl: ControlHandle; partCode: Integer);
- var
- min, max, amount, startValue: Integer;
- up: Boolean;
- begin
- up := partcode in [inUpButton, inPageUp];
- min := GetCtlMin(theControl);
- max := GetCtlMax(theControl);
- startValue := GetCtlValue(theControl);
- if ((up and (startValue > min)) or ((not up) and (startValue < max))) and (partCode <> 0) then
- begin
- if up then
- amount := -1
- else
- amount := 1;
- if partCode in [inPageUp, inPagedown] then
- amount := round(amount * 5)
- else
- amount := round(amount * 1);
- SetCtlValue(theControl, amount + startValue);
- end;
- end; {of TrackScroll}
-
- {--------------------HiLite/UnHilite Radio Buttons---------------------}
- procedure PushRadioButton (theDlog: dialogPtr; item, first, last: integer);
-
- var
- index: integer; {index through the loop}
- itemtype: integer; {the dialog items type}
- itemhandle: handle; {the dialog items handle}
- itemrect: rect; {the dialog items rect}
- itemcntlhand: controlhandle; {we convert the items handle to a cntl handle}
-
- begin
- for index := first to last do {do it for all items in the group}
- begin
- GetDItem(theDlog, index, itemtype, itemhandle, itemrect); {get the handle}
- itemcntlhand := controlhandle(itemhandle); {convert it to a cntl handle}
- if (index = item) then
- begin
- SetCtlValue(itemcntlhand, 1); {hilite the control}
- end
- else
- SetCtlValue(itemcntlhand, 0); {unlilite the control}
- end;
- end;
-
- {--------------------Outline DLOGs Default Button---------------------}
- procedure DrawDefaultBtn (theItem: integer; thisDlog: DialogPtr);
- var
- OptType: Integer;
- OptBox: Rect;
- ItemHdl: Handle;
- oldDlog: DialogPtr;
-
- begin
- GetPort(oldDlog);
- SetPort(thisDlog);{ set window to current graf port }
- {Note: GetDItem gets info about dialogs}
- GetDItem(thisDlog, theItem, OptType, ItemHdl, OptBox); { get item location }
- Pensize(3, 3); { no wimpy outlines here }
- InsetRect(OptBox, -4, -4); { set rectangle around button }
- FrameRoundRect(OptBox, 16, 16); { draw the sucker! }
- PenSize(1, 1); { reset the PenSize}
- SetPort(oldDlog); { RESET to the original port}
- end; { of proc DrawDefaultBtn }
-
-
- procedure HiLiteDLOGButton (theItem: integer; state: boolean; thisDlog: DialogPtr);
- const
- on = TRUE;
- off = FALSE;
- var
- tipe: integer;
- aHdl: Handle;
- tempRect: rect;
- begin
- GetDItem(thisDlog, theItem, tipe, aHdl, tempRect); {Get the item handle}
-
- if state = on then
- HiliteControl(controlhandle(aHdl), 0) {un-dim button}
- else
- HiliteControl(controlhandle(aHdl), 255); {Dim the button}
- end;{}
-
- {--------------------Draw DLOG Title---------------------}
- {this procedure expects the DLOG to already have been set with SetPort}
- procedure DLOGTitle (title, FcnName: str255);
- const
- defaultFont = Geneva;
- niceFont = Helvetica;
- fontSyz = 12;
- fontOffset = 12;
- extraFHeight = 2;
- lineOffset = 5;
- var
- aStr: str255;
- anInt: integer;
- center: integer;
- theFont: integer;
- myFRec: FontInfo;
- pState: PenState; {a great University}
- begin
- GetPenState(pState); {save current pen info}
- PenNormal;
-
- if RealFont(niceFont, fontSyz) then {decide which font to use}
- theFont := niceFont
- else
- theFont := defaultFont;
-
- TextFont(theFont);
- TextSize(fontSyz);
- TextFace([Bold]);
- GetFontInfo(myFRec);
-
- foreColor(blueColor); {old-style color}
- {• anInt := myFRec.ascent + myFRec.descent + extraFHeight;•}
- anInt := myFRec.ascent + extraFHeight;
- MoveTo(fontOffset, anInt);
- WriteDraw(title);
-
- if FcnName <> '' then {if we have a name to draw also…}
- begin
- MoveTo(thePort^.portRect.right - fontOffset - StringWidth(FcnName), anInt);
- TextFace([Italic, Bold]);
- WriteDraw(FcnName);
- end;
-
- foreColor(redColor); {old-style color}
- with thePort^.portRect do
- begin
- MoveTo(lineOffset, anInt + 3);
- LineTo(right - lineOffset, anInt + 3);
- PenSize(1, 2);
- MoveTo(lineOffset, anInt + 5);
- LineTo(right - lineOffset, anInt + 5);
- end;
-
- foreColor(blackColor);
- TextFace([]);
- TextSize(9);
- SetPenState(pState); {restore to saved pen info}
- end;
-
- {======================================================================================= }
- {Get enclosing rectangle of a dialog item}
- function GetDBox (theDlog: dialogPtr; theItem: integer): rect;
- var
- tipe: integer;
- hdl: handle;
- theRect: rect;
- begin
- GetDItem(theDlog, theItem, tipe, hdl, theRect);
- GetDBox := theRect;
- end;{GetDBox}
-
- {======================================================================================= }
- {get handle of item in dialog}
- function GetDLOGIHandle (theDLOG: dialogPtr; theItem: integer): Handle;
- var
- tipe: integer;
- aRect: rect;
- aHdl: handle;
- begin
- GetDItem(theDLOG, theItem, tipe, aHdl, aRect);
- GetDLOGIHandle := aHdl;
- end;{GetHandle}
-
-
- {======================================================================================= }
- {write a label, to the right or left of a rectangle}
- procedure WriteLabel (theStr: Str255; theRect: rect; toTheRight: boolean);
- const
- vertOff = 4;
- horizOff = 6;
- var
- aHandle: handle;
- aPt: point;
- begin
- TextFont(0);
- TextFace([]);
- TextSize(12);
- PenNormal;
- with theRect do
- if ToTheRight then
- begin
- SetPt(aPt, right + horizOff, bottom - vertOff);
- left := right + 1;
- right := right + (StringWidth(theStr) + horizOff + 6);
- end
- else {it's to the left}
- begin
- SetPt(aPt, left - (horizOff + StringWidth(theStr)), bottom - vertOff);
- right := left - 4;
- left := left - (StringWidth(theStr) + horizOff + 6);
- end;{if ToTheRight…}
- EraseRect(theRect);
- MoveTo(aPt.h, aPt.v);
- WriteDraw(theStr);
- end;{WriteLabel}
-
-
- {=======================================================================================}
- procedure ZoomRect (zoomUp: boolean; smallRect, bigRect: rect);
-
- const
- zoomSteps = 16;
-
- var
- rect1, rect2, rect3, rect4: Rect;
- i, j: INTEGER;
- {• savePort, thisPort: GrafPtr;•}
- fract, factor, one: Fixed;
-
- function ZoomBlend (smallCoord, bigCoord: INTEGER): INTEGER;
- var
- smallFix, bigFix, tempFix: Fixed;
- begin
- smallFix := one * smallCoord;
- bigFix := one * bigCoord;
- tempFix := FixMul(fract, bigFix) + FixMul(one - fract, smallFix);
- ZoomBlend := FixRound(tempFix);
- end;
-
- begin
- PenPat(gray);
- PenMode(notPatXor);
-
- one := 65536;
- if zoomUp then
- begin
- rect1 := smallRect;
- factor := FixRatio(6, 5);
- fract := FixRatio(541, 10000);
- end
- else
- begin
- rect1 := bigRect;
- factor := FixRatio(5, 6);
- fract := one;
- end;
-
- rect2 := rect1;
- rect3 := rect1;
- FrameRect(rect1);
-
- for i := 1 to zoomSteps do
- begin
- rect4.left := ZoomBlend(smallRect.left, bigRect.left);
- rect4.right := ZoomBlend(smallRect.right, bigRect.right);
- rect4.top := ZoomBlend(smallRect.top, bigRect.top);
- rect4.bottom := ZoomBlend(smallRect.bottom, bigRect.bottom);
-
- FrameRect(rect4);
- FrameRect(rect1);
- rect1 := rect2;
- rect2 := rect3;
- rect3 := rect4;
-
- fract := FixMul(fract, factor);
- end;
- FrameRect(rect1);
- FrameRect(rect2);
- FrameRect(rect3);
- PenNormal;
- end;
-
- {===========================================================}
- {draws a 2-pixel shadow around a rectangle}
- procedure ShadowBox (theRect: Rect);
- begin
- PenSize(2, 2);
- with theRect do
- begin
- MoveTo(left + 2, bottom);
- LineTo(Right, bottom);
- MoveTo(right, Top + 2);
- LineTo(Right, Bottom);
- end;
- PenSize(1, 1);
- FrameRect(theRect);
- end;{ShadowBox}
-
-
-
-
- {--------------------Simulate MouseDown in Button---------------------}
- procedure ClickButton (Dptr: DialogPtr; ItemNo: integer);
-
- { Inside Macintosh leaves out the fact that if you use a filter procedure }
- {in the ModalDialog call you need to simulate a clicking of the OK button when }
- {the return key is hit. This one of two possible techniques where we directly }
- {highlight and unhighlight the button. The other technique would be to add a }
- {mouse down event to the event queue in which the mouse coordinates are }
- {somewhere inside of the OK button. JWIND}
-
- var
- IType: integer;
- ButtonHandle: Handle;
- Box: rect;
- L: LongInt;
-
- begin
- GetDItem(Dptr, ItemNo, IType, ButtonHandle, Box);
- HiliteControl(ControlHandle(ButtonHandle), 253);
- Delay(8, L);
- HiliteControl(ControlHandle(ButtonHandle), 0);
- end; { ClickButton }
-
-
- {check to see if the string passed contains only numerals and a decimal}
- {Returns a string explaining what was wring, if anything}
- function IsStringReal (theStr: str255; var ItsBadBecause: str255): boolean;
- label
- 99;
- var
- i, decimalFound, negativesFound: integer;
- aChar: char;
- Okay: boolean;
- begin
- okay := TRUE;
- decimalFound := 0;
- negativesFound := 0;
- ItsBadBecause := '';
- for i := 1 to length(theStr) do
- begin
- aChar := Copy(theStr, i, 1);
- if aChar = '.' then
- decimalFound := decimalFound + 1;
- if decimalFound > 1 then
- begin
- ItsBadBecause := 'Too many decimals found';
- okay := FALSE;
- goto 99;
- end;{if decimalFound > 1 then}
- if aChar = '-' then
- negativesFound := negativesFound + 1;
- if negativesFound > 1 then
- begin
- ItsBadBecause := 'Too many "-"s found ';
- okay := FALSE;
- goto 99;
- end;{if negativesFound > 1 then}
- if not (aChar in ['0'..'9', '-', '.']) then
- begin
- ItsBadBecause := Concat('Non-numeric character found: ', aChar);
- okay := FALSE;
- goto 99;
- end;{if not aChar in ['0'..'9', '-','.'] then}
- end;{for i := 1 to length(theStr)}
- 99:
- IsStringReal := Okay;
- end;{IsStringReal}
-
-
-
-
-
- {----------------Convert a Numeric String to an Integer----------------}
- function String2Int (theStr: Str255): integer;
- var
- aLongInt: longint;
- begin
- StringToNum(theStr, aLongInt);
- if aLongInt > maxInt then
- begin
- DoMessage('That number is too big.', 'It must be less than 32767', '', '');
- aLongInt := 0;
- end;
- String2Int := aLongInt;
- end;{String2Int}
-
- {----------------Convert a Numeric String to an Integer----------------}
- function Int2String (theInt: integer): str255;
- var
- aLongInt: longint;
- aStr: str255;
- begin
- aLongInt := theInt;
- NumToString(aLongInt, aStr);
- Int2String := aStr;
- end;{String2Int}
-
- {--------------------Convert a Real to a Str255---------------------}
- function Real2String (aReal: real): str255;
- var
- aDecForm: DecForm;
- aDecStr: DecStr;
- aStr: str255;
- begin
- aDecform.Style := FixedDecimal;
- aDecform.digits := 2;
- Num2Str(aDecForm, aReal, aDecStr);
- aStr := aDecStr;
- Real2String := aStr;
- end;{Real2Str}
-
- {--------------------Convert a Str255 to a Real---------------------}
- {This is actually very simple…}
- function String2Real (aStr: str255): real;
- begin
- String2Real := Str2Num(aStr);
- end;{String2Real}
-
- {======================================================================================= }
- function AddNewPrefs (var aPrefHdl: PrefHdl): Boolean;
- var
- err: OSerr;
- aHandle: Handle;
- begin
- AddNewPrefs := FALSE;
- aPrefHdl := nil;
-
- aPrefHdl := PrefHdl(NewHandle(sizeof(PrefRec)));
-
- HNoPurge(Handle(aPrefHdl));
- MoveHHi(Handle(aPrefHdl));
- HLock(Handle(aPrefHdl));
- AddResource(Handle(aPrefHdl), k_PrefsResType, k_PrefsResID, 'Prefs');
- err := ResError;
-
- if (aPrefHdl = nil) or (err <> noErr) then {AddNewPrefs failed!}
- begin
- DisposeHandle(Handle(aPrefHdl));
- exit(AddNewPrefs);
- end;
- WriteResource(Handle(aPrefHdl));
- err := ResError;
- if err <> noErr then
- exit(AddNewPrefs);
-
- Hunlock(Handle(aPrefHdl));
- AddNewPrefs := TRUE;
-
- end;{AddNewPrefs}
-
- {======================================================================================= }
- procedure RewritePrefs (prefs: PrefRec);
- var
- err: integer;
- aPrefHdl: PrefHdl;
- begin
- UseResFile(appResFileRef); {just in case it got changed somehow…}
- aPrefHdl := PrefHdl(GetResource(k_PrefsResType, k_PrefsResID));
- err := ResError;
- if (aPrefHdl = nil) or (err <> noErr) then
- if not AddNewPrefs(aPrefHdl) then
- exit(RewritePrefs);
-
- {stuff our pref values into the resource's handle}
- aPrefHdl^^.def_alwaysDraw := prefs.def_alwaysDraw;
- aPrefHdl^^.def_alwaysGrowBox := prefs.def_alwaysGrowBox;
- aPrefHdl^^.def_alwaysStatBox := prefs.def_alwaysStatBox;
-
- ChangedResource(Handle(aPrefHdl));
- err := ResError;
- if err = noErr then
- WriteResource(Handle(aPrefHdl));
- err := ResError;
- if err <> noErr then
- SysBeep(1);
-
- DisposHandle(Handle(aPrefHdl));
- end;{RewritePrefs}
-
-
- {======================================================================================= }
- procedure InitPrefs (var thePrefs: PrefRec);
- begin
- thePrefs.def_alwaysDraw := TRUE;
- thePrefs.def_alwaysGrowBox := TRUE;
- thePrefs.def_alwaysStatBox := TRUE;
- end;
-
-
- {======================================================================================= }
- procedure SetUpPrefs (var prefs: PrefRec);
- var
- err: OSerr;
- aPrefHdl: PrefHdl;
- begin
- InitPrefs(prefs); {make sure, no matter what, that we have valid values}
-
- UseResFile(appResFileRef); {just in case it got changed somehow…}
- aPrefHdl := PrefHdl(GetResource(k_PrefsResType, k_PrefsResID));
- err := ResError;
- if (aPrefHdl = nil) or (err <> noErr) then {failed to get resource}
- exit(SetUpPrefs); {so exit and just use the defaults}
-
- {here is where we suck the marrow out of our resource-based prefs}
- {and store it in our humble, global prefs record}
- prefs.def_alwaysDraw := aPrefHdl^^.def_alwaysDraw;
- prefs.def_alwaysGrowBox := aPrefHdl^^.def_alwaysGrowBox;
- prefs.def_alwaysStatBox := aPrefHdl^^.def_alwaysStatBox;
-
- DisposHandle(Handle(aPrefHdl));
-
- end; {SetUpPrefs}
-
-
-
-
- {======================================================================================= }
- procedure PrefsDLOG;
- const
- PrefsDLOGID = 402;
-
- Draw_Chk = 4;
- Grow_Chk = 5;
- Stats_Chk = 6;
- Poly_Chk = 7;
- var
- UserPrefsDLOGPtr: DialogPtr;
- OldPort: GrafPtr;
- itemHit: integer;
- finished: Boolean;
-
- AutoRedraw, GrowBox, StatBox, PolyBox: Boolean;
-
- begin
-
- GetPort(OldPort);
-
- UserPrefsDLOGPtr := GetNewDialog(PrefsDLOGID, nil, Pointer(-1));
- CenterWindow(UserPrefsDLOGPtr);
- SetPort(UserPrefsDLOGPtr);
- ShowWindow(UserPrefsDLOGPtr);
-
- DrawDefaultBtn(ok, UserPrefsDLOGPtr); {Outline Default Button}
-
- with prefs do
- begin
- AutoRedraw := def_alwaysDraw;
- GrowBox := def_alwaysGrowBox;
- StatBox := def_alwaysStatBox;
- PolyBox := def_alwaysPolyBox;
- end; {with}
-
- CheckABox(UserPrefsDLOGPtr, Draw_Chk, AutoRedraw);
- CheckABox(UserPrefsDLOGPtr, Grow_Chk, GrowBox);
- CheckABox(UserPrefsDLOGPtr, Stats_Chk, StatBox);
- CheckABox(UserPrefsDLOGPtr, Poly_Chk, PolyBox);
-
- finished := FALSE;
-
- repeat
- begin
- ModalDialog(nil, itemHit); {Wait until an item is hit}
- case itemHit of
- ok:
- begin
- curSplat.autoRedraw := AutoRedraw;
- if (AutoRedraw <> prefs.def_alwaysDraw) and (showToolWind) then
- begin
- SetPort(toolWindPtr);
- InvalRect(autoDrawChkBox);
- InvalRect(drawBtnRect);
- SetPort(UserPrefsDLOGPtr);
- end;
- prefs.def_alwaysDraw := AutoRedraw;
-
- curSplat.autoFill := PolyBox;
- if (PolyBox <> prefs.def_alwaysPolyBox) and (showToolWind) then
- begin
- SetPort(toolWindPtr);
- InvalRect(autoFillChkBox);
- InvalRect(fillBtnRect);
- SetPort(UserPrefsDLOGPtr);
- end;
- prefs.def_alwaysPolyBox := PolyBox;
-
- if (prefs.def_alwaysGrowBox <> GrowBox) or (prefs.def_alwaysStatBox <> StatBox) then
- begin
- SetPort(DrawWindPtr);
- EraseRect(GrowIconRect);
- InvalRect(GrowIconRect);
- EraseRect(curSplat.statsBox);
- InvalRect(curSplat.statsBox);
- SetPort(UserPrefsDLOGPtr);
- end;
- prefs.def_alwaysGrowBox := GrowBox;
- prefs.def_alwaysStatBox := StatBox;
- finished := TRUE;
- end;
- cancel:
- finished := TRUE;
- Draw_Chk:
- begin
- AutoRedraw := not AutoRedraw;
- CheckABox(UserPrefsDLOGPtr, Draw_Chk, AutoRedraw);
- end;
- Grow_Chk:
- begin
- GrowBox := not GrowBox;
- CheckABox(UserPrefsDLOGPtr, Grow_Chk, GrowBox);
- end;
- Stats_Chk:
- begin
- StatBox := not StatBox;
- CheckABox(UserPrefsDLOGPtr, Stats_Chk, StatBox);
- end;
- Poly_Chk:
- begin
- PolyBox := not PolyBox;
- CheckABox(UserPrefsDLOGPtr, Poly_Chk, PolyBox);
- end;
- otherwise
- ;
- end;{case}
- end;{repeat}
- until finished; {repeat…}
-
- DisposDialog(UserPrefsDLOGPtr);{Flush the dialog out of memory}
-
- end;{PrefsDLOG}
-
- {===========================================================================}
- {For debugging}
- {$SETC debuggIt = FALSE}
-
- {$IFC debuggIt}
- procedure SplatMsg (myStr: str255);
- var
- oldPort: GrafPtr;
- aRect: rect;
- anInt: integer;
- begin
- GetPort(oldPort);
- SetPort(DrawWindPtr);
- aRect := thePort^.portRect;
- aRect.left := aRect.right - 200;
- aRect.bottom := aRect.top + 22;
- ClipRect(aRect);
- EraseRect(aRect);
- TextFont(0);
- TextSize(12);
- anInt := StringWidth(myStr) div 2;
- MoveTo(aRect.left + ((aRect.right - aRect.left) div 2 - anInt), aRect.top + 14);
- DrawString(myStr);
- PenSize(1, 1);
- FrameRect(aRect);
- PenNormal;
- ClipRect(thePort^.portRect);
- SetPort(oldPort);
- end; {SplatMsg}
- {$ENDC debuggIT}
-
- procedure SetForeColor (red, green, blue: integer);
- var
- hue: RGBColor;
- begin
- hue.red := red;
- hue.green := green;
- hue.blue := blue;
- RGBForeColor(hue);
- end;
-
- {===========================================================================}
- procedure SplatStatistics (var aSplatRec: SplatRec);
- const
- linesInParagraph = 3;
- indent = 4;
- var
- oldPort: GrafPtr;
- Paragraph: array[1..linesInParagraph] of str255;
- leading, lineNo, longestLine: integer;
- fInfo: fontInfo;
- aStr: str255;
- aRect: rect;
- begin
- if not prefs.def_alwaysStatBox then
- exit(SplatStatistics);
- GetPort(oldPort);
- SetPort(DrawWindPtr);
-
- TextFont(aSplatRec.statsFont);
- TextSize(9);
- TextFace([]);
- GetFontInfo(fInfo);
- leading := fInfo.ascent + fInfo.descent + fInfo.leading;
-
- Paragraph[1] := aSplatRec.name;
- aStr := Int2String(aSplatRec.numPtsSoFar);
- Paragraph[2] := concat('Num. pts. so far: ', aStr);
- if (aSplatRec.numSplats = 1) then
- Paragraph[3] := 'One splat Drawn'
- else
- begin
- aStr := Int2String(aSplatRec.numSplats);
- Paragraph[3] := concat(aStr, ' Splats Drawn');
- end;
-
- longestLine := StringWidth(Paragraph[1]);
- if StringWidth(Paragraph[2]) > longestLine then
- longestLine := StringWidth(Paragraph[2])
- else if StringWidth(Paragraph[3]) > longestLine then
- longestLine := StringWidth(Paragraph[3]);
-
-
- aRect := aSplatRec.statsBox;
- aRect.bottom := aRect.top + (linesInParagraph * leading + 9);
- aRect.right := aRect.left + 12 + indent + longestLine;
- aSplatRec.statsBox := aRect;
-
- picComment(picGrpBeg, 0, nil); {text and rects}
- picComment(picGrpBeg, 0, nil); {rects}
- {PenPat(Black);}
- SetForeColor($eeee, $eeee, $eeee);
- PaintRect(aRect);
- {Fillrect(aRect, white);}
- SetForeColor($2222, $2222, $2222);
- FrameRect(aRect);
- InsetRect(aRect, 1, 1);
- SetForeColor($5555, $5555, $5555);
- FrameRect(aRect);
- InsetRect(aRect, 1, 1);
- SetForeColor($8888, $8888, $8888);
- FrameRect(aRect);
- InsetRect(aRect, 1, 1);
- SetForeColor($bbbb, $bbbb, $bbbb);
- FrameRect(aRect);
- picComment(picGrpEnd, 0, nil); {rects}
- ClipRect(aRect);
-
- picComment(picGrpBeg, 0, nil); {text}
- for lineNo := 1 to linesInParagraph do
- begin
- picComment(StringBegin, 0, nil); {string begin}
- MoveTo(aRect.left, aRect.top + leading);
- Move(indent, (lineNo - 1) * leading);
- SetForeColor($aaaa, 0, 0);
- DrawString(Paragraph[lineNo]);
- picComment(StringEnd, 0, nil); {string end}
- end;
- picComment(picGrpEnd, 0, nil); {text}
- picComment(picGrpEnd, 0, nil); {text and rects}
-
- PenNormal;
- ClipRect(thePort^.portRect);
- SetPort(oldPort);
- end;
-
- {===========================================================================}
- procedure ClearAllSplats (var aSplatRec: SplatRec);
- var
- oldPort: grafPtr;
- begin
- GetPort(oldPort);
- SetPort(DrawWindPtr);
- EraseRect(thePort^.portRect);
- aSplatRec.numPtsSoFar := 0;
- aSplatRec.numSplats := 0;
- SplatStatistics(aSplatRec);
- SetPort(oldPort);
- end; {ClearAllSplats}
-
- {===========================================================================}
- {port should already be set to DrawWindPtr}
- procedure DragStatsRect (var aSplatRec: SplatRec);
- var
- oldPort: GrafPtr;
- theRegion: rgnHandle;
- slopRect, limitRect: rect;
- mousePoint: point;
- aLong: longint;
- hi, lo: longint;
- width, height: integer;
- tempRect: rect;
- begin
- if not prefs.def_alwaysStatBox then
- exit(DragStatsRect);
-
- if not Button then
- exit(DragStatsRect);
-
- GetPort(oldPort);
- SetPort(DrawWindPtr);
- GetMouse(mousePoint);
- EraseRect(aSplatRec.statsBox);
- slopRect := thePort^.portRect;
- InsetRect(SlopRect, 1, 1);
- limitRect.left := mousePoint.h - aSplatRec.statsBox.left;
- limitRect.top := mousePoint.v - aSplatRec.statsBox.top;
- limitRect.right := slopRect.right - (aSplatRec.statsBox.right - mousePoint.h);
- limitRect.bottom := slopRect.bottom - (aSplatRec.statsBox.bottom - mousePoint.v);
- width := aSplatRec.statsBox.right - aSplatRec.statsBox.left;
- height := aSplatRec.statsBox.bottom - aSplatRec.statsBox.top;
- {PenPat(black);}
- SetForeColor(0, 0, 0);
- theRegion := NewRgn;
- OpenRgn;
- FrameRect(aSplatRec.statsBox);
- CloseRgn(theRegion);
-
- aLong := DragGrayRgn(theRegion, mousePoint, limitRect, slopRect, 0, nil);
-
- hi := HiWord(aLong);
- lo := LoWord(aLong);
- if (hi = -32768) and (lo = -32768) then
- SysBeep(1)
- else
- aSplatRec.statsBox := theRegion^^.RgnBBox;
- DisposeRgn(theRegion);
-
- InvalRect(thePort^.portRect);
-
- SetPort(oldPort);
- end;
-
- {$S Two}
- {===========================================================================}
- function MakeArray (var anArrayHdl: BigArrayHdl): Boolean;
- var
- err: OSErr;
- begin
- anArrayHdl := BigArrayHdl(NewHandle(kArraySiz * sizeof(Point)));
- err := MemError;
- if err <> noErr then
- begin
- Do_OK_ALRT;
- anArrayHdl := nil;
- MakeArray := FALSE;
- exit(MakeArray);
- end;
- MakeArray := TRUE;
- end;
-
-
- {===========================================================================}
- procedure RefreshSplats (var aSplatRec: SplatRec);
- var
- oldPort: GrafPtr;
- arrayPtr: bigArrayPtr;
- counter, numPts: integer;
- aPt: Point;
- begin
- if aSplatRec.myBigArray = nil then
- exit(RefreshSplats);
- if aSplatRec.numPtsSoFar = 0 then
- exit(RefreshSplats);
- GetPort(oldPort);
- SetPort(DrawWindPtr);
- PenNormal;
-
- {$IFC debuggIT}
- SplatMsg('RefreshSplats');
- {$ENDC debuggIT}
-
- MoveHHi(Handle(aSplatRec.myBigArray));
- HLock(Handle(aSplatRec.myBigArray));
- arrayPtr := aSplatRec.myBigArray^;
-
- SetForeColor(Random, Random, Random);
- numPts := aSplatRec.numPtsSoFar - 1; {subtract 1 'cuz numPtsSoFar actually points to 1 greater than last actual pt}
- for counter := 0 to numPts do
- begin
- aPt := arrayPtr^[counter];
- if aPt.h > k_MoveToSentinel then {a negative .h means the point is to be moved-to}
- MoveTo((aPt.h - k_Sentinel) + aSplatRec.blnMiddle.h, aPt.v + aSplatRec.blnMiddle.v)
- else
- LineTo(aPt.h + aSplatRec.blnMiddle.h, aPt.v + aSplatRec.blnMiddle.v);
- end;
-
- SplatStatistics(aSplatRec);
-
- HUnlock(Handle(aSplatRec.myBigArray));
- SetPort(oldPort);
- end;
-
- {===========================================================================}
- {this is very similar to RefreshSplats}
- procedure SplatPICT (aSplatRec: SplatRec; var aPicHdl: PicHandle);
- var
- oldPort: GrafPtr;
- arrayPtr: bigArrayPtr;
- counter, numPts: integer;
- aPt: Point;
- begin
- if aSplatRec.myBigArray = nil then
- exit(SplatPICT);
- if aSplatRec.numPtsSoFar = 0 then
- exit(SplatPICT);
- GetPort(oldPort);
- SetPort(DrawWindPtr);
- PenNormal;
-
- MoveHHi(Handle(aSplatRec.myBigArray));
- HLock(Handle(aSplatRec.myBigArray));
- arrayPtr := aSplatRec.myBigArray^;
-
- if aPicHdl <> nil then
- KillPicture(aPicHdl);
-
- aPicHdl := OpenPicture(thePort^.portRect);
- PicComment(picDwgBeg, 0, nil);
-
- PicComment(PicGrpBeg, 0, nil);
- aPt := arrayPtr^[0]; {first one is alsways a move-to}
- MoveTo((aPt.h - k_Sentinel) + aSplatRec.blnMiddle.h, aPt.v + aSplatRec.blnMiddle.v);
-
- numPts := aSplatRec.numPtsSoFar - 1; {subtract 1 'cuz numPtsSoFar actually points to 1 greater than last actual pt}
- for counter := 1 to numPts do
- begin
- aPt := arrayPtr^[counter];
- if aPt.h > k_MoveToSentinel then {a negative .h means the point is to be moved-to}
- begin
- PicComment(PicGrpEnd, 0, nil); {end last splat, begin next}
- PicComment(PicGrpBeg, 0, nil);
- MoveTo((aPt.h - k_Sentinel) + aSplatRec.blnMiddle.h, aPt.v + aSplatRec.blnMiddle.v);
- end
- else
- LineTo(aPt.h + aSplatRec.blnMiddle.h, aPt.v + aSplatRec.blnMiddle.v);
- end;
- PicComment(PicGrpEnd, 0, nil);
-
- SplatStatistics(aSplatRec);
-
- PicComment(PicDwgEnd, 0, nil);
- ClosePicture;
- HUnlock(Handle(aSplatRec.myBigArray));
- SetPort(oldPort);
- end; {}
-
- {===========================================================================}
- procedure DrawFilledSplat (var aSplatRec: SplatRec);
- var
- oldPort: GrafPtr;
- stepNum: integer;
- originalPt, nextPt: Point;
- thetaStep: real;
- aLong, longSize: longint;
- arrayPtr: bigArrayPtr;
- aSize: Size;
- begin
- GetPort(oldPort);
- SetPort(DrawWindPtr);
- PenNormal;
-
- if aSplatRec.myBigArray = nil then
- begin
- SetPort(oldPort);
- exit(DrawFilledSplat);
- end;
-
- if (aSplatRec.divisions + aSplatRec.numPtsSoFar + 1) > aSplatRec.maxPtsAllowed then
- begin
- aSize := GetHandleSize(Handle(aSplatRec.myBigArray));
- if aSize > 0 then
- SetHandleSize(Handle(aSplatRec.myBigArray), aSize + 100 * sizeof(Point)); {add 100 places to array}
- if (MemError <> noErr) or (aSize = 0) then
- begin
- SetPort(oldPort);
- exit(DrawFilledSplat);
- end;
- end;
-
- MoveHHi(Handle(aSplatRec.myBigArray));
- HLock(Handle(aSplatRec.myBigArray));
- arrayPtr := aSplatRec.myBigArray^;
-
- thetaStep := twoPi / aSplatRec.divisions;
-
- with aSplatRec do
- begin
- SetPt(originalPt, round(innerRadius * cos(theta)), round(innerRadius * sin(theta)));
- SetForeColor(Random, Random, Random);
- poly := OpenPoly;
- MoveTo(blnMiddle.h + originalPt.h, blnMiddle.v + originalPt.v);
- arrayPtr^[numPtsSoFar].h := k_Sentinel + originalPt.h;
- arrayPtr^[numPtsSoFar].v := originalPt.v;
- numPtsSoFar := numPtsSoFar + 1;
- end;
-
- for stepNum := 1 to (aSplatRec.divisions - 1) do
- begin
- aSplatRec.theta := aSplatRec.theta + thetaStep;
- with aSplatRec do
- if odd(stepNum) then
- SetPt(nextPt, round(outerRadius * cos(theta)), round(outerRadius * sin(theta)))
- else
- SetPt(nextPt, round(innerRadius * cos(theta)), round(innerRadius * sin(theta)));
- LineTo(aSplatRec.blnMiddle.h + nextPt.h, aSplatRec.blnMiddle.v + nextPt.v);
- arrayPtr^[aSplatRec.numPtsSoFar].h := nextPt.h;
- arrayPtr^[aSplatRec.numPtsSoFar].v := nextPt.v;
- aSplatRec.numPtsSoFar := aSplatRec.numPtsSoFar + 1;
- end;
- {SetForeColor(0, 0, 0);}
- LineTo(aSplatRec.blnMiddle.h + originalPt.h, aSplatRec.blnMiddle.v + originalPt.v);
- arrayPtr^[aSplatRec.numPtsSoFar].h := originalPt.h;
- arrayPtr^[aSplatRec.numPtsSoFar].v := originalPt.v;
- aSplatRec.numPtsSoFar := aSplatRec.numPtsSoFar + 1;
- aSplatRec.theta := 0.0;
-
- ClosePoly;
- PaintPoly(poly);
- SetForeColor(0, 0, 0);
- FramePoly(poly);
- KillPoly(poly);
- HUnlock(Handle(aSplatRec.myBigArray));
-
- aSplatRec.numSplats := aSplatRec.numSplats + 1;
-
- SetPort(oldPort);
- end; {DrawFilledSplat}
-
-
- {===========================================================================}
- procedure DrawSplat (var aSplatRec: SplatRec);
- var
- oldPort: GrafPtr;
- stepNum: integer;
- originalPt, nextPt: Point;
- thetaStep: real;
- aLong, longSize: longint;
- arrayPtr: bigArrayPtr;
- aSize: Size;
- begin
- GetPort(oldPort);
- SetPort(DrawWindPtr);
- {$IFC debuggIT}
- SplatMsg('DrawSplat');
- {$ENDC debuggIT}
- PenNormal;
-
- if aSplatRec.myBigArray = nil then
- begin
- DoOneLiner('**Error: Point array not allocated.');
- SetPort(oldPort);
- exit(DrawSplat);
- end;
-
- if (aSplatRec.divisions + aSplatRec.numPtsSoFar + 1) > aSplatRec.maxPtsAllowed then
- begin
- {$IFC debuggIT}
- SplatMsg('Growing handle');
- {$ENDC debuggIT}
- aSize := GetHandleSize(Handle(aSplatRec.myBigArray));
- if aSize > 0 then
- SetHandleSize(Handle(aSplatRec.myBigArray), aSize + 100 * sizeof(Point)); {add 100 places to array}
- if (MemError <> noErr) or (aSize = 0) then
- begin
- DoOneLiner('**Error: Could not enlarge point-array. Try smaller number of divisions.');
- SetPort(oldPort);
- exit(DrawSplat);
- end;
- end;
-
- MoveHHi(Handle(aSplatRec.myBigArray));
- HLock(Handle(aSplatRec.myBigArray));
- arrayPtr := aSplatRec.myBigArray^;
-
- thetaStep := twoPi / aSplatRec.divisions;
-
- with aSplatRec do
- begin
- SetPt(originalPt, round(innerRadius * cos(theta)), round(innerRadius * sin(theta)));
- SetForeColor(Random, Random, Random);
- MoveTo(blnMiddle.h + originalPt.h, blnMiddle.v + originalPt.v);
- arrayPtr^[numPtsSoFar].h := k_Sentinel + originalPt.h;
- arrayPtr^[numPtsSoFar].v := originalPt.v;
- numPtsSoFar := numPtsSoFar + 1;
- end;
-
- for stepNum := 1 to (aSplatRec.divisions - 1) do
- begin
- aSplatRec.theta := aSplatRec.theta + thetaStep;
- with aSplatRec do
- if odd(stepNum) then
- SetPt(nextPt, round(outerRadius * cos(theta)), round(outerRadius * sin(theta)))
- else
- SetPt(nextPt, round(innerRadius * cos(theta)), round(innerRadius * sin(theta)));
- LineTo(aSplatRec.blnMiddle.h + nextPt.h, aSplatRec.blnMiddle.v + nextPt.v);
- arrayPtr^[aSplatRec.numPtsSoFar].h := nextPt.h;
- arrayPtr^[aSplatRec.numPtsSoFar].v := nextPt.v;
- aSplatRec.numPtsSoFar := aSplatRec.numPtsSoFar + 1;
- end;
- {SetForeColor(0, 0, 0);}
- LineTo(aSplatRec.blnMiddle.h + originalPt.h, aSplatRec.blnMiddle.v + originalPt.v);
- arrayPtr^[aSplatRec.numPtsSoFar].h := originalPt.h;
- arrayPtr^[aSplatRec.numPtsSoFar].v := originalPt.v;
- aSplatRec.numPtsSoFar := aSplatRec.numPtsSoFar + 1;
- aSplatRec.theta := 0.0;
- HUnlock(Handle(aSplatRec.myBigArray));
-
- aSplatRec.numSplats := aSplatRec.numSplats + 1;
-
- SetPort(oldPort);
- end; {DrawSplat}
-
-
- {===========================================================================}
- procedure InitSplat (var aSplatRec: SplatRec);
- var
- error: boolean;
- begin
- SetPort(DrawWindPtr);
- with thePort^.portRect do
- begin
- aSplatRec.blnMiddle.h := (right - left) div 2;
- aSplatRec.blnMiddle.v := (bottom - top) div 2;
- end;
- aSplatRec.name := 'Untitled';
- aSplatRec.innerRadius := 55;
- aSplatRec.outerRadius := aSplatRec.innerRadius + 12;
- aSplatRec.divisions := 30;
- aSplatRec.numSplats := 0;
- aSplatRec.rad1Start := 120;
- aSplatRec.rad1End := 55;
- aSplatRec.rad2Start := 40;
- aSplatRec.rad2End := 80;
- aSplatRec.thetaEndDegrees := 24.0;
- aSplatRec.theta := 0.0;
- aSplatRec.iterations := 12;
-
- SetRect(aSplatRec.statsBox, 1, 1, 120, 40);
- if RealFont(helvetica, 9) then {decide which font to use}
- aSplatRec.statsFont := helvetica
- else if RealFont(times, 9) then
- aSplatRec.statsFont := times
- else
- aSplatRec.statsFont := 0; {use System font}
-
- aSplatRec.maxPtsAllowed := kArraySiz;
- aSplatRec.numPtsSoFar := 0;
- error := MakeArray(aSplatRec.myBigArray);
-
- end; {InitSplat}
-
-
- {======================================================================================= }
- function NewBlnFltr (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
- label
- 10;
- var
- theRect: Rect;
- aHandle: handle;
- tipe, i: integer;
- myPt: point;
- KeyCh: Char;
- begin
- NewBlnFltr := FALSE;
- ItemHit := 0;
-
- GetMouse(myPt);
- {Let's see if we're over any of the ET rects}
- for i := 3 to name_ET do
- begin
- GetDItem(theDialog, i, tipe, aHandle, theRect); {get the handle}
- if PtInRect(myPt, theRect) then
- if tipe = EditText then
- begin
- SetCursor(gIbeam^^);
- goto 10;
- end;
- end;{for i}
- InitCursor; {make cursor Arrow if not over any ET rect}
- 10:
- case theEvent.what of
- keydown, autoKey:
- begin { trap key down events }
- KeyCh := Chr(BitAnd(theEvent.message, charCodeMask));
- if BitAnd(theEvent.modIFiers, CmdKey) <> 0 then {Cmd key is down}
- begin
- ItemHit := -1; {so the 'v','c', or 'x' won't be 'typed' into text box}
- if theEvent.what <> AutoKey then {we don't want to auto-key cmd-key equivs}
- case KeyCh of
- 'x', 'X':
- DlgCut(theDialog);
- 'c', 'C':
- DlgCopy(theDialog);
- 'v', 'V':
- DlgPaste(theDialog);
- '.':
- begin
- itemHit := 2;
- ClickButton(theDialog, Cancel);
- end;
- otherwise
- SysBeep(1); {not a valid Cmd-Key}
- end; {case KeyCh of}
- end {if Cmd-key is down}
- else
- begin
- ItemHit := 0;
- if KeyCh in [char(k_CR), char(k_Enter)] then
- ItemHit := Okay; { Button equivalents }
- end;
- end;{keydown, autokey}
- otherwise
- ;
- end;{case theEvent.what of}
-
- if ItemHit <> 0 then
- NewBlnFltr := True; { don't pass back to modal }
-
- if ItemHit = Okay then { Simulate clicking of the OK button }
- ClickButton(theDialog, Okay);
-
- end;
- {===========================================================================}
- procedure NewSplat (var aSplatRec: SplatRec);
- var
- OldPort: GrafPtr;
- NewBaloonDLOGPtr: dialogPtr;
- itemHit, Tipe, anInt: integer;
- hdl: Handle;
- theRect: rect;
- aStr: Str255;
- aReal: Real;
- finished: boolean;
-
- begin
- if aSplatRec.myBigArray <> nil then
- DisposeHandle(Handle(aSplatRec.myBigArray));
- InitSplat(aSplatRec);
- SetCursor(gwatch^^);
- GetPort(OldPort);
- NewBaloonDLOGPtr := GetNewDialog(NewBlnDLOG_ID, nil, Pointer(-1));
-
- CenterWindow(NewBaloonDLOGPtr);
- SetPort(NewBaloonDLOGPtr);
-
- GetDItem(NewBaloonDLOGPtr, innerRad_ET, tipe, hdl, theRect); {get the handle}
- aStr := Int2String(aSplatRec.innerRadius);
- SetIText(hdl, aStr);
-
- GetDItem(NewBaloonDLOGPtr, outerRad_ET, tipe, hdl, theRect); {get the handle}
- aStr := Int2String(aSplatRec.outerRadius);
- SetIText(hdl, aStr);
-
- GetDItem(NewBaloonDLOGPtr, divisions_ET, tipe, hdl, theRect); {get the handle}
- aStr := Int2String(aSplatRec.divisions);
- SetIText(hdl, aStr);
-
- GetDItem(NewBaloonDLOGPtr, name_ET, tipe, hdl, theRect); {get the handle}
- SetIText(hdl, aSplatRec.name);
-
- CheckABox(NewBaloonDLOGPtr, autoDraw_Chk, prefs.def_alwaysDraw);
- CheckABox(NewBaloonDLOGPtr, groBox_Chk, prefs.def_alwaysGrowBox);
- CheckABox(NewBaloonDLOGPtr, statsBox_Chk, prefs.def_alwaysStatBox);
-
- InitCursor;
- ShowWindow(NewBaloonDLOGPtr);
- DrawDefaultBtn(Okay, NewBaloonDLOGPtr); {Outline Default Button}
- SelIText(NewBaloonDLOGPtr, name_ET, 0, 32767); {pre-doubleclick the item}
-
- finished := FALSE;
-
- repeat
- begin
- ModalDialog(@NewBlnFltr, itemHit);{Wait until an item is hit}
- case itemHit of
- Okay:
- begin
- GetDItem(NewBaloonDLOGPtr, innerRad_ET, tipe, hdl, theRect); {get the handle}
- GetIText(hdl, aStr);
- aSplatRec.innerRadius := String2Int(aStr);
- GetDItem(NewBaloonDLOGPtr, outerRad_ET, tipe, hdl, theRect); {get the handle}
- GetIText(hdl, aStr);
- aSplatRec.outerRadius := String2Int(aStr);
- GetDItem(NewBaloonDLOGPtr, divisions_ET, tipe, hdl, theRect); {get the handle}
- GetIText(hdl, aStr);
- aSplatRec.divisions := String2Int(aStr);
- GetDItem(NewBaloonDLOGPtr, name_ET, tipe, hdl, theRect); {get the handle}
- GetIText(hdl, aStr);
- aSplatRec.name := aStr;
- finished := TRUE;
- end;
- Cancel:
- begin
- finished := TRUE;
- end;
- autoDraw_Chk:
- begin
- prefs.def_alwaysDraw := not prefs.def_alwaysDraw;
- CheckABox(NewBaloonDLOGPtr, autoDraw_Chk, prefs.def_alwaysDraw);
- end;
- groBox_Chk:
- begin
- prefs.def_alwaysGrowBox := not prefs.def_alwaysGrowBox;
- CheckABox(NewBaloonDLOGPtr, groBox_Chk, prefs.def_alwaysGrowBox);
- end;
- statsBox_Chk:
- begin
- prefs.def_alwaysStatBox := not prefs.def_alwaysStatBox;
- CheckABox(NewBaloonDLOGPtr, statsBox_Chk, prefs.def_alwaysStatBox);
- end;
- otherwise
- ;
- end{case}
- end;{begin}
- until finished;
-
- DisposDialog(NewBaloonDLOGPtr);{Flush the dialog out of memory}
- setPort(oldPort);
-
- end; {NewSplat}
-
- {======================================================================================= }
- {Converts any angle to its positive equivalent angle : 0<=angle<360;}
- {this function takes an angle (can be negative or positive and may}
- {be greater than 360) and returns a positive angle such that any}
- {negative angles are reevaluated into positive ones (e.g.,-15 degrees}
- {gets returned as +345 degrees and any angles over 360 are }
- {factored down, (e.g., 395 degrees becomes 35 degrees).}
- function MakeAngles (theAngle: real): real;
- var
- angleOffset: real;
- begin
- if theAngle < 0 then
- angleOffset := (round(theAngle / 360.0) - 1) * 360
- else
- angleOffset := round(theAngle / 360.0) * 360;
- MakeAngles := (theAngle - angleOffset);
- end;
-
-
- {======================================================================================= }
- procedure SetUpETs (MacroDLOGPtr: dialogPtr);
- var
- aStr: str255;
- tipe, anInt, index: integer;
- hdl: handle;
- theRect: rect;
- begin
-
- GetDItem(MacroDLOGPtr, rad1_Start_ET, tipe, hdl, theRect); {get the handle}
- aStr := Int2String(tempSplat.rad1Start);
- SetIText(hdl, aStr);
-
- GetDItem(MacroDLOGPtr, rad1_End_ET, tipe, hdl, theRect); {get the handle}
- aStr := Int2String(tempSplat.rad1End);
- SetIText(hdl, aStr);
-
- GetDItem(MacroDLOGPtr, rad2_Start_ET, tipe, hdl, theRect); {get the handle}
- aStr := Int2String(tempSplat.rad2Start);
- SetIText(hdl, aStr);
-
- GetDItem(MacroDLOGPtr, rad2_End_ET, tipe, hdl, theRect); {get the handle}
- aStr := Int2String(tempSplat.rad2End);
- SetIText(hdl, aStr);
-
- GetDItem(MacroDLOGPtr, theta_ET, tipe, hdl, theRect); {get the handle}
- aStr := Real2String(tempSplat.thetaEndDegrees);
- SetIText(hdl, aStr);
-
- GetDItem(MacroDLOGPtr, iterations_ET, tipe, hdl, theRect); {get the handle}
- aStr := Int2String(tempSplat.iterations);
- SetIText(hdl, aStr);
-
- GetDItem(MacroDLOGPtr, divs_ET, tipe, hdl, theRect); {get the handle}
- aStr := Int2String(tempSplat.divisions);
- SetIText(hdl, aStr);
-
-
- end;{SetUpETs}
-
- {======================================================================================= }
- {Get text and numbers out of the ETs, error check them, return TRUE if they were}
- {okay, FALSE if there was an error}
- function GetETs (MacroDLOGPtr: dialogPtr): boolean;
- var
- aStr: str255;
- tipe, anInt, index: integer;
- hdl: handle;
- theRect: rect;
- okay: boolean;
- aReal: real;
- function GetStr (theItem: integer): str255;
- var
- aStr2: str255;
- anInt: integer;
- begin
- GetDItem(MacroDLOGPtr, theItem, tipe, hdl, theRect); {get the handle}
- GetIText(hdl, aStr2);
- GetStr := (aStr2);
- end;
- begin
- GetETs := FALSE;
-
- aStr := GetStr(rad1_Start_ET);
- anInt := String2Int(aStr);
- tempSplat.rad1Start := abs(anInt);
-
- aStr := GetStr(rad1_End_ET);
- anInt := String2Int(aStr);
- tempSplat.rad1End := abs(anInt);
-
- aStr := GetStr(rad2_Start_ET);
- anInt := String2Int(aStr);
- tempSplat.rad2Start := abs(anInt);
-
- aStr := GetStr(rad2_End_ET);
- anInt := String2Int(aStr);
- tempSplat.rad2End := abs(anInt);
-
- aStr := GetStr(theta_ET);
- aReal := String2Real(aStr);
- tempSplat.thetaEndDegrees := MakeAngles(aReal);
-
- aStr := GetStr(iterations_ET);
- anInt := String2Int(aStr);
- tempSplat.iterations := abs(anInt);
-
- aStr := GetStr(divs_ET);
- anInt := String2Int(aStr);
- tempSplat.divisions := abs(anInt);
-
-
- GetETs := TRUE;
- end;{GetETs}
-
-
- {======================================================================================= }
- function MacroFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
- label
- 10;
- var
- tempRect: Rect;
- aHandle: handle;
- tipe, i: integer;
- myPt: point;
- KeyCh: Char;
- begin
- MacroFilter := FALSE;
- ItemHit := 0;
-
- GetMouse(myPt);
- {Let's see if we're over any of the ET rects}
- for i := rad1_Start_ET to iterations_ET do
- begin
- GetDItem(theDialog, i, tipe, aHandle, tempRect); {get the handle}
- if PtInRect(myPt, tempRect) and (tipe = EditText) then
- begin
- SetCursor(gIbeam^^);
- goto 10;
- end;{if PtInRect}
- end;{for i}
- InitCursor; {make cursor Arrow if not over any ET rect}
- 10:
- case theEvent.what of
- keydown, autoKey:
- begin { trap key down events }
- KeyCh := Chr(BitAnd(theEvent.message, charCodeMask));
- if BitAnd(theEvent.modIFiers, CmdKey) <> 0 then {Cmd key is down}
- begin
- ItemHit := -1; {so the 'v','c', or 'x' won't be 'typed' into text box}
- if theEvent.what <> AutoKey then {we don't want to auto-key cmd-key equivs}
- case KeyCh of
- 'x', 'X':
- DlgCut(theDialog);
- 'c', 'C':
- DlgCopy(theDialog);
- 'v', 'V':
- DlgPaste(theDialog);
- '.':
- begin
- itemHit := 2;
- ClickButton(theDialog, Cancel);
- end;
- otherwise
- SysBeep(1); {not a valid Cmd-Key}
- end; {case KeyCh of}
- end {if Cmd-key is down}
- else
- begin
- ItemHit := 0;
- if KeyCh in [char(k_CR), char(k_Enter)] then
- ItemHit := Okay; { Button equivalents }
- end;
- end;{keydown, autokey}
- otherwise
- ;
- end;{case theEvent.what of}
-
- if ItemHit <> 0 then
- MacroFilter := True; { don't pass back to modal }
-
- if ItemHit = Okay then { Simulate clicking of the OK button }
- ClickButton(theDialog, Okay);
-
- end;
-
- {======================================================================================= }
- function MakeMacro (var aSplat: SplatRec): boolean;
- var
- OldPort: GrafPtr;
- MacroDLOGPtr: dialogPtr;
- itemHit, Tipe, anInt: integer;
- aHdl: Handle;
- aRect: rect;
- aStr: Str255;
- aReal: Real;
- finished: boolean;
-
- begin
- SetCursor(gwatch^^);
- GetPort(OldPort);
- tempSplat := aSplat;
-
- MacroDLOGPtr := GetNewDialog(MacroDLOG_ID, nil, Pointer(-1));
-
- CenterWindow(MacroDLOGPtr);
- SetPort(MacroDLOGPtr);
- SetUpETs(MacroDLOGPtr);
-
- InitCursor;
- ShowWindow(MacroDLOGPtr);
- DrawDefaultBtn(Okay, MacroDLOGPtr); {Outline Default Button}
- SelIText(MacroDLOGPtr, rad1_Start_ET, 0, 32767); {pre-doubleclick the item}
-
- finished := FALSE;
-
- repeat
- begin
- ModalDialog(@MacroFilter, itemHit);{Wait until an item is hit}
- case itemHit of
- Okay:
- begin
- finished := GetETs(MacroDLOGPtr);{GetETs; if the ETs were okay then we 're done}
- if finished then
- begin
- aSplat := tempSplat;
- end;
- MakeMacro := TRUE;
- end;
- Cancel:
- begin
- finished := TRUE;
- MakeMacro := FALSE;
- end;
- otherwise
- ;
- end{case}
- end;{begin}
- until finished;
-
-
- DisposDialog(MacroDLOGPtr);{Flush the dialog out of memory}
- setPort(oldPort);
- end; {MakeMacro}
-
-
- {======================================================================================= }
- procedure DoMultiSplat (var aSplat: SplatRec);
- var
- curStep: integer;
- rad1Diff, rad2Diff, curTheta, thetaStep: real;
- begin
- tempSplat := aSplat;
- curTheta := 0.0;
- if tempSplat.thetaEndDegrees <> 0.0 then
- thetaStep := (twoPi * (tempSplat.thetaEndDegrees / 360.0)) / tempSplat.divisions
- else
- thetaStep := 0.0;
-
- with tempSplat do
- begin
- rad1Diff := (rad1End - rad1Start) / iterations;
- rad2Diff := (rad2End - rad2Start) / iterations;
- end;
-
- for curStep := 1 to tempSplat.iterations do
- begin
- tempSplat.innerRadius := round(tempSplat.innerRadius + rad1Diff);
- tempSplat.outerRadius := round(tempSplat.outerRadius + rad2Diff);
- DrawSplat(tempSplat);
- curTheta := curTheta + thetaStep;
- tempSplat.theta := curTheta;
- end;
- aSplat.numPtsSoFar := tempSplat.numPtsSoFar;
- {aSplat.numSplats := aSplat.numSplats + tempSplat.iterations;}
-
- end;
-
- {===========================================================================}
- procedure DrawChkBox (chkBoxRect: rect; onOff: Boolean; which: integer);
- var
- aRect: rect;
- begin
- aRect := chkBoxRect;
- { InsetRect(aRect, 2, 2);}
-
- EraseRect(aRect);
- FrameRect(aRect);
- if onOff then {if it's 'on', hilite it}
- begin
- MoveTo(aRect.left, aRect.top);
- LineTo(aRect.right - 1, aRect.bottom - 1);
- MoveTo(aRect.right - 1, aRect.top);
- LineTo(aRect.left, aRect.bottom - 1);
- end;
-
- MoveTo(chkBoxRect.right + 2, chkBoxRect.bottom);
- if (which = 1) then
- DrawString('Auto Draw')
- else if (which = 2) then
- DrawString('Auto Fill')
- end; {DrawChkBox}
-
-
- {===========================================================================}
- procedure HandleChkBox (chkBoxRect: rect; var onOff: Boolean; which: integer);
- var
- mouse: point;
- theRect: rect;
- mouseInBtn: boolean;
- begin
- mouseInBtn := FALSE;
-
- theRect := chkBoxRect;
- GetMouse(mouse);
-
- if not PtInRect(mouse, theRect) then
- exit(HandleChkBox);
-
- while StillDown do
- begin
- GetMouse(mouse);
- if PtInRect(mouse, theRect) then
- begin
- if (not mouseInBtn) then
- begin
- mouseInBtn := TRUE;
- onOff := not onOff;
- if (which = 1) then
- DrawChkBox(theRect, onOff, 1)
- else
- DrawChkBox(theRect, onOff, 2)
- end
- end
- else
- begin
- if (mouseInBtn) then
- begin
- mouseInBtn := FALSE;
- onOff := not onOff;
- if (which = 1) then
- DrawChkBox(theRect, onOff, 1)
- else
- DrawChkBox(theRect, onOff, 2)
- end;
- end;
-
- end;{while}
-
- end; {HandleChkBox}
-
-
- {===========================================================================}
- procedure VerticalLabel (aRect: Rect; aStr: str255);
- const
- center = 5; {center of label is 'center' pixels from left of rect}
- var
- numChars, leading, stringCenter, x, curVert: integer;
- fInfo: fontInfo;
- begin
- TextFont(helvetica);
- TextSize(9);
- TextFace([]);
- GetFontInfo(fInfo);
- leading := fInfo.ascent + fInfo.descent + fInfo.leading;
- stringCenter := aRect.left - center;
-
- foreColor(redColor); {oldStyle color}
- curVert := aRect.top + leading; {primed for first character}
- numChars := Length(aStr);
- for x := 1 to numChars do
- begin
- MoveTo(stringCenter - (CharWidth(aStr[x]) div 2), curVert);
- DrawChar(char(aStr[x]));
- curVert := curVert + leading;
- end;
- foreColor(blackColor); {oldStyle color}
- end; {VerticalLabel}
-
-
- {===========================================================================}
- function TrackButtonRect (therect: rect): boolean;
- {This function will hilite and unhilite the rectangle you pass it as the user moves}
- {the mouse in and out of the rectangle, and returns TRUE if the user released the}
- {mouse button while the mouse was inside the rectangle, and FALSE if he/she did}
- {not. This simulates the effect you get when you click on a standard button, and}
- {is useful to simulate "icon buttons". Make sure your GrafPtr is set first!}
- var
- mouseloc: point;
- wasin, check: boolean;
-
- begin
- TrackButtonRect := false;
- invertroundrect(therect, 8, 8);
- wasin := true;
- repeat
- getmouse(mouseLoc);
- check := ptinrect(mouseloc, therect);
- if check <> wasin then
- begin
- wasin := check;
- invertroundrect(therect, 8, 8);
- end;
- until not stilldown;
- if wasin = true then
- begin
- invertroundrect(therect, 8, 8);
- TrackButtonRect := true;
- end;
- end; {TrackButtonRect}
-
- {===========================================================================}
- procedure ShowScrlValue (theControl: ControlHandle);
- var
- aRect: Rect;
- aStr: Str255;
- anInt: integer;
- begin
- aRect := theControl^^.contrlRect;
- aRect.top := aRect.bottom + 2;
- aRect.bottom := aRect.top + 11;
- aRect.left := aRect.left - 4;
- aRect.right := aRect.right + 4;
-
- EraseRect(aRect);
- anInt := GetCtlValue(theControl);
- aStr := Int2String(anInt);
- anInt := StringWidth(aStr) div 2;
- MoveTo(aRect.left + ((aRect.right - aRect.left) div 2 - anInt), aRect.top + 11);
- DrawString(aStr);
-
- end; {ShowScrlValue}
-
-
- {===========================================================================}
- procedure TrackRadScroll (theControl: ControlHandle; partCode: Integer);
- var
- min, max, amount, startValue: Integer;
- up: Boolean;
- begin
- up := partcode in [inUpButton, inPageUp];
- min := GetCtlMin(theControl);
- max := GetCtlMax(theControl);
- startValue := GetCtlValue(theControl);
- if ((up and (startValue > min)) or ((not up) and (startValue < max))) and (partCode <> 0) then
- begin
- if up then
- amount := -1
- else
- amount := 1;
- if partCode in [inPageUp, inPagedown] then
- amount := round(amount * 5)
- else
- amount := round(amount * 1);
- SetCtlValue(theControl, amount + startValue);
- end;
- ShowScrlValue(theControl);
- end; {of TrackRadScroll}
-
-
- {===========================================================================}
- procedure HandleToolContent (where: Point);
- var
- whichControl, OptType, anInt: integer;
- aControl: ControlHandle;
- dummy: Boolean;
- begin
- SetPort(toolWindPtr);
- GlobalToLocal(where);
- if PtInRect(where, drawBtnRect) and (not curSplat.autoRedraw) then
- begin
- if TrackButtonRect(drawBtnRect) then
- if (not curSplat.autoFill) then
- DrawSplat(curSplat)
- else
- DrawFilledSplat(curSplat);
- SplatStatistics(curSplat);
- end
- else if PtInRect(where, fillBtnRect) and (not curSplat.autoFill) then
- begin
- if TrackButtonRect(fillBtnRect) then
- begin
- DrawFilledSplat(curSplat);
- SplatStatistics(curSplat);
- end
- end
- else if PtInRect(where, clearBtnRect) then
- if TrackButtonRect(clearBtnRect) then
- begin
- ClearAllSplats(curSplat)
- end
- else
- else if PtInRect(where, autoDrawChkBox) then
- begin
- HandleChkBox(autoDrawChkBox, curSplat.autoRedraw, 1);
- InvalRect(drawBtnRect);
- end
- else if PtInRect(where, autoFillChkBox) then
- begin
- HandleChkBox(autoFillChkBox, curSplat.autoFill, 2);
- InvalRect(fillBtnRect);
- end
- else
- begin
- whichControl := FindControl(where, toolWindPtr, aControl);
- if whichControl <> 0 then
- begin
-
- case whichControl of
- inUpButton, inDownButton, inPageUP, inPageDown:
- begin
- OptType := TrackControl(aControl, where, @TrackRadScroll);
- end;
- inThumb:
- begin
- OptType := TrackControl(aControl, where, nil);
- ShowScrlValue(aControl);
- end;
- end;{case whichControl of}
-
- anInt := GetCtlValue(aControl);
- if (aControl = innerRadScrl) and (anInt <> curSplat.innerRadius) then
- begin
- curSplat.innerRadius := anInt;
- if curSplat.autoFill then
- DrawFilledSplat(curSplat)
- else if curSplat.autoRedraw then
- DrawSplat(curSplat);
- end
- else if (aControl = outerRadScrl) and (anInt <> curSplat.outerRadius) then
- begin
- curSplat.outerRadius := anInt;
- if curSplat.autoFill then
- DrawFilledSplat(curSplat)
- else if curSplat.autoRedraw then
- DrawSplat(curSplat);
- end
- else if (aControl = divsScrl) and (anInt <> curSplat.divisions) then
- begin
- if odd(anInt) then {odd numbers in this value make the splat look dopey}
- anInt := anInt + 1;
- SetCtlValue(divsScrl, anInt);
- ShowScrlValue(divsScrl);
- curSplat.divisions := anInt;
-
- if curSplat.autoFill then
- DrawFilledSplat(curSplat)
- else if curSplat.autoRedraw then
- DrawSplat(curSplat);
- end;
-
-
- end; {if whichControl <> 0}
- end;{ else}
-
- end; {HandleToolContent}
-
- {===========================================================================}
- procedure ShowHideTools;
- var
- aStr: Str255;
- begin
- if showToolWind then
- begin
- ShowWindow(toolWindPtr);
- SelectWindow(toolWindPtr);
- SetPort(toolWindPtr);
- end
- else
- begin
- HideWindow(toolWindPtr);
- SelectWindow(drawWindPtr);
- SetPort(drawWindPtr);
- end;
- if showToolWind then
- aStr := 'Hide Tools'
- else
- aStr := 'Show Tools';
- MoveHHi(Handle(myMenus[GoodiesMenuID]));
- HLock(Handle(myMenus[GoodiesMenuID]));
- SetItem(myMenus[GoodiesMenuID], MenuHidePalette, aStr); {SetItem can move memory, as can CheckItem}
- HUnlock(Handle(myMenus[GoodiesMenuID])); {note that Enable & DisableItem do not more memory}
-
- refreshMenus := TRUE;
- end; {ShowHideTools}
-
-
- {===========================================================================}
- procedure RefreshToolWind;
- var
- aRect: Rect;
- anInt: integer;
- begin
-
- if (outerRadScrl <> nil) then
- SetCtlValue(outerRadScrl, curSplat.outerRadius);
- if (innerRadScrl <> nil) then
- SetCtlValue(innerRadScrl, curSplat.innerRadius);
- if (divsScrl <> nil) then
- SetCtlValue(divsScrl, curSplat.divisions);
-
- MoveTo(4, 13);
- foreColor(blueColor);
- LineTo(thePort^.portRect.right - 4, 13);
-
- MoveTo(4, 12);
- ForeColor(redColor);
- DrawString('SingleSplat Tools');
-
- DrawControls(toolWindPtr);
- ShowScrlValue(innerRadScrl);
- aRect := innerRadScrl^^.contrlRect;
- VerticalLabel(aRect, 'Radius 1');
-
- ShowScrlValue(outerRadScrl);
- aRect := outerRadScrl^^.contrlRect;
- VerticalLabel(aRect, 'Radius 2');
-
- ShowScrlValue(divsScrl);
- aRect := divsScrl^^.contrlRect;
- VerticalLabel(aRect, 'Divisions');
-
- anInt := StringWidth(drawBtnName) div 2;
- ClipRect(drawBtnRect);
- MoveTo(drawBtnRect.left + ((drawBtnRect.right - drawBtnRect.left) div 2 - anInt), drawBtnRect.top + 11);
- DrawString(drawBtnName);
- PenSize(1, 1);
- FrameRoundRect(drawBtnRect, 8, 8);
- if curSplat.autoRedraw then
- begin
- PenPat(gray);
- PenMode(patBic);
- PaintRoundRect(drawBtnRect, 8, 8);
- PenNormal;
- end;
-
- anInt := StringWidth(clearBtnName) div 2;
- ClipRect(clearBtnRect);
- MoveTo(clearBtnRect.left + ((clearBtnRect.right - clearBtnRect.left) div 2 - anInt), clearBtnRect.top + 11);
- DrawString(clearBtnName);
- PenSize(1, 1);
- FrameRoundRect(clearBtnRect, 8, 8);
-
- anInt := StringWidth(fillBtnName) div 2;
- ClipRect(fillBtnRect);
- MoveTo(fillBtnRect.left + ((fillBtnRect.right - fillBtnRect.left) div 2 - anInt), fillBtnRect.top + 11);
- DrawString(fillBtnName);
- PenSize(1, 1);
- FrameRoundRect(fillBtnRect, 8, 8);
-
- if curSplat.autoFill then
- begin
- PenPat(gray);
- PenMode(patBic);
- PaintRoundRect(fillBtnRect, 8, 8);
- PenNormal;
- end;
-
- PenNormal;
- ClipRect(thePort^.portRect);
-
- DrawChkBox(autoDrawChkBox, curSplat.autoRedraw, 1);
- DrawChkBox(autoFillChkBox, curSplat.autoFill, 2);
-
- end; {RefreshToolWind}
-
- {===========================================================================}
- procedure PutUpPaletteWIND;
- const
- scrollOffset = 12;
- var
- offSet: point;
- x: integer;
- begin
- if hasColorQD then
- begin
- paletteWindPtr := GetNewCWindow(1002, @paletteWindowStorage, pointer(-1));
- end
- else
- paletteWindPtr := GetNewWindow(1002, @paletteWindowStorage, WindowPtr(-1));
-
- showPaletteWind := TRUE;
-
- SetPort(paletteWindPtr);
- {offSet.h := DrawWindPtr^.portRect.left;}
- {offSet.v := DrawWindPtr^.portRect.top;}
- {LocalToGlobal(offSet);}
-
- {SetPort(paletteWindPtr);}
-
- {MoveWindow(paletteWindPtr, offSet.h - thePort^.portRect.right - 8, offSet.v - 8, TRUE);}
-
- {clippingRect := paletteWindPtr^.portRect;}
- {InsetRect(clippingRect, 1, 1);}
- {ClipRect(clippingRect);}
-
- ShowWindow(paletteWindPtr);
- end;
-
- {===========================================================================}
- procedure PutUpToolWIND;
- const
- scrollOffset = 12;
- var
- offSet: point;
- x: integer;
- begin
- if hasColorQD then
- begin
- toolWindPtr := GetNewCWindow(1001, @toolWindowStorage, pointer(-1));
- end
- else
- toolWindPtr := GetNewWindow(1001, @toolWindowStorage, WindowPtr(-1));
-
- showToolWind := TRUE;
-
- SetPort(DrawWindPtr);
- offSet.h := DrawWindPtr^.portRect.left;
- offSet.v := DrawWindPtr^.portRect.top;
- LocalToGlobal(offSet);
-
- SetPort(toolWindPtr);
-
- MoveWindow(toolWindPtr, offSet.h - thePort^.portRect.right - 5, offSet.v, TRUE);
- SizeWindow(toolWindPtr, toolWindPtr^.portRect.right, toolWindPtr^.portRect.bottom + 40, TRUE);
-
- clippingRect := toolWindPtr^.portRect;
- InsetRect(clippingRect, 1, 1);
- ClipRect(clippingRect);
-
- TextFont(helvetica);
- TextSize(9);
-
-
- innerRadScrl := GetNewControl(400, toolWindPtr);
- SizeControl(innerRadScrl, 16, 200);
- MoveControl(innerRadScrl, scrollOffset, 20);
- SetCtlValue(innerRadScrl, curSplat.innerRadius);
-
- x := innerRadScrl^^.contrlRect.right;
- outerRadScrl := GetNewControl(400, toolWindPtr);
- SizeControl(outerRadScrl, 16, 200);
- MoveControl(outerRadScrl, x + scrollOffset, 20);
- SetCtlValue(outerRadScrl, curSplat.outerRadius);
-
- x := outerRadScrl^^.contrlRect.right;
- divsScrl := GetNewControl(401, toolWindPtr);
- SizeControl(divsScrl, 16, 200);
- MoveControl(divsScrl, x + scrollOffset, 20);
- SetCtlValue(divsScrl, curSplat.divisions);
-
- {Let's put together our button's rectangle}
- drawBtnRect.left := 16;
- drawBtnRect.top := outerRadScrl^^.contrlRect.bottom + 18;
- drawBtnRect.right := drawBtnRect.left + StringWidth(drawBtnName) + 16;
- drawBtnRect.bottom := drawBtnRect.top + 16;
-
- autoDrawChkBox.left := drawBtnRect.left;
- autoDrawChkBox.top := drawBtnRect.bottom + 4;
- autoDrawChkBox.right := autoDrawChkBox.left + 8;
- autoDrawChkBox.bottom := autoDrawChkBox.top + 8;
-
- clearBtnRect := drawBtnRect;
- OffSetRect(clearBtnRect, 0, drawBtnRect.bottom - drawBtnRect.top + 16);
-
- autoFillChkBox.left := clearBtnRect.left;
- autoFillChkBox.top := clearBtnRect.bottom + 4;
- autoFillChkBox.right := autoFillChkBox.left + 8;
- autoFillChkBox.bottom := autoFillChkBox.top + 8;
-
- fillBtnRect := clearBtnRect;
- OffSetRect(fillBtnRect, 0, clearBtnRect.bottom - clearBtnRect.top + 16);
-
- ShowControl(innerRadScrl); {allow controls to be seen in public}
- ShowControl(outerRadScrl);
- ShowControl(divsScrl);
-
- ShowWindow(toolWindPtr);
- end;
-
- {======================================================================================= }
- procedure Panic;
- begin
- ExitToShell;
- end;
-
- {======================================================================================= }
- procedure InitMac;
-
- begin
- MaxApplZone;
- InitGraf(@thePort);
- InitFonts;
- InitWindows;
- InitCursor;
- InitMenus;
- TEInit;
- InitDialogs(@Panic);
- end;
- {======================================================================================= }
- procedure SysCheck;
- {: boolean;}
- label
- 99;
- const
- versRequested = 1;
- envBadVers = -5501;
- envVersTooBig = -5502;
- WNE_TRAP_NUM = $60;
- UNIMPL_TRAP_NUM = $9F;
- var
- str1, str2: str255;
- freeSpace: size;
- myHeapSpace: longint;
- err: OSErr;
- theWorld: sysEnvRec;
- GotColorQD, GotCoProcessor, runability: boolean;
- begin
- {SysCheck:= FALSE;}
- HasColorQD := FALSE;
- HasCoProcessor := FALSE;
- runability := FALSE;
-
- err := SysEnvirons(versRequested, theWorld);
-
- if err <> noErr then {error on SysEnvirons call? If so, }
- goto 99;
-
- {-1 = Macintosh with 64K Rom, -2 = Macintosh XL. We can't run on those.}
- if (theWorld.machineType = -1) or (theWorld.machineType = -2) then
- goto 99;
-
- if theWorld.hasFPU then
- HasCoProcessor := TRUE;
-
- if theWorld.HasColorQD then
- HasColorQD := TRUE;
-
- runability := TRUE;
- gWNEImplemented := (NGetTrapAddress(WNE_TRAP_NUM, ToolTrap) <> NGetTrapAddress(UNIMPL_TRAP_NUM, ToolTrap));
-
- 99:
- if not runability then
- DoMessage('**Sorry, this program', 'is unable to run', 'on this machine.', '')
- else
- ;
- {SysCheck := TRUE;}
-
- end;{SysCheck}
-
-
- {======================================================================================= }
- function GetMBarHeight: INTEGER;
- inline
- $3EB8, $0BAA; {smMoveWord2Stack, smMBarHeight; (from ScriptManager.p interface}
-
- {======================================================================================= }
- procedure InitGlobs;
- var
- aLong: longint;
- anInt: integer;
- begin
-
- GetDateTime(aLong); {make sure the numbers are randomized}
- randSeed := aLong; {seed the system's random generator}
-
- appResFileRef := CurResFile;
-
- savedMenuHeight := GetMBarHeight;
- currMenuHeight := savedMenuHeight;
-
- gIBeam := GetCursor(iBeamCursor);
- gWatch := GetCursor(watchCursor);
- gCrossHairs := GetCursor(crossCursor);
-
- refreshMenus := TRUE;
- errorFlag := FALSE;
- quitting := FALSE;
- finished := FALSE;
-
- graphPICHdl := nil;
-
- cursorIs := k_arrowCurs;
-
- end;{InitGlobs}
-
- {======================================================================================= }
- procedure MakeMenus;
- var
- index: Integer;
- begin
-
- for index := AppleMenuID to GoodiesMenuID do
- begin
- myMenus[index] := GetMenu(index);
- InsertMenu(myMenus[index], 0);
- end;
- AddResMenu(myMenus[AppleMenuID], 'DRVR');
-
-
- DisableItem(myMenus[EditMenuID], MenuUndo);
- EnableItem(myMenus[EditMenuID], MenuCut);
- EnableItem(myMenus[EditMenuID], MenuCopy);
- DisableItem(myMenus[EditMenuID], MenuPaste);
- DisableItem(myMenus[EditMenuID], MenuClear);
-
- refreshMenus := TRUE;
- end;{MakeMenus}
-
- {======================================================================================= }
- function IsOptionKeyDown: boolean;
- var
- keys: keyMap;
- begin
- GetKeys(keys);
- if BitTst(@keys, 61) then
- IsOptionKeyDown := TRUE
- else
- IsOptionKeyDown := FALSE;
- end;{IsOptionKeyDown}
-
-
- {======================================================================================= }
- function IsCommandKeyDown: boolean;
- var
- keys: keyMap;
- begin
- GetKeys(keys);
- if BitTst(@keys, 48) then
- IsCommandKeyDown := TRUE
- else
- IsCommandKeyDown := FALSE;
- end;{IsCommandKeyDown}
-
-
- {======================================================================================= }
- procedure HandleDiskEvt;
- const
- top = 80;
- left = 120;
- var
- highWord: integer;
- aPt: point;
- result: integer;
- begin
- highWord := HiWord(MainEvent.message);
- if highWord <> 0 then {the disk did not mount successfully}
- begin
- SetPt(aPt, top, left);
- DILoad; {load the disk-initialization package}
- result := DIBadMount(aPt, MainEvent.message);
- DIUnLoad; {Unload the disk-initialization package}
- end;
- end;{HandleDiskEvt}
-
- {===========================================================================}
- procedure AnUpDate;
- var
- ActivePort, whichWindow: WindowPtr;
- x, width: integer;
- begin
- { save the current port in 'activeport', set the port to the}
- { window needing updating, redraw the contents of the window,}
- { restore the port to the original 'activeport'}
- GetPort(ActivePort);
- whichWindow := WindowPtr(MainEvent.message);
-
- SetCursor(gWatch^^);
-
- if whichWindow = toolWindPtr then {drawing window}
- begin
- BeginUpdate(toolWindPtr);
- SelectWindow(toolWindPtr);
- SetPort(toolWindPtr);
- RefreshToolWind;
- ENDUpdate(toolWindPtr);
- end;
- if whichWindow = DrawWindPtr then {drawing window}
- begin
- SetPort(DrawWindPtr);
- InvalRect(thePort^.portRect);
- BeginUpdate(DrawWindPtr);
- if (curSplat.myBigArray = nil) or (curSplat.numPtsSoFar = 0) then
- begin
- if curSplat.autoRedraw then
- begin
- DrawSplat(curSplat);
- SplatStatistics(curSplat);
- end
- end
- else
- RefreshSplats(curSplat);
- FakeGrowIcon(DrawWindPtr, prefs.def_alwaysGrowBox);
- ENDUpdate(DrawWindPtr);
- if showToolWind then
- begin
- SelectWindow(toolWindPtr);
- SetPort(toolWindPtr);
- end;
- end;
-
- cursorIs := 0;
-
- SetPort(ActivePort);
- end;{}
-
-
-
- {======================================================================================= }
- procedure ClickInZoom (TheZoom: integer);
-
- var
- TheWindow: WindowPtr;
- begin
- TheWindow := FrontWindow;
- with TheWindow^ do
- if TrackBox(TheWindow, MainEvent.where, TheZoom) then
- begin
- EraseRect(TheWindow^.portRect);
- ZoomWindow(TheWindow, TheZoom, true);
- {• WSize(gWindow);•}
- end;{with…if}
- end;
-
-
- {======================================================================================= }
- procedure HandleContent (theWindow: WindowPtr; where: Point);
- var
- oldPort: GrafPtr;
- aBool: boolean;
- tempRect: rect;
- begin
- if thewindow = DrawWindPtr then
- begin
- GetPort(oldPort);
- SetPort(DrawWindPtr);
- GlobalToLocal(where);
- if (PtInRect(where, curSplat.statsBox)) then
- DragStatsRect(curSplat)
- else if (PtInRect(where, GrowIconRect)) then
- begin
- DoGrow(DrawWindPtr);
- EraseRect(thePort^.portRect);
- InvalRect(thePort^.portRect);
- with thePort^.portRect do
- begin
- curSplat.blnMiddle.h := (right - left) div 2;
- curSplat.blnMiddle.v := (bottom - top) div 2;
- end;
- tempRect := curSplat.statsBox; {is it still visible?}
- InsetRect(tempRect, 4, 4);
- if not SectRect(tempRect, thePort^.portRect, tempRect) then {well, it's not visible *enough*, so:}
- OffSetRect(curSplat.statsBox, -curSplat.statsBox.left + 2, -curSplat.statsBox.top + 2);
- end;
- SetPort(oldPort);
- end { if DrawWindPtr }
- else if thewindow = toolWindPtr then
- begin
- HandleToolContent(where);
-
- end;{ if toolWindPtr}
- end;
-
-
- {======================================================================================= }
- procedure HandleGoAway (theWindow: WindowPtr; where: Point);
- begin
- if TrackGoAway(theWindow, where) then
- begin
- if WindowPeek(theWindow)^.WindowKind = userKind then
- if theWindow = toolWindPtr then
- begin
- showToolWind := False;
- ShowHideTools;
- end
- else
- CloseDeskAcc(WindowPeek(theWindow)^.WindowKind)
- end;
- end;
-
-
- {======================================================================================= }
- procedure ClickInDA (theWindow: WindowPtr);
- begin
- SystemClick(MainEvent, theWindow);
- {• CheckMenus;•}
- end;{ClickInDA}
-
- {======================================================================================= }
- procedure ClickAppleMenu (TheItem: integer);
- var
- SavedPort: GrafPtr;
- TheName: Str255;
- aDLOGPtr: dialogPtr;
- OldPort: GrafPtr;
- itemHit: integer;
- begin
- case theItem of
- MenuAbout:
- begin
- InitCursor;
- cursorIs := k_arrowCurs;
- GetPort(OldPort);
- aDLOGPtr := GetNewDialog(1000, nil, Pointer(-1));
- CenterWindow(WindowPtr(aDLOGPtr));
- SetPort(aDLOGPtr);
- ShowWindow(aDLOGPtr);
- repeat
- ModalDialog(nil, itemHit);
- {Wait until an item is hit}
- until itemhit <> 0;
- {Flush the dialog out of memory}
- DisposDialog(aDLOGPtr);
- SetPort(oldPort);
- end;
- menuHelp:
- begin
- Help(256, 256);
- end;
- otherwise
- begin
- GetPort(SavedPort);
- GetItem(myMenus[AppleMenuID], TheItem, TheName);
- itemHit := OpenDeskAcc(TheName);
- SetPort(SavedPort);
- end; {otherwise}
- end;{case}
- end;{ClickAppleMenu}
-
- {======================================================================================= }
- procedure ClickFileMenu (TheItem: integer);
- var
- Dummy: boolean;
- begin
- case TheItem of
- MenuNew:
- NewSplat(curSplat);
- MenuQuit:
- begin
- quitting := TRUE;
- end;
- otherwise
- ;
- end; {case}
- if quitting = TRUE then
- finished := TRUE;
- end;{ClickFileMenu}
-
- {======================================================================================= }
- procedure DoCutCopy;
- var
- aLong, longSize: longint;
- resultStr: Str255;
- begin
- SplatPICT(curSplat, graphPICHdl);
- MoveHHi(Handle(graphPICHdl)); {get the PICT on the clipboard}
- HLock(Handle(graphPICHdl));
- aLong := ZeroScrap;
- if aLong = noErr then
- begin
- longSize := GetHandlesize(Handle(graphPICHdl));
- aLong := PutScrap(longSize, 'PICT', Ptr(graphPICHdl^));
- if aLong = noErr then
- aLong := UnloadScrap;
- end;
- if aLong <> noErr then
- SysBeep(1);
- HUnlock(Handle(graphPICHdl));
- KillPicture(graphPICHdl);
- graphPICHdl := nil;
- end; {DoCutCopy}
-
-
- {======================================================================================= }
- procedure ClickEditMenu (TheItem: integer);
- var
- aLong: longint;
- begin
- if not SystemEdit(TheItem - 1) then {okay, it's us, not a DA}
- case theItem of
- MenuUndo:
- ;
- MenuCopy, MenuCut:
- begin
- if ZeroScrap = noerr then
- begin
- aLong := ZeroScrap;
- if aLong = noErr then
- DoCutCopy
- else
- SysBeep(1);
- { MoveHHi(Handle(ourPictureHdl));}
- { HLock(Handle(ourPictureHdl));}
- { longSize := GetHandlesize(Handle(ourPictureHdl));}
- { aLong := PutScrap(longSize, 'PICT', Ptr(ourPictureHdl^));}
- { if aLong = noErr then}
- { aLong := UnloadScrap;}
- { HUnlock(Handle(ourPictureHdl));}
- end
- else
- SysBeep(1);
- end;
- MenuPaste:
- ;
- MenuClear:
- ;
- MenuPrefs:
- PrefsDLOG;
- otherwise
- ;
- end;{case}
- {• if (TheItem = MenuCut) or (TheItem = MenuCopy) then•}
- {• ClipChanged := true;•}
- end;{ClickEditMenu}
-
-
- {======================================================================================= }
- procedure ClickGoodiesMenu (TheItem: integer);
- var
- oldPort: GrafPtr;
- begin
- case theItem of
- MenuMultiSplat:
- if MakeMacro(curSplat) then
- begin
- DoMultiSplat(curSplat);
- SplatStatistics(curSplat);
- end;
- MenuClearSplats:
- ClearAllSplats(curSplat);
- MenuHidePalette:
- begin
- showToolWind := not showToolWind;
- ShowHideTools;
- end;
- otherwise
- ;
- end;{case}
- end;{ClickGoodiesMenu}
-
-
- {======================================================================================= }
- 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));
- GoodiesMenuID:
- ClickGoodiesMenu(LoWord(Selection));
- otherwise
- ;
- end;
- HiliteMenu(0); {turns off menu after action has taken place}
- end;{ClickInMenu}
-
- {======================================================================================= }
- procedure AClick;
-
- var
- theWindow: WindowPtr;
- where: Point;
- windowLoc: INTEGER;
-
- begin
-
- where := MainEvent.where;
- theWindow := WindowPtr(MainEvent.message);
- windowLoc := FindWindow(where, theWindow);
-
- case windowLoc of
- inDesk:
- ;
- InMenuBar:
- ClickInMenu;
- inSysWindow:
- ClickInDA(theWindow);
- InGrow:
- DoGrow(theWindow);
- InContent:
- HandleContent(theWindow, where);
- InGoAway:
- HandleGoAway(theWindow, where);
- InDrag:
- DoDrag(theWindow);
- inZoomIn:
- ClickInZoom(inZoomIn);
- inZoomOut:
- ClickInZoom(inZoomOut);
- end;
-
- end;
-
- {• AKey•}
- {• ----•}
- {• •}
- {• AKey first recovers the keycode from the gMainEvent.message•}
- {• field and converts it to a character. If the command key is•}
- {• down, the keystroke is a keyboard equivalent for a menu item,•}
- {• and is sent to the CommandKey routine. Otherwise, it is sent•}
- {• to the current edit record.•}
-
-
- {======================================================================================= }
- {• Commandkey•}
- {• ----------•}
- {• •}
- {• The Commandkey routine dispatches to the various menu routines•}
- {• according to the result of MenuKey. MenuKey converts a key•}
- {• into the corresponding menu Selection, and highlights the•}
- {• appropriate menu.•}
- procedure CommandKey (TheKey: char);
- var
- Selection: longint;
- begin
- { if (DrawNow) and (TheKey = '.') then}
- { begin}
- { StopDrawing;}
- { if userPrefs^^.continueRandom then}
- { userPrefs^^.continueRandom := FALSE;}
- { end}
- { else}
- Selection := MenuKey(TheKey);
- case HiWord(Selection) of
- AppleMenuID:
- ClickAppleMenu(LoWord(Selection));
- FileMenuID:
- ClickFileMenu(LoWord(Selection));
- EditMenuID:
- ClickEditMenu(LoWord(Selection));
- GoodiesMenuID:
- ClickGoodiesMenu(LoWord(Selection));
- otherwise
- ;
- end;
- HiliteMenu(0);
- end;{CommandKey}
-
- {======================================================================================= }
- procedure AKey;
- 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}
-
- {======================================================================================= }
- {***************************************************************}
- { DoActivate - Activate the selected window. }
- { }
- { This guy checks to see if we need to activate or deactivate. }
- { It then calls the appropriate routine. It is also responsible }
- { for the edit menu items. If we are becoming active, the items }
- { are deactivated, otherwise, activate them for the application }
- { or desk accessory that is becoming active. }
- {***************************************************************}
- procedure AnActivate;
- var
- itemIndex: Integer;
- Activate: Boolean;
- theWindow: WindowPtr;
- thePeek: WindowPeek;
- begin
- with MainEvent do
- begin
- theWindow := WindowPtr(message);
- Activate := BAnd(modifiers, activeFlag) <> 0;
- if Activate then
- begin
- SelectWindow(theWindow);
- end
- else
- begin
- HiliteWindow(theWindow, FALSE);
- end;
- end
- end; {AnActivate}
-
-
- {======================================================================================= }
- procedure MenuMaintenance;
- label
- 99;
- var
- x: integer;
- begin
-
- 99:
-
- DrawMenuBar;
- refreshMenus := FALSE;
- end;{MenuMaintenance}
-
-
- {======================================================================================= }
- procedure CursorMaintenance;
- var
- mouse: point;
- begin
-
- GetMouse(mouse);
-
- if PtInRgn(mouse, toolWindPtr^.visRgn) then
- begin
- if cursorIs <> k_crossCurs then
- begin
- SetCursor(gCrossHairs^^);
- cursorIs := k_crossCurs
- end
- end
- else if cursorIs <> k_arrowCurs then
- begin
- InitCursor;
- cursorIs := k_arrowCurs
- end;
- end;{CursorMaintenance}
-
-
- {======================================================================================= }
- procedure HandleNull;
- begin
- if refreshMenus then
- MenuMaintenance;
-
- CursorMaintenance;
-
- end;{HandleNull}
-
- {======================================================================================= }
- procedure MainLoop;
- var
- Dummy: boolean;
- whichDialog: DialogPtr;
- whichItem: integer;
- begin
-
- repeat
-
- if gWNEImplemented then
- Dummy := WaitNextEvent(everyEvent, MainEvent, 6, nil)
- else
- begin
- SystemTask;
- Dummy := GetNextEvent(everyEvent, MainEvent);
- end;
-
- { UnloadSeg(@GetPrefs); set it free--we may need the room!}
- HandleNull;
- if Dummy then
- case MainEvent.what of
- mouseDown:
- AClick;
- mouseUp:
- ;
- keyDown:
- AKey;
- keyUp:
- ;
- autoKey:
- AKey;
- updateEvt:
- AnUpDate;
- DiskEvt:
- HandleDiskEvt;
- activateEvt:
- AnActivate;
- nullEvent:
- ;
- otherwise
- ;
- end; {case}
-
- until finished;
-
- end;
-
- {======================================================================================= }
- {MAIN}
-
- begin
- InitMac;
-
- InitGlobs;
- SetUpPrefs(prefs);
- {if sysCheck then}
- {find out about our environment}
- {begin}
- sysCheck;
- MakeMenus;
- PutUpDrawingWIND;
- InitSplat(curSplat);
- PutUpToolWIND;
- {PutUpPaletteWIND;}
- SelectWindow(toolWindPtr);
- SetPort(toolWindPtr);
- MainLoop; {let's jam}
- {end;}
- RewritePrefs(prefs);
- end.