#ifdef SCCS
static char sccsid[]="@(#)pexdraw.h	1.18 Oki Electric Industry Co., Ltd. 93/05/24";
#endif
/*
	This file is under sccs control at Stardent in:
	/nfs/sole/root/sccs1.p/X11R5/mit/demos/pexdraw/s.pexdraw.h
*/
/*
 *			Copyright (c) 1992 by
 *			Oki Electric Industry Co., Ltd.
 *			All Rights Reserved
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and that
 * both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of Oki not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission. Oki
 * makes no representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 *
 * This supercedes the Stardent copyright granting the same rights that
 * appeared in the pdraw predecessor to pexdraw.
 *
 *************************************************************************
 *
 *                         P E X D R A W
 *
 *  A PEX drawing program based on PDRAW,
 *
 *   This is the header file.
 *
 *************************************************************************/

/*************************************************************************
 * typedefs.
 */
typedef struct _si {
  PEXCoord point;
  PEXVector  offset;
  PEXVector  scale;
  float  x_ang;
  float  y_ang;
  float  z_ang;
  float  delta_x;
  float  delta_y;
  float  delta_z;
  int    strux;
  int    wk_id;
  Display *dpy;
  int     stop;
  struct _si *next;
} SpinInfo;

typedef struct {
  int count;
  SpinInfo *listHead;
} SpinList;
/*
 * other business
 */
#if defined(SVR4_0) || defined(SVR4) || defined(hpux)
#include <string.h>
#define bcopy(b1,b2,len) memmove(b2, b1, len)
#define bzero(b,len) memset(b, 0, len)
#define bcmp(b1,b2,len) memcmp(b1, b2, len)
#endif

#ifndef MAXFLOAT
#define MAXFLOAT 10000000.0
#endif

#ifndef M_PI
#define M_PI            3.14159265358979323846
#endif

/*************************************************************************
 *
 *    F U N C T I O N    P R O T O T Y P E S
 *
 * I know that this is a pain for some people with lesser compilers, but 
 * these save time and energy.
 *
 */
int applyViewSet(
#if NeedFunctionPrototypes
		 int  /* viewNumber */
#endif
);

int getNumberWidgetValue(
#if NeedFunctionPrototypes
			 int  /* id */,
			 float * /* value */
#endif
);

int setNumberWidgetValue(
#if NeedFunctionPrototypes
			 int  /* id */,
			 double  /* value */
#endif
);

void InsertLineCmd(
#if NeedFunctionPrototypes
		   int  /* nCoords */,
		   PEXCoord * /* points */,
		   int  /* select */ 
#endif
);

void InsertMClipCmd(
#if NeedFunctionPrototypes
		   PEXCoord * /* points */,
		   int  /* select */ 
#endif
);

void ResizeWindow(
#if NeedFunctionPrototypes
		  Window  /* w */,
		  int  /* width */,
		  int  /* height */
#endif
);

void SelectSomething(
#if NeedFunctionPrototypes
		     long  /* strux */,
		     long  /* element */ 
#endif
);

void ClearSelection();

void DumpStrux(
#if NeedFunctionPrototypes
	       long  /* strux */,
	       long  /* element */, 
	       int  /* pretty */ 
#endif
);

void PrintElement(
#if NeedFunctionPrototypes
		  long  /* struxID */,
		  long  /* element */, 
		  long  /* ocType */,
		  long  /* eSize */,
		  char * /* elem_data */ 
#endif
);

PEXStructure InitStrux();

PEXLookupTable InitColorLUT(
#if NeedFunctionPrototypes
     Display * /* dpy */,
     Window    /* win */
#endif
);

void TranslateSelected(
#if NeedFunctionPrototypes
		       PEXCoord * /* points */ 
#endif
);

void DeleteSelected();

int DeleteStrux(
#if NeedFunctionPrototypes
		PEXStructure /* strux */
#endif
);

