1 /**
2  ** grx20.h ---- GRX 2.x API functions and data structure declarations
3  **
4  ** Copyright (c) 1995 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
5  ** [e-mail: csaba@vuse.vanderbilt.edu]
6  **
7  ** This file is part of the GRX graphics library.
8  **
9  ** The GRX graphics library is free software; you can redistribute it
10  ** and/or modify it under some conditions; see the "copying.grx" file
11  ** for details.
12  **
13  ** This library is distributed in the hope that it will be useful,
14  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  **
17  **/
18 
19 #ifndef __GRX20_H_INCLUDED__
20 #define __GRX20_H_INCLUDED__
21 
22 /* ================================================================== */
23 /*       COMPILER -- CPU -- SYSTEM SPECIFIC VERSION STUFF             */
24 /* ================================================================== */
25 
26 /* Version of GRX API
27 **
28 ** usage:
29 **    #include <grx20.h>
30 **    #ifndef GRX_VERSION_API
31 **    #ifdef  GRX_VERSION
32 **    #define GRX_VERSION_API 0x0200
33 **    #else
34 **    #define GRX_VERSION_API 0x0103
35 **    #endif
36 **    #endif
37 */
38 #define GRX_VERSION_API 0x0249
39 
40 /* these are the supported configurations: */
41 #define GRX_VERSION_TCC_8086_DOS        1       /* also works with BCC */
42 #define GRX_VERSION_GCC_386_GO32        2       /* deprecated, don't use it */
43 #define GRX_VERSION_GCC_386_DJGPP       2       /* DJGPP v2 */
44 #define GRX_VERSION_GCC_386_LINUX       3       /* the real stuff */
45 #define GRX_VERSION_GENERIC_X11         4       /* generic X11 version */
46 #define GRX_VERSION_WATCOM_DOS4GW       5       /* GS - Watcom C++ 11.0 32 Bit */
47 /*#define GRX_VERSION_WATCOM_REAL_MODE  6*/     /* GS - Watcom C++ 11.0 16 Bit - TODO! */
48 #define GRX_VERSION_GCC_386_WIN32       7       /* WIN32 using Mingw32 */
49 #define GRX_VERSION_MSC_386_WIN32       8       /* WIN32 using MS-VC */
50 #define GRX_VERSION_GCC_386_CYG32       9       /* WIN32 using CYGWIN */
51 #define GRX_VERSION_GCC_386_X11        10       /* X11 version */
52 #define GRX_VERSION_GCC_X86_64_LINUX   11       /* console framebuffer 64 */
53 #define GRX_VERSION_GCC_X86_64_X11     12       /* X11 version 64 */
54 
55 #define GRXMain main  /* From the 2.4.6 version We don't need this */
56                       /* anymore, but it is here for previous apps */
57 
58 #ifdef  __TURBOC__
59 #define GRX_VERSION     GRX_VERSION_TCC_8086_DOS
60 #endif
61 
62 #ifdef  __GNUC__
63 #ifdef  __DJGPP__
64 #define GRX_VERSION     GRX_VERSION_GCC_386_DJGPP
65 #endif
66 #if defined(__XWIN__)
67 #if defined(__linux__) && defined(__i386__)
68 #define GRX_VERSION     GRX_VERSION_GCC_386_X11
69 #endif
70 #if defined(__linux__) && defined(__x86_64__)
71 #define GRX_VERSION     GRX_VERSION_GCC_X86_64_X11
72 #endif
73 #else
74 #if defined(__linux__) && defined(__i386__)
75 #define GRX_VERSION     GRX_VERSION_GCC_386_LINUX
76 #endif
77 #if defined(__linux__) && defined(__x86_64__)
78 #define GRX_VERSION     GRX_VERSION_GCC_X86_64_LINUX
79 #endif
80 #endif
81 #ifdef  __WIN32__
82 #define GRX_VERSION     GRX_VERSION_GCC_386_WIN32
83 #endif
84 #ifdef __CYGWIN32__
85 #define GRX_VERSION     GRX_VERSION_GCC_386_CYG32
86 #define __WIN32__
87 #endif
88 #endif /* __GNUC__ */
89 
90 #ifdef  __WATCOMC__     /* GS - Watcom C++ 11.0 */
91 #ifdef  __DOS__
92 #ifdef  __386__
93 #define GRX_VERSION     GRX_VERSION_WATCOM_DOS4GW
94 #else
95 /* #define GRX_VERSION GRX_VERSION_WATCOM_REAL_MODE  - I haven't tested GRX in 16 bit*/
96 #endif /* __386__ */
97 #endif /* __DOS__ */
98 #endif /* __WATCOMC__ */
99 
100 #ifdef _MSC_VER
101 #ifdef _WIN32
102 #ifdef _M_IX86
103 #define GRX_VERSION     GRX_VERSION_MSC_386_WIN32
104 #if !defined(__WIN32__)
105 #define __WIN32__ _WIN32
106 #endif
107 #endif /* _M_IX86  */
108 #endif /* _WIN32   */
109 #endif /* _MSC_VER */
110 
111 #ifndef GRX_VERSION
112 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(_AIX)
113 #define GRX_VERSION     GRX_VERSION_GENERIC_X11
114 #endif
115 #endif
116 
117 #ifndef GRX_VERSION
118 #error  GRX is not supported on your COMPILER/CPU/OPERATING SYSTEM!
119 #endif
120 
121 #if (GRX_VERSION==GRX_VERSION_WATCOM_DOS4GW)
122 #define near
123 #define far
124 #define huge
125 #endif
126 
127 #if !defined(__TURBOC__) && (GRX_VERSION!=GRX_VERSION_WATCOM_REAL_MODE)
128 #ifndef near            /* get rid of these stupid keywords */
129 #define near
130 #endif
131 #ifndef far
132 #define far
133 #endif
134 #ifndef huge
135 #define huge
136 #endif
137 #endif
138 
139 #ifdef __cplusplus
140 extern "C" {
141 #endif
142 
143 /* a couple of forward declarations ... */
144 typedef struct _GR_frameDriver  GrFrameDriver;
145 typedef struct _GR_videoDriver  GrVideoDriver;
146 typedef struct _GR_videoMode    GrVideoMode;
147 typedef struct _GR_videoModeExt GrVideoModeExt;
148 typedef struct _GR_frame        GrFrame;
149 typedef struct _GR_context      GrContext;
150 
151 /* ================================================================== */
152 /*                        SYSTEM TYPE DEF's                           */
153 /* ================================================================== */
154 
155 /* need unsigned 32 bit integer for color stuff */
156 #if defined(__TURBOC__) && defined(__MSDOS__)
157 /* TCC && BCC are 16 bit compilers */
158 typedef unsigned long int GrColor;
159 #else
160 /* all other platforms (GCC on i386 or x86_64 and ALPHA) have 32 bit ints */
161 typedef unsigned int GrColor;
162 #endif
163 
164 /* ================================================================== */
165 /*                           MODE SETTING                             */
166 /* ================================================================== */
167 
168 /*
169  * available video modes (for 'GrSetMode')
170  */
171 typedef enum _GR_graphicsModes {
172 	GR_unknown_mode = (-1),             /* initial state */
173 	/* ============= modes which clear the video memory ============= */
174 	GR_80_25_text = 0,                  /* Extra parameters for GrSetMode: */
175 	GR_default_text,
176 	GR_width_height_text,               /* int w,int h */
177 	GR_biggest_text,
178 	GR_320_200_graphics,
179 	GR_default_graphics,
180 	GR_width_height_graphics,           /* int w,int h */
181 	GR_biggest_noninterlaced_graphics,
182 	GR_biggest_graphics,
183 	GR_width_height_color_graphics,     /* int w,int h,GrColor nc */
184 	GR_width_height_color_text,         /* int w,int h,GrColor nc */
185 	GR_custom_graphics,                 /* int w,int h,GrColor nc,int vx,int vy */
186 	/* ==== equivalent modes which do not clear the video memory ==== */
187 	GR_NC_80_25_text,
188 	GR_NC_default_text,
189 	GR_NC_width_height_text,            /* int w,int h */
190 	GR_NC_biggest_text,
191 	GR_NC_320_200_graphics,
192 	GR_NC_default_graphics,
193 	GR_NC_width_height_graphics,        /* int w,int h */
194 	GR_NC_biggest_noninterlaced_graphics,
195 	GR_NC_biggest_graphics,
196 	GR_NC_width_height_color_graphics,  /* int w,int h,GrColor nc */
197 	GR_NC_width_height_color_text,      /* int w,int h,GrColor nc */
198 	GR_NC_custom_graphics,              /* int w,int h,GrColor nc,int vx,int vy */
199 	/* ==== plane instead of color based modes ==== */
200 	/* colors = 1 << bpp  >>> resort enum for GRX3 <<< */
201 	GR_width_height_bpp_graphics,       /* int w,int h,int bpp */
202 	GR_width_height_bpp_text,           /* int w,int h,int bpp */
203 	GR_custom_bpp_graphics,             /* int w,int h,int bpp,int vx,int vy */
204 	GR_NC_width_height_bpp_graphics,    /* int w,int h,int bpp */
205 	GR_NC_width_height_bpp_text,        /* int w,int h,int bpp */
206 	GR_NC_custom_bpp_graphics           /* int w,int h,int bpp,int vx,int vy */
207 } GrGraphicsMode;
208 
209 /*
210  * Available frame modes (video memory layouts)
211  */
212 typedef enum _GR_frameModes {
213 	/* ====== video frame buffer modes ====== */
214 	GR_frameUndef,                      /* undefined */
215 	GR_frameText,                       /* text modes */
216 	GR_frameHERC1,                      /* Hercules mono */
217 	GR_frameEGAVGA1,                    /* EGA VGA mono */
218 	GR_frameEGA4,                       /* EGA 16 color */
219 	GR_frameSVGA4,                      /* (Super) VGA 16 color */
220 	GR_frameSVGA8,                      /* (Super) VGA 256 color */
221 	GR_frameVGA8X,                      /* VGA 256 color mode X */
222 	GR_frameSVGA16,                     /* Super VGA 32768/65536 color */
223 	GR_frameSVGA24,                     /* Super VGA 16M color */
224 	GR_frameSVGA32L,                    /* Super VGA 16M color padded #1 */
225 	GR_frameSVGA32H,                    /* Super VGA 16M color padded #2 */
226 	/* ==== modes provided by the X11 driver ===== */
227 	GR_frameXWIN1   = GR_frameEGAVGA1,
228 	GR_frameXWIN4   = GR_frameSVGA4,
229 	GR_frameXWIN8   = GR_frameSVGA8,
230 	GR_frameXWIN16  = GR_frameSVGA16,
231 	GR_frameXWIN24  = GR_frameSVGA24,
232 	GR_frameXWIN32L = GR_frameSVGA32L,
233 	GR_frameXWIN32H = GR_frameSVGA32H,
234 	/* ==== modes provided by the WIN32 driver ===== */
235 	GR_frameWIN32_1   = GR_frameEGAVGA1,
236 	GR_frameWIN32_4   = GR_frameSVGA4,
237 	GR_frameWIN32_8   = GR_frameSVGA8,
238 	GR_frameWIN32_16  = GR_frameSVGA16,
239 	GR_frameWIN32_24  = GR_frameSVGA24,
240 	GR_frameWIN32_32L = GR_frameSVGA32L,
241 	GR_frameWIN32_32H = GR_frameSVGA32H,
242 	/* ==== modes provided by the SDL driver ===== */
243 	GR_frameSDL8   = GR_frameSVGA8,
244 	GR_frameSDL16  = GR_frameSVGA16,
245 	GR_frameSDL24  = GR_frameSVGA24,
246 	GR_frameSDL32L = GR_frameSVGA32L,
247 	GR_frameSDL32H = GR_frameSVGA32H,
248 	/* ==== linear frame buffer modes  ====== */
249 	GR_frameSVGA8_LFB,                  /* (Super) VGA 256 color */
250 	GR_frameSVGA16_LFB,                 /* Super VGA 32768/65536 color */
251 	GR_frameSVGA24_LFB,                 /* Super VGA 16M color */
252 	GR_frameSVGA32L_LFB,                /* Super VGA 16M color padded #1 */
253 	GR_frameSVGA32H_LFB,                /* Super VGA 16M color padded #2 */
254 	/* ====== system RAM frame buffer modes ====== */
255 	GR_frameRAM1,                       /* mono */
256 	GR_frameRAM4,                       /* 16 color planar */
257 	GR_frameRAM8,                       /* 256 color */
258 	GR_frameRAM16,                      /* 32768/65536 color */
259 	GR_frameRAM24,                      /* 16M color */
260 	GR_frameRAM32L,                     /* 16M color padded #1 */
261 	GR_frameRAM32H,                     /* 16M color padded #2 */
262 	GR_frameRAM3x8,                     /* 16M color planar (image mode) */
263 	/* ====== markers for scanning modes ====== */
264 	GR_firstTextFrameMode     = GR_frameText,
265 	GR_lastTextFrameMode      = GR_frameText,
266 	GR_firstGraphicsFrameMode = GR_frameHERC1,
267 	GR_lastGraphicsFrameMode  = GR_frameSVGA32H_LFB,
268 	GR_firstRAMframeMode      = GR_frameRAM1,
269 	GR_lastRAMframeMode       = GR_frameRAM3x8
270 } GrFrameMode;
271 
272 /*
273  * supported video adapter types
274  */
275 typedef enum _GR_videoAdapters {
276 	GR_UNKNOWN = (-1),                  /* not known (before driver set) */
277 	GR_VGA,                             /* VGA adapter */
278 	GR_EGA,                             /* EGA adapter */
279 	GR_HERC,                            /* Hercules mono adapter */
280 	GR_8514A,                           /* 8514A or compatible */
281 	GR_S3,                              /* S3 graphics accelerator */
282 	GR_XWIN,                            /* X11 driver */
283 	GR_WIN32,                           /* WIN32 driver */
284 	GR_LNXFB,                           /* Linux framebuffer */
285 	GR_SDL,                             /* SDL driver */
286 	GR_MEM                              /* memory only driver */
287 } GrVideoAdapter;
288 
289 /*
290  * The video driver descriptor structure
291  */
292 struct _GR_videoDriver {
293 	char   *name;                       /* driver name */
294 	enum   _GR_videoAdapters adapter;   /* adapter type */
295 	struct _GR_videoDriver  *inherit;   /* inherit video modes from this */
296 	struct _GR_videoMode    *modes;     /* table of supported modes */
297 	int     nmodes;                     /* number of modes */
298 	int   (*detect)(void);
299 	int   (*init)(char *options);
300 	void  (*reset)(void);
301 	GrVideoMode * (*selectmode)(GrVideoDriver *drv,int w,int h,int bpp,
302 					int txt,unsigned int *ep);
303 	unsigned  drvflags;
304 };
305 /* bits in the drvflags field: */
306 #define GR_DRIVERF_USER_RESOLUTION 1
307   /* set if driver supports user setable arbitrary resolution */
308 
309 
310 /*
311  * Video driver mode descriptor structure
312  */
313 struct _GR_videoMode {
314 	char    present;                    /* is it really available? */
315 	char    bpp;                        /* log2 of # of colors */
316 	short   width,height;               /* video mode geometry */
317 	short   mode;                       /* BIOS mode number (if any) */
318 	int     lineoffset;                 /* scan line length */
319 	int     privdata;                   /* driver can use it for anything */
320 	struct _GR_videoModeExt *extinfo;   /* extra info (maybe shared) */
321 };
322 
323 /*
324  * Video driver mode descriptor extension structure. This is a separate
325  * structure accessed via a pointer from the main mode descriptor. The
326  * reason for this is that frequently several modes can share the same
327  * extended info.
328  */
329 struct _GR_videoModeExt {
330 	enum   _GR_frameModes   mode;       /* frame driver for this video mode */
331 	struct _GR_frameDriver *drv;        /* optional frame driver override */
332 	char    far *frame;                 /* frame buffer address */
333 	char    cprec[3];                   /* color component precisions */
334 	char    cpos[3];                    /* color component bit positions */
335 	int     flags;                      /* mode flag bits; see "grdriver.h" */
336 	int   (*setup)(GrVideoMode *md,int noclear);
337 	int   (*setvsize)(GrVideoMode *md,int w,int h,GrVideoMode *result);
338 	int   (*scroll)(GrVideoMode *md,int x,int y,int result[2]);
339 	void  (*setbank)(int bk);
340 	void  (*setrwbanks)(int rb,int wb);
341 	void  (*loadcolor)(int c,int r,int g,int b);
342 	int     LFB_Selector;
343 };
344 
345 /*
346  * The frame driver descriptor structure.
347  */
348 struct _GR_frameDriver {
349     enum    _GR_frameModes mode;         /* supported frame access mode */
350     enum    _GR_frameModes rmode;        /* matching RAM frame (if video) */
351     int      is_video;                   /* video RAM frame driver ? */
352     int      row_align;                  /* scan line size alignment */
353     int      num_planes;                 /* number of planes */
354     int      bits_per_pixel;             /* bits per pixel */
355     long     max_plane_size;             /* maximum plane size in bytes */
356     int      (*init)(GrVideoMode *md);
357     GrColor  (*readpixel)(GrFrame *c,int x,int y);
358     void     (*drawpixel)(int x,int y,GrColor c);
359     void     (*drawline)(int x,int y,int dx,int dy,GrColor c);
360     void     (*drawhline)(int x,int y,int w,GrColor c);
361     void     (*drawvline)(int x,int y,int h,GrColor c);
362     void     (*drawblock)(int x,int y,int w,int h,GrColor c);
363     void     (*drawbitmap)(int x,int y,int w,int h,char far *bmp,int pitch,int start,GrColor fg,GrColor bg);
364     void     (*drawpattern)(int x,int y,int w,char patt,GrColor fg,GrColor bg);
365     void     (*bitblt)(GrFrame *dst,int dx,int dy,GrFrame *src,int x,int y,int w,int h,GrColor op);
366     void     (*bltv2r)(GrFrame *dst,int dx,int dy,GrFrame *src,int x,int y,int w,int h,GrColor op);
367     void     (*bltr2v)(GrFrame *dst,int dx,int dy,GrFrame *src,int x,int y,int w,int h,GrColor op);
368     /* new functions in v2.3 */
369     GrColor far *(*getindexedscanline)(GrFrame *c,int x, int y, int w, int *indx);
370       /* will return an array of pixel values pv[] read from frame   */
371       /*    if indx == NULL: pv[i=0..w-1] = readpixel(x+i,y)         */
372       /*    else             pv[i=0..w-1] = readpixel(x+indx[i],y)   */
373     void     (*putscanline)(int x, int y, int w,const GrColor far *scl, GrColor op);
374       /** will draw scl[i=0..w-1] to frame:                          */
375       /*    if (scl[i] != skipcolor) drawpixel(x+i,y,(scl[i] | op))  */
376 };
377 
378 /*
379  * driver and mode info structure
380  */
381 extern const struct _GR_driverInfo {
382 	struct _GR_videoDriver  *vdriver;   /* the current video driver */
383 	struct _GR_videoMode    *curmode;   /* current video mode pointer */
384 	struct _GR_videoMode     actmode;   /* copy of above, resized if virtual */
385 	struct _GR_frameDriver   fdriver;   /* frame driver for the current context */
386 	struct _GR_frameDriver   sdriver;   /* frame driver for the screen */
387 	struct _GR_frameDriver   tdriver;   /* a dummy driver for text modes */
388 	enum   _GR_graphicsModes mcode;     /* code for the current mode */
389 	int     deftw,defth;                /* default text mode size */
390 	int     defgw,defgh;                /* default graphics mode size */
391 	GrColor deftc,defgc;                /* default text and graphics colors */
392 	int     vposx,vposy;                /* current virtual viewport position */
393 	int     errsfatal;                  /* if set, exit upon errors */
394 	int     moderestore;                /* restore startup video mode if set */
395 	int     splitbanks;                 /* indicates separate R/W banks */
396 	int     curbank;                    /* currently mapped bank */
397 	void  (*mdsethook)(void);           /* callback for mode set */
398 	void  (*setbank)(int bk);           /* banking routine */
399 	void  (*setrwbanks)(int rb,int wb); /* split banking routine */
400 } * const GrDriverInfo;
401 
402 /*
403  * setup stuff
404  */
405 int  GrSetDriver(char *drvspec);
406 int  GrSetMode(GrGraphicsMode which,...);
407 int  GrSetViewport(int xpos,int ypos);
408 void GrSetModeHook(void (*hookfunc)(void));
409 void GrSetModeRestore(int restoreFlag);
410 void GrSetErrorHandling(int exitIfError);
411 void GrSetEGAVGAmonoDrawnPlane(int plane);
412 void GrSetEGAVGAmonoShownPlane(int plane);
413 
414 unsigned GrGetLibraryVersion(void);
415 unsigned GrGetLibrarySystem(void);
416 
417 /*
418  * inquiry stuff ---- many of these are actually macros (see below)
419  */
420 GrGraphicsMode GrCurrentMode(void);
421 GrVideoAdapter GrAdapterType(void);
422 GrFrameMode    GrCurrentFrameMode(void);
423 GrFrameMode    GrScreenFrameMode(void);
424 GrFrameMode    GrCoreFrameMode(void);
425 
426 const GrVideoDriver *GrCurrentVideoDriver(void);
427 const GrVideoMode   *GrCurrentVideoMode(void);
428 const GrVideoMode   *GrVirtualVideoMode(void);
429 const GrFrameDriver *GrCurrentFrameDriver(void);
430 const GrFrameDriver *GrScreenFrameDriver(void);
431 const GrVideoMode   *GrFirstVideoMode(GrFrameMode fmode);
432 const GrVideoMode   *GrNextVideoMode(const GrVideoMode *prev);
433 
434 int  GrScreenX(void);
435 int  GrScreenY(void);
436 int  GrVirtualX(void);
437 int  GrVirtualY(void);
438 int  GrViewportX(void);
439 int  GrViewportY(void);
440 
441 int  GrScreenIsVirtual(void);
442 
443 /*
444  * RAM context geometry and memory allocation inquiry stuff
445  */
446 int  GrFrameNumPlanes(GrFrameMode md);
447 int  GrFrameLineOffset(GrFrameMode md,int width);
448 long GrFramePlaneSize(GrFrameMode md,int w,int h);
449 long GrFrameContextSize(GrFrameMode md,int w,int h);
450 
451 int  GrNumPlanes(void);
452 int  GrLineOffset(int width);
453 long GrPlaneSize(int w,int h);
454 long GrContextSize(int w,int h);
455 
456 /*
457  * inline implementation for some of the above
458  */
459 #ifndef GRX_SKIP_INLINES
460 #define GrAdapterType()         (GrDriverInfo->vdriver ? GrDriverInfo->vdriver->adapter : GR_UNKNOWN)
461 #define GrCurrentMode()         (GrDriverInfo->mcode)
462 #define GrCurrentFrameMode()    (GrDriverInfo->fdriver.mode)
463 #define GrScreenFrameMode()     (GrDriverInfo->sdriver.mode)
464 #define GrCoreFrameMode()       (GrDriverInfo->sdriver.rmode)
465 
466 #define GrCurrentVideoDriver()  ((const GrVideoDriver *)( GrDriverInfo->vdriver))
467 #define GrCurrentVideoMode()    ((const GrVideoMode   *)( GrDriverInfo->curmode))
468 #define GrVirtualVideoMode()    ((const GrVideoMode   *)(&GrDriverInfo->actmode))
469 #define GrCurrentFrameDriver()  ((const GrFrameDriver *)(&GrDriverInfo->fdriver))
470 #define GrScreenFrameDriver()   ((const GrFrameDriver *)(&GrDriverInfo->sdriver))
471 
472 #define GrIsFixedMode()      (!(  GrCurrentVideoDriver()->drvflags \
473 				   & GR_DRIVERF_USER_RESOLUTION))
474 
475 #define GrScreenX()             (GrCurrentVideoMode()->width)
476 #define GrScreenY()             (GrCurrentVideoMode()->height)
477 #define GrVirtualX()            (GrVirtualVideoMode()->width)
478 #define GrVirtualY()            (GrVirtualVideoMode()->height)
479 #define GrViewportX()           (GrDriverInfo->vposx)
480 #define GrViewportY()           (GrDriverInfo->vposy)
481 
482 #define GrScreenIsVirtual()     ((GrScreenX() + GrScreenY()) < (GrVirtualX() + GrVirtualY()))
483 
484 #define GrNumPlanes()           GrFrameNumPlanes(GrCoreFrameMode())
485 #define GrLineOffset(w)         GrFrameLineOffset(GrCoreFrameMode(),w)
486 #define GrPlaneSize(w,h)        GrFramePlaneSize(GrCoreFrameMode(),w,h)
487 #define GrContextSize(w,h)      GrFrameContextSize(GrCoreFrameMode(),w,h)
488 #endif  /* GRX_SKIP_INLINES */
489 
490 
491 /* ================================================================== */
492 /*              FRAME BUFFER, CONTEXT AND CLIPPING STUFF              */
493 /* ================================================================== */
494 
495 struct _GR_frame {
496 	char    far *gf_baseaddr[4];        /* base address of frame memory */
497 	short   gf_selector;                /* frame memory segment selector */
498 	char    gf_onscreen;                /* is it in video memory ? */
499 	char    gf_memflags;                /* memory allocation flags */
500 	int     gf_lineoffset;              /* offset to next scan line in bytes */
501 	struct _GR_frameDriver *gf_driver;  /* frame access functions */
502 };
503 
504 struct _GR_context {
505 	struct _GR_frame    gc_frame;       /* frame buffer info */
506 	struct _GR_context *gc_root;        /* context which owns frame */
507 	int    gc_xmax;                     /* max X coord (width  - 1) */
508 	int    gc_ymax;                     /* max Y coord (height - 1) */
509 	int    gc_xoffset;                  /* X offset from root's base */
510 	int    gc_yoffset;                  /* Y offset from root's base */
511 	int    gc_xcliplo;                  /* low X clipping limit */
512 	int    gc_ycliplo;                  /* low Y clipping limit */
513 	int    gc_xcliphi;                  /* high X clipping limit */
514 	int    gc_ycliphi;                  /* high Y clipping limit */
515 	int    gc_usrxbase;                 /* user window min X coordinate */
516 	int    gc_usrybase;                 /* user window min Y coordinate */
517 	int    gc_usrwidth;                 /* user window width  */
518 	int    gc_usrheight;                /* user window height */
519 #   define gc_baseaddr                  gc_frame.gf_baseaddr
520 #   define gc_selector                  gc_frame.gf_selector
521 #   define gc_onscreen                  gc_frame.gf_onscreen
522 #   define gc_memflags                  gc_frame.gf_memflags
523 #   define gc_lineoffset                gc_frame.gf_lineoffset
524 #   define gc_driver                    gc_frame.gf_driver
525 };
526 
527 extern const struct _GR_contextInfo {
528 	struct _GR_context current;         /* the current context */
529 	struct _GR_context screen;          /* the screen context */
530 } * const GrContextInfo;
531 
532 GrContext *GrCreateContext(int w,int h,char far *memory[4],GrContext *where);
533 GrContext *GrCreateFrameContext(GrFrameMode md,int w,int h,char far *memory[4],GrContext *where);
534 GrContext *GrCreateSubContext(int x1,int y1,int x2,int y2,const GrContext *parent,GrContext *where);
535 GrContext *GrSaveContext(GrContext *where);
536 
537 GrContext *GrCurrentContext(void);
538 GrContext *GrScreenContext(void);
539 
540 void  GrDestroyContext(GrContext *context);
541 void  GrResizeSubContext(GrContext *context,int x1,int y1,int x2,int y2);
542 void  GrSetContext(const GrContext *context);
543 
544 void  GrSetClipBox(int x1,int y1,int x2,int y2);
545 void  GrSetClipBoxC(GrContext *c,int x1,int y1,int x2,int y2);
546 void  GrGetClipBox(int *x1p,int *y1p,int *x2p,int *y2p);
547 void  GrGetClipBoxC(const GrContext *c,int *x1p,int *y1p,int *x2p,int *y2p);
548 void  GrResetClipBox(void);
549 void  GrResetClipBoxC(GrContext *c);
550 
551 int   GrMaxX(void);
552 int   GrMaxY(void);
553 int   GrSizeX(void);
554 int   GrSizeY(void);
555 int   GrLowX(void);
556 int   GrLowY(void);
557 int   GrHighX(void);
558 int   GrHighY(void);
559 
560 #ifndef GRX_SKIP_INLINES
561 #define GrCreateContext(w,h,m,c) (GrCreateFrameContext(GrCoreFrameMode(),w,h,m,c))
562 #define GrCurrentContext()       ((GrContext *)(&GrContextInfo->current))
563 #define GrScreenContext()        ((GrContext *)(&GrContextInfo->screen))
564 #define GrMaxX()                 (GrCurrentContext()->gc_xmax)
565 #define GrMaxY()                 (GrCurrentContext()->gc_ymax)
566 #define GrSizeX()                (GrMaxX() + 1)
567 #define GrSizeY()                (GrMaxY() + 1)
568 #define GrLowX()                 (GrCurrentContext()->gc_xcliplo)
569 #define GrLowY()                 (GrCurrentContext()->gc_ycliplo)
570 #define GrHighX()                (GrCurrentContext()->gc_xcliphi)
571 #define GrHighY()                (GrCurrentContext()->gc_ycliphi)
572 #define GrGetClipBoxC(C,x1p,y1p,x2p,y2p) do {           \
573 	*(x1p) = (C)->gc_xcliplo;                           \
574 	*(y1p) = (C)->gc_ycliplo;                           \
575 	*(x2p) = (C)->gc_xcliphi;                           \
576 	*(y2p) = (C)->gc_ycliphi;                           \
577 } while(0)
578 #define GrGetClipBox(x1p,y1p,x2p,y2p) do {              \
579 	*(x1p) = GrLowX();                                  \
580 	*(y1p) = GrLowY();                                  \
581 	*(x2p) = GrHighX();                                 \
582 	*(y2p) = GrHighY();                                 \
583 } while(0)
584 #endif  /* GRX_SKIP_INLINES */
585 
586 /* ================================================================== */
587 /*                            COLOR STUFF                             */
588 /* ================================================================== */
589 
590 /*
591  * Flags to 'OR' to colors for various operations
592  */
593 #define GrWRITE         0UL             /* write color */
594 #define GrXOR           0x01000000UL    /* to "XOR" any color to the screen */
595 #define GrOR            0x02000000UL    /* to "OR" to the screen */
596 #define GrAND           0x03000000UL    /* to "AND" to the screen */
597 #define GrIMAGE         0x04000000UL    /* BLIT: write, except given color */
598 #define GrCVALUEMASK    0x00ffffffUL    /* color value mask */
599 #define GrCMODEMASK     0xff000000UL    /* color operation mask */
600 #define GrNOCOLOR       (GrXOR | 0)     /* GrNOCOLOR is used for "no" color */
601 
602 GrColor GrColorValue(GrColor c);
603 GrColor GrColorMode(GrColor c);
604 GrColor GrWriteModeColor(GrColor c);
605 GrColor GrXorModeColor(GrColor c);
606 GrColor GrOrModeColor(GrColor c);
607 GrColor GrAndModeColor(GrColor c);
608 GrColor GrImageModeColor(GrColor c);
609 
610 /*
611  * color system info structure (all [3] arrays are [r,g,b])
612  */
613 extern const struct _GR_colorInfo {
614 	GrColor       ncolors;              /* number of colors */
615 	GrColor       nfree;                /* number of unallocated colors */
616 	GrColor       black;                /* the black color */
617 	GrColor       white;                /* the white color */
618 	unsigned int  RGBmode;              /* set when RGB mode */
619 	unsigned int  prec[3];              /* color field precisions */
620 	unsigned int  pos[3];               /* color field positions */
621 	unsigned int  mask[3];              /* masks for significant bits */
622 	unsigned int  round[3];             /* add these for rounding */
623 	unsigned int  shift[3];             /* shifts for (un)packing color */
624 	unsigned int  norm;                 /* normalization for (un)packing */
625 	struct {                            /* color table for non-RGB modes */
626 		unsigned char r,g,b;            /* loaded components */
627 		unsigned int  defined:1;        /* r,g,b values are valid if set */
628 		unsigned int  writable:1;       /* can be changed by 'GrSetColor' */
629 		unsigned long int nused;        /* usage count */
630 	} ctable[256];
631 } * const GrColorInfo;
632 
633 void    GrResetColors(void);
634 void    GrSetRGBcolorMode(void);
635 void    GrRefreshColors(void);
636 
637 GrColor GrNumColors(void);
638 GrColor GrNumFreeColors(void);
639 
640 GrColor GrBlack(void);
641 GrColor GrWhite(void);
642 
643 GrColor GrBuildRGBcolorT(int r,int g,int b);
644 GrColor GrBuildRGBcolorR(int r,int g,int b);
645 int     GrRGBcolorRed(GrColor c);
646 int     GrRGBcolorGreen(GrColor c);
647 int     GrRGBcolorBlue(GrColor c);
648 
649 GrColor GrAllocColor(int r,int g,int b);   /* shared, read-only */
650 GrColor GrAllocColorID(int r,int g,int b); /* potentially inlined version */
651 GrColor GrAllocColor2(long hcolor);        /* shared, read-only, 0xRRGGBB */
652 GrColor GrAllocColor2ID(long hcolor);      /* potentially inlined version */
653 GrColor GrAllocCell(void);                 /* unshared, read-write */
654 
655 GrColor *GrAllocEgaColors(void);           /* shared, read-only standard EGA colors */
656 
657 void    GrSetColor(GrColor c,int r,int g,int b);
658 void    GrFreeColor(GrColor c);
659 void    GrFreeCell(GrColor c);
660 
661 void    GrQueryColor(GrColor c,int *r,int *g,int *b);
662 void    GrQueryColorID(GrColor c,int *r,int *g,int *b);
663 void    GrQueryColor2(GrColor c,long *hcolor);
664 void    GrQueryColor2ID(GrColor c,long *hcolor);
665 
666 int     GrColorSaveBufferSize(void);
667 void    GrSaveColors(void *buffer);
668 void    GrRestoreColors(void *buffer);
669 
670 #ifndef GRX_SKIP_INLINES
671 #define GrColorValue(c)         ((GrColor)(c) & GrCVALUEMASK)
672 #define GrColorMode(c)          ((GrColor)(c) & GrCMODEMASK)
673 #define GrWriteModeColor(c)     (GrColorValue(c) | GrWRITE)
674 #define GrXorModeColor(c)       (GrColorValue(c) | GrXOR)
675 #define GrOrModeColor(c)        (GrColorValue(c) | GrOR)
676 #define GrAndModeColor(c)       (GrColorValue(c) | GrAND)
677 #define GrImageModeColor(c)     (GrColorValue(c) | GrIMAGE)
678 #define GrNumColors()           (GrColorInfo->ncolors)
679 #define GrNumFreeColors()       (GrColorInfo->nfree)
680 #define GrBlack() (                                                            \
681 	(GrColorInfo->black == GrNOCOLOR) ?                                    \
682 	(GrBlack)() :                                                          \
683 	GrColorInfo->black                                                     \
684 )
685 #define GrWhite() (                                                            \
686 	(GrColorInfo->white == GrNOCOLOR) ?                                    \
687 	(GrWhite)() :                                                          \
688 	GrColorInfo->white                                                     \
689 )
690 #define GrBuildRGBcolorT(r,g,b) ((                                             \
691 	((GrColor)((int)(r) & GrColorInfo->mask[0]) << GrColorInfo->shift[0]) |\
692 	((GrColor)((int)(g) & GrColorInfo->mask[1]) << GrColorInfo->shift[1]) |\
693 	((GrColor)((int)(b) & GrColorInfo->mask[2]) << GrColorInfo->shift[2])  \
694 	) >> GrColorInfo->norm                                                 \
695 )
696 #define GrBuildRGBcolorR(r,g,b) GrBuildRGBcolorT(                              \
697 	(((unsigned int)(r)) > GrColorInfo->mask[0]) ? 255 : (unsigned int)(r) + GrColorInfo->round[0], \
698 	(((unsigned int)(g)) > GrColorInfo->mask[1]) ? 255 : (unsigned int)(g) + GrColorInfo->round[1], \
699 	(((unsigned int)(b)) > GrColorInfo->mask[2]) ? 255 : (unsigned int)(b) + GrColorInfo->round[2]  \
700 )
701 #define GrRGBcolorRed(c) (                                                     \
702 	(int)(((GrColor)(c) << GrColorInfo->norm) >> GrColorInfo->shift[0]) &  \
703 	(GrColorInfo->mask[0])                                                 \
704 )
705 #define GrRGBcolorGreen(c) (                                                   \
706 	(int)(((GrColor)(c) << GrColorInfo->norm) >> GrColorInfo->shift[1]) &  \
707 	(GrColorInfo->mask[1])                                                 \
708 )
709 #define GrRGBcolorBlue(c) (                                                    \
710 	(int)(((GrColor)(c) << GrColorInfo->norm) >> GrColorInfo->shift[2]) &  \
711 	(GrColorInfo->mask[2])                                                 \
712 )
713 #define GrAllocColorID(r,g,b) (GrColorInfo->RGBmode ?                          \
714 	GrBuildRGBcolorR(r,g,b) :                                              \
715 	GrAllocColor(r,g,b)                                                    \
716 )
717 #define GrAllocColor2(hcolor) (GrAllocColor(                                   \
718         ((hcolor & 0xff0000) >> 16),                                           \
719         ((hcolor & 0x00ff00) >> 8),                                            \
720         (hcolor & 0x0000ff))                                                   \
721 )
722 #define GrAllocColor2ID(hcolor) (GrAllocColorID(                               \
723         ((hcolor & 0xff0000) >> 16),                                           \
724         ((hcolor & 0x00ff00) >> 8),                                            \
725         (hcolor & 0x0000ff))                                                   \
726 )
727 #define GrQueryColorID(c,r,g,b) do {                                           \
728 	if(GrColorInfo->RGBmode) {                                             \
729 	*(r) = GrRGBcolorRed(c);                                               \
730 	*(g) = GrRGBcolorGreen(c);                                             \
731 	*(b) = GrRGBcolorBlue(c);                                              \
732 	break;                                                                 \
733 	}                                                                      \
734 	if(((GrColor)(c) < GrColorInfo->ncolors) &&                            \
735 	   (GrColorInfo->ctable[(GrColor)(c)].defined)) {                      \
736 	*(r) = GrColorInfo->ctable[(GrColor)(c)].r;                            \
737 	*(g) = GrColorInfo->ctable[(GrColor)(c)].g;                            \
738 	*(b) = GrColorInfo->ctable[(GrColor)(c)].b;                            \
739 	break;                                                                 \
740 	}                                                                      \
741 	*(r) = *(g) = *(b) = 0;                                                \
742 } while(0)
743 #define GrQueryColor2ID(c,hcolor) do {                                         \
744 	if(GrColorInfo->RGBmode) {                                             \
745         *(hcolor) = GrRGBcolorRed(c) << 16;                                    \
746         *(hcolor) |= GrRGBcolorGreen(c) << 8;                                  \
747         *(hcolor) |= GrRGBcolorBlue(c);                                        \
748 	break;                                                                 \
749 	}                                                                      \
750 	if(((GrColor)(c) < GrColorInfo->ncolors) &&                            \
751 	   (GrColorInfo->ctable[(GrColor)(c)].defined)) {                      \
752         *(hcolor) = GrColorInfo->ctable[(GrColor)(c)].r;                       \
753         *(hcolor) = GrColorInfo->ctable[(GrColor)(c)].g;                       \
754         *(hcolor) = GrColorInfo->ctable[(GrColor)(c)].b;                       \
755 	break;                                                                 \
756 	}                                                                      \
757         *(hcolor) = 0;                                                         \
758 } while(0)
759 #endif  /* GRX_SKIP_INLINES */
760 
761 /*
762  * color table (for primitives using several colors):
763  *   it is an array of colors with the first element being
764  *   the number of colors in the table
765  */
766 typedef GrColor *GrColorTableP;
767 
768 #define GR_CTABLE_SIZE(table) (                                                \
769 	(table) ? (unsigned int)((table)[0]) : 0U                              \
770 )
771 #define GR_CTABLE_COLOR(table,index) (                                         \
772 	((unsigned)(index) < GR_CTABLE_SIZE(table)) ?                          \
773 	(table)[((unsigned)(index)) + 1] :                                     \
774 	GrNOCOLOR                                                              \
775 )
776 #define GR_CTABLE_ALLOCSIZE(ncolors)    ((ncolors) + 1)
777 
778 /* ================================================================== */
779 /*                       GRAPHICS PRIMITIVES                          */
780 /* ================================================================== */
781 
782 #ifdef  __TURBOC__
783 /* this is for GRX compiled with SMALL_STACK: */
784 #define GR_MAX_POLYGON_POINTS   (8192)
785 #define GR_MAX_ELLIPSE_POINTS   (1024 + 5)
786 /* old values without SMALL_STACK: */
787 /* #define GR_MAX_POLYGON_POINTS   (512) */
788 /* #define GR_MAX_ELLIPSE_POINTS   (256 + 5) */
789 #else
790 #define GR_MAX_POLYGON_POINTS   (1000000)
791 #define GR_MAX_ELLIPSE_POINTS   (1024 + 5)
792 #endif
793 #define GR_MAX_ANGLE_VALUE      (3600)
794 #define GR_ARC_STYLE_OPEN       0
795 #define GR_ARC_STYLE_CLOSE1     1
796 #define GR_ARC_STYLE_CLOSE2     2
797 
798 typedef struct {                        /* framed box colors */
799 	GrColor fbx_intcolor;
800 	GrColor fbx_topcolor;
801 	GrColor fbx_rightcolor;
802 	GrColor fbx_bottomcolor;
803 	GrColor fbx_leftcolor;
804 } GrFBoxColors;
805 
806 void GrClearScreen(GrColor bg);
807 void GrClearContext(GrColor bg);
808 void GrClearContextC(GrContext *ctx, GrColor bg);
809 void GrClearClipBox(GrColor bg);
810 void GrPlot(int x,int y,GrColor c);
811 void GrLine(int x1,int y1,int x2,int y2,GrColor c);
812 void GrHLine(int x1,int x2,int y,GrColor c);
813 void GrVLine(int x,int y1,int y2,GrColor c);
814 void GrBox(int x1,int y1,int x2,int y2,GrColor c);
815 void GrFilledBox(int x1,int y1,int x2,int y2,GrColor c);
816 void GrFramedBox(int x1,int y1,int x2,int y2,int wdt,const GrFBoxColors *c);
817 int  GrGenerateEllipse(int xc,int yc,int xa,int ya,int points[GR_MAX_ELLIPSE_POINTS][2]);
818 int  GrGenerateEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int points[GR_MAX_ELLIPSE_POINTS][2]);
819 void GrLastArcCoords(int *xs,int *ys,int *xe,int *ye,int *xc,int *yc);
820 void GrCircle(int xc,int yc,int r,GrColor c);
821 void GrEllipse(int xc,int yc,int xa,int ya,GrColor c);
822 void GrCircleArc(int xc,int yc,int r,int start,int end,int style,GrColor c);
823 void GrEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrColor c);
824 void GrFilledCircle(int xc,int yc,int r,GrColor c);
825 void GrFilledEllipse(int xc,int yc,int xa,int ya,GrColor c);
826 void GrFilledCircleArc(int xc,int yc,int r,int start,int end,int style,GrColor c);
827 void GrFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrColor c);
828 void GrPolyLine(int numpts,int points[][2],GrColor c);
829 void GrPolygon(int numpts,int points[][2],GrColor c);
830 void GrFilledConvexPolygon(int numpts,int points[][2],GrColor c);
831 void GrFilledPolygon(int numpts,int points[][2],GrColor c);
832 void GrBitBlt(GrContext *dst,int x,int y,GrContext *src,int x1,int y1,int x2,int y2,GrColor op);
833 void GrBitBlt1bpp(GrContext *dst,int dx,int dy,GrContext *src,int x1,int y1,int x2,int y2,GrColor fg,GrColor bg);
834 void GrFloodFill(int x, int y, GrColor border, GrColor c);
835 void GrFloodSpill(int x1, int y1, int x2, int y2, GrColor old_c, GrColor new_c);
836 void GrFloodSpill2(int x1, int y1, int x2, int y2, GrColor old_c1, GrColor new_c1, GrColor old_c2, GrColor new_c2);
837 void GrFloodSpillC(GrContext *ctx, int x1, int y1, int x2, int y2, GrColor old_c, GrColor new_c);
838 void GrFloodSpillC2(GrContext *ctx, int x1, int y1, int x2, int y2, GrColor old_c1, GrColor new_c1, GrColor old_c2, GrColor new_c2);
839 
840 GrColor GrPixel(int x,int y);
841 GrColor GrPixelC(GrContext *c,int x,int y);
842 
843 const GrColor *GrGetScanline(int x1,int x2,int yy);
844 const GrColor *GrGetScanlineC(GrContext *ctx,int x1,int x2,int yy);
845 /* Input   ctx: source context, if NULL the current context is used */
846 /*         x1 : first x coordinate read                             */
847 /*         x2 : last  x coordinate read                             */
848 /*         yy : y coordinate                                        */
849 /* Output  NULL     : error / no data (clipping occured)            */
850 /*         else                                                     */
851 /*           p[0..w]: pixel values read                             */
852 /*                      (w = |x2-y1|)                               */
853 /*           Output data is valid until next GRX call !             */
854 
855 void GrPutScanline(int x1,int x2,int yy,const GrColor *c, GrColor op);
856 /* Input   x1 : first x coordinate to be set                        */
857 /*         x2 : last  x coordinate to be set                        */
858 /*         yy : y coordinate                                        */
859 /*         c  : c[0..(|x2-x1|] hold the pixel data                  */
860 /*         op : Operation (GrWRITE/GrXOR/GrOR/GrAND/GrIMAGE)        */
861 /*                                                                  */
862 /* Note    c[..] data must fit GrCVALUEMASK otherwise the results   */
863 /*         are implementation dependend.                            */
864 /*         => You can't supply operation code with the pixel data!  */
865 
866 
867 #ifndef GRX_SKIP_INLINES
868 #define GrGetScanline(x1,x2,yy) \
869 	GrGetScanlineC(NULL,(x1),(x2),(yy))
870 #endif
871 
872 /* ================================================================== */
873 /*                 NON CLIPPING DRAWING PRIMITIVES                    */
874 /* ================================================================== */
875 
876 void GrPlotNC(int x,int y,GrColor c);
877 void GrLineNC(int x1,int y1,int x2,int y2,GrColor c);
878 void GrHLineNC(int x1,int x2,int y,GrColor c);
879 void GrVLineNC(int x,int y1,int y2,GrColor c);
880 void GrBoxNC(int x1,int y1,int x2,int y2,GrColor c);
881 void GrFilledBoxNC(int x1,int y1,int x2,int y2,GrColor c);
882 void GrFramedBoxNC(int x1,int y1,int x2,int y2,int wdt,const GrFBoxColors *c);
883 void GrBitBltNC(GrContext *dst,int x,int y,GrContext *src,int x1,int y1,int x2,int y2,GrColor op);
884 
885 GrColor GrPixelNC(int x,int y);
886 GrColor GrPixelCNC(GrContext *c,int x,int y);
887 
888 #ifndef GRX_SKIP_INLINES
889 #define GrPlotNC(x,y,c) (                                                      \
890 	(*GrCurrentFrameDriver()->drawpixel)(                                  \
891 	((x) + GrCurrentContext()->gc_xoffset),                                \
892 	((y) + GrCurrentContext()->gc_yoffset),                                \
893 	((c))                                                                  \
894 	)                                                                      \
895 )
896 #define GrPixelNC(x,y) (                                                       \
897 	(*GrCurrentFrameDriver()->readpixel)(                                  \
898 	(GrFrame *)(&GrCurrentContext()->gc_frame),                            \
899 	((x) + GrCurrentContext()->gc_xoffset),                                \
900 	((y) + GrCurrentContext()->gc_yoffset)                                 \
901 	)                                                                      \
902 )
903 #define GrPixelCNC(c,x,y) (                                                    \
904 	(*(c)->gc_driver->readpixel)(                                          \
905 	(&(c)->gc_frame),                                                      \
906 	((x) + (c)->gc_xoffset),                                               \
907 	((y) + (c)->gc_yoffset)                                                \
908 	)                                                                      \
909 )
910 #endif  /* GRX_SKIP_INLINES */
911 
912 /* ================================================================== */
913 /*                   FONTS AND TEXT PRIMITIVES                        */
914 /* ================================================================== */
915 
916 /*
917  * text drawing directions
918  */
919 #define GR_TEXT_RIGHT           0       /* normal */
920 #define GR_TEXT_DOWN            1       /* downward */
921 #define GR_TEXT_LEFT            2       /* upside down, right to left */
922 #define GR_TEXT_UP              3       /* upward */
923 #define GR_TEXT_DEFAULT         GR_TEXT_RIGHT
924 #define GR_TEXT_IS_VERTICAL(d)  ((d) & 1)
925 
926 /*
927  * text alignment options
928  */
929 #define GR_ALIGN_LEFT           0       /* X only */
930 #define GR_ALIGN_TOP            0       /* Y only */
931 #define GR_ALIGN_CENTER         1       /* X, Y   */
932 #define GR_ALIGN_RIGHT          2       /* X only */
933 #define GR_ALIGN_BOTTOM         2       /* Y only */
934 #define GR_ALIGN_BASELINE       3       /* Y only */
935 #define GR_ALIGN_DEFAULT        GR_ALIGN_LEFT
936 
937 /*
938  * character types in text strings
939  */
940 #define GR_BYTE_TEXT            0       /* one byte per character */
941 #define GR_WORD_TEXT            1       /* two bytes per character */
942 #define GR_ATTR_TEXT            2       /* chr w/ PC style attribute byte */
943 
944 /*
945  * macros to access components of various string/character types
946  */
947 #define GR_TEXTCHR_SIZE(ty)     (((ty) == GR_BYTE_TEXT) ? sizeof(char) : sizeof(short))
948 #define GR_TEXTCHR_CODE(ch,ty)  (((ty) == GR_WORD_TEXT) ? (unsigned short)(ch) : (unsigned char)(ch))
949 #define GR_TEXTCHR_ATTR(ch,ty)  (((ty) == GR_ATTR_TEXT) ? ((unsigned short)(ch) >> 8) : 0)
950 #define GR_TEXTSTR_CODE(pt,ty)  (((ty) == GR_WORD_TEXT) ? ((unsigned short *)(pt))[0] : ((unsigned char *)(pt))[0])
951 #define GR_TEXTSTR_ATTR(pt,ty)  (((ty) == GR_ATTR_TEXT) ? ((unsigned char *)(pt))[1] : 0)
952 
953 /*
954  * text attribute macros for the GR_ATTR_TEXT type
955  * _GR_textattrintensevideo drives if the eighth bit is used for
956  * underline (false, default) or more background colors (true)
957  */
958 extern int _GR_textattrintensevideo;
959 
960 #define GR_BUILD_ATTR(fg,bg,ul) (_GR_textattrintensevideo ? \
961                                 (((fg) & 15) | (((bg) & 15) << 4)) \
962                                 : \
963                                 (((fg) & 15) | (((bg) & 7) << 4) | ((ul) ? 128 : 0)) \
964                                 )
965 #define GR_ATTR_FGCOLOR(attr)   (((attr)     ) &  15)
966 #define GR_ATTR_BGCOLOR(attr)   (_GR_textattrintensevideo ? \
967                                 (((attr) >> 4) &  15) \
968                                 : \
969                                 (((attr) >> 4) &   7) \
970                                 )
971 #define GR_ATTR_UNDERLINE(attr) (_GR_textattrintensevideo ? \
972                                 (0) \
973                                 : \
974                                 (((attr)     ) & 128) \
975                                 )
976 
977 /*
978  * OR this to the foreground color value for underlined text when
979  * using GR_BYTE_TEXT or GR_WORD_TEXT modes.
980  */
981 #define GR_UNDERLINE_TEXT       (GrXOR << 4)
982 
983 /*
984  * Font conversion flags for 'GrLoadConvertedFont'. OR them as desired.
985  */
986 #define GR_FONTCVT_NONE         0       /* no conversion */
987 #define GR_FONTCVT_SKIPCHARS    1       /* load only selected characters */
988 #define GR_FONTCVT_RESIZE       2       /* resize the font */
989 #define GR_FONTCVT_ITALICIZE    4       /* tilt font for "italic" look */
990 #define GR_FONTCVT_BOLDIFY      8       /* make a "bold"(er) font  */
991 #define GR_FONTCVT_FIXIFY       16      /* convert prop. font to fixed wdt */
992 #define GR_FONTCVT_PROPORTION   32      /* convert fixed font to prop. wdt */
993 
994 /*
995  * font structures
996  */
997 typedef struct _GR_fontHeader {         /* font descriptor */
998 	char    *name;                      /* font name */
999 	char    *family;                    /* font family name */
1000 	char     proportional;              /* characters have varying width */
1001 	char     scalable;                  /* derived from a scalable font */
1002 	char     preloaded;                 /* set when linked into program */
1003 	char     modified;                  /* "tweaked" font (resized, etc..) */
1004 	unsigned int  width;                /* width (proportional=>average) */
1005 	unsigned int  height;               /* font height */
1006 	unsigned int  baseline;             /* baseline pixel pos (from top) */
1007 	unsigned int  ulpos;                /* underline pixel pos (from top) */
1008 	unsigned int  ulheight;             /* underline width */
1009 	unsigned int  minchar;              /* lowest character code in font */
1010 	unsigned int  numchars;             /* number of characters in font */
1011 } GrFontHeader;
1012 
1013 typedef struct _GR_fontChrInfo {        /* character descriptor */
1014 	unsigned int  width;                /* width of this character */
1015 	unsigned int  offset;               /* offset from start of bitmap */
1016 } GrFontChrInfo;
1017 
1018 typedef struct _GR_font {               /* the complete font */
1019 	struct  _GR_fontHeader  h;          /* the font info structure */
1020 	char     far *bitmap;               /* character bitmap array */
1021 	char     far *auxmap;               /* map for rotated & underline chrs */
1022 	unsigned int  minwidth;             /* width of narrowest character */
1023 	unsigned int  maxwidth;             /* width of widest character */
1024 	unsigned int  auxsize;              /* allocated size of auxiliary map */
1025 	unsigned int  auxnext;              /* next free byte in auxiliary map */
1026 	unsigned int  far      *auxoffs[7]; /* offsets to completed aux chars */
1027 	struct  _GR_fontChrInfo chrinfo[1]; /* character info (not act. size) */
1028 } GrFont;
1029 
1030 extern  GrFont          GrFont_PC6x8;
1031 extern  GrFont          GrFont_PC8x8;
1032 extern  GrFont          GrFont_PC8x14;
1033 extern  GrFont          GrFont_PC8x16;
1034 #define GrDefaultFont   GrFont_PC8x14
1035 
1036 GrFont *GrLoadFont(char *name);
1037 GrFont *GrLoadConvertedFont(char *name,int cvt,int w,int h,int minch,int maxch);
1038 GrFont *GrBuildConvertedFont(const GrFont *from,int cvt,int w,int h,int minch,int maxch);
1039 
1040 void GrUnloadFont(GrFont *font);
1041 void GrDumpFont(const GrFont *f,char *CsymbolName,char *fileName);
1042 void GrDumpFnaFont(const GrFont *f, char *fileName);
1043 void GrSetFontPath(char *path_list);
1044 
1045 int  GrFontCharPresent(const GrFont *font,int chr);
1046 int  GrFontCharWidth(const GrFont *font,int chr);
1047 int  GrFontCharHeight(const GrFont *font,int chr);
1048 int  GrFontCharBmpRowSize(const GrFont *font,int chr);
1049 int  GrFontCharBitmapSize(const GrFont *font,int chr);
1050 int  GrFontStringWidth(const GrFont *font,void *text,int len,int type);
1051 int  GrFontStringHeight(const GrFont *font,void *text,int len,int type);
1052 int  GrProportionalTextWidth(const GrFont *font,const void *text,int len,int type);
1053 
1054 char far *GrBuildAuxiliaryBitmap(GrFont *font,int chr,int dir,int ul);
1055 char far *GrFontCharBitmap(const GrFont *font,int chr);
1056 char far *GrFontCharAuxBmp(GrFont *font,int chr,int dir,int ul);
1057 
1058 typedef union _GR_textColor {           /* text color union */
1059 	GrColor       v;                    /* color value for "direct" text */
1060 	GrColorTableP p;                    /* color table for attribute text */
1061 } GrTextColor;
1062 
1063 typedef struct _GR_textOption {         /* text drawing option structure */
1064 	struct _GR_font     *txo_font;      /* font to be used */
1065 	union  _GR_textColor txo_fgcolor;   /* foreground color */
1066 	union  _GR_textColor txo_bgcolor;   /* background color */
1067 	char    txo_chrtype;                /* character type (see above) */
1068 	char    txo_direct;                 /* direction (see above) */
1069 	char    txo_xalign;                 /* X alignment (see above) */
1070 	char    txo_yalign;                 /* Y alignment (see above) */
1071 } GrTextOption;
1072 
1073 typedef struct {                        /* fixed font text window desc. */
1074 	struct _GR_font     *txr_font;      /* font to be used */
1075 	union  _GR_textColor txr_fgcolor;   /* foreground color */
1076 	union  _GR_textColor txr_bgcolor;   /* background color */
1077 	void   *txr_buffer;                 /* pointer to text buffer */
1078 	void   *txr_backup;                 /* optional backup buffer */
1079 	int     txr_width;                  /* width of area in chars */
1080 	int     txr_height;                 /* height of area in chars */
1081 	int     txr_lineoffset;             /* offset in buffer(s) between rows */
1082 	int     txr_xpos;                   /* upper left corner X coordinate */
1083 	int     txr_ypos;                   /* upper left corner Y coordinate */
1084 	char    txr_chrtype;                /* character type (see above) */
1085 } GrTextRegion;
1086 
1087 int  GrCharWidth(int chr,const GrTextOption *opt);
1088 int  GrCharHeight(int chr,const GrTextOption *opt);
1089 void GrCharSize(int chr,const GrTextOption *opt,int *w,int *h);
1090 int  GrStringWidth(void *text,int length,const GrTextOption *opt);
1091 int  GrStringHeight(void *text,int length,const GrTextOption *opt);
1092 void GrStringSize(void *text,int length,const GrTextOption *opt,int *w,int *h);
1093 
1094 void GrDrawChar(int chr,int x,int y,const GrTextOption *opt);
1095 void GrDrawString(void *text,int length,int x,int y,const GrTextOption *opt);
1096 void GrTextXY(int x,int y,char *text,GrColor fg,GrColor bg);
1097 
1098 void GrDumpChar(int chr,int col,int row,const GrTextRegion *r);
1099 void GrDumpText(int col,int row,int wdt,int hgt,const GrTextRegion *r);
1100 void GrDumpTextRegion(const GrTextRegion *r);
1101 
1102 #ifndef GRX_SKIP_INLINES
1103 #define GrFontCharPresent(f,ch) (                                              \
1104 	((unsigned int)(ch) - (f)->h.minchar) < (f)->h.numchars                \
1105 )
1106 #define GrFontCharWidth(f,ch) (                                                \
1107 	GrFontCharPresent(f,ch) ?                                              \
1108 	(int)(f)->chrinfo[(unsigned int)(ch) - (f)->h.minchar].width :         \
1109 	(f)->h.width                                                           \
1110 )
1111 #define GrFontCharHeight(f,ch) (                                               \
1112 	(f)->h.height                                                          \
1113 )
1114 #define GrFontCharBmpRowSize(f,ch) (                                           \
1115 	GrFontCharPresent(f,ch) ?                                              \
1116 	(((f)->chrinfo[(unsigned int)(ch) - (f)->h.minchar].width + 7) >> 3) : \
1117 	0                                                                      \
1118 )
1119 #define GrFontCharBitmapSize(f,ch) (                                           \
1120 	GrFontCharBmpRowSize(f,ch) * (f)->h.height                             \
1121 )
1122 #define GrFontStringWidth(f,t,l,tp) (                                          \
1123 	(f)->h.proportional ?                                                  \
1124 	GrProportionalTextWidth((f),(t),(l),(tp)) :                            \
1125 	(f)->h.width * (l)                                                     \
1126 )
1127 #define GrFontStringHeight(f,t,l,tp) (                                         \
1128 	(f)->h.height                                                          \
1129 )
1130 #define GrFontCharBitmap(f,ch) (                                               \
1131 	GrFontCharPresent(f,ch) ?                                              \
1132 	&(f)->bitmap[(f)->chrinfo[(unsigned int)(ch) - (f)->h.minchar].offset]:\
1133 	(char far *)0                                                          \
1134 )
1135 #define GrFontCharAuxBmp(f,ch,dir,ul) (                                        \
1136 	(((dir) == GR_TEXT_DEFAULT) && !(ul)) ?                                \
1137 	GrFontCharBitmap(f,ch) :                                               \
1138 	GrBuildAuxiliaryBitmap((f),(ch),(dir),(ul))                            \
1139 )
1140 #define GrCharWidth(c,o) (                                                     \
1141 	GR_TEXT_IS_VERTICAL((o)->txo_direct) ?                                 \
1142 	GrFontCharHeight((o)->txo_font,GR_TEXTCHR_CODE(c,(o)->txo_chrtype)) :  \
1143 	GrFontCharWidth( (o)->txo_font,GR_TEXTCHR_CODE(c,(o)->txo_chrtype))    \
1144 )
1145 #define GrCharHeight(c,o) (                                                    \
1146 	GR_TEXT_IS_VERTICAL((o)->txo_direct) ?                                 \
1147 	GrFontCharWidth( (o)->txo_font,GR_TEXTCHR_CODE(c,(o)->txo_chrtype)) :  \
1148 	GrFontCharHeight((o)->txo_font,GR_TEXTCHR_CODE(c,(o)->txo_chrtype))    \
1149 )
1150 #define GrCharSize(c,o,wp,hp) do {                                             \
1151 	*(wp) = GrCharHeight(c,o);                                             \
1152 	*(hp) = GrCharWidth( c,o);                                             \
1153 } while(0)
1154 #define GrStringWidth(t,l,o) (                                                 \
1155 	GR_TEXT_IS_VERTICAL((o)->txo_direct) ?                                 \
1156 	GrFontStringHeight((o)->txo_font,(t),(l),(o)->txo_chrtype) :           \
1157 	GrFontStringWidth( (o)->txo_font,(t),(l),(o)->txo_chrtype)             \
1158 )
1159 #define GrStringHeight(t,l,o) (                                                \
1160 	GR_TEXT_IS_VERTICAL((o)->txo_direct) ?                                 \
1161 	GrFontStringWidth( (o)->txo_font,(t),(l),(o)->txo_chrtype) :           \
1162 	GrFontStringHeight((o)->txo_font,(t),(l),(o)->txo_chrtype)             \
1163 )
1164 #define GrStringSize(t,l,o,wp,hp) do {                                         \
1165 	*(wp) = GrStringWidth( t,l,o);                                         \
1166 	*(hp) = GrStringHeight(t,l,o);                                         \
1167 } while(0)
1168 #endif /* GRX_SKIP_INLINES */
1169 
1170 /* ================================================================== */
1171 /*            THICK AND DASHED LINE DRAWING PRIMITIVES                */
1172 /* ================================================================== */
1173 
1174 /*
1175  * custom line option structure
1176  *   zero or one dash pattern length means the line is continuous
1177  *   the dash pattern always begins with a drawn section
1178  */
1179 typedef struct {
1180 	GrColor lno_color;                  /* color used to draw line */
1181 	int     lno_width;                  /* width of the line */
1182 	int     lno_pattlen;                /* length of the dash pattern */
1183 	unsigned char *lno_dashpat;         /* draw/nodraw pattern */
1184 } GrLineOption;
1185 
1186 void GrCustomLine(int x1,int y1,int x2,int y2,const GrLineOption *o);
1187 void GrCustomBox(int x1,int y1,int x2,int y2,const GrLineOption *o);
1188 void GrCustomCircle(int xc,int yc,int r,const GrLineOption *o);
1189 void GrCustomEllipse(int xc,int yc,int xa,int ya,const GrLineOption *o);
1190 void GrCustomCircleArc(int xc,int yc,int r,int start,int end,int style,const GrLineOption *o);
1191 void GrCustomEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,const GrLineOption *o);
1192 void GrCustomPolyLine(int numpts,int points[][2],const GrLineOption *o);
1193 void GrCustomPolygon(int numpts,int points[][2],const GrLineOption *o);
1194 
1195 /* ================================================================== */
1196 /*             PATTERNED DRAWING AND FILLING PRIMITIVES               */
1197 /* ================================================================== */
1198 
1199 /*
1200  * BITMAP: a mode independent way to specify a fill pattern of two
1201  *   colors. It is always 8 pixels wide (1 byte per scan line), its
1202  *   height is user-defined. SET THE TYPE FLAG TO ZERO!!!
1203  */
1204 typedef struct _GR_bitmap {
1205 	int     bmp_ispixmap;               /* type flag for pattern union */
1206 	int     bmp_height;                 /* bitmap height */
1207 	char   *bmp_data;                   /* pointer to the bit pattern */
1208 	GrColor bmp_fgcolor;                /* foreground color for fill */
1209 	GrColor bmp_bgcolor;                /* background color for fill */
1210 	int     bmp_memflags;               /* set if dynamically allocated */
1211 } GrBitmap;
1212 
1213 /*
1214  * PIXMAP: a fill pattern stored in a layout identical to the video RAM
1215  *   for filling using 'bitblt'-s. It is mode dependent, typically one
1216  *   of the library functions is used to build it. KEEP THE TYPE FLAG
1217  *   NONZERO!!!
1218  */
1219 typedef struct _GR_pixmap {
1220 	int     pxp_ispixmap;               /* type flag for pattern union */
1221 	int     pxp_width;                  /* pixmap width (in pixels)  */
1222 	int     pxp_height;                 /* pixmap height (in pixels) */
1223 	GrColor pxp_oper;                   /* bitblt mode (SET, OR, XOR, AND, IMAGE) */
1224 	struct _GR_frame pxp_source;        /* source context for fill */
1225 } GrPixmap;
1226 
1227 /*
1228  * Fill pattern union -- can either be a bitmap or a pixmap
1229  */
1230 typedef union _GR_pattern {
1231 	int      gp_ispixmap;               /* nonzero for pixmaps */
1232 	GrBitmap gp_bitmap;                 /* fill bitmap */
1233 	GrPixmap gp_pixmap;                 /* fill pixmap */
1234 } GrPattern;
1235 
1236 #define gp_bmp_data                     gp_bitmap.bmp_data
1237 #define gp_bmp_height                   gp_bitmap.bmp_height
1238 #define gp_bmp_fgcolor                  gp_bitmap.bmp_fgcolor
1239 #define gp_bmp_bgcolor                  gp_bitmap.bmp_bgcolor
1240 
1241 #define gp_pxp_width                    gp_pixmap.pxp_width
1242 #define gp_pxp_height                   gp_pixmap.pxp_height
1243 #define gp_pxp_oper                     gp_pixmap.pxp_oper
1244 #define gp_pxp_source                   gp_pixmap.pxp_source
1245 
1246 /*
1247  * Draw pattern for line drawings -- specifies both the:
1248  *   (1) fill pattern, and the
1249  *   (2) custom line drawing option
1250  */
1251 typedef struct {
1252 	GrPattern     *lnp_pattern;         /* fill pattern */
1253 	GrLineOption  *lnp_option;          /* width + dash pattern */
1254 } GrLinePattern;
1255 
1256 GrPattern *GrBuildPixmap(const char *pixels,int w,int h,const GrColorTableP colors);
1257 GrPattern *GrBuildPixmapFromBits(const char *bits,int w,int h,GrColor fgc,GrColor bgc);
1258 GrPattern *GrConvertToPixmap(GrContext *src);
1259 
1260 void GrDestroyPattern(GrPattern *p);
1261 
1262 void GrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp);
1263 void GrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp);
1264 void GrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp);
1265 void GrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp);
1266 void GrPatternedCircleArc(int xc,int yc,int r,int start,int end,int style,GrLinePattern *lp);
1267 void GrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrLinePattern *lp);
1268 void GrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp);
1269 void GrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp);
1270 
1271 void GrPatternFilledPlot(int x,int y,GrPattern *p);
1272 void GrPatternFilledLine(int x1,int y1,int x2,int y2,GrPattern *p);
1273 void GrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p);
1274 void GrPatternFilledCircle(int xc,int yc,int r,GrPattern *p);
1275 void GrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p);
1276 void GrPatternFilledCircleArc(int xc,int yc,int r,int start,int end,int style,GrPattern *p);
1277 void GrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrPattern *p);
1278 void GrPatternFilledConvexPolygon(int numpts,int points[][2],GrPattern *p);
1279 void GrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p);
1280 void GrPatternFloodFill(int x, int y, GrColor border, GrPattern *p);
1281 
1282 void GrPatternDrawChar(int chr,int x,int y,const GrTextOption *opt,GrPattern *p);
1283 void GrPatternDrawString(void *text,int length,int x,int y,const GrTextOption *opt,GrPattern *p);
1284 void GrPatternDrawStringExt(void *text,int length,int x,int y,const GrTextOption *opt,GrPattern *p);
1285 
1286 /* ================================================================== */
1287 /*                      IMAGE MANIPULATION                            */
1288 /* ================================================================== */
1289 
1290 /*
1291  *  by Michal Stencl Copyright (c) 1998 for GRX
1292  *  <e-mail>    - [stenclpmd@ba.telecom.sk]
1293  */
1294 
1295 #ifndef GrImage
1296 #define GrImage GrPixmap
1297 #endif
1298 
1299 /* Flags for GrImageInverse() */
1300 
1301 #define GR_IMAGE_INVERSE_LR  0x01  /* inverse left right */
1302 #define GR_IMAGE_INVERSE_TD  0x02  /* inverse top down */
1303 
1304 GrImage *GrImageBuild(const char *pixels,int w,int h,const GrColorTableP colors);
1305 void     GrImageDestroy(GrImage *i);
1306 void     GrImageDisplay(int x,int y, GrImage *i);
1307 void     GrImageDisplayExt(int x1,int y1,int x2,int y2, GrImage *i);
1308 void     GrImageFilledBoxAlign(int xo,int yo,int x1,int y1,int x2,int y2,GrImage *p);
1309 void     GrImageHLineAlign(int xo,int yo,int x,int y,int width,GrImage *p);
1310 void     GrImagePlotAlign(int xo,int yo,int x,int y,GrImage *p);
1311 
1312 GrImage *GrImageInverse(GrImage *p,int flag);
1313 GrImage *GrImageStretch(GrImage *p,int nwidth,int nheight);
1314 
1315 GrImage *GrImageFromPattern(GrPattern *p);
1316 GrImage *GrImageFromContext(GrContext *c);
1317 GrImage *GrImageBuildUsedAsPattern(const char *pixels,int w,int h,const GrColorTableP colors);
1318 
1319 GrPattern *GrPatternFromImage(GrImage *p);
1320 
1321 
1322 #ifndef GRX_SKIP_INLINES
1323 #define GrImageFromPattern(p) \
1324 	(((p) && (p)->gp_ispixmap) ? (&(p)->gp_pixmap) : NULL)
1325 #define GrImageFromContext(c) \
1326 	(GrImage *)GrConvertToPixmap(c)
1327 #define GrPatternFromImage(p) \
1328 	(GrPattern *)(p)
1329 #define GrImageBuildUsedAsPattern(pixels,w,h,colors) \
1330 	(GrImage *)GrBuildPixmap(pixels,w,h,colors);
1331 #define GrImageDestroy(i)   \
1332 	  GrDestroyPattern((GrPattern *)(i));
1333 #endif
1334 
1335 /* ================================================================== */
1336 /*               DRAWING IN USER WINDOW COORDINATES                   */
1337 /* ================================================================== */
1338 
1339 void GrSetUserWindow(int x1,int y1,int x2,int y2);
1340 void GrGetUserWindow(int *x1,int *y1,int *x2,int *y2);
1341 void GrGetScreenCoord(int *x,int *y);
1342 void GrGetUserCoord(int *x,int *y);
1343 
1344 void GrUsrPlot(int x,int y,GrColor c);
1345 void GrUsrLine(int x1,int y1,int x2,int y2,GrColor c);
1346 void GrUsrHLine(int x1,int x2,int y,GrColor c);
1347 void GrUsrVLine(int x,int y1,int y2,GrColor c);
1348 void GrUsrBox(int x1,int y1,int x2,int y2,GrColor c);
1349 void GrUsrFilledBox(int x1,int y1,int x2,int y2,GrColor c);
1350 void GrUsrFramedBox(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c);
1351 void GrUsrCircle(int xc,int yc,int r,GrColor c);
1352 void GrUsrEllipse(int xc,int yc,int xa,int ya,GrColor c);
1353 void GrUsrCircleArc(int xc,int yc,int r,int start,int end,int style,GrColor c);
1354 void GrUsrEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrColor c);
1355 void GrUsrFilledCircle(int xc,int yc,int r,GrColor c);
1356 void GrUsrFilledEllipse(int xc,int yc,int xa,int ya,GrColor c);
1357 void GrUsrFilledCircleArc(int xc,int yc,int r,int start,int end,int style,GrColor c);
1358 void GrUsrFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrColor c);
1359 void GrUsrPolyLine(int numpts,int points[][2],GrColor c);
1360 void GrUsrPolygon(int numpts,int points[][2],GrColor c);
1361 void GrUsrFilledConvexPolygon(int numpts,int points[][2],GrColor c);
1362 void GrUsrFilledPolygon(int numpts,int points[][2],GrColor c);
1363 void GrUsrFloodFill(int x, int y, GrColor border, GrColor c);
1364 
1365 GrColor GrUsrPixel(int x,int y);
1366 GrColor GrUsrPixelC(GrContext *c,int x,int y);
1367 
1368 void GrUsrCustomLine(int x1,int y1,int x2,int y2,const GrLineOption *o);
1369 void GrUsrCustomBox(int x1,int y1,int x2,int y2,const GrLineOption *o);
1370 void GrUsrCustomCircle(int xc,int yc,int r,const GrLineOption *o);
1371 void GrUsrCustomEllipse(int xc,int yc,int xa,int ya,const GrLineOption *o);
1372 void GrUsrCustomCircleArc(int xc,int yc,int r,int start,int end,int style,const GrLineOption *o);
1373 void GrUsrCustomEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,const GrLineOption *o);
1374 void GrUsrCustomPolyLine(int numpts,int points[][2],const GrLineOption *o);
1375 void GrUsrCustomPolygon(int numpts,int points[][2],const GrLineOption *o);
1376 
1377 void GrUsrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp);
1378 void GrUsrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp);
1379 void GrUsrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp);
1380 void GrUsrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp);
1381 void GrUsrPatternedCircleArc(int xc,int yc,int r,int start,int end,int style,GrLinePattern *lp);
1382 void GrUsrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrLinePattern *lp);
1383 void GrUsrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp);
1384 void GrUsrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp);
1385 
1386 void GrUsrPatternFilledPlot(int x,int y,GrPattern *p);
1387 void GrUsrPatternFilledLine(int x1,int y1,int x2,int y2,GrPattern *p);
1388 void GrUsrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p);
1389 void GrUsrPatternFilledCircle(int xc,int yc,int r,GrPattern *p);
1390 void GrUsrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p);
1391 void GrUsrPatternFilledCircleArc(int xc,int yc,int r,int start,int end,int style,GrPattern *p);
1392 void GrUsrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrPattern *p);
1393 void GrUsrPatternFilledConvexPolygon(int numpts,int points[][2],GrPattern *p);
1394 void GrUsrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p);
1395 void GrUsrPatternFloodFill(int x, int y, GrColor border, GrPattern *p);
1396 
1397 void GrUsrDrawChar(int chr,int x,int y,const GrTextOption *opt);
1398 void GrUsrDrawString(char *text,int length,int x,int y,const GrTextOption *opt);
1399 void GrUsrTextXY(int x,int y,char *text,GrColor fg,GrColor bg);
1400 
1401 /* ================================================================== */
1402 /*                    GRAPHICS CURSOR UTILITIES                       */
1403 /* ================================================================== */
1404 
1405 typedef struct _GR_cursor {
1406 	struct _GR_context work;                    /* work areas (4) */
1407 	int     xcord,ycord;                        /* cursor position on screen */
1408 	int     xsize,ysize;                        /* cursor size */
1409 	int     xoffs,yoffs;                        /* LU corner to hot point offset */
1410 	int     xwork,ywork;                        /* save/work area sizes */
1411 	int     xwpos,ywpos;                        /* save/work area position on screen */
1412 	int     displayed;                          /* set if displayed */
1413 } GrCursor;
1414 
1415 GrCursor *GrBuildCursor(char far *pixels,int pitch,int w,int h,int xo,int yo,const GrColorTableP c);
1416 void GrDestroyCursor(GrCursor *cursor);
1417 void GrDisplayCursor(GrCursor *cursor);
1418 void GrEraseCursor(GrCursor *cursor);
1419 void GrMoveCursor(GrCursor *cursor,int x,int y);
1420 
1421 /* ================================================================== */
1422 /*               MOUSE AND KEYBOARD INPUT UTILITIES                   */
1423 /* ================================================================== */
1424 
1425 #define GR_M_MOTION         0x001               /* mouse event flag bits */
1426 #define GR_M_LEFT_DOWN      0x002
1427 #define GR_M_LEFT_UP        0x004
1428 #define GR_M_RIGHT_DOWN     0x008
1429 #define GR_M_RIGHT_UP       0x010
1430 #define GR_M_MIDDLE_DOWN    0x020
1431 #define GR_M_MIDDLE_UP      0x040
1432 #define GR_M_P4_DOWN        0x400
1433 #define GR_M_P4_UP          0x800
1434 #define GR_M_P5_DOWN        0x2000
1435 #define GR_M_P5_UP          0x4000
1436 #define GR_M_BUTTON_DOWN    (GR_M_LEFT_DOWN | GR_M_MIDDLE_DOWN | GR_M_RIGHT_DOWN | GR_M_P4_DOWN | GR_M_P5_DOWN)
1437 #define GR_M_BUTTON_UP      (GR_M_LEFT_UP   | GR_M_MIDDLE_UP   | GR_M_RIGHT_UP   | GR_M_P4_UP   | GR_M_P5_UP)
1438 #define GR_M_BUTTON_CHANGE  (GR_M_BUTTON_UP | GR_M_BUTTON_DOWN )
1439 
1440 #define GR_M_LEFT           0x01                /* mouse button index bits */
1441 #define GR_M_RIGHT          0x02
1442 #define GR_M_MIDDLE         0x04
1443 #define GR_M_P4             0x08
1444 #define GR_M_P5             0x10
1445 
1446 #define GR_M_KEYPRESS       0x080               /* other event flag bits */
1447 #define GR_M_POLL           0x100
1448 #define GR_M_NOPAINT        0x200
1449 #define GR_COMMAND          0x1000
1450 #define GR_M_EVENT          (GR_M_MOTION | GR_M_KEYPRESS | GR_M_BUTTON_CHANGE | GR_COMMAND)
1451 
1452 #define GR_KB_RIGHTSHIFT    0x01                /* Keybd states: right shift key depressed */
1453 #define GR_KB_LEFTSHIFT     0x02                /* left shift key depressed */
1454 #define GR_KB_CTRL          0x04                /* CTRL depressed */
1455 #define GR_KB_ALT           0x08                /* ALT depressed */
1456 #define GR_KB_SCROLLOCK     0x10                /* SCROLL LOCK active */
1457 #define GR_KB_NUMLOCK       0x20                /* NUM LOCK active */
1458 #define GR_KB_CAPSLOCK      0x40                /* CAPS LOCK active */
1459 #define GR_KB_INSERT        0x80                /* INSERT state active */
1460 #define GR_KB_SHIFT         (GR_KB_LEFTSHIFT | GR_KB_RIGHTSHIFT)
1461 
1462 #define GR_M_CUR_NORMAL     0                   /* MOUSE CURSOR modes: just the cursor */
1463 #define GR_M_CUR_RUBBER     1                   /* rectangular rubber band (XOR-d to the screen) */
1464 #define GR_M_CUR_LINE       2                   /* line attached to the cursor */
1465 #define GR_M_CUR_BOX        3                   /* rectangular box dragged by the cursor */
1466 
1467 #define GR_M_QUEUE_SIZE     128                 /* default queue size */
1468 
1469 typedef struct _GR_mouseEvent {                 /* mouse event buffer structure */
1470 	int  flags;                                 /* event type flags (see above) */
1471 	int  x,y;                                   /* mouse coordinates */
1472 	int  buttons;                               /* mouse button state */
1473 	int  key;                                   /* key code from keyboard */
1474 	int  kbstat;                                /* keybd status (ALT, CTRL, etc..) */
1475 	long dtime;                                 /* time since last event (msec) */
1476 } GrMouseEvent;
1477 
1478 /*
1479  * mouse status information
1480  */
1481 extern const struct _GR_mouseInfo {
1482 	int   (*block)(GrContext*,int,int,int,int); /* mouse block function */
1483 	void  (*unblock)(int flags);                /* mouse unblock function */
1484 	void  (*uninit)(void);                      /* mouse cleanupt function */
1485 	struct _GR_cursor     *cursor;              /* the mouse cursor */
1486 	struct _GR_mouseEvent *queue;               /* queue of pending input events */
1487 	int     msstatus;                           /* -1:missing, 0:unknown, 1:present, 2:initted */
1488 	int     displayed;                          /* cursor is (generally) drawn */
1489 	int     blockflag;                          /* cursor temp. erase/block flag */
1490 	int     docheck;                            /* need to check before gr. op. to screen */
1491 	int     cursmode;                           /* mouse cursor draw mode */
1492 	int     x1,y1,x2,y2;                        /* auxiliary params for some cursor draw modes */
1493 	GrColor curscolor;                          /* color for some cursor draw modes */
1494 	int     owncursor;                          /* auto generated cursor */
1495 	int     xpos,ypos;                          /* current mouse position */
1496 	int     xmin,xmax;                          /* mouse movement X coordinate limits */
1497 	int     ymin,ymax;                          /* mouse movement Y coordinate limits */
1498 	int     spmult,spdiv;                       /* mouse cursor speed factors */
1499 	int     thresh,accel;                       /* mouse acceleration parameters */
1500 	int     moved;                              /* mouse cursor movement flag */
1501 	int     qsize;                              /* max size of the queue */
1502 	int     qlength;                            /* current # of items in the queue */
1503 	int     qread;                              /* read pointer for the queue */
1504 	int     qwrite;                             /* write pointer for the queue */
1505 } * const GrMouseInfo;
1506 
1507 int  GrMouseDetect(void);
1508 void GrMouseEventMode(int dummy);
1509 void GrMouseInit(void);
1510 void GrMouseInitN(int queue_size);
1511 void GrMouseUnInit(void);
1512 void GrMouseSetSpeed(int spmult,int spdiv);
1513 void GrMouseSetAccel(int thresh,int accel);
1514 void GrMouseSetLimits(int x1,int y1,int x2,int y2);
1515 void GrMouseGetLimits(int *x1,int *y1,int *x2,int *y2);
1516 void GrMouseWarp(int x,int y);
1517 void GrMouseEventEnable(int enable_kb,int enable_ms);
1518 void GrMouseGetEvent(int flags,GrMouseEvent *event);
1519 
1520 void GrMouseGetEventT(int flags,GrMouseEvent *event,long timout_msecs);
1521 /* Note:
1522 **       event->dtime is only valid if any event occured (event->flags !=0)
1523 **       otherwise it's set as -1.
1524 **       Additionally event timing is now real world time. (X11 && Linux
1525 **       used clock(), user process time, up to 2.28f)
1526 */
1527 
1528 int  GrMousePendingEvent(void);
1529 
1530 GrCursor *GrMouseGetCursor(void);
1531 void GrMouseSetCursor(GrCursor *cursor);
1532 void GrMouseSetColors(GrColor fg,GrColor bg);
1533 void GrMouseSetCursorMode(int mode,...);
1534 void GrMouseDisplayCursor(void);
1535 void GrMouseEraseCursor(void);
1536 void GrMouseUpdateCursor(void);
1537 int  GrMouseCursorIsDisplayed(void);
1538 
1539 int  GrMouseBlock(GrContext *c,int x1,int y1,int x2,int y2);
1540 void GrMouseUnBlock(int return_value_from_GrMouseBlock);
1541 
1542 #if 0
1543 /* !! old style (before grx v2.26) keyboard interface    !!
1544    !! old functions still linkable but for compatibility !!
1545    !! across platforms and with future versions of GRX   !!
1546    !! one use functions from grkeys.h                    !! */
1547 #ifndef __MSDOS__
1548 int  kbhit(void);
1549 int  getch(void);
1550 #endif
1551 #ifndef __DJGPP__
1552 int  getkey(void);
1553 int  getxkey(void);
1554 #endif
1555 int  getkbstat(void);
1556 #endif
1557 /* Why this ???
1558 #ifdef __WATCOMC__
1559 int  getxkey(void);
1560 #endif
1561 */
1562 
1563 #ifndef GRX_SKIP_INLINES
1564 #define GrMouseEventMode(x)         /* nothing! */
1565 #define GrMouseGetCursor()          (GrMouseInfo->cursor)
1566 #define GrMouseCursorIsDisplayed()  (GrMouseInfo->displayed)
1567 #define GrMouseInit()               GrMouseInitN(GR_M_QUEUE_SIZE);
1568 #define GrMouseGetEvent(f,ev)       GrMouseGetEventT((f),(ev),(-1L));
1569 #define GrMousePendingEvent() (                                                \
1570 	GrMouseUpdateCursor(),                                                 \
1571    (GrMouseInfo->qlength > 0)                                                  \
1572 )
1573 #define GrMouseUnInit() do {                                                   \
1574 	if(GrMouseInfo->uninit) {                                              \
1575 	(*GrMouseInfo->uninit)();                                              \
1576 	}                                                                      \
1577 } while(0)
1578 #define GrMouseGetLimits(x1p,y1p,x2p,y2p) do {                                 \
1579 	*(x1p) = GrMouseInfo->xmin; *(y1p) = GrMouseInfo->ymin;                \
1580 	*(x2p) = GrMouseInfo->xmax; *(y2p) = GrMouseInfo->ymax;                \
1581 } while(0)
1582 #define GrMouseBlock(c,x1,y1,x2,y2) (                                          \
1583 	(((c) ? (const GrContext*)(c) : GrCurrentContext())->gc_onscreen &&    \
1584 	 (GrMouseInfo->docheck)) ?                                             \
1585 	(*GrMouseInfo->block)((c),(x1),(y1),(x2),(y2)) :                       \
1586 	0                                                                      \
1587 )
1588 #define GrMouseUnBlock(f) do {                                                 \
1589 	if((f) && GrMouseInfo->displayed) {                                    \
1590 	(*GrMouseInfo->unblock)((f));                                          \
1591 	}                                                                      \
1592 } while(0)
1593 #endif  /* GRX_SKIP_INLINES */
1594 
1595 /* ================================================================== */
1596 /*                           PNM FUNCTIONS                            */
1597 /* ================================================================== */
1598 
1599 /*
1600  *  The PNM formats, grx support load/save of
1601  *  binaries formats (4,5,6) only
1602  */
1603 
1604 #define PLAINPBMFORMAT 1
1605 #define PLAINPGMFORMAT 2
1606 #define PLAINPPMFORMAT 3
1607 #define PBMFORMAT      4
1608 #define PGMFORMAT      5
1609 #define PPMFORMAT      6
1610 
1611 /* The PNM functions */
1612 
1613 int GrSaveContextToPbm( GrContext *grc, char *pbmfn, char *docn );
1614 int GrSaveContextToPgm( GrContext *grc, char *pgmfn, char *docn );
1615 int GrSaveContextToPpm( GrContext *grc, char *ppmfn, char *docn );
1616 int GrLoadContextFromPnm( GrContext *grc, char *pnmfn );
1617 int GrQueryPnm( char *pnmfn, int *width, int *height, int *maxval );
1618 int GrLoadContextFromPnmBuffer( GrContext *grc, const char *buffer );
1619 int GrQueryPnmBuffer( const char *buffer, int *width, int *height, int *maxval );
1620 
1621 /* ================================================================== */
1622 /*                           PNG FUNCTIONS                            */
1623 /*  these functions may not be installed or available on all system   */
1624 /* ================================================================== */
1625 
1626 int GrPngSupport( void );
1627 int GrSaveContextToPng( GrContext *grc, char *pngfn );
1628 int GrLoadContextFromPng( GrContext *grc, char *pngfn, int use_alpha );
1629 int GrQueryPng( char *pngfn, int *width, int *height );
1630 
1631 /* ================================================================== */
1632 /*                          JPEG FUNCTIONS                            */
1633 /*  these functions may not be installed or available on all system   */
1634 /* ================================================================== */
1635 
1636 int GrJpegSupport( void );
1637 int GrLoadContextFromJpeg( GrContext *grc, char *jpegfn, int scale );
1638 int GrQueryJpeg( char *jpegfn, int *width, int *height );
1639 int GrSaveContextToJpeg( GrContext *grc, char *jpegfn, int quality );
1640 int GrSaveContextToGrayJpeg( GrContext *grc, char *jpegfn, int quality );
1641 
1642 /* ================================================================== */
1643 /*               MISCELLANEOUS UTILITIY FUNCTIONS                     */
1644 /* ================================================================== */
1645 
1646 void GrResizeGrayMap(unsigned char far *map,int pitch,int ow,int oh,int nw,int nh);
1647 int  GrMatchString(const char *pattern,const char *strg);
1648 void GrSetWindowTitle(char *title);
1649 void GrSleep(int msec);
1650 void GrFlush(void);
1651 long GrMsecTime(void);
1652 
1653 /* ================================================================== */
1654 /*                        TIFF ADDON FUNCTIONS                        */
1655 /*  these functions may not be installed or available on all system   */
1656 /* ================================================================== */
1657 
1658 /*
1659 ** SaveContextToTiff - Dump a context in a TIFF file
1660 **
1661 ** Arguments:
1662 **   cxt:   Context to be saved (NULL -> use current context)
1663 **   tiffn: Name of tiff file
1664 **   compr: Compression method (see tiff.h), 0: automatic selection
1665 **   docn:  string saved in the tiff file (DOCUMENTNAME tag)
1666 **
1667 **  Returns  0 on success
1668 **          -1 on error
1669 **
1670 ** requires tifflib by  Sam Leffler (sam@engr.sgi.com)
1671 **        available at  ftp://ftp.sgi.com/graphics/tiff
1672 */
1673 int SaveContextToTiff(GrContext *cxt, char *tiffn, unsigned compr, char *docn);
1674 
1675 #ifdef __cplusplus
1676 }
1677 #endif
1678 #endif  /* whole file */
1679