/*  File drawmap.h  */

#define MAX(a,b) ((a)>=(b) ? (a) : (b))
#define ABS(a) ((a)>=0 ? (a) : (-(a)))

#define NOABORT 1<<1                   /* used in printmap() */
#define U_ABORT 1<<2
#define P_ABORT 1<<3

#define PDERR_NOERR 0L

#define BITVAL(x,n)  ((x>>n)&1)
#define BITSETT(x,n)  (x | bitval[n])
#define BITCLEAR(x,n)  (x & (~bitval[n]))
#define BITSTORE(x,n,val)  ((val==0) ? (x=BITCLEAR(x,n)) : (x=BITSETT(x,n)))

#define SHADOW_DISP  4                 /* shadow displacement (pix) */

#define WC WINDOWCLOSE
#define WDP WINDOWDEPTH

#define IDCMPFLAGS (CLOSEWINDOW | MOUSEBUTTONS | MENUPICK)

#define WINFLAGS1 (SMART_REFRESH | ACTIVATE | BACKDROP)
#define WINFLAGS2 (BORDERLESS | REPORTMOUSE)

#define WWIDTH 640                     /* window width (pixels)       */
#define WHEIGHT 400                    /* window height (pixels)      */
#define VMODE (HIRES | LACE)           /* view mode                   */
#define DEPTH 4                        /* 16 colors => 4 bitplanes    */

#define CENTERX (WWIDTH/2)             /* place origin at center of   */
#define CENTERY (WHEIGHT/2)            /*   window                    */
#define NUMPTS 760                     /* max. no. points per area    */
#define MAXVAL 169600                  /* number of words in map      */
#define HFACTOR (WWIDTH/360.)          /* horizontal scale (pix/deg)  */
#define VFACTOR (WHEIGHT/180.)         /* vertical scale (pix/deg)    */
#define M_VFACTOR (WHEIGHT/4.87)       /* vertical scale for Mercator */
                                       /*   map (+/- 80 degrees lat.) */
#define ASP_RAT ((640./400.)*(188./260.)) /* screen aspect ratio      */
                                       /*  (max width / max hgt)      */
#define VRADIUS 160                    /* vertical radius of ellipse  */
                                       /*   (pixels)                  */
#define HRADIUS (short)(ASP_RAT * VRADIUS+0.5) /* horiz. radius (pix) */
#define ROWOFFSET (WWIDTH/8)           /* length of each screen row   */
                                       /*   in bytes                  */

#define OK     0                       /* result flags */
#define NOT_OK 1
#define ABORT  2

#define BLUE       0L                  /* default colors */
#define WHITE      1L
#define LT_VIO     2L
#define DK_VIO     3L
#define LT_GRN     4L
#define DK_GRN     5L
#define LT_BL      6L
#define DK_BL      7L
#define LT_YEL     8L
#define DK_YEL     9L
#define LT_PUR    10L
#define DK_PUR    11L
#define LT_RED    12L
#define DK_RED    13L
#define BLACK     14L
#define ORANGE    15L

UWORD mapcolors[] = {                  /* default color table            */
   0x006b, 0x0fff, 0x0caf, 0x095f,     /* blue, white, lt vio, dk vio    */
   0x00f0, 0x00a0, 0x00bf, 0x000f,     /* lt grn, dk grn, lt bl, dk bl   */
   0x0ff0, 0x0cc0, 0x0f0f, 0x0b0b,     /* lt yel, dk yel, lt pur, dk pur */
   0x0f44, 0x0c00, 0x0000, 0x0f90      /* lt red, dk red, black, orange  */
};

                                       /* number of colors in color table */
#define NUM_COLORS (sizeof(mapcolors)/sizeof(UWORD))

UWORD configcolors[NUM_COLORS];        /* color configuration */

char mapname[]      = "map.bin";       /* names of files containing    */
char mapname_trig[] = "map-trig.bin";  /*   map data and configuration */
char configfile[]   = "map.config";
char limitsfile[]   = "map.limits.bin";
char flatmapfile[]  = "map.flat.pic";

#define RE 6378.165                    /* radius of Earth (kilometers) */
#define VIEW_HEIGHT 300.               /* default height for orbital   */
                                       /*   view (km)                  */
#define MIN_HEIGHT 10.                 /* minimum view height (km)     */

double view_height, eta, etap, facp;   /* declare global constants */

#define PI    3.141592653589793        /* define constants */
#define PI2   (PI/2.)
#define TWOPI (2.*PI)
#define RAD   (PI/180.)
#define EXPAND_SCALE_FACTOR 2.0        /* for box zoom out option */

