// base.h // // by John D. de Boer #define pi (3.141592653589793) #define twopi (2.0 * pi) #define pibytwo (pi / 2.0) #define fiftyseven (180.0 / pi) // Type definitions typedef unsigned char uchar; //typedef unsigned short ushort; typedef unsigned long ulong; typedef CGPoint point; typedef CGRect rect; typedef CGImageRef picture; // Integer utility functions bool range(SInt64 N, SInt64 RANGE); bool interval(SInt64 N, SInt64 LOWER, SInt64 UPPER); SInt64 mod(SInt64 N, SInt64 DIV); SInt64 gtr(SInt64 N, SInt64 LOWER); SInt64 lsr(SInt64 N, SInt64 UPPER); SInt64 between(SInt64 N, SInt64 LOWER, SInt64 UPPER); SInt64 abso(SInt64 X); // Random-number functions void setseed(double S); void randomise(void); double randfrac(void); long randzb(long N); int die(int D); int dice(int N, int D); bool pc(int P); bool onein(int N); // String conversion functions void pascalstring(const char *S, Str255 R); void str255to63(const Str255 A, Str63 B); void copypascal(const Str255 A, Str255 B); CFStringRef macstring(const char *S); // O-S interface routines void beep(void); void quit(void); // QuickDraw interface routines // The "grafvars" struct provides shorthand definition of several automatic // variables which are needed when switching graphics contexts. typedef struct { CGrafPtr port; // The current CGrafPtr and GDHandle must be saved before using GDHandle dev; // either SetPort() or SetGWorld(), and restored when done. PixMapHandle pixmap; // A PixMap must be locked during drawing and copying. } grafvars; void savegraf(grafvars *V); void restoregraf(const grafvars *V); void localtoglobal(WindowRef WP, Point *Pt); void globaltolocal(WindowRef WP, Point *Pt); int rectwidth(const Rect *R); int rectheight(const Rect *R); // Quartz points and rectangles bool equalpoints(point A, point B); void setrect(rect *Q, float X, float Y, float W, float H); void setlbrt(rect *Q, float L, float B, float R, float T); void cgrect(const Rect *R, CGRect *Q); void setpenrect(rect *R, point P, float Width); void setleft(rect *R, float L); void setright(rect *R, float Rt); void setbottom(rect *R, float B); void settop(rect *R, float T); void scalerect(rect *R, float F); void offsetrect(rect *R, float DX, float DY); void alignrect(rect *R, float L, float T); float left(rect R); float right(rect R); float top(rect R); float bottom(rect R); float width(rect R); float height(rect R); point middle(rect R); bool emptyrect(rect R); bool pointinrect(point P, rect R); void inset(rect *R, float F); point mappoint(point P, rect A, rect B); void centrerect(rect *R, point P); void stretchrect(rect *R, point P); void shrinkpointtorect(rect R, point *P); rect rectintersection(rect A, rect B); rect rectunion(rect A, rect B);