1@ifnottex 2@node Top, A User Manual For GRX2, , 3@comment node-name, next,previous, up 4 5@center @majorheading GRX 2.4.9 User's Manual 6 7@center @chapheading A 2D graphics library for DOS, Linux, X11 and Win32 8@end ifnottex 9 10@center Based on the original doc written by: Csaba Biegl on August 10, 1992 11@center Updated by: Mariano Alvarez Fernandez on August 17, 2000 12@center Last update: July 10, 2012 13 14@unnumbered Abstract 15 16 @strong{GRX} is a 2D graphics library originaly written by 17Csaba Biegl for DJ Delorie's DOS port of the GCC compiler. Now it support 18a big range of platforms, the main four are: DOS (DJGPPv2), Linux console, 19X11 and Win32 (Mingw). On DOS it supports VGA, EGA and VESA compliant cards. 20On Linux console it uses svgalib or the framebuffer. On X11 it must work on 21any X11R5 (or later). From the 2.4 version, GRX comes with a Win32 driver. 22The framebuffer Linux console driver was new in 2.4.2. From 2.4.7 there is a 23support for x86_64 bits Linux machines and a support for an SDL driver 24on MingW and X11. On MingW and X11 it runs on a window with the original 25driver, and either full screen or on a window with the SDL driver. 26 27@menu 28* A User Manual For GRX2:: 29@end menu 30 31@c ----------------------------------------------------------------------------- 32@node A User Manual For GRX2, Hello world, Top, Top 33@unnumbered GRX2 User's Manual 34 35@menu 36* Top:: 37* Hello world:: 38* Data types and function declarations:: 39* Setting the graphics driver:: 40* Setting video modes:: 41* Graphics contexts:: 42* Context use:: 43* Color management:: 44* Portable use of a few colors:: 45* Graphics primitives:: 46* Non-clipping graphics primitives:: 47* Customized line drawing:: 48* Pattern filled graphics primitives:: 49* Patterned line drawing:: 50* Image manipulation:: 51* Text drawing:: 52* Drawing in user coordinates:: 53* Graphics cursors:: 54* Keyboard input:: 55* Mouse event handling:: 56* Writing/reading PNM graphics files:: 57* Writing/reading PNG graphics files:: 58* Writing/reading JPEG graphics files:: 59* Miscellaneous functions:: 60* BGI interface:: 61* Pascal interface:: 62* References:: 63@end menu 64 65@c ----------------------------------------------------------------------------- 66 67@node Hello world, Data types and function declarations, A User Manual For GRX2, A User Manual For GRX2 68@unnumberedsec Hello world 69The next program draws a double frame around the screen and writes "Hello, GRX 70world" centered. Then it waits after a key is pressed. 71 72@example 73#include <string.h> 74#include <grx20.h> 75#include <grxkeys.h> 76 77int main() 78@{ 79 char *message = "Hello, GRX world"; 80 int x, y; 81 GrTextOption grt; 82 83 GrSetMode( GR_default_graphics ); 84 85 grt.txo_font = &GrDefaultFont; 86 grt.txo_fgcolor.v = GrWhite(); 87 grt.txo_bgcolor.v = GrBlack(); 88 grt.txo_direct = GR_TEXT_RIGHT; 89 grt.txo_xalign = GR_ALIGN_CENTER; 90 grt.txo_yalign = GR_ALIGN_CENTER; 91 grt.txo_chrtype = GR_BYTE_TEXT; 92 93 GrBox( 0,0,GrMaxX(),GrMaxY(),GrWhite() ); 94 GrBox( 4,4,GrMaxX()-4,GrMaxY()-4,GrWhite() ); 95 96 x = GrMaxX()/2; 97 y = GrMaxY()/2; 98 GrDrawString( message,strlen( message ),x,y,&grt ); 99 100 GrKeyRead(); 101 102 return 0; 103@} 104 105@end example 106How to compile the hello world (assuming the GRX library was 107previously installed) 108@example 109 DJGPP: gcc -o hellogrx.exe hellogrx.c -lgrx20 110 Mingw: gcc -o hellogrx.exe hellogrx.c -lgrx20 -mwindows 111 X11 : gcc -o hellogrx hellogrx.c -D__XWIN__ -I/usr/X11R6/include 112 -lgrx20X -L/usr/X11R6/lib -lX11 113 Linux: gcc -o hellogrx hellogrx.c -lgrx20 -lvga 114 115 For the SDL driver: 116 Mingw: gcc -o hellogrx.exe hellogrx.c -lgrx20S -lSDL 117 X11 : gcc -o hellogrx hellogrx.c -D__XWIN__ -I/usr/X11R6/include 118 -lgrx20S -lSDL -lpthread -L/usr/X11R6/lib -lX11 119 120 For x86_64 systems add -m32 or -m64 for 32/64 bits executables 121 and replace /lib by /lib64 or /lib32 as needed 122 123@end example 124 125@c ----------------------------------------------------------------------------- 126@node Data types and function declarations, Setting the graphics driver, Hello world, A User Manual For GRX2 127@unnumberedsec Data types and function declarations 128All public data structures and graphics primitives meant for usage by the 129application program are declared/prototyped in the header files (in the 130'include' sub-directory): 131 132@example 133 * grdriver.h graphics driver format specifications 134 * grfontdv.h format of a font when loaded into memory 135 * grx20.h drawing-related structures and functions 136 * grxkeys.h platform independent key definitions 137 138User programs normally only include @strong{include/grx20.h} and @strong{include/grxkeys.h} 139@end example 140 141@c ----------------------------------------------------------------------------- 142@node Setting the graphics driver, Setting video modes, Data types and function declarations, A User Manual For GRX2 143@unnumberedsec Setting the graphics driver 144The graphics driver is normally set by the final user by the environment 145variable GRX20DRV, but a program can set it using: 146 147@example 148int GrSetDriver(char *drvspec); 149@end example 150 151The drvspec string has the same format as the environment variable: 152 153@example 154<driver> gw <width> gh <height> nc <colors> 155@end example 156 157Available drivers are for: 158 159@example 160* DOS => herc, stdvga, stdega, et4000, cl5426, mach64, ati28800, s3, VESA, memory 161* Linux => svgalib, linuxfb, memory 162* X11 => xwin, memory 163* Win32 => win32, memory 164* SDL (Win32 and X11) => sdl::fs, sdl::ww, memory 165@end example 166 167The xwin and win32 drivers are windowed. 168The SDL driver on the same systems can be either fullscreen (::fs) or windowed (::ww). 169 170The optionals gw, gh and nc parameters set the desired default graphics mode. 171Normal values for 'nc' are 2, 16, 256, 64K and 16M. The current driver name can 172be obtained from: 173 174@example 175GrCurrentVideoDriver()->name 176@end example 177 178@c ----------------------------------------------------------------------------- 179@node Setting video modes, Graphics contexts, Setting the graphics driver, A User Manual For GRX2 180@unnumberedsec Setting video modes 181 182Before a program can do any graphics drawing it has to configure the graphics 183driver for the desired graphics mode. It is done with the GrSetMode function as 184follows: 185 186@example 187int GrSetMode(int which,...); 188@end example 189 190On succes it returns non-zero (TRUE). The which parameter can be one of the 191following constants, declared in grx20.h: 192 193@example 194typedef enum _GR_graphicsModes @{ 195 GR_80_25_text, 196 GR_default_text, 197 GR_width_height_text, 198 GR_biggest_text, 199 GR_320_200_graphics, 200 GR_default_graphics, 201 GR_width_height_graphics, 202 GR_biggest_noninterlaced_graphics, 203 GR_biggest_graphics, 204 GR_width_height_color_graphics, 205 GR_width_height_color_text, 206 GR_custom_graphics, 207 GR_width_height_bpp_graphics, 208 GR_width_height_bpp_text, 209 GR_custom_bpp_graphics, 210 GR_NC_80_25_text, 211 GR_NC_default_text, 212 GR_NC_width_height_text, 213 GR_NC_biggest_text, 214 GR_NC_320_200_graphics, 215 GR_NC_default_graphics, 216 GR_NC_width_height_graphics, 217 GR_NC_biggest_noninterlaced_graphics, 218 GR_NC_biggest_graphics, 219 GR_NC_width_height_color_graphics, 220 GR_NC_width_height_color_text, 221 GR_NC_custom_graphics, 222 GR_NC_width_height_bpp_graphics, 223 GR_NC_width_height_bpp_text, 224 GR_NC_custom_bpp_graphics, 225@} GrGraphicsMode; 226@end example 227 228The GR_width_height_text and GR_width_height_graphics modes require the two 229size arguments: int width and int height. 230 231The GR_width_height_color_graphics and GR_width_height_color_text modes 232require three arguments: int width, int height and GrColor colors. 233 234The GR_width_height_bpp_graphics and GR_width_height_bpp_text modes require 235three arguments: int width, int height and int bpp (bits per plane instead 236number of colors). 237 238The GR_custom_graphics and GR_custom_bpp_graphics modes require five 239arguments: int width, int height, GrColor colors or int bpp, int vx and int vy. 240Using this modes you can set a virtual screen of vx by vy size. 241 242A call with any other mode does not require any arguments. 243 244The GR_NC_... modes are equivalent to the GR_.. ones, but they don't clear the 245video memory. 246 247Graphics drivers can provide info of the supported graphics modes, use the 248next code skeleton to colect the data: 249 250@example 251@{ 252 GrFrameMode fm; 253 const GrVideoMode *mp; 254 for(fm =GR_firstGraphicsFrameMode; fm <= GR_lastGraphicsFrameMode; fm++) @{ 255 mp = GrFirstVideoMode(fm); 256 while( mp != NULL ) @{ 257 .. 258 .. use the mp info 259 .. 260 mp = GrNextVideoMode(mp)) 261 @} 262 @} 263@} 264@end example 265 266Don't worry if you don't understand it, normal user programs don't need to 267know about FrameModes. The GrVideoMode structure has the following fields: 268 269@example 270typedef struct _GR_videoMode GrVideoMode; 271 272struct _GR_videoMode @{ 273 char present; /* is it really available? */ 274 char bpp; /* log2 of # of colors */ 275 short width,height; /* video mode geometry */ 276 short mode; /* BIOS mode number (if any) */ 277 int lineoffset; /* scan line length */ 278 int privdata; /* driver can use it for anything */ 279 struct _GR_videoModeExt *extinfo; /* extra info (maybe shared) */ 280@}; 281@end example 282 283The width, height and bpp members are the useful information if you are 284interested in set modes other than the GR_default_graphics. 285 286A user-defined function can be invoked every time the video mode is changed 287(i.e. GrSetMode is called). This function should not take any parameters and 288don't return any value. It can be installed (for all subsequent GrSetMode calls) 289with the: 290 291@example 292void GrSetModeHook(void (*hookfunc)(void)); 293@end example 294 295function. The current graphics mode (one of the valid mode argument values for 296GrSetMode) can be obtained with the: 297 298@example 299GrGraphicsMode GrCurrentMode(void); 300@end example 301 302function, while the type of the installed graphics adapter can be determined 303with the: 304 305@example 306GrVideoAdapter GrAdapterType(void); 307@end example 308 309function. GrAdapterType returns the type of the adapter as one of the following 310symbolic constants (defined in grx20.h): 311 312@example 313typedef enum _GR_videoAdapters @{ 314 GR_UNKNOWN = (-1), /* not known (before driver set) */ 315 GR_VGA, /* VGA adapter */ 316 GR_EGA, /* EGA adapter */ 317 GR_HERC, /* Hercules mono adapter */ 318 GR_8514A, /* 8514A or compatible */ 319 GR_S3, /* S3 graphics accelerator */ 320 GR_XWIN, /* X11 driver */ 321 GR_WIN32, /* WIN32 driver */ 322 GR_LNXFB, /* Linux framebuffer */ 323 GR_SDL, /* SDL driver */ 324 GR_MEM /* memory only driver */ 325@} GrVideoAdapter; 326@end example 327 328Note that the VESA driver return GR_VGA here. 329 330@c ----------------------------------------------------------------------------- 331@node Graphics contexts, Context use, Setting video modes, A User Manual For GRX2 332@unnumberedsec Graphics contexts 333 334 335The library supports a set of drawing regions called contexts (the GrContext 336structure). These can be in video memory or in system memory. Contexts in system 337memory always have the same memory organization as the video memory. When 338GrSetMode is called, a default context is created which maps to the whole 339graphics screen. Contexts are described by the GrContext data structure: 340 341@example 342typedef struct _GR_context GrContext; 343 344struct _GR_context @{ 345 struct _GR_frame gc_frame; /* frame buffer info */ 346 struct _GR_context *gc_root; /* context which owns frame */ 347 int gc_xmax; /* max X coord (width - 1) */ 348 int gc_ymax; /* max Y coord (height - 1) */ 349 int gc_xoffset; /* X offset from root's base */ 350 int gc_yoffset; /* Y offset from root's base */ 351 int gc_xcliplo; /* low X clipping limit */ 352 int gc_ycliplo; /* low Y clipping limit */ 353 int gc_xcliphi; /* high X clipping limit */ 354 int gc_ycliphi; /* high Y clipping limit */ 355 int gc_usrxbase; /* user window min X coordinate */ 356 int gc_usrybase; /* user window min Y coordinate */ 357 int gc_usrwidth; /* user window width */ 358 int gc_usrheight; /* user window height */ 359# define gc_baseaddr gc_frame.gf_baseaddr 360# define gc_selector gc_frame.gf_selector 361# define gc_onscreen gc_frame.gf_onscreen 362# define gc_memflags gc_frame.gf_memflags 363# define gc_lineoffset gc_frame.gf_lineoffset 364# define gc_driver gc_frame.gf_driver 365@}; 366@end example 367 368The following four functions return information about the layout of and memory 369occupied by a graphics context of size width by height in the current graphics 370mode (as set up by GrSetMode): 371 372@example 373int GrLineOffset(int width); 374int GrNumPlanes(void); 375long GrPlaneSize(int w,int h); 376long GrContextSize(int w,int h); 377@end example 378 379GrLineOffset always returns the offset between successive pixel rows of the 380context in bytes. GrNumPlanes returns the number of bitmap planes in the current 381graphics mode. GrContextSize calculates the total amount of memory needed by a 382context, while GrPlaneSize calculates the size of a bitplane in the context. The 383function: 384 385@example 386GrContext *GrCreateContext(int w,int h,char far *memory[4],GrContext *where); 387@end example 388 389can be used to create a new context in system memory. The NULL pointer is also 390accepted as the value of the memory and where arguments, in this case the 391library allocates the necessary amount of memory internally. It is a general 392convention in the library that functions returning pointers to any GRX 393specific data structure have a last argument (most of the time named where in 394the prototypes) which can be used to pass the address of the data structure 395which should be filled with the result. If this where pointer has the value of 396NULL, then the library allocates space for the data structure internally. 397 398The memory argument is really a 4 pointer array, each pointer must point to 399space to handle GrPlaneSize(w,h) bytes, really only GrNumPlanes() pointers must 400be malloced, the rest can be NULL. Nevertheless the normal use (see below) is 401 402@example 403gc = GrCreateContext(w,h,NULL,NULL); 404@end example 405 406so yo don't need to care about. 407 408The function: 409@example 410 411GrContext *GrCreateSubContext(int x1,int y1,int x2,int y2, 412 const GrContext *parent,GrContext *where); 413@end example 414 415creates a new sub-context which maps to a part of an existing context. The 416coordinate arguments (x1 through y2) are interpreted relative to the parent 417context's limits. Pixel addressing is zero-based even in sub-contexts, i.e. the 418address of the top left pixel is (0,0) even in a sub-context which has been 419mapped onto the interior of its parent context. 420 421Sub-contexts can be resized, but not their parents (i.e. anything returned by 422GrCreateContext or set up by GrSetMode cannot be resized -- because this could 423lead to irrecoverable "loss" of drawing memory. The following function can be 424used for this purpose: 425 426@example 427void GrResizeSubContext(GrContext *context,int x1,int y1,int x2,int y2); 428@end example 429 430The current context structure is stored in a static location in the library. 431(For efficiency reasons -- it is used quite frequently, and this way no pointer 432dereferencing is necessary.) The context stores all relevant information about 433the video organization, coordinate limits, etc... The current context can be set 434with the: 435 436@example 437void GrSetContext(const GrContext *context); 438@end example 439 440function. This function will reset the current context to the full graphics 441screen if it is passed the NULL pointer as argument. The value of the current 442context can be saved into a GrContext structure pointed to by where using: 443 444@example 445GrContext *GrSaveContext(GrContext *where); 446@end example 447 448(Again, if where is NULL, the library allocates the space.) The next two 449functions: 450 451@example 452const GrContext *GrCurrentContext(void); 453const GrContext *GrScreenContext(void); 454@end example 455 456return the current context and the screen context respectively. Contexts can be 457destroyed with: 458 459@example 460void GrDestroyContext(GrContext *context); 461@end example 462 463This function will free the memory occupied by the context only if it was 464allocated originally by the library. The next three functions set up and query 465the clipping limits associated with the current context: 466 467@example 468void GrSetClipBox(int x1,int y1,int x2,int y2); 469void GrGetClipBox(int *x1p,int *y1p,int *x2p,int *y2p); 470void GrResetClipBox(void); 471@end example 472 473GrResetClipBox sets the clipping limits to the limits of context. These are 474the limits set up initially when a context is created. There are three similar 475functions to sets/gets the clipping limits of any context: 476 477@example 478void GrSetClipBoxC(GrContext *c,int x1,int y1,int x2,int y2); 479void GrGetClipBoxC(const GrContext *c,int *x1p,int *y1p,int *x2p,int *y2p); 480void GrResetClipBoxC(GrContext *c); 481@end example 482 483The limits of the current context can be obtained using the following 484functions: 485 486@example 487int GrMaxX(void); 488int GrMaxY(void); 489int GrSizeX(void); 490int GrSizeY(void); 491@end example 492 493The Max functions return the biggest valid coordinate, while the Size 494functions return a value one higher. The limits of the graphics screen 495(regardless of the current context) can be obtained with: 496 497@example 498int GrScreenX(void); 499int GrScreenY(void); 500@end example 501 502If you had set a virtual screen (using a custom graphics mode), the limits of 503the virtual screen can be fetched with: 504 505@example 506int GrVirtualX(void); 507int GrVirtualY(void); 508@end example 509 510The routine: 511 512@example 513int GrScreenIsVirtual(void); 514@end example 515 516returns non zero if a virtual screen is set. The rectangle showed in the real 517screen can be set with: 518 519@example 520int GrSetViewport(int xpos,int ypos); 521@end example 522 523and the current viewport position can be obtained by: 524 525@example 526int GrViewportX(void); 527int GrViewportY(void); 528@end example 529 530@c ----------------------------------------------------------------------------- 531@node Context use, Color management, Graphics contexts, A User Manual For GRX2 532@unnumberedsec Context use 533 534 535Here is a example of normal context use: 536 537@example 538GrContext *grc; 539 540if( (grc = GrCreateContext( w,h,NULL,NULL )) == NULL )@{ 541 ...process the error 542 @} 543else @{ 544 GrSetContext( grc ); 545 ...do some drawing 546 ...and probably bitblt to the screen context 547 GrSetContext( NULL ); /* the screen context! */ 548 GrDestroyContext( grc ); 549 @} 550 551@end example 552 553But if you have a GrContext variable (not a pointer) you want to use (probably 554because is static to some routines) you can do: 555 556@example 557static GrContext grc; /* not a pointer!! */ 558 559if( GrCreateContext( w,h,NULL,&grc )) == NULL ) @{ 560 ...process the error 561 @} 562else @{ 563 GrSetContext( &grc ); 564 ...do some drawing 565 ...and probably bitblt to the screen context 566 GrSetContext( NULL ); /* the screen context! */ 567 GrDestroyContext( &grc ); 568 @} 569 570@end example 571 572Note that GrDestoryContext knows if grc was automatically malloced or not!! 573 574Only if you don't want GrCreateContext use malloc at all, you must allocate 575the memory buffers and pass it to GrCreateContext. 576 577Using GrCreateSubContext is the same, except it doesn't need the buffer, 578because it uses the parent buffer. 579 580See the @strong{test/winclip.c} and @strong{test/wintest.c} examples. 581 582@c ----------------------------------------------------------------------------- 583@node Color management, Portable use of a few colors, Context use, A User Manual For GRX2 584@unnumberedsec Color management 585 586GRX defines the type GrColor for color variables. GrColor it's a 32 bits 587integer. The 8 left bits are reserved for the write mode (see below). The 24 588bits right are the color value. 589 590The library supports two models for color management. In the 'indirect' (or 591color table) model, color values are indices to a color table. The color table 592slots will be allocated with the highest resolution supported by the hardware 593(EGA: 2 bits, VGA: 6 bits) with respect to the component color intensities. In 594the 'direct' (or RGB) model, color values map directly into component color 595intensities with non-overlapping bitfields of the color index representing the 596component colors. 597 598Color table model is supported until 256 color modes. The RGB model is 599supported in 256 color and up color modes. 600 601In RGB model the color index map to component color intensities depend on the 602video mode set, so it can't be assumed the component color bitfields (but if you 603are curious check the GrColorInfo global structure in grx20.h). 604 605After the first GrSetMode call two colors are always defined: black and white. 606The color values of these two colors are returned by the functions: 607 608@example 609GrColor GrBlack(void); 610GrColor GrWhite(void); 611@end example 612 613GrBlack() is guaranteed to be 0. 614 615The library supports five write modes (a write mode descibes the operation 616between the actual bit color and the one to be set): write, XOR, logical OR, 617logical AND and IMAGE. These can be selected with OR-ing the color value with 618one of the following constants declared in grx20.h : 619 620@example 621#define GrWRITE 0UL /* write color */ 622#define GrXOR 0x01000000UL /* to "XOR" any color to the screen */ 623#define GrOR 0x02000000UL /* to "OR" to the screen */ 624#define GrAND 0x03000000UL /* to "AND" to the screen */ 625#define GrIMAGE 0x04000000UL /* blit: write, except given color */ 626@end example 627 628The GrIMAGE write mode only works with the bitblt function. 629By convention, the no-op color is obtained by combining color value 0 (black) 630with the XOR operation. This no-op color has been defined in grx20.h as: 631 632@example 633#define GrNOCOLOR (GrXOR | 0) /* GrNOCOLOR is used for "no" color */ 634@end example 635 636The write mode part and the color value part of a GrColor variable can be 637obtained OR-ing it with one of the following constants declared in grx20.h: 638 639@example 640#define GrCVALUEMASK 0x00ffffffUL /* color value mask */ 641#define GrCMODEMASK 0xff000000UL /* color operation mask */ 642@end example 643 644The number of colors in the current graphics mode is returned by the: 645 646@example 647GrColor GrNumColors(void); 648@end example 649 650function, while the number of unused, available color can be obtained by 651calling: 652 653@example 654GrColor GrNumFreeColors(void); 655@end example 656 657Colors can be allocated with the: 658 659@example 660GrColor GrAllocColor(int r,int g,int b); 661GrColor GrAllocColor2(long hcolor); 662@end example 663 664functions (component intensities can range from 0 to 255, 665hcolor must be in 0xRRGGBB format), or with the: 666 667@example 668GrColor GrAllocCell(void); 669@end example 670 671function. In the second case the component intensities of the returned color can 672be set with: 673 674@example 675void GrSetColor(GrColor color,int r,int g,int b); 676@end example 677 678In the color table model both Alloc functions return GrNOCOLOR if there are no 679more free colors available. In the RGB model GrNumFreeColors returns 0 and 680GrAllocCell always returns GrNOCOLOR, as colors returned by GrAllocCell are 681meant to be changed -- what is not supposed to be done in RGB mode. Also note 682that GrAllocColor operates much more efficiently in RGB mode, and that it never 683returns GrNOCOLOR in this case. 684 685Color table entries can be freed (when not in RGB mode) by calling: 686 687@example 688void GrFreeColor(GrColor color); 689@end example 690 691The component intensities of any color can be queried using one of this function: 692 693@example 694void GrQueryColor(GrColor c,int *r,int *g,int *b); 695void GrQueryColor2(GrColor c,long *hcolor); 696@end example 697 698Initially the color system is in color table (indirect) model if there are 256 699or less colors. 256 color modes can be put into the RGB model by calling: 700 701@example 702void GrSetRGBcolorMode(void); 703@end example 704 705The color system can be reset (i.e. put back into color table model if 706possible, all colors freed except for black and white) by calling: 707 708@example 709void GrResetColors(void); 710@end example 711 712The function: 713 714@example 715void GrRefreshColors(void); 716@end example 717 718reloads the currently allocated color values into the video hardware. This 719function is not needed in typical applications, unless the display adapter is 720programmed directly by the application. 721 722This functions: 723 724@example 725GrColor GrAllocColorID(int r,int g,int b); 726GrColor GrAllocColor2ID(long hcolor); 727void GrQueryColorID(GrColor c,int *r,int *g,int *b); 728void GrQueryColor2ID(GrColor c,long *hcolor); 729@end example 730 731are inlined versions (except if you compile GRX with GRX_SKIP_INLINES defined) 732to be used in the RGB model (in the color table model they call the normal 733routines). 734 735See the @strong{test/rgbtest.c} and @strong{test/colorops.c} examples. 736 737 738@c ----------------------------------------------------------------------------- 739@node Portable use of a few colors, Graphics primitives, Color management, A User Manual For GRX2 740@unnumberedsec Portable use of a few colors 741 742People that only want to use a few colors find the GRX color handling a bit 743confusing, but it gives the power to manage a lot of color deeps and two color 744models. Here are some guidelines to easily use the famous 16 ega colors in GRX 745programs. We need this GRX function: 746 747@example 748GrColor *GrAllocEgaColors(void); 749@end example 750 751it returns a 16 GrColor array with the 16 ega colors alloced (really it's a 752trivial function, read the source src/setup/colorega.c). We can use a 753construction like that: 754 755First, in your C code make a global pointer, and init it after set the 756graphics mode: 757 758@example 759GrColor *egacolors; 760.... 761int your_setup_function( ... ) 762@{ 763 ... 764 GrSetMode( ... ) 765 ... 766 egacolors = GrAllocEgaColors(); 767 ... 768@} 769 770@end example 771 772Next, add this to your main include file: 773 774@example 775extern GrColor *egacolors; 776#define BLACK egacolors[0] 777#define BLUE egacolors[1] 778#define GREEN egacolors[2] 779#define CYAN egacolors[3] 780#define RED egacolors[4] 781#define MAGENTA egacolors[5] 782#define BROWN egacolors[6] 783#define LIGHTGRAY egacolors[7] 784#define DARKGRAY egacolors[8] 785#define LIGHTBLUE egacolors[9] 786#define LIGHTGREEN egacolors[10] 787#define LIGHTCYAN egacolors[11] 788#define LIGHTRED egacolors[12] 789#define LIGHTMAGENTA egacolors[13] 790#define YELLOW egacolors[14] 791#define WHITE egacolors[15] 792@end example 793 794Now you can use the defined colors in your code. Note that if you are in color 795table model in a 16 color mode, you have exhausted the color table. Note too 796that this don't work to initialize static variables with a color, because 797egacolors is not initialized. 798 799 800@c ----------------------------------------------------------------------------- 801@node Graphics primitives, Non-clipping graphics primitives, Portable use of a few colors, A User Manual For GRX2 802@unnumberedsec Graphics primitives 803 804The screen, the current context or the current clip box can be cleared (i.e. 805set to a desired background color) by using one of the following three 806functions: 807 808@example 809void GrClearScreen(GrColor bg); 810void GrClearContext(GrColor bg); 811void GrClearClipBox(GrColor bg); 812@end example 813 814Any context can be cleared using this function: 815@example 816void GrClearContextC(GrContext *ctx, GrColor bg); 817@end example 818 819Thanks to the special GrColor definition, you can do more than simple clear 820with this functions, by example with: 821 822@example 823GrClearScreen( GrWhite()|GrXOR ); 824@end example 825 826the graphics screen is negativized, do it again and the screen is restored. 827 828The following line drawing graphics primitives are supported by the library: 829 830@example 831void GrPlot(int x,int y,GrColor c); 832void GrLine(int x1,int y1,int x2,int y2,GrColor c); 833void GrHLine(int x1,int x2,int y,GrColor c); 834void GrVLine(int x,int y1,int y2,GrColor c); 835void GrBox(int x1,int y1,int x2,int y2,GrColor c); 836void GrCircle(int xc,int yc,int r,GrColor c); 837void GrEllipse(int xc,int yc,int xa,int ya,GrColor c); 838void GrCircleArc(int xc,int yc,int r,int start,int end,int style,GrColor c); 839void GrEllipseArc(int xc,int yc,int xa,int ya, 840 int start,int end,int style,GrColor c); 841void GrPolyLine(int numpts,int points[][2],GrColor c); 842void GrPolygon(int numpts,int points[][2],GrColor c); 843@end example 844 845All primitives operate on the current graphics context. The last argument of 846these functions is always the color to use for the drawing. The HLine and VLine 847primitives are for drawing horizontal and vertical lines. They have been 848included in the library because they are more efficient than the general line 849drawing provided by GrLine. The ellipse primitives can only draw ellipses with 850their major axis parallel with either the X or Y coordinate axis. They take the 851half X and Y axis length in the xa and ya arguments. The arc (circle and 852ellipse) drawing functions take the start and end angles in tenths of degrees 853(i.e. meaningful range: 0 ... 3600). The angles are interpreted 854counter-clockwise starting from the positive X axis. The style argument can be 855one of this defines from grx20.h: 856 857@example 858#define GR_ARC_STYLE_OPEN 0 859#define GR_ARC_STYLE_CLOSE1 1 860#define GR_ARC_STYLE_CLOSE2 2 861@end example 862 863GR_ARC_STYLE_OPEN draws only the arc, GR_ARC_STYLE_CLOSE1 closes the arc with 864a line between his start and end point, GR_ARC_STYLE_CLOSE1 draws the typical 865cake slice. This routine: 866 867@example 868void GrLastArcCoords(int *xs,int *ys,int *xe,int *ye,int *xc,int *yc); 869@end example 870 871can be used to retrieve the start, end, and center points used by the last arc 872drawing functions. 873 874See the @strong{test/circtest.c} and @strong{test/arctest.c} examples. 875 876The polyline and polygon primitives take the address of an n by 2 coordinate 877array. The X values should be stored in the elements with 0 second index, and 878the Y values in the elements with a second index value of 1. Coordinate arrays 879passed to the polygon primitive can either contain or omit the closing edge of 880the polygon -- the primitive will append it to the list if it is missing. 881 882See the @strong{test/polytest.c} example. 883 884Because calculating the arc points it's a very time consuming operation, there 885are two functions to pre-calculate the points, that can be used next with 886polyline and polygon primitives: 887 888@example 889int GrGenerateEllipse(int xc,int yc,int xa,int ya, 890 int points[GR_MAX_ELLIPSE_POINTS][2]); 891int GrGenerateEllipseArc(int xc,int yc,int xa,int ya,int start,int end, 892 int points[GR_MAX_ELLIPSE_POINTS][2]); 893@end example 894 895The following filled primitives are available: 896 897@example 898void GrFilledBox(int x1,int y1,int x2,int y2,GrColor c); 899void GrFramedBox(int x1,int y1,int x2,int y2,int wdt,const GrFBoxColors *c); 900void GrFilledCircle(int xc,int yc,int r,GrColor c); 901void GrFilledEllipse(int xc,int yc,int xa,int ya,GrColor c); 902void GrFilledCircleArc(int xc,int yc,int r, 903 int start,int end,int style,GrColor c); 904void GrFilledEllipseArc(int xc,int yc,int xa,int ya, 905 int start,int end,int style,GrColor c); 906void GrFilledPolygon(int numpts,int points[][2],GrColor c); 907void GrFilledConvexPolygon(int numpts,int points[][2],GrColor c); 908@end example 909 910Similarly to the line drawing, all of the above primitives operate on the 911current graphics context. The GrFramedBox primitive can be used to draw 912motif-like shaded boxes and "ordinary" framed boxes as well. The x1 through y2 913coordinates specify the interior of the box, the border is outside this area, 914wdt pixels wide. The primitive uses five different colors for the interior and 915four borders of the box which are specified in the GrFBoxColors structure: 916 917@example 918typedef struct @{ 919 GrColor fbx_intcolor; 920 GrColor fbx_topcolor; 921 GrColor fbx_rightcolor; 922 GrColor fbx_bottomcolor; 923 GrColor fbx_leftcolor; 924@} GrFBoxColors; 925@end example 926 927The GrFilledConvexPolygon primitive can be used to fill convex polygons. It 928can also be used to fill some concave polygons whose boundaries do not intersect 929any horizontal scan line more than twice. All other concave polygons have to be 930filled with the (somewhat less efficient) GrFilledPolygon primitive. This 931primitive can also be used to fill several disjoint non�overlapping polygons in 932a single operation. 933 934The function: 935 936@example 937void GrFloodFill(int x, int y, GrColor border, GrColor c); 938@end example 939 940flood-fills the area bounded by the color border using x, y like the starting 941point. 942 943Floodspill is a color replacer, replacing color A with color B. 944This is quite useful for highlighting a selected item in a list, or changing 945a selected color(s) in a multi colored area. 946 947@example 948void GrFloodSpill(int x1, int y1, int x2, int y2, 949 GrColor old_c, GrColor new_c) 950@end example 951 952replaces old color with new color in the rectangle bounded by x1, y1, x2, y2. 953 954@example 955void GrFloodSpillC(GrContext *ctx, int x1, int y1, int x2, int y2, 956 GrColor old_c, GrColor new_c) 957@end example 958 959as above but in the specified context. 960 961@example 962void GrFloodSpill2(int x1, int y1, int x2, int y2, 963 GrColor old_c1, GrColor new_c1, 964 GrColor old_c2, GrColor new_c2) 965@end example 966 967replaces 2 colors, a one stop shop for highlighting a selection in a list. 968 969@example 970void GrFloodSpillC2(GrContext *ctx, int x1, int y1, int x2, int y2, 971 GrColor old_c1, GrColor new_c1, 972 GrColor old_c2, GrColor new_c2) 973@end example 974 975as above but in the specified context. 976 977The current color value of any pixel in the current context can be obtained 978with: 979 980@example 981GrColor GrPixel(int x,int y); 982@end example 983 984and: 985 986@example 987GrColor GrPixelC(GrContext *c,int x,int y); 988@end example 989 990do the same for any context. 991 992Rectangular areas can be transferred within a context or between contexts by 993calling: 994 995@example 996void GrBitBlt(GrContext *dest,int x,int y,GrContext *source, 997 int x1,int y1,int x2,int y2,GrColor op); 998@end example 999 1000x, y is the position in the destination context, and x1, y1, x2, y2 the area 1001from the source context to be transfered. The op argument should be one of 1002supported color write modes (GrWRITE, GrXOR, GrOR, GrAND, GrIMAGE), it will 1003control how the pixels from the source context are combined with the pixels in 1004the destination context (the GrIMAGE op must be ored with the color value to be 1005handled as transparent). If either the source or the destination context 1006argument is the NULL pointer then the current context is used for that argument. 1007 1008See the @strong{test/blittest.c} example. 1009 1010A efficient form to get/put pixels from/to a context can be achieved using the 1011next functions: 1012 1013@example 1014const GrColor *GrGetScanline(int x1,int x2,int yy); 1015const GrColor *GrGetScanlineC(GrContext *ctx,int x1,int x2,int yy); 1016void GrPutScanline(int x1,int x2,int yy,const GrColor *c, GrColor op); 1017@end example 1018 1019The Get functions return a pointer to a static GrColor pixel array (or NULL if 1020they fail) with the color values of a row (yy) segment (x1 to x2). GrGetScanline 1021uses the current context. GrGestScanlineC uses the context ctx (that can be NULL 1022to refer to the current context). Note that the output is only valid until the 1023next GRX call. 1024 1025GrPutScanline puts the GrColor pixel array c on the yy row segmet defined by 1026x1 to x2 in the current context using the op operation. op can be any of 1027GrWRITE, GrXOR, GrOR, GrAND or GrIMAGE. Data in c must fit GrCVALUEMASK 1028otherwise the results are implementation dependend. So you can't supply 1029operation code with the pixel data!. 1030 1031@c ----------------------------------------------------------------------------- 1032@node Non-clipping graphics primitives, Customized line drawing, Graphics primitives, A User Manual For GRX2 1033@unnumberedsec Non-clipping graphics primitives 1034 1035There is a non-clipping version of some of the elementary primitives. These 1036are somewhat more efficient than the regular versions. These are to be used only 1037in situations when it is absolutely certain that no drawing will be performed 1038beyond the boundaries of the current context. Otherwise the program will almost 1039certainly crash! The reason for including these functions is that they are 1040somewhat more efficient than the regular, clipping versions. ALSO NOTE: These 1041function do not check for conflicts with the mouse cursor. (See the explanation 1042about the mouse cursor handling later in this document.) The list of the 1043supported non-clipping primitives: 1044 1045@example 1046void GrPlotNC(int x,int y,GrColor c); 1047void GrLineNC(int x1,int y1,int x2,int y2,GrColor c); 1048void GrHLineNC(int x1,int x2,int y,GrColor c); 1049void GrVLineNC(int x,int y1,int y2,GrColor c); 1050void GrBoxNC(int x1,int y1,int x2,int y2,GrColor c); 1051void GrFilledBoxNC(int x1,int y1,int x2,int y2,GrColor c); 1052void GrFramedBoxNC(int x1,int y1,int x2,int y2,int wdt,const GrFBoxColors *c); 1053void grbitbltNC(GrContext *dst,int x,int y,GrContext *src, 1054 int x1,int y1,int x2,int y2,GrColor op); 1055GrColor GrPixelNC(int x,int y); 1056GrColor GrPixelCNC(GrContext *c,int x,int y); 1057@end example 1058 1059@c ----------------------------------------------------------------------------- 1060@node Customized line drawing, Pattern filled graphics primitives, Non-clipping graphics primitives, A User Manual For GRX2 1061@unnumberedsec Customized line drawing 1062 1063The basic line drawing graphics primitives described previously always draw 1064continuous lines which are one pixel wide. There is another group of line 1065drawing functions which can be used to draw wide and/or patterned lines. These 1066functions have similar parameter passing conventions as the basic ones with one 1067difference: instead of the color value a pointer to a structure of type 1068GrLineOption has to be passed to them. The definition of the GrLineOption 1069structure: 1070 1071@example 1072typedef struct @{ 1073 GrColor lno_color; /* color used to draw line */ 1074 int lno_width; /* width of the line */ 1075 int lno_pattlen; /* length of the dash pattern */ 1076 unsigned char *lno_dashpat; /* draw/nodraw pattern */ 1077@} GrLineOption; 1078@end example 1079 1080The lno_pattlen structure element should be equal to the number of alternating 1081draw -- no draw section length values in the array pointed to by the lno_dashpat 1082element. The dash pattern array is assumed to begin with a drawn section. If the 1083pattern length is equal to zero a continuous line is drawn. 1084 1085Example, a white line 3 bits wide (thick) and pattern 6 bits draw, 4 bits nodraw: 1086 1087@example 1088GrLineOption mylineop; 1089... 1090mylineop.lno_color = GrWhite(); 1091mylineop.lno_width = 3; 1092mylineop.lno_pattlen = 2; 1093mylineop.lno_dashpat = "\x06\x04"; 1094@end example 1095 1096The available custom line drawing primitives: 1097 1098@example 1099void GrCustomLine(int x1,int y1,int x2,int y2,const GrLineOption *o); 1100void GrCustomBox(int x1,int y1,int x2,int y2,const GrLineOption *o); 1101void GrCustomCircle(int xc,int yc,int r,const GrLineOption *o); 1102void GrCustomEllipse(int xc,int yc,int xa,int ya,const GrLineOption *o); 1103void GrCustomCircleArc(int xc,int yc,int r, 1104 int start,int end,int style,const GrLineOption *o); 1105void GrCustomEllipseArc(int xc,int yc,int xa,int ya, 1106 int start,int end,int style,const GrLineOption *o); 1107void GrCustomPolyLine(int numpts,int points[][2],const GrLineOption *o); 1108void GrCustomPolygon(int numpts,int points[][2],const GrLineOption *o); 1109@end example 1110 1111See the @strong{test/linetest.c} example. 1112 1113@c ----------------------------------------------------------------------------- 1114@node Pattern filled graphics primitives, Patterned line drawing, Customized line drawing, A User Manual For GRX2 1115@unnumberedsec Pattern filled graphics primitives 1116 1117The library also supports a pattern filled version of the basic filled 1118primitives described above. These functions have similar parameter passing 1119conventions as the basic ones with one difference: instead of the color value a 1120pointer to an union of type 'GrPattern' has to be passed to them. The GrPattern 1121union can contain either a bitmap or a pixmap fill pattern. The first integer 1122slot in the union determines which type it is. Bitmap fill patterns are 1123rectangular arrays of bits, each set bit representing the foreground color of 1124the fill operation, and each zero bit representing the background. Both the 1125foreground and background colors can be combined with any of the supported 1126logical operations. Bitmap fill patterns have one restriction: their width must 1127be eight pixels. Pixmap fill patterns are very similar to contexts. The relevant 1128structure declarations (from grx20.h): 1129 1130@example 1131/* 1132 * BITMAP: a mode independent way to specify a fill pattern of two 1133 * colors. It is always 8 pixels wide (1 byte per scan line), its 1134 * height is user-defined. SET THE TYPE FLAG TO ZERO!!! 1135 */ 1136typedef struct _GR_bitmap @{ 1137 int bmp_ispixmap; /* type flag for pattern union */ 1138 int bmp_height; /* bitmap height */ 1139 char *bmp_data; /* pointer to the bit pattern */ 1140 GrColor bmp_fgcolor; /* foreground color for fill */ 1141 GrColor bmp_bgcolor; /* background color for fill */ 1142 int bmp_memflags; /* set if dynamically allocated */ 1143@} GrBitmap; 1144 1145/* 1146 * PIXMAP: a fill pattern stored in a layout identical to the video RAM 1147 * for filling using 'bitblt'-s. It is mode dependent, typically one 1148 * of the library functions is used to build it. KEEP THE TYPE FLAG 1149 * NONZERO!!! 1150 */ 1151typedef struct _GR_pixmap @{ 1152 int pxp_ispixmap; /* type flag for pattern union */ 1153 int pxp_width; /* pixmap width (in pixels) */ 1154 int pxp_height; /* pixmap height (in pixels) */ 1155 GrColor pxp_oper; /* bitblt mode (SET, OR, XOR, AND, IMAGE) */ 1156 struct _GR_frame pxp_source; /* source context for fill */ 1157@} GrPixmap; 1158 1159/* 1160 * Fill pattern union -- can either be a bitmap or a pixmap 1161 */ 1162typedef union _GR_pattern @{ 1163 int gp_ispixmap; /* nonzero for pixmaps */ 1164 GrBitmap gp_bitmap; /* fill bitmap */ 1165 GrPixmap gp_pixmap; /* fill pixmap */ 1166@} GrPattern; 1167 1168@end example 1169 1170This define group (from grx20.h) help to acces the GrPattern menbers: 1171 1172@example 1173#define gp_bmp_data gp_bitmap.bmp_data 1174#define gp_bmp_height gp_bitmap.bmp_height 1175#define gp_bmp_fgcolor gp_bitmap.bmp_fgcolor 1176#define gp_bmp_bgcolor gp_bitmap.bmp_bgcolor 1177 1178#define gp_pxp_width gp_pixmap.pxp_width 1179#define gp_pxp_height gp_pixmap.pxp_height 1180#define gp_pxp_oper gp_pixmap.pxp_oper 1181#define gp_pxp_source gp_pixmap.pxp_source 1182@end example 1183 1184Bitmap patterns can be easily built from initialized character arrays and 1185static structures by the C compiler, thus no special support is included in the 1186library for creating them. The only action required from the application program 1187might be changing the foreground and background colors as needed. Pixmap 1188patterns are more difficult to build as they replicate the layout of the video 1189memory which changes for different video modes. For this reason the library 1190provides three functions to create pixmap patterns in a mode-independent way: 1191 1192@example 1193GrPattern *GrBuildPixmap(const char *pixels,int w,int h,const GrColorTableP colors); 1194GrPattern *GrBuildPixmapFromBits(const char *bits,int w,int h, 1195 GrColor fgc,GrColor bgc); 1196GrPattern *GrConvertToPixmap(GrContext *src); 1197@end example 1198 1199GrBuildPixmap build a pixmap from a two dimensional (w by h) array of 1200characters. The elements in this array are used as indices into the color table 1201specified with the argument colors. (This means that pixmaps created this way 1202can use at most 256 colors.) The color table pointer: 1203 1204@example 1205typedef GrColor *GrColorTableP; 1206@end example 1207 1208should point to an array of integers with the first element being the number of 1209colors in the table and the color values themselves starting with the second 1210element. NOTE: any color modifiers (GrXOR, GrOR, GrAND) OR-ed to the elements of 1211the color table are ignored. 1212 1213The GrBuildPixmapFromBits function builds a pixmap fill pattern from bitmap 1214data. It is useful if the width of the bitmap pattern is not eight as such 1215bitmap patterns can not be used to build a GrBitmap structure. 1216 1217The GrConvertToPixmap function converts a graphics context to a pixmap fill 1218pattern. It is useful when the pattern can be created with graphics drawing 1219operations. NOTE: the pixmap pattern and the original context share the drawing 1220RAM, thus if the context is redrawn the fill pattern changes as well. Fill 1221patterns which were built by library routines can be destroyed when no longer 1222needed (i.e. the space occupied by them can be freed) by calling: 1223 1224@example 1225void GrDestroyPattern(GrPattern *p); 1226@end example 1227 1228NOTE: when pixmap fill patterns converted from contexts are destroyed, the 1229drawing RAM is not freed. It is freed when the original context is destroyed. 1230Fill patterns built by the application have to be destroyed by the application 1231as well (if this is needed). 1232 1233The list of supported pattern filled graphics primitives is shown below. These 1234functions are very similar to their solid filled counterparts, only their last 1235argument is different: 1236 1237@example 1238void GrPatternFilledPlot(int x,int y,GrPattern *p); 1239void GrPatternFilledLine(int x1,int y1,int x2,int y2,GrPattern *p); 1240void GrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p); 1241void GrPatternFilledCircle(int xc,int yc,int r,GrPattern *p); 1242void GrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p); 1243void GrPatternFilledCircleArc(int xc,int yc,int r,int start,int end, 1244 int style,GrPattern *p); 1245void GrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end, 1246 int style,GrPattern *p); 1247void GrPatternFilledConvexPolygon(int numpts,int points[][2],GrPattern *p); 1248void GrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p); 1249void GrPatternFloodFill(int x, int y, GrColor border, GrPattern *p); 1250@end example 1251 1252Strictly speaking the plot and line functions in the above group are not 1253filled, but they have been included here for convenience. 1254 1255@c ----------------------------------------------------------------------------- 1256@node Patterned line drawing, Image manipulation, Pattern filled graphics primitives, A User Manual For GRX2 1257@unnumberedsec Patterned line drawing 1258 1259The custom line drawing functions introduced above also have a version when 1260the drawn sections can be filled with a (pixmap or bitmap) fill pattern. To 1261achieve this these functions must be passed both a custom line drawing option 1262(GrLineOption structure) and a fill pattern (GrPattern union). These two have 1263been combined into the GrLinePattern structure: 1264 1265@example 1266typedef struct @{ 1267 GrPattern *lnp_pattern; /* fill pattern */ 1268 GrLineOption *lnp_option; /* width + dash pattern */ 1269@} GrLinePattern; 1270 1271@end example 1272 1273All patterned line drawing functions take a pointer to this structure as their 1274last argument. The list of available functions: 1275 1276@example 1277void GrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp); 1278void GrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp); 1279void GrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp); 1280void GrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp); 1281void GrPatternedCircleArc(int xc,int yc,int r,int start,int end, 1282 int style,GrLinePattern *lp); 1283void GrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end, 1284 int style,GrLinePattern *lp); 1285void GrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp); 1286void GrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp); 1287 1288@end example 1289 1290@c ----------------------------------------------------------------------------- 1291@node Image manipulation, Text drawing, Patterned line drawing, A User Manual For GRX2 1292@unnumberedsec Image manipulation 1293 1294GRX defines the GrImage type like a GrPixmap synonym: 1295 1296@example 1297#define GrImage GrPixmap 1298@end example 1299 1300nevertheless the GrImage type enforces the image character of this object, so 1301for compatibility with future GRX versions use the next functions if you need to 1302convert between GrImage and GrPixmap objects: 1303 1304@example 1305GrImage *GrImageFromPattern(GrPattern *p); 1306GrPattern *GrPatternFromImage(GrImage *p); 1307@end example 1308 1309the GrImageFromPattern function returns NULL if the GrPattern given is not a 1310GrPixmap. 1311 1312Like pixmaps patterns images are dependent of the actual video mode set. So 1313the library provides functions to create images in a mode-independent way: 1314 1315@example 1316GrImage *GrImageBuild(const char *pixels,int w,int h,const GrColorTableP colors); 1317GrImage *GrImageFromContext(GrContext *c); 1318@end example 1319 1320these functions work like the GrBuildPixmap and GrConvertToPixmap ones. 1321Remember: the image and the original context share the drawing RAM. 1322 1323There are a number of functions to display all or part of an image in the 1324current context: 1325 1326@example 1327void GrImageDisplay(int x,int y, GrImage *i); 1328void GrImageDisplayExt(int x1,int y1,int x2,int y2, GrImage *i); 1329void GrImageFilledBoxAlign(int xo,int yo,int x1,int y1,int x2,int y2, 1330 GrImage *p); 1331void GrImageHLineAlign(int xo,int yo,int x,int y,int width,GrImage *p); 1332void GrImagePlotAlign(int xo,int yo,int x,int y,GrImage *p); 1333@end example 1334 1335GrImageDisplay display the whole image using x, y like the upper left corner 1336in the current context. GrImageDisplayExt display as much as it can (repiting 1337the image if necesary) in the rectangle defined by x1, y1 and x2, y2. 1338 1339GrImageFilledBoxAlign is a most general funtion (really the later two call it) 1340display as much as it can in the defined rectangle using xo, yo like the align 1341point, it is the virtual point in the destination context (it doesn't need to be 1342into the rectangle) with that the upper left image corner is aligned. 1343 1344GrImageHLineAlign and GrImagePlotAlign display a row segment or a point of the 1345image at x y position using the xo, yo allign point. 1346 1347The most usefull image funtions are these: 1348 1349@example 1350GrImage *GrImageInverse(GrImage *p,int flag); 1351GrImage *GrImageStretch(GrImage *p,int nwidth,int nheight); 1352@end example 1353 1354GrImageInverse creates a new image object, flipping p left-right or top-down 1355as indicated by flag that can be: 1356 1357@example 1358#define GR_IMAGE_INVERSE_LR 0x01 /* inverse left right */ 1359#define GR_IMAGE_INVERSE_TD 0x02 /* inverse top down */ 1360@end example 1361 1362GrImageStretch creates a new image stretching p to nwidth by nheight. 1363 1364To destroy a image objet when you don't need it any more use: 1365 1366@example 1367void GrImageDestroy(GrImage *i); 1368@end example 1369 1370See the @strong{test/imgtest.c} example. 1371 1372@c ----------------------------------------------------------------------------- 1373@node Text drawing, Drawing in user coordinates, Image manipulation, A User Manual For GRX2 1374@unnumberedsec Text drawing 1375 1376The library supports loadable fonts. When in memory they are bit-mapped (i.e. 1377not scalable!) fonts. A driver design allow GRX to load different font formats, 1378the last GRX release come with drivers to load the GRX own font format and the 1379BGI Borland format for all platforms supported, the X11 version can load X11 1380fonts too. 1381 1382The GRX distribution come with a font collection in the GRX own format. Some 1383of these fonts were converted from VGA fonts. These fonts have all 256 1384characters from the PC-437 codepage. Some additional fonts were converted from 1385fonts in the MIT X11 distribution. Most of these are ISO-8859-1 coded. Fonts 1386also have family names. The following font families are included: 1387 1388@example 1389Font file name Family Description 1390pc<W>x<H>[t].fnt pc VGA font, fixed 1391xm<W>x<H>[b][i].fnt X_misc X11, fixed, miscellaneous group 1392char<H>[b][i].fnt char X11, proportional, charter family 1393cour<H>[b][i].fnt cour X11, fixed, courier 1394helve<H>[b][i].fnt helve X11, proportional, helvetica 1395lucb<H>[b][i].fnt lucb X11, proportional, lucida bright 1396lucs<H>[b][i].fnt lucs X11, proportional, lucida sans serif 1397luct<H>[b][i].fnt luct X11, fixed, lucida typewriter 1398ncen<H>[b][i].fnt ncen X11, proportional, new century schoolbook 1399symb<H>.fnt symbol X11, proportional, greek letters, symbols 1400tms<H>[b][i].fnt times X11, proportional, times 1401@end example 1402 1403In the font names <W> means the font width, <H> the font height. Many font 1404families have bold and/or italic variants. The files containing these fonts 1405contain a 'b' and/or 'i' character in their name just before the extension. 1406Additionally, the strings "_bold" and/or "_ital" are appended to the font family 1407names. Some of the pc VGA fonts come in thin formats also, these are denoted by 1408a 't' in their file names and the string "_thin" in their family names. 1409 1410The GrFont structure hold a font in memory. A number of 'pc' fonts are 1411built-in to the library and don't need to be loaded: 1412 1413@example 1414extern GrFont GrFont_PC6x8; 1415extern GrFont GrFont_PC8x8; 1416extern GrFont GrFont_PC8x14; 1417extern GrFont GrFont_PC8x16; 1418@end example 1419 1420Other fonts must be loaded with the GrLoadFont function. If the font file name 1421starts with any path separator character or character sequence (':', '/' or '\') 1422then it is loaded from the specified directory, otherwise the library try load 1423the font first from the current directory and next from the default font path. 1424The font path can be set up with the GrSetFontPath function. If the font path is 1425not set then the value of the 'GRXFONT' environment variable is used as the font 1426path. If GrLoadFont is called again with the name of an already loaded font then 1427it will return a pointer to the result of the first loading. Font loading 1428routines return NULL if the font was not found. When not needed any more, fonts 1429can be unloaded (i.e. the storage occupied by them freed) by calling 1430GrUnloadFont. 1431 1432The prototype declarations for these functions: 1433 1434@example 1435GrFont *GrLoadFont(char *name); 1436void GrUnloadFont(GrFont *font); 1437void GrSetFontPath(char *path_list); 1438@end example 1439 1440Using these functions: 1441 1442@example 1443GrFont *GrLoadConvertedFont(char *name,int cvt,int w,int h, 1444 int minch,int maxch); 1445GrFont *GrBuildConvertedFont(const GrFont *from,int cvt,int w,int h, 1446 int minch,int maxch); 1447@end example 1448 1449a new font can be generated from a file font or a font in memory, the 'cvt' 1450argument direct the conversion or-ing the desired operations from these defines: 1451 1452@example 1453/* 1454 * Font conversion flags for 'GrLoadConvertedFont'. OR them as desired. 1455 */ 1456#define GR_FONTCVT_NONE 0 /* no conversion */ 1457#define GR_FONTCVT_SKIPCHARS 1 /* load only selected characters */ 1458#define GR_FONTCVT_RESIZE 2 /* resize the font */ 1459#define GR_FONTCVT_ITALICIZE 4 /* tilt font for "italic" look */ 1460#define GR_FONTCVT_BOLDIFY 8 /* make a "bold"(er) font */ 1461#define GR_FONTCVT_FIXIFY 16 /* convert prop. font to fixed wdt */ 1462#define GR_FONTCVT_PROPORTION 32 /* convert fixed font to prop. wdt */ 1463@end example 1464 1465GR_FONTCVT_SKIPCHARS needs 'minch' and 'maxch' arguments. 1466 1467GR_FONTCVT_RESIZE needs 'w' and 'h' arguments. 1468 1469The function: 1470 1471@example 1472void GrDumpFnaFont(const GrFont *f, char *fileName); 1473@end example 1474 1475writes a font to an ascii font file, so it can be quickly edited with a text 1476editor. For a description of the ascii font format, see the fna.txt file. 1477 1478The function: 1479 1480@example 1481void GrDumpFont(const GrFont *f,char *CsymbolName,char *fileName); 1482@end example 1483 1484writes a font to a C source code file, so it can be compiled and linked with a 1485user program. GrDumpFont would not normally be used in a release program because 1486its purpose is to produce source code. When the source code is compiled and 1487linked into a program distributing the font file with the program in not 1488necessary, avoiding the possibility of the font file being deleted or corrupted. 1489 1490You can use the premade fnt2c.c program (see the source, it's so simple) to 1491dump a selected font to source code, by example: 1492 1493@example 1494fnt2c helv15 myhelv15 myhelv15.c 1495@end example 1496 1497Next, if this line is included in your main include file: 1498 1499@example 1500extern GrFont myhelv15 1501@end example 1502 1503and "myhelv15.c" compiled and linked with your project, you can use 'myhelv15' 1504in every place a GrFont is required. 1505 1506This simple function: 1507 1508@example 1509void GrTextXY(int x,int y,char *text,GrColor fg,GrColor bg); 1510@end example 1511 1512draw text in the current context in the standard direction, using the 1513GrDefaultFont (mapped in the grx20.h file to the GrFont_PC8x14 font) with x, y 1514like the upper left corner and the foreground and background colors given (note 1515that bg equal to GrNOCOLOR make the background transparent). 1516 1517For other functions the GrTextOption structure specifies how to draw a 1518character string: 1519 1520@example 1521typedef struct _GR_textOption @{ /* text drawing option structure */ 1522 struct _GR_font *txo_font; /* font to be used */ 1523 union _GR_textColor txo_fgcolor; /* foreground color */ 1524 union _GR_textColor txo_bgcolor; /* background color */ 1525 char txo_chrtype; /* character type (see above) */ 1526 char txo_direct; /* direction (see above) */ 1527 char txo_xalign; /* X alignment (see above) */ 1528 char txo_yalign; /* Y alignment (see above) */ 1529@} GrTextOption; 1530 1531typedef union _GR_textColor @{ /* text color union */ 1532 GrColor v; /* color value for "direct" text */ 1533 GrColorTableP p; /* color table for attribute text */ 1534@} GrTextColor; 1535 1536@end example 1537 1538The text can be rotated in increments of 90 degrees (txo_direct), alignments 1539can be set in both directions (txo_xalign and txo_yalign), and separate fore and 1540background colors can be specified. The accepted text direction values: 1541 1542@example 1543#define GR_TEXT_RIGHT 0 /* normal */ 1544#define GR_TEXT_DOWN 1 /* downward */ 1545#define GR_TEXT_LEFT 2 /* upside down, right to left */ 1546#define GR_TEXT_UP 3 /* upward */ 1547#define GR_TEXT_DEFAULT GR_TEXT_RIGHT 1548@end example 1549 1550The accepted horizontal and vertical alignment option values: 1551 1552@example 1553#define GR_ALIGN_LEFT 0 /* X only */ 1554#define GR_ALIGN_TOP 0 /* Y only */ 1555#define GR_ALIGN_CENTER 1 /* X, Y */ 1556#define GR_ALIGN_RIGHT 2 /* X only */ 1557#define GR_ALIGN_BOTTOM 2 /* Y only */ 1558#define GR_ALIGN_BASELINE 3 /* Y only */ 1559#define GR_ALIGN_DEFAULT GR_ALIGN_LEFT 1560@end example 1561 1562Text strings can be of three different types: one character per byte (i.e. the 1563usual C character string, this is the default), one character per 16-bit word 1564(suitable for fonts with a large number of characters), and a PC-style 1565character-attribute pair. In the last case the GrTextOption structure must 1566contain a pointer to a color table of size 16 (fg color bits in attrib) or 8 (bg 1567color bits). (The color table format is explained in more detail in the previous 1568section explaining the methods to build fill patterns.) The supported text 1569types: 1570 1571@example 1572#define GR_BYTE_TEXT 0 /* one byte per character */ 1573#define GR_WORD_TEXT 1 /* two bytes per character */ 1574#define GR_ATTR_TEXT 2 /* chr w/ PC style attribute byte */ 1575@end example 1576 1577The PC-style attribute text uses the same layout (first byte: character, 1578second: attributes) and bitfields as the text mode screen on the PC. The only 1579difference is that the 'blink' bit is not supported (it would be very time 1580consuming -- the PC text mode does it with hardware support). This bit is used 1581instead to control the underlined display of characters. For convenience the 1582following attribute manipulation macros have been declared in grx20.h: 1583 1584@example 1585#define GR_BUILD_ATTR(fg,bg,ul) \ 1586 (((fg) & 15) | (((bg) & 7) << 4) | ((ul) ? 128 : 0)) 1587#define GR_ATTR_FGCOLOR(attr) (((attr) ) & 15) 1588#define GR_ATTR_BGCOLOR(attr) (((attr) >> 4) & 7) 1589#define GR_ATTR_UNDERLINE(attr) (((attr) ) & 128) 1590@end example 1591 1592Text strings of the types GR_BYTE_TEXT and GR_WORD_TEXT can also be drawn 1593underlined. This is controlled by OR-ing the constant GR_UNDERLINE_TEXT to the 1594foreground color value: 1595 1596@example 1597#define GR_UNDERLINE_TEXT (GrXOR << 4) 1598@end example 1599 1600After the application initializes a text option structure with the desired 1601values it can call one of the following two text drawing functions: 1602 1603@example 1604void GrDrawChar(int chr,int x,int y,const GrTextOption *opt); 1605void GrDrawString(void *text,int length,int x,int y,const GrTextOption *opt); 1606@end example 1607 1608NOTE: text drawing is fastest when it is drawn in the 'normal' direction, and 1609the character does not have to be clipped. It this case the library can use the 1610appropriate low-level video RAM access routine, while in any other case the text 1611is drawn pixel-by-pixel by the higher-level code. 1612 1613There are pattern filed versions too: 1614 1615@example 1616void GrPatternDrawChar(int chr,int x,int y,const GrTextOption *opt,GrPattern *p); 1617void GrPatternDrawString(void *text,int length,int x,int y,const GrTextOption *opt, 1618 GrPattern *p); 1619void GrPatternDrawStringExt(void *text,int length,int x,int y, 1620 const GrTextOption *opt,GrPattern *p); 1621@end example 1622 1623The size of a font, a character or a text string can be obtained by calling 1624one of the following functions. These functions also take into consideration the 1625text direction specified in the text option structure passed to them. 1626 1627@example 1628int GrFontCharPresent(const GrFont *font,int chr); 1629int GrFontCharWidth(const GrFont *font,int chr); 1630int GrFontCharHeight(const GrFont *font,int chr); 1631int GrFontCharBmpRowSize(const GrFont *font,int chr); 1632int GrFontCharBitmapSize(const GrFont *font,int chr); 1633int GrFontStringWidth(const GrFont *font,void *text,int len,int type); 1634int GrFontStringHeight(const GrFont *font,void *text,int len,int type); 1635int GrProportionalTextWidth(const GrFont *font,void *text,int len,int type); 1636int GrCharWidth(int chr,const GrTextOption *opt); 1637int GrCharHeight(int chr,const GrTextOption *opt); 1638void GrCharSize(int chr,const GrTextOption *opt,int *w,int *h); 1639int GrStringWidth(void *text,int length,const GrTextOption *opt); 1640int GrStringHeight(void *text,int length,const GrTextOption *opt); 1641void GrStringSize(void *text,int length,const GrTextOption *opt,int *w,int *h); 1642@end example 1643 1644 The GrTextRegion structure and its associated functions can be used to 1645implement a fast (as much as possible in graphics modes) rectangular text window 1646using a fixed font. Clipping for such windows is done in character size 1647increments instead of pixels (i.e. no partial characters are drawn). Only fixed 1648fonts can be used in their natural size. GrDumpText will cache the code of the 1649drawn characters in the buffer pointed to by the 'backup' slot (if it is 1650non-NULL) and will draw a character only if the previously drawn character in 1651that grid element is different. 1652 1653This can speed up text scrolling significantly in graphics modes. The 1654supported text types are the same as above. 1655 1656@example 1657typedef struct @{ /* fixed font text window desc. */ 1658 struct _GR_font *txr_font; /* font to be used */ 1659 union _GR_textColor txr_fgcolor; /* foreground color */ 1660 union _GR_textColor txr_bgcolor; /* background color */ 1661 void *txr_buffer; /* pointer to text buffer */ 1662 void *txr_backup; /* optional backup buffer */ 1663 int txr_width; /* width of area in chars */ 1664 int txr_height; /* height of area in chars */ 1665 int txr_lineoffset; /* offset in buffer(s) between rows */ 1666 int txr_xpos; /* upper left corner X coordinate */ 1667 int txr_ypos; /* upper left corner Y coordinate */ 1668 char txr_chrtype; /* character type (see above) */ 1669@} GrTextRegion; 1670 1671void GrDumpChar(int chr,int col,int row,const GrTextRegion *r); 1672void GrDumpText(int col,int row,int wdt,int hgt,const GrTextRegion *r); 1673void GrDumpTextRegion(const GrTextRegion *r); 1674 1675@end example 1676 1677The GrDumpTextRegion function outputs the whole text region, while GrDumpText 1678draws only a user-specified part of it. GrDumpChar updates the character in the 1679buffer at the specified location with the new character passed to it as argument 1680and then draws the new character on the screen as well. With these functions you 1681can simulate a text mode window, write chars directly to the txr_buffer and call 1682GrDumpTextRegion when you want to update the window (or GrDumpText if you know 1683the area to update is small). 1684 1685See the @strong{test/fonttest.c} example. 1686 1687@c ----------------------------------------------------------------------------- 1688@node Drawing in user coordinates, Graphics cursors, Text drawing, A User Manual For GRX2 1689@unnumberedsec Drawing in user coordinates 1690 1691 1692There is a second set of the graphics primitives which operates in user 1693coordinates. Every context has a user to screen coordinate mapping associated 1694with it. An application specifies the user window by calling the GrSetUserWindow 1695function. 1696 1697@example 1698void GrSetUserWindow(int x1,int y1,int x2,int y2); 1699@end example 1700 1701A call to this function it in fact specifies the virtual coordinate limits 1702which will be mapped onto the current context regardless of the size of the 1703context. For example, the call: 1704 1705@example 1706GrSetUserWindow(0,0,11999,8999); 1707@end example 1708 1709tells the library that the program will perform its drawing operations in a 1710coordinate system X:0...11999 (width = 12000) and Y:0...8999 (height = 9000). 1711This coordinate range will be mapped onto the total area of the current context. 1712The virtual coordinate system can also be shifted. For example: 1713 1714@example 1715GrSetUserWindow(5000,2000,16999,10999); 1716@end example 1717 1718The user coordinates can even be used to turn the usual left-handed coordinate 1719system (0:0 corresponds to the upper left corner) to a right handed one (0:0 1720corresponds to the bottom left corner) by calling: 1721 1722@example 1723GrSetUserWindow(0,8999,11999,0); 1724@end example 1725 1726The library also provides three utility functions for the query of the current 1727user coordinate limits and for converting user coordinates to screen coordinates 1728and vice versa. 1729 1730@example 1731void GrGetUserWindow(int *x1,int *y1,int *x2,int *y2); 1732void GrGetScreenCoord(int *x,int *y); 1733void GrGetUserCoord(int *x,int *y); 1734@end example 1735 1736If an application wants to take advantage of the user to screen coordinate 1737mapping it has to use the user coordinate version of the graphics primitives. 1738These have exactly the same parameter passing conventions as their screen 1739coordinate counterparts. NOTE: the user coordinate system is not initialized by 1740the library! The application has to set up its coordinate mapping before calling 1741any of the use coordinate drawing functions -- otherwise the program will almost 1742certainly exit (in a quite ungraceful fashion) with a 'division by zero' error. 1743The list of supported user coordinate drawing functions: 1744 1745@example 1746void GrUsrPlot(int x,int y,GrColor c); 1747void GrUsrLine(int x1,int y1,int x2,int y2,GrColor c); 1748void GrUsrHLine(int x1,int x2,int y,GrColor c); 1749void GrUsrVLine(int x,int y1,int y2,GrColor c); 1750void GrUsrBox(int x1,int y1,int x2,int y2,GrColor c); 1751void GrUsrFilledBox(int x1,int y1,int x2,int y2,GrColor c); 1752void GrUsrFramedBox(int x1,int y1,int x2,int y2,int wdt,GrFBoxColors *c); 1753void GrUsrCircle(int xc,int yc,int r,GrColor c); 1754void GrUsrEllipse(int xc,int yc,int xa,int ya,GrColor c); 1755void GrUsrCircleArc(int xc,int yc,int r,int start,int end, 1756 int style,GrColor c); 1757void GrUsrEllipseArc(int xc,int yc,int xa,int ya,int start,int end, 1758 int style,GrColor c); 1759void GrUsrFilledCircle(int xc,int yc,int r,GrColor c); 1760void GrUsrFilledEllipse(int xc,int yc,int xa,int ya,GrColor c); 1761void GrUsrFilledCircleArc(int xc,int yc,int r,int start,int end, 1762 int style,GrColor c); 1763void GrUsrFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end, 1764 int style,GrColor c); 1765void GrUsrPolyLine(int numpts,int points[][2],GrColor c); 1766void GrUsrPolygon(int numpts,int points[][2],GrColor c); 1767void GrUsrFilledConvexPolygon(int numpts,int points[][2],GrColor c); 1768void GrUsrFilledPolygon(int numpts,int points[][2],GrColor c); 1769void GrUsrFloodFill(int x, int y, GrColor border, GrColor c); 1770GrColor GrUsrPixel(int x,int y); 1771GrColor GrUsrPixelC(GrContext *c,int x,int y); 1772void GrUsrCustomLine(int x1,int y1,int x2,int y2,const GrLineOption *o); 1773void GrUsrCustomBox(int x1,int y1,int x2,int y2,const GrLineOption *o); 1774void GrUsrCustomCircle(int xc,int yc,int r,const GrLineOption *o); 1775void GrUsrCustomEllipse(int xc,int yc,int xa,int ya,const GrLineOption *o); 1776void GrUsrCustomCircleArc(int xc,int yc,int r,int start,int end, 1777 int style,const GrLineOption *o); 1778void GrUsrCustomEllipseArc(int xc,int yc,int xa,int ya,int start,int end, 1779 int style,const GrLineOption *o); 1780void GrUsrCustomPolyLine(int numpts,int points[][2],const GrLineOption *o); 1781void GrUsrCustomPolygon(int numpts,int points[][2],const GrLineOption *o); 1782void GrUsrPatternedLine(int x1,int y1,int x2,int y2,GrLinePattern *lp); 1783void GrUsrPatternedBox(int x1,int y1,int x2,int y2,GrLinePattern *lp); 1784void GrUsrPatternedCircle(int xc,int yc,int r,GrLinePattern *lp); 1785void GrUsrPatternedEllipse(int xc,int yc,int xa,int ya,GrLinePattern *lp); 1786void GrUsrPatternedCircleArc(int xc,int yc,int r,int start,int end, 1787 int style,GrLinePattern *lp); 1788void GrUsrPatternedEllipseArc(int xc,int yc,int xa,int ya,int start,int end, 1789 int style,GrLinePattern *lp); 1790void GrUsrPatternedPolyLine(int numpts,int points[][2],GrLinePattern *lp); 1791void GrUsrPatternedPolygon(int numpts,int points[][2],GrLinePattern *lp); 1792void GrUsrPatternFilledPlot(int x,int y,GrPattern *p); 1793void GrUsrPatternFilledLine(int x1,int y1,int x2,int y2,GrPattern *p); 1794void GrUsrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p); 1795void GrUsrPatternFilledCircle(int xc,int yc,int r,GrPattern *p); 1796void GrUsrPatternFilledEllipse(int xc,int yc,int xa,int ya,GrPattern *p); 1797void GrUsrPatternFilledCircleArc(int xc,int yc,int r,int start,int end,int style,GrPattern *p); 1798void GrUsrPatternFilledEllipseArc(int xc,int yc,int xa,int ya,int start,int end,int style,GrPattern *p); 1799void GrUsrPatternFilledConvexPolygon(int numpts,int points[][2],GrPattern *p); 1800void GrUsrPatternFilledPolygon(int numpts,int points[][2],GrPattern *p); 1801void GrUsrPatternFloodFill(int x, int y, GrColor border, GrPattern *p); 1802void GrUsrDrawChar(int chr,int x,int y,const GrTextOption *opt); 1803void GrUsrDrawString(char *text,int length,int x,int y,const GrTextOption *opt); 1804void GrUsrTextXY(int x,int y,char *text,GrColor fg,GrColor bg); 1805@end example 1806 1807@c ----------------------------------------------------------------------------- 1808@node Graphics cursors, Keyboard input, Drawing in user coordinates, A User Manual For GRX2 1809@unnumberedsec Graphics cursors 1810 1811The library provides support for the creation and usage of an unlimited number 1812of graphics cursors. An application can use these cursors for any purpose. 1813Cursors always save the area they occupy before they are drawn. When moved or 1814erased they restore this area. As a general rule of thumb, an application should 1815erase a cursor before making changes to an area it occupies and redraw the 1816cursor after finishing the drawing. Cursors are created with the GrBuildCursor 1817function: 1818 1819@example 1820GrCursor *GrBuildCursor(char far *pixels,int pitch,int w,int h, 1821 int xo,int yo,const GrColorTableP c); 1822@end example 1823 1824The pixels, w (=width), h (=height) and c (= color table) arguments are 1825similar to the arguments of the pixmap building library function GrBuildPixmap 1826(see that paragraph for a more detailed explanation.), but with two differences. 1827First, is not assumed that the pixels data is w x h sized, the pitch argument 1828set the offset between rows. Second, the pixmap data is interpreted slightly 1829differently, any pixel with value zero is taken as a "transparent" pixel, i.e. 1830the background will show through the cursor pattern at that pixel. A pixmap data 1831byte with value = 1 will refer to the first color in the table, and so on. 1832 1833The xo (= X offset) and yo (= Y offset) arguments specify the position (from 1834the top left corner of the cursor pattern) of the cursor's "hot point". 1835 1836The GrCursor data structure: 1837 1838@example 1839typedef struct _GR_cursor @{ 1840 struct _GR_context work; /* work areas (4) */ 1841 int xcord,ycord; /* cursor position on screen */ 1842 int xsize,ysize; /* cursor size */ 1843 int xoffs,yoffs; /* LU corner to hot point offset */ 1844 int xwork,ywork; /* save/work area sizes */ 1845 int xwpos,ywpos; /* save/work area position on screen */ 1846 int displayed; /* set if displayed */ 1847@} GrCursor; 1848@end example 1849 1850is typically not used (i.e. read or changed) by the application program, it 1851should just pass pointers to these structures to the appropriate library 1852functions. Other cursor manipulation functions: 1853 1854@example 1855void GrDisplayCursor(GrCursor *cursor); 1856void GrEraseCursor(GrCursor *cursor); 1857void GrMoveCursor(GrCursor *cursor,int x,int y); 1858void GrDestroyCursor(GrCursor *cursor); 1859@end example 1860 1861See the @strong{test/curstest.c} example. 1862 1863@c ----------------------------------------------------------------------------- 1864@node Keyboard input, Mouse event handling, Graphics cursors, A User Manual For GRX2 1865@unnumberedsec Keyboard input 1866 1867GRX can handle platform independant key input. The file grxkeys.h defines the 1868keys to be used in the user's program. This is an extract: 1869 1870@example 1871#define GrKey_Control_A 0x0001 1872#define GrKey_Control_B 0x0002 1873#define GrKey_Control_C 0x0003 1874... 1875#define GrKey_A 0x0041 1876#define GrKey_B 0x0042 1877#define GrKey_C 0x0043 1878... 1879#define GrKey_F1 0x013b 1880#define GrKey_F2 0x013c 1881#define GrKey_F3 0x013d 1882... 1883#define GrKey_Alt_F1 0x0168 1884#define GrKey_Alt_F2 0x0169 1885#define GrKey_Alt_F3 0x016a 1886@end example 1887 1888But you can be confident that the standard ASCII is right maped. 1889The GrKeyType type is defined to store keycodes: 1890 1891@example 1892typedef unsigned short GrKeyType; 1893@end example 1894 1895This function: 1896 1897@example 1898int GrKeyPressed(void); 1899@end example 1900 1901returns non zero if there are any keycode waiting, that can be read with: 1902 1903@example 1904GrKeyType GrKeyRead(void); 1905@end example 1906 1907The function: 1908 1909@example 1910int GrKeyStat(void); 1911@end example 1912 1913returns a keyboard status word, or-ing it with the next defines it can be known 1914the status of some special keys: 1915 1916@example 1917#define GR_KB_RIGHTSHIFT 0x01 /* right shift key depressed */ 1918#define GR_KB_LEFTSHIFT 0x02 /* left shift key depressed */ 1919#define GR_KB_CTRL 0x04 /* CTRL depressed */ 1920#define GR_KB_ALT 0x08 /* ALT depressed */ 1921#define GR_KB_SCROLLOCK 0x10 /* SCROLL LOCK active */ 1922#define GR_KB_NUMLOCK 0x20 /* NUM LOCK active */ 1923#define GR_KB_CAPSLOCK 0x40 /* CAPS LOCK active */ 1924#define GR_KB_INSERT 0x80 /* INSERT state active */ 1925#define GR_KB_SHIFT (GR_KB_LEFTSHIFT | GR_KB_RIGHTSHIFT) 1926@end example 1927 1928See the @strong{test/keys.c} example. 1929 1930@c ----------------------------------------------------------------------------- 1931@node Mouse event handling, Writing/reading PNM graphics files, Keyboard input, A User Manual For GRX2 1932@unnumberedsec Mouse event handling 1933 1934All mouse services need the presence of a mouse. An application can test 1935whether a mouse is available by calling the function: 1936 1937@example 1938int GrMouseDetect(void); 1939@end example 1940 1941which will return zero if no mouse (or mouse driver) is present, non-zero 1942otherwise. The mouse must be initialized by calling one (and only one) of these 1943functions: 1944 1945@example 1946void GrMouseInit(void); 1947void GrMouseInitN(int queue_size); 1948@end example 1949 1950GrMouseInit sets a event queue (see below) size to GR_M_QUEU_SIZE (128). A 1951user supply event queue size can be set calling GrMouseInitN instead. 1952 1953It is a good practice to call GrMouseUnInit before exiting the program. This 1954will restore any interrupt vectors hooked by the program to their original 1955values. 1956 1957@example 1958void GrMouseUnInit(void); 1959@end example 1960 1961The mouse can be controlled with the following functions: 1962 1963@example 1964void GrMouseSetSpeed(int spmult,int spdiv); 1965void GrMouseSetAccel(int thresh,int accel); 1966void GrMouseSetLimits(int x1,int y1,int x2,int y2); 1967void GrMouseGetLimits(int *x1,int *y1,int *x2,int *y2); 1968void GrMouseWarp(int x,int y); 1969@end example 1970 1971The library calculates the mouse position only from the mouse mickey counters. 1972(To avoid the limit and 'rounding to the next multiple of eight' problem with 1973some mouse driver when it finds itself in a graphics mode unknown to it.) The 1974parameters to the GrMouseSetSpeed function specify how coordinate changes are 1975obtained from mickey counter changes, multipling by spmult and dividing by 1976spdiv. In high resolution graphics modes the value of one just works fine, in 1977low resolution modes (320x200 or similar) it is best set the spdiv to two or 1978three. (Of course, it also depends on the sensitivity the mouse.) The 1979GrMouseSetAccel function is used to control the ballistic effect: if a mouse 1980coordinate changes between two samplings by more than the thresh parameter, the 1981change is multiplied by the accel parameter. NOTE: some mouse drivers perform 1982similar calculations before reporting the coordinates in mickeys. In this case 1983the acceleration done by the library will be additional to the one already 1984performed by the mouse driver. The limits of the mouse movement can be set 1985(passed limits will be clipped to the screen) with GrMouseSetLimits (default is 1986the whole screen) and the current limits can be obtained with GrMouseGetLimits. 1987GrMouseWarp sets the mouse cursor to the specified position. 1988 1989As typical mouse drivers do not know how to draw mouse cursors in high 1990resolution graphics modes, the mouse cursor is drawn by the library. The mouse 1991cursor can be set with: 1992 1993@example 1994void GrMouseSetCursor(GrCursor *cursor); 1995void GrMouseSetColors(GrColor fg,GrColor bg); 1996@end example 1997 1998GrMouseSetColors uses an internal arrow pattern, the color fg will be used as 1999the interior of it and bg will be the border. The current mouse cursor can be 2000obtained with: 2001 2002@example 2003GrCursor *GrMouseGetCursor(void); 2004@end example 2005 2006The mouse cursor can be displayed/erased with: 2007 2008@example 2009void GrMouseDisplayCursor(void); 2010void GrMouseEraseCursor(void); 2011@end example 2012 2013The mouse cursor can be left permanently displayed. All graphics primitives 2014except for the few non-clipping functions check for conflicts with the mouse 2015cursor and erase it before the drawing if necessary. Of course, it may be more 2016efficient to erase the cursor manually before a long drawing sequence and redraw 2017it after completion. The library provides an alternative pair of calls for this 2018purpose which will erase the cursor only if it interferes with the drawing: 2019 2020@example 2021int GrMouseBlock(GrContext *c,int x1,int y1,int x2,int y2); 2022void GrMouseUnBlock(int return_value_from_GrMouseBlock); 2023@end example 2024 2025GrMouseBlock should be passed the context in which the drawing will take place 2026(the usual convention of NULL meaning the current context is supported) and the 2027limits of the affected area. It will erase the cursor only if it interferes with 2028the drawing. When the drawing is finished GrMouseUnBlock must be called with the 2029argument returned by GrMouseBlock. 2030 2031The status of the mouse cursor can be obtained with calling 2032GrMouseCursorIsDisplayed. This function will return non-zero if the cursor is 2033displayed, zero if it is erased. 2034 2035@example 2036int GrMouseCursorIsDisplayed(void); 2037@end example 2038 2039The library supports (beside the simple cursor drawing) three types of 2040"rubberband" attached to the mouse cursor. The GrMouseSetCursorMode function is 2041used to select the cursor drawing mode. 2042 2043@example 2044void GrMouseSetCursorMode(int mode,...); 2045@end example 2046 2047The parameter mode can have the following values: 2048 2049@example 2050#define GR_M_CUR_NORMAL 0 /* MOUSE CURSOR modes: just the cursor */ 2051#define GR_M_CUR_RUBBER 1 /* rect. rubber band (XOR-d to the screen) */ 2052#define GR_M_CUR_LINE 2 /* line attached to the cursor */ 2053#define GR_M_CUR_BOX 3 /* rectangular box dragged by the cursor */ 2054@end example 2055 2056GrMouseSetCursorMode takes different parameters depending on the cursor 2057drawing mode selected. The accepted call formats are: 2058 2059@example 2060GrMouseSetCursorMode(M_CUR_NORMAL); 2061GrMouseSetCursorMode(M_CUR_RUBBER,xanchor,yanchor,GrColor); 2062GrMouseSetCursorMode(M_CUR_LINE,xanchor,yanchor,GrColor); 2063GrMouseSetCursorMode(M_CUR_BOX,dx1,dy1,dx2,dy2,GrColor); 2064@end example 2065 2066The anchor parameters for the rubberband and rubberline modes specify a fixed 2067screen location to which the other corner of the primitive is bound. The dx1 2068through dy2 parameters define the offsets of the corners of the dragged box from 2069the hotpoint of the mouse cursor. The color value passed is always XOR-ed to the 2070screen, i.e. if an application wants the rubberband to appear in a given color 2071on a given background then it has to pass the XOR of these two colors to 2072GrMouseSetCursorMode. 2073 2074The GrMouseGetEvent function is used to obtain the next mouse or keyboard 2075event. It takes a flag with various bits encoding the type of event needed. It 2076returns the event in a GrMouseEvent structure. The relevant declarations from 2077grx20.h: 2078 2079@example 2080void GrMouseGetEvent(int flags,GrMouseEvent *event); 2081 2082typedef struct _GR_mouseEvent @{ /* mouse event buffer structure */ 2083 int flags; /* event type flags (see above) */ 2084 int x,y; /* mouse coordinates */ 2085 int buttons; /* mouse button state */ 2086 int key; /* key code from keyboard */ 2087 int kbstat; /* keybd status (ALT, CTRL, etc..) */ 2088 long dtime; /* time since last event (msec) */ 2089@} GrMouseEvent; 2090@end example 2091 2092The event structure has been extended with a keyboard status word (thus a 2093program can check for combinations like ALT-<left mousebutton press>) and a time 2094stamp which can be used to check for double clicks, etc... The following macros 2095have been defined in grx20.h to help in creating the control flag for 2096GrMouseGetEvent and decoding the various bits in the event structure: 2097 2098@example 2099#define GR_M_MOTION 0x001 /* mouse event flag bits */ 2100#define GR_M_LEFT_DOWN 0x002 2101#define GR_M_LEFT_UP 0x004 2102#define GR_M_RIGHT_DOWN 0x008 2103#define GR_M_RIGHT_UP 0x010 2104#define GR_M_MIDDLE_DOWN 0x020 2105#define GR_M_MIDDLE_UP 0x040 2106#define GR_M_BUTTON_DOWN (GR_M_LEFT_DOWN | GR_M_MIDDLE_DOWN | \ 2107 GR_M_RIGHT_DOWN | GR_M_P4_DOWN | GR_M_P5_DOWN) 2108#define GR_M_BUTTON_UP (GR_M_LEFT_UP | GR_M_MIDDLE_UP | \ 2109 GR_M_RIGHT_UP | GR_M_P4_UP | GR_M_P5_UP) 2110#define GR_M_BUTTON_CHANGE (GR_M_BUTTON_UP | GR_M_BUTTON_DOWN ) 2111 2112#define GR_M_LEFT 0x01 /* mouse button index bits */ 2113#define GR_M_RIGHT 0x02 2114#define GR_M_MIDDLE 0x04 2115#define GR_M_P4 0x08 /* wheel rolls up */ 2116#define GR_M_P5 0x10 /* wheel rolls down */ 2117 2118#define GR_M_KEYPRESS 0x080 /* other event flag bits */ 2119#define GR_M_POLL 0x100 2120#define GR_M_NOPAINT 0x200 2121#define GR_COMMAND 0x1000 2122#define GR_M_EVENT (GR_M_MOTION | GR_M_KEYPRESS | \ 2123 GR_M_BUTTON_CHANGE | GR_COMMAND) 2124@end example 2125 2126GrMouseGetEvent will display the mouse cursor if it was previously erased and 2127the GR_M_NOPAINT bit is not set in the flag passed to it. In this case it will 2128also erase the cursor after an event has been obtained. 2129 2130GrMouseGetEvent block until a event is produced, except if the GR_M_POLL bit 2131is set in the flag passed to it. 2132 2133Another version of GetEvent: 2134 2135@example 2136void GrMouseGetEventT(int flags,GrMouseEvent *event,long timout_msecs); 2137@end example 2138 2139can be istructed to wait timout_msec for the presence of an event. Note that 2140event->dtime is only valid if any event occured (event->flags != 0) otherwise 2141it's set as -1. Additionally event timing is real world time even in X11 && 2142Linux. 2143 2144If there are one or more events waiting the function: 2145 2146@example 2147int GrMousePendingEvent(void); 2148@end example 2149 2150returns non-zero value. 2151 2152The generation of mouse and keyboard events can be individually enabled or 2153disabled (by passing a non-zero or zero, respectively, value in the 2154corresponding enable_XX parameter) by calling: 2155 2156@example 2157void GrMouseEventEnable(int enable_kb,int enable_ms); 2158@end example 2159 2160Note that GrMouseInit set both by default. If you want to use 2161GrMouseGetEvent and GrKeyRead at the same time, a call to 2162GrMouseEventEnable( 0,1 ) is needed before input process. 2163 2164See the @strong{test/mousetst.c} example. 2165 2166@node Writing/reading PNM graphics files, Writing/reading PNG graphics files,Mouse event handling , A User Manual For GRX2 2167@unnumberedsec Writing/reading PNM graphics files 2168 2169GRX includes functions to load/save a context from/to a PNM file. 2170 2171PNM is a group of simple graphics formats from the 2172@uref{http://netpbm.sourceforge.net, NetPbm} 2173distribution. NetPbm can convert from/to PNM lots of graphics formats, 2174and apply some transformations to PNM files. 2175(Note. You don't need the NetPbm distribution to use this functions). 2176 2177There are six PNM formats: 2178 2179@example 2180 P1 text PBM (bitmap) 2181 P2 text PGM (gray scale) 2182 P3 text PPM (real color) 2183 P4 binary PBM (bitmap) 2184 P5 binary PGM (gray scale) 2185 P6 binary PPM (real color) 2186@end example 2187 2188GRX can handle the binary formats only (get the NetPbm distribution if you 2189need convert text to binary formats). 2190 2191To save a context in a PNM file you have three functions: 2192 2193@example 2194int GrSaveContextToPbm( GrContext *grc, char *pbmfn, char *docn ); 2195int GrSaveContextToPgm( GrContext *grc, char *pgmfn, char *docn ); 2196int GrSaveContextToPpm( GrContext *grc, char *ppmfn, char *docn ); 2197@end example 2198 2199they work both in RGB and palette modes, grc must be a pointer to the context to 2200be saved, if it is NULL the current context is saved; p-mfn is the file name to 2201be created and docn is an optional text comment to be written in the file, it 2202can be NULL. Three functions return 0 on succes and -1 on error. 2203 2204GrSaveContextToPbm dumps a context in a PBM file (bitmap). If the pixel color 2205isn't Black it asumes White. 2206 2207GrSaveContextToPgm dumps a context in a PGM file (gray scale). The colors are 2208quantized to gray scale using .299r + .587g + .114b. 2209 2210GrSaveContextToPpm dumps a context in a PPM file (real color). 2211To load a PNM file in a context you must use: 2212 2213@example 2214int GrLoadContextFromPnm( GrContext *grc, char *pnmfn ); 2215@end example 2216 2217it support reading PBM, PGM and PPM binary files. grc must be a pointer to the 2218context to be written, if it is NULL the current context is used; p-mfn is the 2219file name to be read. If context dimensions are lesser than pnm dimensions, the 2220function loads as much as it can. If color mode is not in RGB mode, the routine 2221allocates as much colors as it can. The function returns 0 on succes and -1 on 2222error. 2223 2224To query the file format, width and height of a PNM file you can use: 2225 2226@example 2227int GrQueryPnm( char *ppmfn, int *width, int *height, int *maxval ); 2228@end example 2229 2230pnmfn is the name of pnm file; width returns the pnm width; height returns the 2231pnm height; maxval returns the max color component value. The function returns 1 2232to 6 on success (the PNM format) or -1 on error. 2233 2234The two next functions: 2235 2236@example 2237int GrLoadContextFromPnmBuffer( GrContext *grc, const char *pnmbuf ); 2238int GrQueryPnmBuffer( const char *pnmbuf, int *width, int *height, int *maxval ); 2239@end example 2240 2241work like GrLoadContextFromPnm and 2242GrQueryPnmBuffer, but they get his input from a buffer instead 2243of a file. This way, pnm files can be embeded in a program (using the 2244bin2c program by example). 2245 2246@node Writing/reading PNG graphics files, Writing/reading JPEG graphics files, Writing/reading PNM graphics files, A User Manual For GRX2 2247@unnumberedsec Writing/reading PNG graphics files 2248 2249GRX includes functions to load/save a context 2250from/to a png file. But note, for this purpose it needs the 2251@uref{http://www.libpng.org/pub/png/libpng.html, libpng} library, 2252and to enable the png support before make the GRX lib. 2253 2254Use next function to save a context in a PNG file: 2255 2256@example 2257int GrSaveContextToPng( GrContext *grc, char *pngfn ); 2258@end example 2259 2260it works both in RGB and palette modes, grc must be 2261a pointer to the context to be saved, if it is NULL the current context is 2262saved; pngfn is the file name to be created. 2263The function returns 0 on succes and -1 on error. 2264 2265To load a PNG file in a context you must use: 2266 2267@example 2268int GrLoadContextFromPng( GrContext *grc, char *pngfn, int use_alpha ); 2269@end example 2270 2271grc must be a pointer to the context to be written, if it 2272is NULL the current context is used; pngfn is the file name 2273to be read; set use_alpha to 1 if you want to use the image 2274alpha channel (if available). If context dimensions are lesser than png 2275dimensions, the function loads as much as it can. If color mode is not 2276in RGB mode, the routine allocates as much colors as it can. The function 2277returns 0 on succes and -1 on error. 2278 2279To query the width and height of a PNG file you can use: 2280 2281@example 2282int GrQueryPng( char *pngfn, int *width, int *height ); 2283@end example 2284 2285pngfn is the name of png file; width returns the 2286png width; height returns the png height. 2287The function returns 0 on success or -1 on error. 2288 2289The function: 2290 2291@example 2292int GrPngSupport( void ); 2293@end example 2294 2295returns 1 if there is png support in the library, 0 otherwise. If there is 2296not support for png, dummy functions are added to the library, returning 2297error (-1) ever. 2298 2299@node Writing/reading JPEG graphics files, Miscellaneous functions, Writing/reading PNG graphics files, A User Manual For GRX2 2300@unnumberedsec Writing/reading PNG graphics files 2301 2302GRX includes functions to load/save a context 2303from/to a jpeg file. But note, for this purpose it needs the 2304@uref{http://www.ijg.org, libjpeg} library, 2305and to enable the jpeg support before make the GRX lib. 2306 2307Use next function to save a context in a JPEG file: 2308 2309@example 2310int GrSaveContextToJpeg( GrContext *grc, char *jpegfn, int quality ); 2311@end example 2312 2313it works both in RGB and palette modes, grc must be 2314a pointer to the context to be saved, if it is NULL the current context is 2315saved; jpegfn is the file name to be created; 2316quality is a number between 1 and 100 to drive the compression 2317quality, use higher values for better quality (and bigger files), you can 2318use 75 as a standard value, normally a value between 50 and 95 is good. 2319The function returns 0 on succes and -1 on error. 2320 2321This function saves a context in a grayscale JPEG file: 2322 2323@example 2324int GrSaveContextToGrayJpeg( GrContext *grc, char *jpegfn, int quality ); 2325@end example 2326 2327parameters and return codes are like in GrSaveContextToJpeg. 2328The colors are quantized to gray scale using .299r + .587g + .114b. 2329 2330To load a JPEG file in a context you must use: 2331 2332@example 2333int GrLoadContextFromJpeg( GrContext *grc, char *jpegfn, int scale ); 2334@end example 2335 2336grc must be a pointer to the context to be written, if it 2337is NULL the current context is used; jpegfn is the file name 2338to be read; set scale to 1, 2, 4 or 8 to reduce the loaded 2339image to 1/1, 1/2, 1/4 or 1/8. If context dimensions are lesser than jpeg 2340dimensions, the function loads as much as it can. If color mode is not 2341in RGB mode, the routine allocates as much colors as it can. The function 2342returns 0 on succes and -1 on error. 2343 2344To query the width and height of a JPEG file you can use: 2345 2346@example 2347int GrQueryJpeg( char *jpegfn, int *width, int *height ); 2348@end example 2349 2350jpegfn is the name of jpeg file; width returns the 2351jpeg width; height returns the jpeg height. 2352The function returns 0 on success or -1 on error. 2353 2354The function: 2355 2356@example 2357int GrJpegSupport( void ); 2358@end example 2359 2360returns 1 if there is jpeg support in the library, 0 otherwise. If there is 2361not support for jpeg, dummy functions are added to the library, returning 2362error (-1) ever. 2363 2364@node Miscellaneous functions, BGI interface, Writing/reading JPEG graphics files, A User Manual For GRX2 2365@unnumberedsec Miscellaneous functions 2366 2367Here we will describe some miscellaneous functions. 2368 2369@example 2370unsigned GrGetLibraryVersion(void); 2371@end example 2372 2373GrGetLibraryVersion returns the GRX version API, like a hexadecimal coded 2374number. By example 0x0241 means 2.4.1 Because grx20.h defines the 2375GRX_VERSION_API macro, you can check if both, the library and the 2376include file, are in the same version using 2377if(GrGetLibraryVersion() == GRX_VERSION_API ) 2378 2379@example 2380unsigned GrGetLibrarySystem(void); 2381@end example 2382 2383This functions returns a unsigned integer identifing the system you are 2384working in. grx20.h defines some macros you can use: 2385 2386@example 2387/* these are the supported configurations: */ 2388#define GRX_VERSION_TCC_8086_DOS 1 /* also works with BCC */ 2389#define GRX_VERSION_GCC_386_DJGPP 2 /* DJGPP v2 */ 2390#define GRX_VERSION_GCC_386_LINUX 3 /* the real stuff */ 2391#define GRX_VERSION_GENERIC_X11 4 /* generic X11 version */ 2392#define GRX_VERSION_WATCOM_DOS4GW 5 /* GS - Watcom C++ 11.0 32 Bit 2393#define GRX_VERSION_GCC_386_WIN32 7 /* WIN32 using Mingw32 */ 2394#define GRX_VERSION_MSC_386_WIN32 8 /* WIN32 using MS-VC */ 2395#define GRX_VERSION_GCC_386_CYG32 9 /* WIN32 using CYGWIN */ 2396#define GRX_VERSION_GCC_386_X11 10 /* X11 version */ 2397#define GRX_VERSION_GCC_X86_64_LINUX 11 /* console framebuffer 64 */ 2398#define GRX_VERSION_GCC_X86_64_X11 12 /* X11 version 64 */ 2399@end example 2400 2401Note. On Linux, GrGetLibrarySystem returns GRX_VERSION_GCC_386_LINUX even in the 2402X11 version. 2403 2404@example 2405void GrSetWindowTitle(char *title); 2406@end example 2407GrSetWindowTitle sets the main window title in the X11 an Win32 versions. It 2408doesn't do nothing in the DOS and Linux-SvgaLib versions. 2409 2410@example 2411void GrSleep(int msec); 2412@end example 2413This function stops the program execution for msec miliseconds. 2414 2415@example 2416long GrMsecTime( void ); 2417@end example 2418This function gives the current time with millisecond resolution 2419 2420 2421@example 2422void GrFlush( void ); 2423@end example 2424This funnction flushes the graphics window. Not dummy because useful only on 2425X11 when switching between graphics and console windows open simultaneously. 2426 2427@example 2428 GrContext *GrCreateFrameContext(GrFrameMode md,int w,int h, 2429 char far *memory[4],GrContext *where); 2430 2431@end example 2432This function is like GrCreateContext, except that you can specify any valid 2433memory frame mode, not only the Screen associated frame mode. It can be used for 2434special purposes (see GrBitBlt1bpp for an example). 2435 2436@example 2437 void GrBitBlt1bpp(GrContext *dst,int dx,int dy,GrContext *src, 2438 int x1,int y1,int x2,int y2,GrColor fg,GrColor bg); 2439 2440@end example 2441This special function does a bitblt from a 1bpp context (a bitmap really), 2442using fg and bg like the color+opcode when bit=1 and bit=0 respectively. Here is 2443an example: 2444 2445@example 2446 pContext = GrCreateFrameContext(GR_frameRAM1, sizex, sizey, NULL, NULL); 2447 /* draw something (black and white) into the bitmap */ 2448 GrSetContext(pContext); 2449 GrClearContext( GrBlack() ); 2450 GrLine(0, 0, sizex-1, sizey-1, GrWhite()); 2451 GrLine(0, sizey-1, sizex-1, 0, GrWhite()); 2452 2453 /* Put the bitmap into the screen */ 2454 GrSetContext(NULL); 2455 fcolor = GrAllocColor( 255,0,0 ); 2456 bcolor = GrAllocColor( 0,0,255 ); 2457 GrBitBlt1bpp(NULL,x,y,pContext,0,0,sizex-1,sizey-1,fcolor,bcolor); 2458@end example 2459 2460@c ----------------------------------------------------------------------------- 2461@node BGI interface, Pascal interface, Miscellaneous functions, A User Manual For GRX2 2462@unnumberedsec BGI interface 2463 2464From the 2.3.1 version, GRX includes the BCC2GRX library created by Hartmut 2465Schirmer. The BCC2GRX was created to allow users of GRX to compile graphics 2466programs written for Borland-C++ and Turbo-C graphics interface. BCC2GRX is not 2467a convenient platform to develop new BGI programs. Of course you should use 2468native GRX interface in such cases! 2469 2470Read the readme.bgi file for more info. 2471 2472@c ----------------------------------------------------------------------------- 2473@node Pascal interface, References, BGI interface, A User Manual For GRX2 2474@unnumberedsec Pascal interface 2475 2476The Pascal (gpc) support is produced by two unit files @strong{pascal/grx.pas} 2477and @strong{pascal/bgi/graph.pas} which are the Pascal translations of the C 2478header files @strong{include/grx20.h + include/grxkeys.h} 2479and @strong{include/libbcc.h}. 2480 2481Compilation of the examples and installation of the header files is allowed 2482by setting INCLUDE_GPC_SUPPORT=y in makedef.grx. 2483 2484The unit files contain at the beginning instructions to load the required 2485libraries (libgrx20..., depending on the system) and addon libraries 2486(e.g. libpng). 2487You can uncomment manually the addons you want. 2488You can also use the configure script which does that automatically, 2489together with editing the makedefs.grx file. 2490 2491By default they are installed in a @strong{units} directory below the 2492INSTALLDIR directory. But you can put them where you like. 2493 2494@c ----------------------------------------------------------------------------- 2495@node References, , Pascal interface, A User Manual For GRX2 2496@unnumberedsec References 2497 2498@multitable {MGRX site (fork from GRX)----}{----http://www.libpng.org/pub/png/libpng.html} 2499@item Official GRX site 2500@tab @uref{http://grx.gnu.de} 2501@item GRX mailing list archive 2502@tab @uref{http://grx.gnu.de/archive/grx/en/} 2503@item MGRX site (fork from GRX) 2504@tab @uref{http://mgrx.fgrim.com} 2505@item NetPbm distribution 2506@tab @uref{http://netpbm.sourceforge.net} 2507@item PNG library 2508@tab @uref{http://www.libpng.org/pub/png/libpng.html} 2509@item JPEG library 2510@tab @uref{http://www.ijg.org} 2511@item TIFF library 2512@tab @uref{http://www.remotesensing.org/libtiff/} 2513@end multitable 2514 2515@c ----------------------------------------------------------------------------- 2516 2517