home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-05 | 12.2 KB | 297 lines | [TEXT/PJMM] |
- {SATAddOnLib is a lib of the "Add-ons" that are easily put in a library (i.e. the ones without}
- {a "stubs" file). They include:}
- {}
- {GammaFade}
- {ProgressBar}
- {FaceFromPict}
- {SATToolbox}
- {Preferences}
-
- unit SATAddOnLib;
- interface
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Menus, ToolUtils, Resources, {}
- {$ENDC}
- SAT;
-
- {*** GammaFade ***}
- {Screen fading routines.}
-
- procedure FadeToBlack (ticks: Longint);
- procedure FadeFromBlack (ticks: Longint);
-
- {*** FaceFromPict/ICN/Text ***}
-
- {Load a face from PICTs, an ICN# or a string}
-
- function GetFaceFromPICT (colorPICTid, bwPICTid, maskPICTid: integer): FacePtr;
- function GetFaceFromPICTToRect (colorPICTid, bwPICTid, maskPICTid: integer; bounds: Rect): FacePtr;
- function SATGetFaceFromICN (id: Integer): FacePtr;
- function FaceFromText (myString: Str255; shadow: Integer): FacePtr;
-
- {*** Pixels ***}
-
- {Pixel array types and routines}
- type
- Pixel = record
- position: Point;
- data1, data2, data3, data4: SignedByte;
- end;
- Pixels = array[0..32000] of Pixel;
- PixelPtr = ^Pixels;
-
- procedure SATDrawPixels (pix: PixelPtr; var port: SATPort; value: Longint);
- procedure SATCopyPixels (pix: PixelPtr; var src, dest: SATPort);
- procedure SATDrawPixelsSafe (pix: PixelPtr; var port: SATPort; value: Longint);
- procedure SATCopyPixelsSafe (pix: PixelPtr; var src, dest: SATPort);
-
- {*** Preferences ***}
- {Create a preference file in the Preferences folder.}
-
- {Open the pref file if needed. Return the variables appFile and prefFile.}
- {If alwaysExternal is true, we always want a pref file in the system folder even if we can save in the application.}
- {Returns true if a new prefFile was created.}
- function SetPrefFile (prefsFileName: Str255; prefCreator, prefType: OSType; var appFile, prefFile: Integer; alwaysExternal: Boolean): Boolean;
-
- {Copy a resource from one file to another. Useful when SetPrefFile returns true!}
- function CopyResource (fromFile, toFile: integer; theResType: ResType; id: integer): OSErr;
-
- {*** ProgressBar ***}
- {An adaptive progress bar, adjusts itself automatically by remembering how much time the}
- {time-consuming operation took last time.}
-
- {Note: The full type declarations are removed to make this brief. See ProgressBar.p if you need them.}
- type
- ProgressBarColorPtr = Ptr;
- ProgressBarPtr = Ptr;
-
- function InitProgressBar (prefFile, resID: Integer; bounds: Rect; colors: ProgressBarColorPtr): ProgressBarPtr;
- function ProgressBarColors (frameRed, frameGreen, frameBlue, backRed, backGreen, backBlue, foreRed, foreGreen, foreBlue: Integer): ProgressBarColorPtr;
- function ProgressBarColorsRGB (frame, back, fore: RGBColor): ProgressBarColorPtr;
- procedure AdvanceProgressBar (thePB: ProgressBarPtr);
- procedure FinishProgressBar (thePB: ProgressBarPtr);
-
- {*** SATToolbox ***}
- {Some sprite handling routines, plus some math routines.}
-
- {The following switch should be true if your SAT.p has a fixedPointPosition field.}
- {MUST MATCH THE FLAG IN SATToolbox.p WHEN THE LIB WAS COMPILED!}
- {$setc _hasfixedpoint = true}
-
- type
- FixSpritePtr = ^FixSprite;
- FixSprite = record
- { Variables that you should change as appropriate }
- kind: Integer; { Used for identification. >0: friend. <0 foe }
- position: Point;
- hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
- {hotRect is set by you. hotRect2 is offset to the current position.}
- face: FacePtr; { Pointer to the Face (appearance) to be used. }
- task: ProcPtr; { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
- hitTask: ProcPtr; { Callback in collisions. }
- destructTask: ProcPtr; { Called when a sprite is disposed. (Usually nil.) }
- clip: RgnHandle; {Clip region to be used when this sprite is drawn.}
- { SAT variables that you shouldn't change: }
- oldpos: Point; {Used by RunSAT2}
- next, prev: SpritePtr; {You may change them in your own sorting routine, but be careful if you do.}
- r, oldr: Rect; {Rectangle telling where to draw. Avoid messing with it.}
- oldFace: FacePtr; {Used by RunSAT2}
- dirty: Boolean; {Used by RunSAT2}
- {Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default}
- {set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately}
- {after initializing (before any sprites are created)!}
- layer: integer; {For layer-sorting. When not used for that, use freely.}
- speed: Point; { Can be used for speed, but not necessarily. }
- mode: integer; { Usually used for different modes and/or to determine what image to show next. }
- fixedPointPosition: Point; {fixed point position}
- appLong: Longint; {Longint for free use by the application.}
- end;
-
- {Constants for separation/bounceoff between sprites}
- const
- kPushBoth = 0;
- kPushMe = 1;
- kPushHim = 2;
-
- (*Sprite utilities*)
- procedure MoveSprite (theSprite: SpritePtr);
- function KeepOnScreen (theSprite: SpritePtr): Boolean;
- {$ifc _hasfixedpoint}
- procedure MoveSpriteFixedPoint (theSprite: FixSpritePtr);
- function KeepOnScreenFixed (theSprite: FixSpritePtr): Boolean;
- {$endc}
- function KeepSpriteInRect (theSprite: SpritePtr; r: Rect): Boolean;
- function RectSeparate (theSprite: SpritePtr; anotherSprite: SpritePtr; push: Integer): Integer;
- procedure RectBounce (me, him: SpritePtr; push: Integer);
- procedure RectBounceFixed (me, him: FixSpritePtr; push: Integer);
- function PtInSpriteRgn (p: Point; theSprite: SpritePtr): Boolean;
- function RegionHit (theSprite: SpritePtr; anotherSprite: SpritePtr): Boolean;
- procedure SplitVector (v: Point; d: Point; var p: Point; var n: Point);
-
- function RegionBounce (s1, s2: FixSpritePtr; elasticity: Integer): Boolean;
- function RegionBounce2 (s1, s2: FixSpritePtr; elasticity: Integer): Boolean;
-
- {* Look-up table based fixed-point math operations. *}
- {Good for high-speed trig functions on 68k Macs. (Not tested too much yet.)}
-
- {Don't change these constants without recompiling the lib!}
- const
- kFixedPointShift = 4; {Number of fixed-point positions}
- kFixedOne = 16; {The "one" in the fixed-point system being used!}
-
- procedure InitTables; {Init not required}
- function SquareRoot (arg: Longint): Longint;
- function Sinus (arg: Longint): Longint;
- function Cosinus (arg: Longint): Longint;
- function VectorLength (vector: Point): Longint;
- function FPVectorLength (vector: Point): Longint;
- function ApproxVectorLength (vector: Point): Longint;
-
- {*** AlphaSAT ***}
-
- procedure SATFillAlphaRect (box: Rect; port: SATPort);
- procedure SATPaintAlphaRect (box: Rect; port: SATPort; value: Integer);
- procedure SATEraseAlphaRect (box: Rect; port: SATPort);
-
- {*** MiscGraphics ***}
-
- {* Some QuickDraw-related utilities: *}
-
- function MakeRGBColor (r, g, b: Integer): RGBColor;
- function RectWidth (r: Rect): integer;
- function RectHeight (r: Rect): integer;
-
- {Is smallR completely within bigR?}
- function RectInsideRect (smallR, bigR: Rect): Boolean;
- {Center the Rect s1R on s2R}
- function CenterRectInRect (s1R: Rect; s2R: Rect): Rect;
-
- {Draw a string centered withing the box.}
- procedure StringCenter (aString: Str255; box: Rect; truncate: Boolean; shadow: Integer);
-
- {Wipes for using as transitions after changing gSAT.offScreen.}
- procedure WipeIn (ticks: Longint);
- procedure WipeOut (ticks: Longint);
-
- {Copy the contents of one SATPort to another.}
- procedure CopyScreen (fromScreen, toScreen: SATPort);
-
- {Make a zoom animation}
- procedure ZoomRects (fromRect, toRect: Rect);
-
- {* A face manipulation routine. *}
-
- {Copy srcFace to destFace. If destFace is nil, a new face is created, otherwise srcFace is}
- {copied to the existing dstFace.}
- procedure SATDupFace (var destFace: FacePtr; srcFace: FacePtr);
-
- {* Pattern and cursor utilities. *}
-
- {These pattern utilities replaces the old ones in the SAT lib. These are much easier to use}
- {and just as compatible. The point with them is to have glue routies that make it really}
- {easy to stay compatible with all old Macs, even old MacPlusses!}
-
- function SATGetPattern (patID: Integer): PixPatHandle;
- procedure SATForePattern (pat: PixPatHandle);
- procedure SATBackPattern (pat: PixPatHandle);
- procedure SATFillRect (r: Rect; pat: PixPatHandle);
- procedure SATDisposePattern (pat: PixPatHandle);
-
- function SATGetCursor (id: Integer): CursHandle;
- procedure SATSetCursor (curs: CursHandle);
- procedure SATDisposeCursor (curs: CursHandle);
-
- {*** MySlotVBL ***}
-
- function InstallVBL (myGDevHand: GDHandle): OSErr;
- procedure RemoveVBL;
-
- function GetVBLValue: Longint;
- procedure SetVBLValue (value: Longint);
-
- {To synch SAT by VBL, install SATSynch as synch procedure.}
- {CAUTION: InstallVBL must have succeeded, or SATSynch will wait forever!}
- {Also, don't forget a RemoveVBL when you quit!}
- function SATSynch: Boolean;
-
- {*** SATSetDepth ***}
-
- function SATHasDepth (theDevice: GDHandle; desiredDepth: Integer): Boolean;
- function SATGetDepth (theDevice: GDHandle): Integer;
- function SATSetDepth (theDevice: GDHandle; desiredDepth: Integer): OSErr;
- function SATGetMode (theDevice: GDHandle): Boolean;
- function SATSetMode (theDevice: GDHandle; wantsColor: Boolean): OSErr;
- procedure SATRestoreDepth;
-
- {*** FastLoad ***}
-
- {For loading a large number of faces of equal size from a single PICT}
- {and a corresponding mask PICT. Load2DFaceArray is the most used call.}
- {BuildFaceInOffscreen is a low-level call that you only need if you want to}
- {load the faces in a different way, e.g. faces with different sizes.}
- {PeekFaceInOffscreen is a special-purpose call.}
- {Note that you can save much time and some memory by instructing}
- {these routines not to create any mask region, but if you do, they will NOT}
- {work with the clip region in sprites.}
-
- type
- FaceArr = array[0..1000] of Face;
- FaceArrPtr = ^FaceArr;
-
- {PeekFaceInOffscreen: A variation on BuildFaceInOffscreen, intended for special effects. It doesn't}
- {allocate the face data, but demands that the face already exists. Use it for making a sprite face}
- {peek into some image buffer other than its own private one.}
- procedure PeekFaceInOffscreen (var theFace: Face; imageOff, maskOff: SATPortPtr; bounds: Rect;{}
- needsRegion, makeRowList: Boolean);
-
- {BuildFaceInOffscreen: This is the heart of FastLoad. It builds a face pointing into some image of}
- {your choice.}
- procedure BuildFaceInOffscreen (var theFace: Face; imageOff, maskOff: SATPort; bounds: Rect;{}
- needsRegion, makeRowList: Boolean);
-
- {LoadFaceArray and Load2DFaceArray: High-level functions, for loading faces arrange in arrays}
- {in PICTs.}
- function LoadFaceArray (facesPictId, masksPictID: Integer; numFaces, sizeH, sizeV: Integer; {}
- needsRegion, makeRowList: Boolean): FaceArrPtr;
- function Load2DFaceArray (facesPictId, masksPictID: Integer; numFaces, sizeH, sizeV: Integer;{}
- facesPerRow: Integer; needsRegion, makeRowList: Boolean): FaceArrPtr;
-
- {*** SortingUtils ***}
-
- {Sprite sorting routines.}
-
- {But doesn't SAT sort automatically, unless you turn sorting off? Yes, it does, but there are}
- {times when you know more than SAT concerning how to sort. SAT does its best, but it can't}
- {know that you are moving around a whole pile of objects, or grab certain objects and need}
- {them brought to front immediately; SAT can't waste the time to do a complete sort for}
- {every frame.}
- {}
- {Use the SortOne routines if you have one sprite that needs to be perfectly sorted.}
- {}
- {If you want to sort the entire sprite list, use BucketSort. The actual sorting is extremely}
- {fast, but does not keep track of what sprites were moved.}
- {}
- {Note: If you use SATRun2, you must set the "dirty" flags of any sprites that overlap and change}
- {order, or you will get incorrect results! (SAT does this itself in the internal sorting system.)}
- {}
- {Note: Don't sort the sprite list from within a sprite handler! If you do, some sprite handler}
- {calls may be called severeal times or not at all. Manipulation of the sprite list should}
- {usually be done from the main loop.}
-
- {Unlinks a sprite from the sprite list.}
- procedure UnlinkSprite (sp: SpritePtr);
-
- {Puts a certain sprite at a sorted position according to layer.}
- procedure SortOne (sp: SpritePtr);
- {Same thing using position.v:}
- procedure SortOneV (sp: SpritePtr);
-
- {BucketSort is useful if you need to make sure the sprite list gets sorted at}
- {once - and it is really fast!}
- procedure BucketSort (minLayer, maxLayer: Integer);
- {Same thing using position.v:}
- procedure BucketSortV (minLayer, maxLayer: Integer);
-
- implementation
- end.