int ExecStrux(
#if NeedFunctionPrototypes
		PEXStructure /* strux */
#endif
);

void InsertTriStripCmd(
#if NeedFunctionPrototypes
		       int  /* nCoords */,
		       PEXCoord * /* points */, 
		       int  /* select */
#endif
);

int StartSpinning(
#if NeedFunctionPrototypes
		PEXStructure /* sidToStart */
#endif
);


int ApplySpin(
#if NeedFunctionPrototypes
		SpinInfo */* si */
#endif
);

int LoadSpinWidget(
#if NeedFunctionPrototypes
		SpinInfo */* si */
#endif
);

SpinInfo *GetSpinInfo(
#if NeedFunctionPrototypes
		PEXStructure /* sidToStart */
#endif
);

int manageSpin(
#if NeedFunctionPrototypes
	    char * /* client_data */
#endif
);

int oneSpin(
#if NeedFunctionPrototypes
	    char * /* client_data */
#endif
);

int StopSpinning(
#if NeedFunctionPrototypes
		PEXStructure /* sidToStop */
#endif
);

int LoadColorWidget(
#if NeedFunctionPrototypes
		    PEXStructure /* sidToStart */,
		    long  /* element */,
		    PEXColorRGB * /* rgb */
#endif
);


int ApplyColor(
#if NeedFunctionPrototypes
		    PEXStructure /* sidToStart */,
		    long  /* element */
#endif
);

int GetColorAttribute(
#if NeedFunctionPrototypes
		    PEXStructure /* sidToStart */,
		    long  /* element */,
		    PEXColorRGB * /* rgb */
#endif
);

int SetColorAttribute(
#if NeedFunctionPrototypes
		    PEXStructure /* sidToStart */,
		    long  /* element */,
		    PEXColorRGB * /* rgb */
#endif
);

GC CreateDynGC();

int GetXPointsFromSelected(
#if NeedFunctionPrototypes
			   int * /* count */,
			   XPoint ** /* points */
#endif
);

void DumpStruxCmd(
#if NeedFunctionPrototypes
		  int  /* pretty */
#endif
);

int InteriorStyleCmd(
#if NeedFunctionPrototypes
		     int  /* style */
#endif
);

int SurfaceInterpCmd(
#if NeedFunctionPrototypes
		     int  /* method */
#endif
);

int FacetCullingCmd(
#if NeedFunctionPrototypes
		    int  /* mode */
#endif
);

int ReflectionAttributesCmd(
#if NeedFunctionPrototypes
			    PEXReflectionAttributes * /* reflAttrs */
#endif
);

void AddWorkProc(
#if NeedFunctionPrototypes
		 int (*)()/* worker */,
		 char * /* info */
#endif
);

void InitUserInterface(
#if NeedFunctionPrototypes
		       int  /* argc */,
		       char ** /* argv */
#endif
);

void InitPEX();
void MainLoop();
void ApplySurfaceAttrs();

long Cubeoctahedron(
#if NeedFunctionPrototypes
		    PEXCoord * /* offset */,
		    double  /* radius */
#endif
);

int FindBetterPEXVisual(
#if NeedFunctionPrototypes
			Display * /* dpy */, 
			Window  /* w */, 
			int  /* type */, 
			Visual * /* visIn */,
			XVisualInfo * /* visBest */ 
#endif
);

Window
MakeBetterPEXWindow(
#if NeedFunctionPrototypes
			Display * /* dpy */, 
			Window  /* w */, 
		        XWindowAttributes * /* winAttrs */,
			XVisualInfo * /* visBest */ 
#endif
);

PEXLookupTable
MakeColorApprox(
#if NeedFunctionPrototypes
			Display * /* dpy */, 
			Window  /* w */, 
			XVisualInfo * /* visBest */ 
#endif
);

int GetStandardColormap(
#if NeedFunctionPrototypes
			Display * /* dpy */,
			XVisualInfo * /* visInfo */, 
			XStandardColormap * /* cmap */ 
#endif
);

