{$U-} {$R-} unit Utilities(20); interface uses MemTypes, QuickDraw, OSIntf, ToolIntf,MacPrint,FixMath,Graf3D, Globals; function min (a, b : integer) : integer; function max (a, b : integer) : integer; procedure SelectRectangle (P1 : Point; var dstRect : Rect); procedure UnZoom; procedure GetMatrixBounds(r : rect; var x1,x2,y1,y2 : integer); procedure ChangeWindow(myWindow : WindowPtr); implementation function min; {(a, b : integer) : integer} begin if a < b then min := a else min := b; end; function max; {(a, b : integer) : integer} begin if a > b then max := a else max := b; end; { The procedure below can be used to achieve a marquee effect } { that is , the rectangle is framed with a dashed line , where the dashes move . } { To use it set up a rectangle, then call MarqueeRect repeatedly to achieve the effect of motion . } { A generalization to MarqueeRgn for regions is straightforward .} procedure SelectRectangle; {(P1 : Point;} {var dstRect : Rect)} { return the rectangle of selection starting at P1 } var P2, P3 : Point; R : Rect; marqueePat : Pattern; clipRgn : RgnHandle; P : PenState; b : 0..255; i : integer; begin if zooming[windowIndex] then UnZoom; clipRgn := NewRgn; GetClip(clipRgn); ClipRect(plotRect[windowIndex]); StuffHex(@marqueePat, '0f87c3e11e3c78f0 '); GetPenState(p); PenMode(PatXor); GetMouse(P2); Pt2Rect(P1, P2, R); PenPat(marqueePat); FrameRect(R); { draw } repeat GetMouse(P2); { SYNCHs } FrameRect(R); { erase } Pt2Rect(P1, P2, R); {/* shift pattern up for next call */} b := marqueePat[0]; for i := 0 to 6 do marqueePat[i] := marqueePat[i+1]; marqueePat[7] := b; PenPat(marqueePat); {SYNCHs } FrameRect(R); { draw } until not Button; dstRect := R; marqueeRect[windowIndex] := dstRect; GetPenState(marqueeState[windowIndex]); SetPenState(p); SetClip(clipRgn); DisposeRgn(clipRgn); end; procedure UnZoom; {exits from zooming mode} var PState : PenState; PPtr : WindowPtr; begin if FrontWindow <> ContourWindow[windowIndex] then begin GetPort(PPtr); SetPort(ContourWindow[windowIndex]); end; GetPenState(PState); SetPenState(marqueeState[windowIndex]); FrameRect(marqueeRect[windowIndex]); DisableItem(GoodiesMenu,1); DisableItem(GoodiesMenu,2); DisableItem(PlotMenu,3); SetItem(FileMenu,4,'Print ...'); SetItem(EditMenu,4,'Copy'); selection[windowIndex] := false; InitCursor; SetPenState(PState); zooming[windowIndex] := false; zoomed[windowIndex] := false; if FrontWindow <> ContourWindow[windowIndex] then SetPort(PPtr); end; { ---------------------------------------------------------- } procedure GetMatrixBounds; {r : rect; var x1,x2,y1,y2 : integer)} begin with r do begin x1 := max(minDataX,left div currentGridSize); x2 := min(maxX[windowIndex]-1, round(right/currentGridSize+0.49)); y1 := max(minDataY, top div currentGridSize); y2 := min(maxY[windowIndex]-1, round(bottom/currentGridSize+0.49)); end; end; procedure ChangeWindow{(myWindow : WindowPtr)}; var i : integer; done : boolean; begin i := 1; done := false; while (i <= maxWindows) and not done do begin if (contourWindow[i] = myWindow) or (threeDWindow[i] = myWindow) then begin oldWindowIndex := windowIndex; gridSize[windowIndex] := currentGridSize; windowIndex := i; currentGridSize := gridSize[windowIndex]; done := true; end; i := i + 1; end; SelectWindow(myWindow); end; end. .