/* graphics.h -
 *
 *     ********************************************************************* 
 *     * Copyright (C) 1985, 1990 Regents of the University of California. * 
 *     * 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.  The University of California        * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     *********************************************************************
 *
 * This file contains a bunch of macros that look like
 * normal procedure calls but really indirect through procedure
 * pointers in order to achieve graphics display independence.
 */

/* rcsid "$Header: /ufs/repository/magic/graphics/graphics.h,v 1.5 2006/07/08 19:05:30 fang Exp $" */

#ifndef	_GRAPHICS
#define	_GRAPHICS

#include "windows/windows_types.h"	/* for MagWindow forward declaration */
#include "misc/magic.h"
#include "utils/geometry_types.h"

/* Housekeeping and initialization routines */
extern bool (*GrInitPtr)(void);
extern void (*GrClosePtr)();
extern void (*GrTextSizePtr)();

/* 
 * Display painting and text routines 
 *
 *    You must call GrLock() before using these, and 
 *    call GrUnlock() afterwards.
 */
extern void (*GrLockPtr)();
extern void (*GrUnlockPtr)();
extern bool GrHaveLock();
extern void GrClipTo();
extern void GrClipBox();
extern void GrClipLine();
extern void GrClipTriangle(register Rect *r, Rect *c, bool clipped, int dir,
    int side, Point *points, int *np);
extern bool GrPutText();
extern void (*GrDrawGlyphPtr)();
extern void (*GrBitBltPtr)();
extern int  (*GrReadPixelPtr)();
extern void (*GrFlushPtr)();

/* Tablet routines */
extern void (*GrEnableTabletPtr)();
extern void (*GrDisableTabletPtr)();
extern void (*GrSetCursorPtr)();

/* graphics routines that are called in the same way for all displays */
extern bool GrLoadStyles();
extern bool GrLoadCursors();
extern bool GrSetDisplay();
extern void GrLabelSize();
extern void GrSetStuff();
extern void GrFastBox();
extern void GrGuessDisplayType();
extern void GrResetStyles(void);

/* external color map routines */
extern bool GrReadCMap(), GrSaveCMap();
extern void GrGetColor(), GrPutColor(), GrPutManyColors();
extern void (*GrSetCMapPtr)();
extern void GrResetCMap();

/* Routines for windows, called only if non-null.  See SUN160 driver for
 * details.
 */
extern int (*GrCreateWindowPtr)(MagWindow*);
					/* Passed a window just after it is
					 * created.
					 */
extern void (*GrDeleteWindowPtr)(MagWindow*);
					/* Passed a window just before it
					 * is destroyed.
					 */
extern void (*GrDamagedPtr)();		/* Called at a conventient time after
					 * receiving a SIG_WINCH signal.
					 */
extern void (*GrUpdateIconPtr)(); 	/* Adjust text on icon.
					 */
extern void (*GrConfigureWindowPtr)();	/* Called to reconfigure size/location
					 * of an existing window.
					 */
extern void (*GrOverWindowPtr)();	/* Raise window to top of stack.
					 */
extern void (*GrUnderWindowPtr)();	/* Lower window to bottom of stack.
					 */

/* Text output routine, should be called only by the textio module.  It is 
 * located here so that graphics drivers can do the text in a special way if 
 * they want to.  It is normally set to point to 'vfprintf', a varargs version
 * of fprintf.  If this doesn't exist (i.e. if the #define NOVARARGS is present)
 * then it normally points to fprintf.
 */
#ifndef	NO_VARARGS
extern int (*GrVfprintfPtr)();
#define GrVfprintf (*GrVfprintfPtr)
#else	/* NO_VARARGS */
extern int (*GrFprintfPtr)();
#define GrFprintf (*GrFprintfPtr)
#endif	/* NO_VARARGS */


/* Terminal state routine, called by the Textio module after it decides what
 * mode the terminal driver should be in.  This gives the graphics module a
 * chance to change it.  The pointer is normally NULL, in which case it is 
 * ignored.  */ 
extern void (*GrTermStatePtr)();


/* Routines called by the signals module just before Magic is stopped
 * (such as via ^Z) and just after it is resumed.
 */
extern void (*GrStopPtr)();
extern void (*GrResumePtr)();
#define GrStop	(*GrStopPtr)
#define GrResume (*GrResumePtr)


/* The size of the screen in screen coordinates */
extern Rect GrScreenRect;

/* The size of crosses (drawn for zero-size boxes), in pixels. */
extern Rect GrCrossRect;

/* Short names for styles */
extern int GrStyleNames[];

/*     
 * How wide to draw the select (highlight) box.  This is graphics device-  
 * dependent according to the way boundaries are treated on area fills.    
 */    
extern int GrBoxWidenFactor;

#ifndef lint

/* Constants for easy access */

#define GrLock (*GrLockPtr)
#define GrUnlock (*GrUnlockPtr)
#define GrInit (*GrInitPtr)
#define GrClose (*GrClosePtr)
#define GrSetCMap (*GrSetCMapPtr)
#define GrTextSize (*GrTextSizePtr)
#define GrDrawGlyph (*GrDrawGlyphPtr)
#define GrBitBlt (*GrBitBltPtr)
#define	GrReadPixel (*GrReadPixelPtr)
#define GrFlush (*GrFlushPtr)

#define GrEnableTablet (*GrEnableTabletPtr)
#define GrDisableTablet (*GrDisableTabletPtr)
#define GrGetCursorPos (*GrGetCursorPosPtr)
#define GrGetButtons (*GrGetButtonsPtr)
#define GrSetCursor (*GrSetCursorPtr)

#endif


/* 4 text sizes that are specified by the graphics driver, plus a 5th one.  
 * This last one is for systems that allow the user to specify a default font 
 * (such as a sun) -- on other systems it's size is decided by the driver.
 *
 * Note: 
 *    These must be in sequential, ascending order.
 */
#define GR_TEXT_SMALL	0
#define GR_TEXT_MEDIUM	1
#define GR_TEXT_LARGE	2
#define GR_TEXT_XLARGE	3
#define GR_TEXT_DEFAULT	4

/* Default cursor position -- used on startup and if we can't read the cursor */
#define GR_CURSOR_X	100
#define GR_CURSOR_Y	100

/* Special full-screen access for window manager only */
#define GR_LOCK_SCREEN	-1

#endif	/* _GRAPHICS */