int GetTextRect(
#if NeedFunctionPrototypes
		PEXOCData * /* OCData */,
		XID  /* strux */, 
		int  /* offset */, 
		PEXCoord ** /* rect */ 
#endif
);

int CheckImpDepInteger(
#if NeedFunctionPrototypes
     int /* impDepConst; */
#endif
);

int CheckEnumType(
#if NeedFunctionPrototypes
     int	 /* eType; */,
     int         /* eValue; */
#endif
);

/* static void MyPHIGSErrorHandler( Pint errnum, Pint funcnum, char *fname); */

void set_tool_pointer();
void set_tool_line();
void set_tool_view();
void set_tool_tristrip();
void set_tool_zoom();
void set_tool_mclip();

#define RADIAN(x) ((x)*(3.1415927 / 180.0))

typedef struct {
  long strux;
  long seqNo;
  PEXMatrix matrix;
} MCMatrix;

/*************************************************************************
 *
 *    G L O B A L    V A R I A B L E S
 *
 */

#ifdef DECL_GLOBALS
#define GLOBAL 
#define INIT(_a) =_a
#else
#define GLOBAL extern
#define INIT(_a)
#endif

/*************************************************************************
 * theRenderProcs -
 *
 * This global allows the pexdraw application to talk to either a Renderer
 * Resource or a PHIGS Workstation object.
 *
 * The procedures defined are:
 *  Init
 *  ReDraw
 *  MapXToMC
 *  MapMCToX
 *  SetView
 *  SetNPCToDC
 *  Post
 *  DeleteAll
 *  PickOne
 *  PickAll
 *  MapXToNPC
 *  ReconfigureWindow
 *  GetColorFromIndex
 *
 * The two sets of procedures are defines in wks.c & rdr.c
 */
typedef struct {
 XID (*Init)(
#if NeedNestedPrototypes
	     Display * /* dpy */, 
	     Window  /* w */,
	     PEXLookupTable  /* colorLUT */,
	     PEXLookupTable  /* lightLUT */,
	     PEXLookupTable  /* textLUT */,
	     PEXLookupTable  /* depthCueLUT */,
	     PEXLookupTable  /* colorApproxLUT */ 
#endif
);

 void (*ReDraw)();

 int  (*MapXToMC)(
#if NeedNestedPrototypes
		  MCMatrix * /* mc */,
		  int  /* inCount */,
		  XPoint * /* xPoints */,
		  PEXCoord ** /* mcPoints */ 
#endif
);

 int  (*MapMCToX)(
#if NeedNestedPrototypes
		  MCMatrix * /* mc */,
		  int  /* inCount */,
		  PEXCoord * /* mcPoints */,
		  XPoint ** /* xPoints */ 
#endif
);

 void (*SetView)(
#if NeedNestedPrototypes
		  int  /*  viewNumber */,
                  PEXViewEntry * /* view; */
#endif
 );

 void (*SetNPCToDC)(
#if NeedNestedPrototypes
		    PEXNPCSubVolume * /* volume */,
		    PEXViewport * /* viewport */ 
#endif
);

 void (*Post)(
#if NeedNestedPrototypes
	      long  /* struxid */
#endif
);

 void (*DeleteAll)();

 void (*PickOne)(
#if NeedNestedPrototypes
		 short  /* x */,
		 short  /* y */,
		 long * /* strux */,
		 int * /* element */ 
#endif
);

 void (*PickAll)(
#if NeedNestedPrototypes
		 short  /* x */,
		 short  /* y */,
		 short  /* x2 */,
		 short  /* y2 */, 
		 int * /* nFound */,
		 long ** /* struxArray */,
		 int ** /* elemArray */ 
#endif
);

 int  (*MapXToNPC)(
#if NeedNestedPrototypes
		   int  /* inCount */,
		   PEXCoord * /* points */ 
#endif
);

 int  (*ReconfigureWindow)(
#if NeedNestedPrototypes
			   long  /* w */,
			   int  /* width */,
			   int  /* height */
#endif
);

 int  (*GetColorFromIndex)(
#if NeedFunctionPrototypes
     int           /* cIndex; */,
     PEXColorRGB * /* rgb */
#endif
);

 void (*Unpost)(
#if NeedNestedPrototypes
	      long  /* struxid */
#endif
);

 } renderProcs;

