home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / SAT 2.4.0 / SAT / Add-ons / Lib ƒ / SATAddOnLib.p < prev   
Encoding:
Text File  |  1997-03-05  |  12.2 KB  |  297 lines  |  [TEXT/PJMM]

  1. {SATAddOnLib is a lib of the "Add-ons" that are easily put in a library (i.e. the ones without}
  2. {a "stubs" file). They include:}
  3. {}
  4. {GammaFade}
  5. {ProgressBar}
  6. {FaceFromPict}
  7. {SATToolbox}
  8. {Preferences}
  9.  
  10. unit SATAddOnLib;
  11. interface
  12.     uses
  13. {$IFC UNDEFINED THINK_PASCAL}
  14.         Types, QuickDraw, Menus, ToolUtils, Resources, {}
  15. {$ENDC}
  16.         SAT;
  17.  
  18. {*** GammaFade ***}
  19. {Screen fading routines.}
  20.  
  21.     procedure FadeToBlack (ticks: Longint);
  22.     procedure FadeFromBlack (ticks: Longint);
  23.  
  24. {*** FaceFromPict/ICN/Text ***}
  25.  
  26. {Load a face from PICTs, an ICN# or a string}
  27.  
  28.     function GetFaceFromPICT (colorPICTid, bwPICTid, maskPICTid: integer): FacePtr;
  29.     function GetFaceFromPICTToRect (colorPICTid, bwPICTid, maskPICTid: integer; bounds: Rect): FacePtr;
  30.     function SATGetFaceFromICN (id: Integer): FacePtr;
  31.     function FaceFromText (myString: Str255; shadow: Integer): FacePtr;
  32.  
  33. {*** Pixels ***}
  34.  
  35. {Pixel array types and routines}
  36.     type
  37.         Pixel = record
  38.                 position: Point;
  39.                 data1, data2, data3, data4: SignedByte;
  40.             end;
  41.         Pixels = array[0..32000] of Pixel;
  42.         PixelPtr = ^Pixels;
  43.  
  44.     procedure SATDrawPixels (pix: PixelPtr; var port: SATPort; value: Longint);
  45.     procedure SATCopyPixels (pix: PixelPtr; var src, dest: SATPort);
  46.     procedure SATDrawPixelsSafe (pix: PixelPtr; var port: SATPort; value: Longint);
  47.     procedure SATCopyPixelsSafe (pix: PixelPtr; var src, dest: SATPort);
  48.  
  49. {*** Preferences ***}
  50. {Create a preference file in the Preferences folder.}
  51.  
  52. {Open the pref file if needed. Return the variables appFile and prefFile.}
  53. {If alwaysExternal is true, we always want a pref file in the system folder even if we can save in the application.}
  54. {Returns true if a new prefFile was created.}
  55.     function SetPrefFile (prefsFileName: Str255; prefCreator, prefType: OSType; var appFile, prefFile: Integer; alwaysExternal: Boolean): Boolean;
  56.  
  57. {Copy a resource from one file to another. Useful when SetPrefFile returns true!}
  58.     function CopyResource (fromFile, toFile: integer; theResType: ResType; id: integer): OSErr;
  59.  
  60. {*** ProgressBar ***}
  61. {An adaptive progress bar, adjusts itself automatically by remembering how much time the}
  62. {time-consuming operation took last time.}
  63.  
  64. {Note: The full type declarations are removed to make this brief. See ProgressBar.p if you need them.}
  65.     type
  66.         ProgressBarColorPtr = Ptr;
  67.         ProgressBarPtr = Ptr;
  68.  
  69.     function InitProgressBar (prefFile, resID: Integer; bounds: Rect; colors: ProgressBarColorPtr): ProgressBarPtr;
  70.     function ProgressBarColors (frameRed, frameGreen, frameBlue, backRed, backGreen, backBlue, foreRed, foreGreen, foreBlue: Integer): ProgressBarColorPtr;
  71.     function ProgressBarColorsRGB (frame, back, fore: RGBColor): ProgressBarColorPtr;
  72.     procedure AdvanceProgressBar (thePB: ProgressBarPtr);
  73.     procedure FinishProgressBar (thePB: ProgressBarPtr);
  74.  
  75. {*** SATToolbox ***}
  76. {Some sprite handling routines, plus some math routines.}
  77.  
  78. {The following switch should be true if your SAT.p has a fixedPointPosition field.}
  79. {MUST MATCH THE FLAG IN SATToolbox.p WHEN THE LIB WAS COMPILED!}
  80. {$setc _hasfixedpoint = true}
  81.  
  82.     type
  83.         FixSpritePtr = ^FixSprite;
  84.         FixSprite = record
  85. { Variables that you should change as appropriate }
  86.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  87.                 position: Point;
  88.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  89.                                     {hotRect is set by you. hotRect2 is offset to the current position.}
  90.                 face: FacePtr;            { Pointer to the Face (appearance) to be used. }
  91.                 task: ProcPtr;            { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  92.                 hitTask: ProcPtr;        { Callback in collisions. }
  93.                 destructTask: ProcPtr;    { Called when a sprite is disposed. (Usually nil.) }
  94.                 clip: RgnHandle;            {Clip region to be used when this sprite is drawn.}
  95. { SAT variables that you shouldn't change: }
  96.                 oldpos: Point;                {Used by RunSAT2}
  97.                 next, prev: SpritePtr;    {You may change them in your own sorting routine, but be careful if you do.}
  98.                 r, oldr: Rect;                {Rectangle telling where to draw. Avoid messing with it.}
  99.                 oldFace: FacePtr;            {Used by RunSAT2}
  100.                 dirty: Boolean;            {Used by RunSAT2}
  101. {Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default}
  102. {set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately}
  103. {after initializing (before any sprites are created)!}
  104.                 layer: integer; {For layer-sorting. When not used for that, use freely.}
  105.                 speed: Point; { Can be used for speed, but not necessarily. }
  106.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  107.                 fixedPointPosition: Point; {fixed point position}
  108.                 appLong: Longint; {Longint for free use by the application.}
  109.             end;
  110.  
  111. {Constants for separation/bounceoff between sprites}
  112.     const
  113.         kPushBoth = 0;
  114.         kPushMe = 1;
  115.         kPushHim = 2;
  116.  
  117. (*Sprite utilities*)
  118.     procedure MoveSprite (theSprite: SpritePtr);
  119.     function KeepOnScreen (theSprite: SpritePtr): Boolean;
  120. {$ifc _hasfixedpoint}
  121.     procedure MoveSpriteFixedPoint (theSprite: FixSpritePtr);
  122.     function KeepOnScreenFixed (theSprite: FixSpritePtr): Boolean;
  123. {$endc}
  124.     function KeepSpriteInRect (theSprite: SpritePtr; r: Rect): Boolean;
  125.     function RectSeparate (theSprite: SpritePtr; anotherSprite: SpritePtr; push: Integer): Integer;
  126.     procedure RectBounce (me, him: SpritePtr; push: Integer);
  127.     procedure RectBounceFixed (me, him: FixSpritePtr; push: Integer);
  128.     function PtInSpriteRgn (p: Point; theSprite: SpritePtr): Boolean;
  129.     function RegionHit (theSprite: SpritePtr; anotherSprite: SpritePtr): Boolean;
  130.     procedure SplitVector (v: Point; d: Point; var p: Point; var n: Point);
  131.  
  132.     function RegionBounce (s1, s2: FixSpritePtr; elasticity: Integer): Boolean;
  133.     function RegionBounce2 (s1, s2: FixSpritePtr; elasticity: Integer): Boolean;
  134.  
  135. {* Look-up table based fixed-point math operations. *}
  136. {Good for high-speed trig functions on 68k Macs. (Not tested too much yet.)}
  137.  
  138. {Don't change these constants without recompiling the lib!}
  139.     const
  140.         kFixedPointShift = 4; {Number of fixed-point positions}
  141.         kFixedOne = 16; {The "one" in the fixed-point system being used!}
  142.  
  143.     procedure InitTables; {Init not required}
  144.     function SquareRoot (arg: Longint): Longint;
  145.     function Sinus (arg: Longint): Longint;
  146.     function Cosinus (arg: Longint): Longint;
  147.     function VectorLength (vector: Point): Longint;
  148.     function FPVectorLength (vector: Point): Longint;
  149.     function ApproxVectorLength (vector: Point): Longint;
  150.  
  151. {*** AlphaSAT ***}
  152.  
  153.     procedure SATFillAlphaRect (box: Rect; port: SATPort);
  154.     procedure SATPaintAlphaRect (box: Rect; port: SATPort; value: Integer);
  155.     procedure SATEraseAlphaRect (box: Rect; port: SATPort);
  156.  
  157. {*** MiscGraphics ***}
  158.  
  159. {* Some QuickDraw-related utilities: *}
  160.  
  161.     function MakeRGBColor (r, g, b: Integer): RGBColor;
  162.     function RectWidth (r: Rect): integer;
  163.     function RectHeight (r: Rect): integer;
  164.  
  165. {Is smallR completely within bigR?}
  166.     function RectInsideRect (smallR, bigR: Rect): Boolean;
  167. {Center the Rect s1R on s2R}
  168.     function CenterRectInRect (s1R: Rect; s2R: Rect): Rect;
  169.  
  170. {Draw a string centered withing the box.}
  171.     procedure StringCenter (aString: Str255; box: Rect; truncate: Boolean; shadow: Integer);
  172.  
  173. {Wipes for using as transitions after changing gSAT.offScreen.}
  174.     procedure WipeIn (ticks: Longint);
  175.     procedure WipeOut (ticks: Longint);
  176.  
  177. {Copy the contents of one SATPort to another.}
  178.     procedure CopyScreen (fromScreen, toScreen: SATPort);
  179.  
  180. {Make a zoom animation}
  181.     procedure ZoomRects (fromRect, toRect: Rect);
  182.  
  183. {* A face manipulation routine. *}
  184.  
  185. {Copy srcFace to destFace. If destFace is nil, a new face is created, otherwise srcFace is}
  186. {copied to the existing dstFace.}
  187.     procedure SATDupFace (var destFace: FacePtr; srcFace: FacePtr);
  188.  
  189. {* Pattern and cursor utilities. *}
  190.  
  191. {These pattern utilities replaces the old ones in the SAT lib. These are much easier to use}
  192. {and just as compatible. The point with them is to have glue routies that make it really}
  193. {easy to stay compatible with all old Macs, even old MacPlusses!}
  194.  
  195.     function SATGetPattern (patID: Integer): PixPatHandle;
  196.     procedure SATForePattern (pat: PixPatHandle);
  197.     procedure SATBackPattern (pat: PixPatHandle);
  198.     procedure SATFillRect (r: Rect; pat: PixPatHandle);
  199.     procedure SATDisposePattern (pat: PixPatHandle);
  200.  
  201.     function SATGetCursor (id: Integer): CursHandle;
  202.     procedure SATSetCursor (curs: CursHandle);
  203.     procedure SATDisposeCursor (curs: CursHandle);
  204.  
  205. {*** MySlotVBL ***}
  206.  
  207.     function InstallVBL (myGDevHand: GDHandle): OSErr;
  208.     procedure RemoveVBL;
  209.  
  210.     function GetVBLValue: Longint;
  211.     procedure SetVBLValue (value: Longint);
  212.  
  213. {To synch SAT by VBL, install SATSynch as synch procedure.}
  214. {CAUTION: InstallVBL must have succeeded, or SATSynch will wait forever!}
  215. {Also, don't forget a RemoveVBL when you quit!}
  216.     function SATSynch: Boolean;
  217.  
  218. {*** SATSetDepth ***}
  219.  
  220.     function SATHasDepth (theDevice: GDHandle; desiredDepth: Integer): Boolean;
  221.     function SATGetDepth (theDevice: GDHandle): Integer;
  222.     function SATSetDepth (theDevice: GDHandle; desiredDepth: Integer): OSErr;
  223.     function SATGetMode (theDevice: GDHandle): Boolean;
  224.     function SATSetMode (theDevice: GDHandle; wantsColor: Boolean): OSErr;
  225.     procedure SATRestoreDepth;
  226.  
  227. {*** FastLoad ***}
  228.  
  229. {For loading a large number of faces of equal size from a single PICT}
  230. {and a corresponding mask PICT. Load2DFaceArray is the most used call.}
  231. {BuildFaceInOffscreen is a low-level call that you only need if you want to}
  232. {load the faces in a different way, e.g. faces with different sizes.}
  233. {PeekFaceInOffscreen is a special-purpose call.}
  234. {Note that you can save much time and some memory by instructing}
  235. {these routines not to create any mask region, but if you do, they will NOT}
  236. {work with the clip region in sprites.}
  237.  
  238.     type
  239.         FaceArr = array[0..1000] of Face;
  240.         FaceArrPtr = ^FaceArr;
  241.  
  242. {PeekFaceInOffscreen: A variation on BuildFaceInOffscreen, intended for special effects. It doesn't}
  243. {allocate the face data, but demands that the face already exists. Use it for making a sprite face}
  244. {peek into some image buffer other than its own private one.}
  245.     procedure PeekFaceInOffscreen (var theFace: Face; imageOff, maskOff: SATPortPtr; bounds: Rect;{}
  246.                                     needsRegion, makeRowList: Boolean);
  247.  
  248. {BuildFaceInOffscreen: This is the heart of FastLoad. It builds a face pointing into some image of}
  249. {your choice.}
  250.     procedure BuildFaceInOffscreen (var theFace: Face; imageOff, maskOff: SATPort; bounds: Rect;{}
  251.                                     needsRegion, makeRowList: Boolean);
  252.  
  253. {LoadFaceArray and Load2DFaceArray: High-level functions, for loading faces arrange in arrays}
  254. {in PICTs.}
  255.     function LoadFaceArray (facesPictId, masksPictID: Integer; numFaces, sizeH, sizeV: Integer; {}
  256.                                     needsRegion, makeRowList: Boolean): FaceArrPtr;
  257.     function Load2DFaceArray (facesPictId, masksPictID: Integer; numFaces, sizeH, sizeV: Integer;{}
  258.                                     facesPerRow: Integer; needsRegion, makeRowList: Boolean): FaceArrPtr;
  259.  
  260. {*** SortingUtils ***}
  261.  
  262. {Sprite sorting routines.}
  263.  
  264. {But doesn't SAT sort automatically, unless you turn sorting off? Yes, it does, but there are}
  265. {times when you know more than SAT concerning how to sort. SAT does its best, but it can't}
  266. {know that you are moving around a whole pile of objects, or grab certain objects and need}
  267. {them brought to front immediately; SAT can't waste the time to do a complete sort for}
  268. {every frame.}
  269. {}
  270. {Use the SortOne routines if you have one sprite that needs to be perfectly sorted.}
  271. {}
  272. {If you want to sort the entire sprite list, use BucketSort. The actual sorting is extremely}
  273. {fast, but does not keep track of what sprites were moved.}
  274. {}
  275. {Note: If you use SATRun2, you must set the "dirty" flags of any sprites that overlap and change}
  276. {order, or you will get incorrect results! (SAT does this itself in the internal sorting system.)}
  277. {}
  278. {Note: Don't sort the sprite list from within a sprite handler! If you do, some sprite handler}
  279. {calls may be called severeal times or not at all. Manipulation of the sprite list should}
  280. {usually be done from the main loop.}
  281.  
  282. {Unlinks a sprite from the sprite list.}
  283.     procedure UnlinkSprite (sp: SpritePtr);
  284.  
  285. {Puts a certain sprite at a sorted position according to layer.}
  286.     procedure SortOne (sp: SpritePtr);
  287. {Same thing using position.v:}
  288.     procedure SortOneV (sp: SpritePtr);
  289.  
  290. {BucketSort is useful if you need to make sure the sprite list gets sorted at}
  291. {once - and it is really fast!}
  292.     procedure BucketSort (minLayer, maxLayer: Integer);
  293. {Same thing using position.v:}
  294.     procedure BucketSortV (minLayer, maxLayer: Integer);
  295.  
  296. implementation
  297. end.