char fontname[] = "topaz.font";        /* screen font name */

struct TextAttr mapfont = {            /* screen font */
   (STRPTR) &fontname, 8, 0, 0
};

struct NewScreen mapscreen = {
   0,                                  /* left edge of screen     */
   0,                                  /* top edge of screen      */
   WWIDTH, WHEIGHT,                    /* width, height of screen */
   DEPTH,                              /* 16 colors               */
   1, 0,                               /* detail pen, block pen   */
   VMODE,                              /* view mode               */
   CUSTOMSCREEN,                       /* type of screen          */
   &mapfont,                           /* screen font             */
   (UBYTE *) "Drawmap v. 3.1, by Bryan Brown",  /* screen title   */
   NULL,
   NULL
};

struct NewWindow mapWindow = {
   0,                                  /* LeftEdge for window measured
                                          in pixels, at the current
                                          horizontal resolution, from the
                                          leftmost edge of the Screen   */
   0,                                  /* TopEdge for window is measured
                                          in lines from the top of the
                                          current Screen.               */
   WWIDTH, WHEIGHT,                    /* Width, Height of this window  */
   0,                                  /* DetailPen - what pen number is
                                          to be used to draw the borders
                                          of the window                 */
   1,                                  /* BlockPen - what pen number is
                                          to be used to draw system
                                          generated window gadgets      */
                                       /* (for DetailPen and BlockPen,
                                           the value of -1 says
                                           "use the default value")     */
   IDCMPFLAGS,                         /* IDCMP Flags                   */
   WINFLAGS1 | WINFLAGS2,              /* Window Flags                  */
   NULL,                               /* FirstGadget                   */
   NULL,                               /* CheckMark                     */
   NULL,                               /* window title                  */
   NULL,                               /* Pointer to Screen if not
                                          workbench                     */
   NULL,                               /* Pointer to BitMap if a
                                          SUPERBITMAP window            */
   10, 10,                             /* minimum width, minimum height */
   WWIDTH, WHEIGHT,                    /* maximum width, maximum height */
   CUSTOMSCREEN
};

UWORD arrow_data[] = {                 /* mouse pointer = arrow  */
   0x0000, 0x0000,

   0x8000, 0x0000,
   0xc000, 0x0000,
   0xe000, 0x0000,

   0xf000, 0x0000,

   0xe000, 0x0000,
   0x2000, 0x0000,
   0x0000, 0x0000,

   0x0000, 0x0000
};

#define ARROW_X_OFFSET -1
#define ARROW_Y_OFFSET  0
#define ARROW_SIZE      sizeof(arrow_data)

UWORD cross_data[] = {                 /* mouse pointer = cross */
   0x0000, 0x0000,

   0x0400, 0x0000,
   0x0400, 0x0000,
   0x0400, 0x0000,
   0x0400, 0x0000,
   0x0000, 0x0000,

   0xf1e0, 0x0000,

   0x0000, 0x0000,
   0x0400, 0x0000,
   0x0400, 0x0000,
   0x0400, 0x0000,
   0x0400, 0x0000,

   0x0000, 0x0000
};

#define CROSS_X_OFFSET -6
#define CROSS_Y_OFFSET -5
#define CROSS_SIZE     (sizeof(cross_data))

UWORD waiter_data[] = {                /* mouse pointer = 'wait' */
   0x0000, 0x0000,

   0x892e, 0x0000,
   0xaaa4, 0x0000,
   0xaba4, 0x0000,
   0x52a4, 0x0000,

   0x0000, 0x0000
};

#define WAITER_X_OFFSET -1
#define WAITER_Y_OFFSET  0
#define WAITER_SIZE      (sizeof(waiter_data))

UWORD transparent_data[] = {           /* mouse pointer = transparent */
   0x0000, 0x0000,

   0x0000, 0x0000,
   0x0000, 0x0000,
   0x0000, 0x0000,

   0x0000, 0x0000
};

#define TRANSPARENT_X_OFFSET 0
#define TRANSPARENT_Y_OFFSET 0
#define TRANSPARENT_SIZE     (sizeof(transparent_data))

#define NSEGS 1409                     /* number of segments */

struct Arc  {                          /* format for limits in */
   short lat_min, lat_max, lam_min, lam_max;
   int first, last;                    /*   each segment       */
};

struct Arc *seg;

#define SEG_LIST_SIZE (unsigned)(NSEGS*sizeof(struct Arc))