GLOBAL renderProcs theRenderProcs;
GLOBAL int the51Flag;

GLOBAL XID theRenderObj INIT( 1);
GLOBAL MCMatrix theMCMatrix;

GLOBAL float theDepth INIT( 0.5);
GLOBAL PEXMatrix theMatOri, theMatMap;

GLOBAL SpinList theSpinList;
GLOBAL Display *theDisplay;
GLOBAL Window   theWindow;
GLOBAL int theWinHeight;

GLOBAL GC theDynGC INIT( NULL);
GLOBAL XID theFontLUT;
GLOBAL int theFontInitFlag INIT(0);
/*
 * if theSelectedElement == -1 then nothing is slected. These are
 * needed in fb.c
 *
 * index is only used for stretch, so far.
 */
GLOBAL long theSelectedStrux INIT(0);
GLOBAL long theSelectedElement INIT( -1);
GLOBAL long theSelectedIndex; /* which point in list */
GLOBAL long theNewStrux INIT(0);

GLOBAL int thedebug;
GLOBAL Window theWimpyWindow;

#define TOOL_POINTER 1
#define TOOL_LINE 2
#define TOOL_VIEW 3
#define TOOL_TRISTRIP 4
#define TOOL_ZOOM 5
#define TOOL_NURBC 6
#define TOOL_TEXT 7
#define TOOL_PGON 8
#define TOOL_CIRCLE 9
#define TOOL_MCLIP 9

GLOBAL int theCurrentTool;

GLOBAL int thePMDBFlag INIT(0);
GLOBAL int theForceWKSFlag INIT(0);

GLOBAL int theNoDitherFlag INIT(0);
GLOBAL int theSetEchoColorFlag INIT(0);
GLOBAL int theFF;

/* these are in NPC space to allow zooming */
GLOBAL float theWindowCenterX INIT(0.5);
GLOBAL float theWindowCenterY INIT(0.5);
GLOBAL float theWindowSize INIT(0.5);

GLOBAL int theScreen;

typedef int (*pexFileCmd)();
int ReadArchiveFile(
#if NeedFunctionPrototypes
	char * /*filename */
#endif
	);

int WriteArchiveFile(
#if NeedFunctionPrototypes
	char * /*filename */
#endif
	);

GLOBAL pexFileCmd theFileCmd INIT(ReadArchiveFile);

/*************************************************************************
 * input dispatch tables
 */
typedef void (*pexdrawHandler)();
pexdrawHandler thePressHandlerTable[3];
pexdrawHandler theMotionHandlerTable[3];
pexdrawHandler theReleaseHandlerTable[3];

/*************************************************************************
 * markers start at 70
 * 0 if marker
 * 1
 */
#define OCPRIMTAB_BASE 79
#define OCPRIMTAB_MAX  98

#define OCPRIM_MARKER 1
#define OCPRIM_LINE   2
#define OCPRIM_PGON   3
#define OCPRIM_TEXT   5


#ifdef DECL_GLOBALS
int myOCPrimType[] = {1,1,3,3,3,3,2,2,2,2,/* 89 */3,3,3,3,3,3,3,3,3,3};
#else
extern int myOCPrimType[];
#endif

typedef struct {
  unsigned int index;
  int path;
  double expansion;
  double spacing;
  double height;
  int halign;
  int valign;
} TextAttributes;

GLOBAL TextAttributes scratchTextAttrs;
GLOBAL PEXCoord textRect[4];

GLOBAL Window theTopWindow;
