1 2 /* 3 * AA-lib, an ascii-art gfx library 4 * Copyright (C) 1998,1999,2001 by 5 * 6 * Jan Hubicka (hubicka@freesoft.cz) 7 * Kamil Toman (toman@artax.karlin.mff.cuni.cz) 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU Library General Public License as published 11 * by the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU Library General Public 20 * License along with this program; if not, write to the Free Software 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 */ 23 #ifndef __AALIB_INCLUDED__ 24 #define __AALIB_INCLUDED__ 25 #include <stdio.h> 26 #include <string.h> 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 #define __AA_CONST const 32 33 /* The -malign-double switch changes binarry compatibility with structures 34 containing floating point values. To avoid this, set alignment manually 35 to old value. */ 36 37 #ifdef __GNUC__ 38 #ifdef __i386__ 39 #define __AA_ALIGN __attribute__ ((__aligned__ (4))) 40 #define __AA_NOALIGN __attribute__ ((__packed__)) 41 #endif 42 #endif 43 #ifndef __AA_ALIGN 44 #define __AA_ALIGN 45 #endif 46 #ifndef __AA_NOALIGN 47 #define __AA_NOALIGN 48 #endif 49 50 #define AA_LIB_VERSION 1 51 #define AA_LIB_MINNOR 4 52 #define AA_LIB_VERSIONCODE 104000 53 54 #define AA_NATTRS 5 55 #define AA_NPARAMS 5 56 57 #define AA_RESIZE 258 /*special keycodes */ 58 #define AA_MOUSE 259 59 #define AA_UP 300 60 #define AA_DOWN 301 61 #define AA_LEFT 302 62 #define AA_RIGHT 303 63 #define AA_BACKSPACE 304 64 #define AA_ESC 305 65 #define AA_UNKNOWN 400 66 #define AA_RELEASE 65536 67 68 69 #define AA_NORMAL_MASK 1 /*masks for attributes */ 70 #define AA_DIM_MASK 2 71 #define AA_BOLD_MASK 4 72 #define AA_BOLDFONT_MASK 8 73 #define AA_REVERSE_MASK 16 74 #define AA_ALL 128 75 #define AA_EIGHT 256 76 #define AA_EXTENDED (AA_ALL|AA_EIGHT) 77 78 /* The characters may be output with following attributes: */ 79 enum aa_attribute { 80 AA_NORMAL=0, /* Normal characters. */ 81 AA_DIM=1, /* Dark characters. */ 82 AA_BOLD=2, /* Bright characters. */ 83 AA_BOLDFONT=3, /* Characters rendered in bold font. */ 84 AA_REVERSE=4, /* Reversed (black on whilte) characters. */ 85 AA_SPECIAL=5 /* Render characters in a way easilly visible on the 86 screen. The exact rendering is driver dependent, 87 but this mode ought to be used to output texts you 88 want to make easilly visible in the image. */ 89 }; 90 91 enum aa_dithering_mode { 92 AA_NONE=0, 93 AA_ERRORDISTRIB=1, /* Error distribution. */ 94 AA_FLOYD_S=2, /* Floyd-Steinberg dithering. */ 95 AA_DITHERTYPES=3 /* Number of supported dithering modes. */ 96 }; 97 98 #define AA_BUTTON1 1 /*mouse */ 99 #define AA_BUTTON2 2 100 #define AA_BUTTON3 4 101 #define AA_MOUSEMOVEMASK 1 102 #define AA_MOUSEPRESSMASK 2 103 #define AA_PRESSEDMOVEMASK 4 104 #define AA_MOUSEALLMASK 7 105 #define AA_HIDECURSOR 8 106 107 #define AA_SENDRELEASE 1 108 #define AA_KBDALLMASK 1 109 110 #define AA_USE_PAGES 1 /*save format flags */ 111 #define AA_NORMAL_SPACES 8 112 113 /* These structures are subject to change in future. Thus they are hidden 114 behind final user. */ 115 struct aa_driver; 116 struct aa_kbddriver; 117 struct aa_mousedriver; 118 struct aa_edit; 119 120 struct aa_hardware_params { 121 __AA_CONST struct aa_font *font; /*Font bitmap used by hardware. */ 122 int supported; /*Mask of supported features. 123 Following masks are available: 124 AA_NORMAL_MASK, AA_DIM_MASK, 125 AA_BOLD_MASK, AA_BOLDFONT_MASK, 126 AA_REVERSE_MASK 127 */ 128 int minwidth, minheight; /*Minimal alowed screen size 129 in characters */ 130 int maxwidth, maxheight; /*Maximal alowed screen size 131 in characters */ 132 int recwidth, recheight; /*Recommended screen size (driver 133 attempts to find resolution nearest 134 to this value within given bounds 135 bit min and max fields */ 136 int mmwidth, mmheight; /*Physical screen size */ 137 int width, height; /*Current screen size */ 138 double dimmul __AA_ALIGN; /*Bright value of dim characters (0 black, 139 1 white) */ 140 double boldmul __AA_ALIGN; /*Bright value of bold characters 141 (0 black, 1 white) */ 142 }; 143 144 /* 145 * aa_context contains information about the display. It is passed to most 146 * of AA-lib functions. The full definition of structure is present just 147 * for compatibility with older programs. Dirrect access to it's fields 148 * is not recommended, because you might surfer to problems with future 149 * releases of AA-lib. Use standard AA-lib functions instead. 150 */ 151 struct aa_context { 152 __AA_CONST struct aa_driver *driver; /*Current display driver */ 153 __AA_CONST struct aa_kbddriver *kbddriver; /*Current keyboard driver */ 154 __AA_CONST struct aa_mousedriver *mousedriver; /*Current mouse driver */ 155 struct aa_hardware_params __AA_NOALIGN params; /*Parameters of output 156 hardware used by AA-lib. */ 157 struct aa_hardware_params __AA_NOALIGN driverparams; /*Parameters of output 158 hardware as reported 159 by display driver. */ 160 int mulx, muly; /* Ratio of character size over pixel size */ 161 int imgwidth, imgheight; /* Dimensions of emulated image */ 162 unsigned char *imagebuffer; /* Virtual buffer containing image */ 163 unsigned char *textbuffer; /* Virtual buffer containing text */ 164 unsigned char *attrbuffer; /* Virtual buffer containing attributes */ 165 unsigned short *table; /* Precalculated values used by rendering 166 algorithm. 167 168 WARNING! 169 It is _strongly_ depreached 170 to access fields behind this point, because 171 they can change in future releases.*/ 172 unsigned short *filltable; 173 struct parameters *parameters; 174 int cursorx, cursory, cursorstate; /* Cursor possition. */ 175 int mousex, mousey, buttons,mousemode; /* Mouse state. */ 176 void (*resizehandler) (struct aa_context *); /* Handler to be called when 177 resize happends. */ 178 void *driverdata; /* Internal data used by hardware drivers. */ 179 void *kbddriverdata; 180 void *mousedriverdata; 181 }; 182 183 184 /* 185 * The hardware driver specification. Used internally by AA-lib only. 186 * Provided for compatibility with older programs. 187 */ 188 struct aa_driver { 189 __AA_CONST char *shortname, *name; 190 int (*init) (__AA_CONST struct aa_hardware_params *, __AA_CONST void *, struct aa_hardware_params *,void **); 191 void (*uninit) (struct aa_context *); 192 void (*getsize) (struct aa_context *, int *, int *); 193 void (*setattr) (struct aa_context *, int); 194 void (*print) (struct aa_context *, __AA_CONST char *); 195 void (*gotoxy) (struct aa_context *, int, int); 196 void (*flush) (struct aa_context *); 197 void (*cursormode) (struct aa_context *, int); 198 }; 199 200 /* 201 * The hardware driver specification. Used internally by AA-lib only. 202 * Provided for compatibility with older programs. 203 */ 204 struct aa_kbddriver { 205 __AA_CONST char *shortname, *name; 206 int flags; 207 int (*init) (struct aa_context *, int mode); 208 void (*uninit) (struct aa_context *); 209 int (*getkey) (struct aa_context *, int); 210 }; 211 212 /* 213 * The hardware driver specification. Used internally by AA-lib only. 214 * Provided for compatibility with older programs. 215 */ 216 struct aa_mousedriver { 217 __AA_CONST char *shortname, *name; 218 int flags; 219 int (*init) (struct aa_context *, int mode); 220 void (*uninit) (struct aa_context *); 221 void (*getmouse) (struct aa_context *, int *, int *, int *); 222 void (*cursormode) (struct aa_context *,int); 223 }; 224 /* 225 * Parameters used for rendering. 226 */ 227 struct aa_renderparams { 228 int bright; /* Brighness in range 0 (normal) to 255 229 (white) */ 230 int contrast; /* Contrast value in range 0 (normal) 231 to 127 (white) */ 232 float gamma __AA_ALIGN; /* Gama value in the standard range */ 233 enum aa_dithering_mode dither; /* Dithering algorithm */ 234 int inversion; /* Set 1 for inversed terminals (black on 235 white) */ 236 int randomval; /* Range of random value added to each 237 pixel. Used to crate random dithering 238 effect. */ 239 }; 240 241 242 struct aa_font { 243 __AA_CONST unsigned char *data; /* Bitmap of 8xheight font. */ 244 int height; /* Height of font. */ 245 __AA_CONST char *name; /* Long name of font. */ 246 __AA_CONST char *shortname; /* One-word name of the font. */ 247 }; 248 249 /* 250 * Output format specification used by aa_save driver. 251 */ 252 struct aa_format { 253 int width, height; 254 int pagewidth, pageheight; 255 int flags; 256 int supported; 257 __AA_CONST struct aa_font *font; 258 __AA_CONST char *formatname; 259 __AA_CONST char *extension; 260 /*fields after this line may change in future versions*/ 261 __AA_CONST char *head; 262 __AA_CONST char *end; 263 __AA_CONST char *newline; 264 __AA_CONST char * __AA_CONST prints[AA_NATTRS]; 265 __AA_CONST char * __AA_CONST begin[AA_NATTRS]; 266 __AA_CONST char * __AA_CONST ends[AA_NATTRS]; 267 __AA_CONST char * __AA_CONST *conversions; 268 }; 269 270 /* 271 * Initialization data used by aa_save driver. 272 */ 273 struct aa_savedata { 274 char *name; /* Base name of the output file. The page number and extension 275 is attached automatically. */ 276 __AA_CONST struct aa_format *format; /* Format to save into. */ 277 FILE *file; /* You might specify output file by field too, 278 in case the name field is NULL*/ 279 }; 280 281 typedef struct aa_context aa_context; 282 typedef struct aa_linkedlist aa_linkedlist; 283 typedef struct aa_linkedlist aa_reclist; 284 typedef struct aa_renderparams aa_renderparams; 285 typedef struct aa_hardware_params aa_hardwareparams; 286 typedef struct aa_driver aa_driver; 287 typedef struct aa_font aa_font; 288 typedef struct aa_format aa_format; 289 typedef struct aa_savedata aa_savedata; 290 typedef int aa_palette[256]; 291 292 293 /* 294 * AA-lib driver used to save ascii-art image into file in used specified format. 295 * Initialize this driver using aa_init function and specify the driver 296 * dependent parameters in aa_savedata structure to save image into file. 297 * See the texinfo documentation for details. 298 */ 299 extern __AA_CONST struct aa_driver save_d; 300 301 /* 302 * AA-lib memory driver. 303 * Used to render ascii-art images into memory. 304 * You might use this driver to render images into memory and then use your 305 * own routines to handle them in case you want to avoid AA-lib's output 306 * mechanizms. 307 */ 308 extern __AA_CONST struct aa_driver mem_d; 309 310 /* 311 * AA-lib help string for the default command line parser. 312 */ 313 extern __AA_CONST char * __AA_CONST aa_help; 314 315 /* 316 * NULL terminated array of save formats supported by AA-lib. 317 */ 318 extern __AA_CONST struct aa_format * __AA_CONST aa_formats[]; 319 extern __AA_CONST struct aa_format aa_nhtml_format, aa_html_format, 320 aa_html_alt_format, aa_ansi_format, aa_text_format, aa_more_format, 321 aa_hp_format, aa_hp2_format, aa_irc_format, aa_zephyr_format, 322 aa_htmlk_format; 323 324 /* 325 * Null-terminated array of available fonts. 326 */ 327 extern __AA_CONST struct aa_font *aa_fonts[]; 328 extern __AA_CONST struct aa_font aa_font8, aa_font14, aa_font16, aa_font9, 329 aa_fontline, aa_fontgl, aa_fontX13, aa_fontX16, aa_fontX13B, 330 aa_fontcourier, aa_fontvyhen; 331 /* 332 * Names of dithering methods supported by AA-lib. 333 * NULL terminated array containing the names of supported dithering methods 334 * as ascii strings. 335 */ 336 extern __AA_CONST char * __AA_CONST aa_dithernames[]; 337 338 /* 339 * NULL-terminated array of output drivers available in AA-lib. 340 */ 341 extern __AA_CONST struct aa_driver * __AA_CONST aa_drivers[]; 342 extern __AA_CONST struct aa_driver curses_d, dos_d, linux_d, slang_d, stdout_d, 343 stderr_d, X11_d, os2vio_d; 344 345 /* 346 * NULL-terminated array of keyboard drivers available in AA_lib. 347 */ 348 extern __AA_CONST struct aa_kbddriver * __AA_CONST aa_kbddrivers[]; 349 extern __AA_CONST struct aa_kbddriver kbd_curses_d, kbd_slang_d, kbd_stdin_d, 350 kbd_dos_d, kbd_X11_d, kbd_os2_d, 351 kbd_linux_d; 352 353 /* 354 * NULL terminated array of mouse drivers supported by AA-lib. 355 */ 356 extern __AA_CONST struct aa_mousedriver * __AA_CONST aa_mousedrivers[]; 357 extern __AA_CONST struct aa_mousedriver mouse_curses_d, mouse_gpm_d, 358 mouse_X11_d, mouse_dos_d, mouse_os2_d; 359 360 /* 361 * List of recommended drivers. 362 * List of recommended drivers is used by aa_autoinit familly of functions 363 * and altered by aa_recommend familly of functions. 364 */ 365 extern aa_linkedlist *aa_kbdrecommended, *aa_mouserecommended, *aa_displayrecommended; 366 367 /* 368 * default hardware paramters requested by AA-lib programs. Pa 369 * Default hardware paramters requested by AA-lib programs. Passed to aa_init 370 * function familly. 371 */ 372 extern struct aa_hardware_params aa_defparams; 373 374 /* 375 * default rendering parameters. 376 * Default rendering parameters. Passed to aa_render function familly. 377 */ 378 extern struct aa_renderparams aa_defrenderparams; 379 380 381 /* returns width of the output screen in characters. */ 382 int aa_scrwidth( 383 /* Specifies the AA-lib context to operate on. */ 384 aa_context *a); 385 /* returns height of the output screen in characters. */ 386 int aa_scrheight( 387 /* Specifies the AA-lib context to operate on. */ 388 aa_context *a); 389 /* returns width of the output screen in millimeters. */ 390 int aa_mmwidth( 391 /* Specifies the AA-lib context to operate on. */ 392 aa_context *a); 393 /* returns height of the output screen in millimeters. */ 394 int aa_mmheight( 395 /* Specifies the AA-lib context to operate on. */ 396 aa_context *a); 397 /* returns width of the emulated image in pixels. */ 398 int aa_imgwidth( 399 /* Specifies the AA-lib context to operate on. */ 400 aa_context *a); 401 /* returns height of the emulated image in pixels. */ 402 int aa_imgheight( 403 /* Specifies the AA-lib context to operate on. */ 404 aa_context *a); 405 /* 406 * returns pointer to the framebuffer emulated by AA-lib. 407 * The framebuffer is simple array of characters specifying 408 * the brightness value (or palette index depending on the aa_render 409 * call). The array is organizated in the aa_imgheight (a) rows of 410 * aa_imgwidth(a) characters. 411 * Returns pointer to framebuffer emulated by AA-lib. 412 */ 413 char *aa_image( 414 /* Specifies the AA-lib context to operate on. */ 415 aa_context *a); 416 /* 417 * returns pointer to the text output buffer used by AA-lib. 418 * The text output buffer is simple array of characters specifying 419 * the ascii-value of the characters. 420 * The array is organizated in the aa_scrheight (a) rows of 421 * aa_scrwidth(a) characters. 422 * 423 * Returns pointer the text output buffer used by AA-lib. 424 */ 425 char *aa_text( 426 /* Specifies the AA-lib context to operate on. */ 427 aa_context *a); 428 /* 429 * returns pointer to the text output buffer used by AA-lib. 430 * The attribute output buffer is simple array of characters specifying 431 * the attributes. 432 * The array is organizated in the aa_scrheight (a) rows of 433 * aa_scrwidth(a) characters. 434 * 435 * Returns pointer the text output buffer used by AA-lib. 436 */ 437 char *aa_attrs( 438 /* Specifies the AA-lib context to operate on. */ 439 aa_context *a); 440 441 /* 442 * returns specification of the fonts used by AA-lib rendering routines. 443 */ 444 __AA_CONST struct aa_font *aa_currentfont( 445 /* Specifies the AA-lib context to operate on. */ 446 aa_context *a); 447 448 /* 449 * easy to use AA-lib initialization function. 450 * Attempts to find available output driver supporting the specified 451 * parameters. First attempts to initialize the recommended drivers 452 * and then in order drivers available in the aa_drivers array 453 * (all regular output drivers compiled into AA-lib). 454 * Returns pointer to initialized context structure when succesfull or 455 * NULL on failure. 456 */ 457 aa_context *aa_autoinit( 458 /* Hardware parameters you want. Use aa_defparams 459 for default values. */ 460 __AA_CONST struct aa_hardware_params *params); 461 /* 462 * easy to use AA-lib keyboard initialization function. 463 * Attempts to find available keyboard driver supporting the specified 464 * mode. First attempts to initialize the recommended drivers 465 * and then in order drivers available in the aa_kbddrivers array 466 * (all regular output drivers compiled into AA-lib). 467 * 468 * Every AA-lib program ought to have call to aa_parseoptions before 469 * first call to aa_init. 470 * 471 * Returns 1 when succesfull or 0 on failure. 472 */ 473 int aa_autoinitkbd( 474 /* Specifies the AA-lib context to operate on. */ 475 struct aa_context *context, 476 /* Mask of extra features you request. Can contain 477 AA_SENDRELEASE if you are interested in release events 478 too. */ 479 int mode); 480 /* 481 * easy to use AA-lib mouse initialization function. 482 * Attempts to find available mouse driver supporting the specified 483 * mode. First attempts to initialize the recommended drivers 484 * and then in order drivers available in the aa_kbddrivers array 485 * (all regular output drivers compiled into AA-lib). 486 * Returns 1 when succesfull or 0 on failure. 487 */ 488 int aa_autoinitmouse( 489 /* Specifies the AA-lib context to operate on. */ 490 struct aa_context *c, 491 /* Mask of extra features you request. No such features 492 are available in the current AA-lib version. */ 493 int mode); 494 495 /* insert the given driver on beggining of the list of recommended drivers. */ 496 void aa_recommendhi( 497 /* List to operate on (aa_displayrecommended, 498 aa_kbdrecommended or aa_mouserecommended) */ 499 aa_linkedlist ** l, 500 /* Name of the driver (ought to match the "shortname" 501 field of the driver definition structure). */ 502 __AA_CONST char *name); 503 504 /* Add the given driver to the end of list of recommended drivers. */ 505 void aa_recommendlow( 506 /* List to operate on (aa_displayrecommended, 507 aa_kbdrecommended or aa_mouserecommended) */ 508 aa_linkedlist ** l, 509 /* Name of the driver (ought to match the "shortname" 510 field of the driver definition structure). */ 511 __AA_CONST char *name); 512 char *aa_getfirst(aa_linkedlist ** l); 513 514 /*init functions */ 515 516 /* 517 * open the output display for AA-lib. 518 * This is the most primitive AA-lib initialization function. 519 * Allows better control over the process than the easier to use 520 * aa_autoinit function. 521 * 522 * Every AA-lib program ought to have call to aa_parseoptions before 523 * first call to aa_init. 524 * 525 * returns pointer to new AA-lib context or NULL if failed. 526 */ 527 528 aa_context *aa_init( 529 /* Driver you want to use. Available drivers are listed 530 in the NULL terminated aa_drivers array. */ 531 __AA_CONST struct aa_driver *driver, 532 /* Hardware parameters you want. Use aa_defparams 533 for default values. */ 534 __AA_CONST struct aa_hardware_params *defparams, 535 /* This pointer is passed dirrectly to driver used 536 to specify additional driver dependent parameters. */ 537 __AA_CONST void *driverdata); 538 539 /* 540 * initialize the AA-lib keyboard driver. 541 * This is the most primitive AA-lib keyboard initialization function. 542 * Allows better control over the process than the easier to use 543 * aa_autoinitkbd function. 544 * returns 1 on success and 0 on fail. 545 */ 546 547 int aa_initkbd( 548 /* Specifies the AA-lib context to operate on. */ 549 struct aa_context *context, 550 /* Driver you wish to use */ 551 __AA_CONST struct aa_kbddriver *drv, 552 /* Mask of extra features you request. Can contain 553 AA_SENDRELEASE if you are interested in release events 554 too. */ 555 int mode); 556 /* 557 * initialize the AA-lib mouse driver. 558 * This is the most primitive AA-lib keyboard initialization function. 559 * Allows better control over the process than the easier to use 560 * aa_autoinitmouse function. 561 * returns 1 on success and 0 on fail. 562 */ 563 564 int aa_initmouse( 565 /* Specifies the AA-lib context to operate on. */ 566 struct aa_context *c, 567 /* Driver you wish to use. */ 568 __AA_CONST struct aa_mousedriver *d, 569 /* Mask of extra features you request. No such features 570 are available in the current AA-lib version. */ 571 int mode); 572 573 /*uninicializing functions */ 574 575 /* 576 * close the AA-lib context. 577 * Uninitialize all activated drivers and frees the memory used by context 578 * structures. 579 */ 580 void aa_close(aa_context * c /* Specifies the AA-lib context to operate on. */ 581 ); 582 /* 583 * uninitialize the keyboard driver. 584 * Calls "uninitialize" function of the keyboard driver. It ought to undo 585 * all actions done by "initialize" function. 586 */ 587 void aa_uninitkbd( 588 /* Specifies the AA-lib context to operate on. */ 589 aa_context *context); 590 /* 591 * uninitialize the mouse driver. 592 * Calls "uninitialize" function of the mouse driver. It ought to undo 593 * all actions done by "initialize" function. 594 */ 595 void aa_uninitmouse( 596 /* Specifies the AA-lib context to operate on. */ 597 aa_context *context); 598 599 /* simple and fast AA-lib rendering function. 600 * This function does the trick of converting the emulated framebuffer 601 * into high quality ASCII-art. It is slightly faster and less flexible 602 * the aa_render function. 603 * 604 * Note that to see the effect you need to call aa_flush too. 605 * 606 * First call to this function may take a while, because the rendering 607 * tables are produced. 608 */ 609 void aa_fastrender( 610 /* Specifies the AA-lib context to operate on. */ 611 aa_context * c, 612 /* column of top left coner of rendered area 613 (in characters!) */ 614 int x1, 615 /* row of top left coner of rendered area */ 616 int y1, 617 /* column of bottom right coner of rendered area */ 618 int x2, 619 /* row of bottom right coner of rendered area */ 620 int y2); 621 /* convert image buffer to ASCII-art. 622 * This function does the trick of converting the emulated framebuffer 623 * into high quality ASCII-art. If you want to be really fast, you might 624 * use aa_fastrender. If you want to emulate palette, use aa_renderpalette. 625 * 626 * Note that to see the effect you need to call aa_flush too. 627 * 628 * First call to this function may take a while, because the rendering 629 * tables are produced. 630 */ 631 void aa_render( 632 /* Specifies the AA-lib context to operate on. */ 633 aa_context * c, 634 /* Rendering parametters used to specify brightness, gamma 635 correction and other usefull stuff. Use aa_defrenderparams 636 for default values. */ 637 __AA_CONST aa_renderparams * p, 638 /* column of top left coner of rendered area 639 (in characters!) */ 640 int x1, 641 /* row of top left coner of rendered area */ 642 int y1, 643 /* column of bottom right coner of rendered area */ 644 int x2, 645 /* row of bottom right coner of rendered area */ 646 int y2); 647 648 void aa_renderpalette(aa_context * c, __AA_CONST aa_palette table, 649 __AA_CONST aa_renderparams * p, int x1, int y1, int x2, int y2); 650 aa_renderparams *aa_getrenderparams(void); 651 void aa_flush(aa_context * c); 652 653 /* output string to AA-lib output buffers. 654 Output given string to AA-lib output buffers. To see the effect you need to 655 call aa_flush too. */ 656 void aa_puts( 657 /* Specifies the AA-lib context to operate on. */ 658 aa_context * c, 659 /* X coordinate of the first character. */ 660 int x, 661 /* Y coordinate of the first character. */ 662 int y, 663 /* Attribute to use. */ 664 enum aa_attribute attr, 665 /* String to output. */ 666 __AA_CONST char *s); 667 /* 668 * print text to AA-lib output buffers. 669 * Print given text to AA-lib output buffers. To see the effect you need to 670 * call aa_flush too. 671 */ 672 int aa_printf( 673 /* Specifies the AA-lib context to operate on. */ 674 aa_context * c, 675 /* X coordinate of the first character. */ 676 int x, 677 /* Y coordinate of the first character. */ 678 int y, 679 /* Attribute to use. */ 680 enum aa_attribute attr, 681 /* Text to output in standard printf format. */ 682 __AA_CONST char *fmt, ...); 683 /* 684 * move the hardware cursor (if any) to specified position. 685 * Move the hardware cursor (if any) to specified position. 686 * To see the effect you need to call aa_flush too. 687 */ 688 void aa_gotoxy( 689 /* Specifies the AA-lib context to operate on. */ 690 aa_context * c, 691 /* X coordinate of new position. */ 692 int x, 693 /* Y coordinate of the position. */ 694 int y); 695 /* 696 * hide the hardware cursor. 697 * Hide the hardware cursor. 698 * This function may be ignored by some drivers. 699 */ 700 void aa_hidecursor( 701 /* Specifies the AA-lib context to operate on. */ 702 aa_context * c); 703 /* 704 * show the hardware cursor. 705 * Show the hardware cursor. 706 * This function may not be ignored by some drivers. 707 */ 708 void aa_showcursor( 709 /* Specifies the AA-lib context to operate on. */ 710 aa_context * c); 711 /* 712 * Get mouse position as specified by last mouse event read by aa_getevent. 713 */ 714 void aa_getmouse( 715 /* Specifies the AA-lib context to operate on. */ 716 aa_context * c, 717 /* Used to return X coordinate of mouse in characters. */ 718 int *x, 719 /* Used to return Y coordinate of mouse in characters. */ 720 int *y, 721 /* Used to return button mask of mouse. 722 (values used are AA_BUTTON1, AA_BUTTON2 and AA_BUTTON3)*/ 723 int *b); 724 /* 725 * hide the mouse cursor. 726 * Hide the mouse cursor. 727 * This function may be ignored by some drivers. 728 */ 729 void aa_hidemouse(aa_context *c); 730 /* 731 * show the mouse cursor. 732 * Show the mouse cursor. 733 * This function may be ignored by some drivers. 734 */ 735 void aa_showmouse(aa_context *c); 736 737 /* 738 * add new font specification to aa_fonts array. 739 * Returns 1 when succesfull or 0 on failure. 740 */ 741 int aa_registerfont( 742 /* Font specification structure. */ 743 __AA_CONST struct aa_font *f); 744 /* 745 * alter the "supported" field of hardware_params structure used by AA-lib 746 * This function can be used to alter "supported" field of hardware-params 747 * structure used by AA-lib. 748 */ 749 void aa_setsupported( 750 /* Specifies the AA-lib context to operate on. */ 751 aa_context * c, 752 /* New mask of requested features. Can contain 753 AA_EXTENDED to enable use of all 256 characters 754 and AA_EIGHT to enable use of the character numbered 755 higher than 127. */ 756 int supported); 757 /* set font specification to be used by rendering functions. */ 758 void aa_setfont( 759 /* Specifies the AA-lib context to operate on. */ 760 aa_context * c, 761 /* Font specification structure. */ 762 __AA_CONST struct aa_font *font); 763 764 /*keyboard functions */ 765 /* return next event from queue. 766 * Return next even from queue. Optionally wait for even when queue is 767 * empty. 768 * Returns next event from queue (values lower than 256 are used to report 769 * ascii values of pressed keys and higher values have special meanings) 770 * See the AA-lib texinfo documentation for more details. 771 * 0 is returned when queue is empty and wait is set to 0. 772 */ 773 int aa_getevent( 774 /* Specifies the AA-lib context to operate on. */ 775 aa_context * c, 776 /* 1 if you wish to wait for the even when queue is empty. */ 777 int wait); 778 /* return next keypress event from queue. 779 * Returns next keypress event from queue (values lower than 256 are used 780 * to report ascii values of pressed keys and higher values are used to 781 * represent some special keys like arrows) 782 * See the AA-lib texinfo documentation for more details. 783 */ 784 int aa_getkey( 785 /* Specifies the AA-lib context to operate on. */ 786 aa_context * c, 787 /* 1 if you wish to wait for the even when queue is empty. */ 788 int wait); 789 790 /*resize functions */ 791 /* 792 * Do resize action. This function ought to be called when application 793 * takes into account the AA_RESIZE event. The context is reinitialized 794 * and set to new sizes. 795 * Returns 0 when no resizing is done and 1 when resizing was succesfull. 796 */ 797 int aa_resize( 798 /* Specifies the AA-lib context to operate on. */ 799 aa_context * c); 800 /* 801 * Set user handler to be called on resize event. 802 */ 803 void aa_resizehandler( 804 /* Specifies the AA-lib context to operate on. */ 805 aa_context * c, 806 /* Function to be called when resize happends. */ 807 void (*handler) (aa_context *)); 808 809 /* 810 * parse the standard command line options used by AA-lib. 811 * Use this function to parse the standard command line options used by 812 * AA-lib. Every AA-lib program ought to call this function to let user 813 * specify some extra parameters. The function alters the aa_hardware_params 814 * and aa_renderparams structures and removes known options from the 815 * argc/argv lists. It also parse the AAOPTS environment variable. 816 * When called with NULL for the argc/argv parameters, it parses AAOPTS 817 * only. At least this call ought to be in every AA-lib program. 818 * Returns 1 when sucesfull and 0 on failure. The program then can 819 * print the help text available in aa_help variable. 820 */ 821 int aa_parseoptions( 822 /* Hardware parameters structure to alter. It is expected 823 * that this structure only with necessary modifications 824 * will be later used to initialize the AA-lib context. */ 825 struct aa_hardware_params *p, 826 /* Rendering prameters structure to alter. It is expected 827 * that this structure only with necessary modifications 828 * will be later used to render images. */ 829 aa_renderparams * r, 830 /* Pointer to argc parameter passed to function "main". */ 831 int *argc, 832 /* Pointer to argv parameter passed to function "main". */ 833 char **argv); 834 835 /* 836 * Simple interactive line editor. 837 * This function produces the simple interactive line editor that can 838 * be used by AA-lib programs to input strings. 839 */ 840 void aa_edit( 841 /* Specifies the AA-lib context to operate on. */ 842 aa_context * c, 843 /* X coordinate of the edited text. */ 844 int x, 845 /* Y coordinate of the edited text. */ 846 int y, 847 /* Length of the editor window. */ 848 int size, 849 /* Buffer to edit (containing default value). */ 850 char *s, 851 /* Size of the buffer. */ 852 int maxsize); 853 /* 854 * Simple interactive line editor provided as helper function. 855 * 856 * You might use this function to input strings in AA-lib programs. 857 * This function initializes the aa_edit structure used by event-based 858 * editor. You might then call the aa_editkey function when key is pressed. 859 * 860 * Returns pointer to edit context when succesfull and NULL on failure. 861 */ 862 struct aa_edit *aa_createedit( 863 /* Specifies the AA-lib context to operate on. */ 864 aa_context * c, 865 /* X coordinate of the edited text. */ 866 int x, 867 /* Y coordinate of the edited text. */ 868 int y, 869 /* Length of the editor window. */ 870 int size, 871 /* Buffer to edit (containing default value). */ 872 char *s, 873 /* Size of the buffer. */ 874 int maxsize); 875 876 /* Notify the line editor about keypress. */ 877 void aa_editkey( 878 /* Editor context to use (see aa_createedit) */ 879 struct aa_edit *e, 880 /* Key pressed */ 881 int c); 882 883 /* 884 * put pixel to emulated framebuffer 885 */ 886 void aa_putpixel( 887 /* Specifies the AA-lib context to operate on. */ 888 aa_context * c, 889 /* X coordinate. */ 890 int x, 891 /* Y coordinate. */ 892 int y, 893 /* Palette index or brightness value (0..255) */ 894 int color); 895 896 /* insert the given driver on beggining of the list of recommended keyboard drivers. */ 897 void aa_recommendhikbd( 898 /* Name of the driver (ought to match the "shortname" 899 field of the driver definition structure). */ 900 __AA_CONST char *name); 901 902 /* Add the given driver to the end of list of keyboard recommended drivers. */ 903 void aa_recommendlowkbd( 904 /* Name of the driver (ought to match the "shortname" 905 field of the driver definition structure). */ 906 __AA_CONST char *name); 907 /* insert the given driver on beggining of the list of recommended mouse drivers. */ 908 void aa_recommendhimouse( 909 /* Name of the driver (ought to match the "shortname" 910 field of the driver definition structure). */ 911 __AA_CONST char *name); 912 913 /* Add the given driver to the end of list of mouse recommended drivers. */ 914 void aa_recommendlowmouse( 915 /* Name of the driver (ought to match the "shortname" 916 field of the driver definition structure). */ 917 __AA_CONST char *name); 918 /* insert the given driver on beggining of the list of recommended display drivers. */ 919 void aa_recommendhidisplay( 920 /* Name of the driver (ought to match the "shortname" 921 field of the driver definition structure). */ 922 __AA_CONST char *name); 923 924 /* Add the given driver to the end of list of display recommended drivers. */ 925 void aa_recommendlowdisplay( 926 /* Name of the driver (ought to match the "shortname" 927 field of the driver definition structure). */ 928 __AA_CONST char *name); 929 930 931 932 /* This macro implementations are proved for faster compilation. */ 933 #ifdef __GNUC__ 934 /* The putpixel macro can be implemented reliably only using GNU-C extension. */ 935 #define aa_putpixel(c,x,y,color) ({aa_context *___aa_context=(c); ((___aa_context)->imagebuffer[(x)+(y)*(aa_imgwidth(___aa_context))]=(color)); 0;}) 936 #endif 937 #define aa_setpalette(palette,index,r,g,b) ((palette)[index]=(((r)*30+(g)*59+(b)*11)>>8)) 938 #define aa_recommendhikbd(t) aa_recommendhi(&aa_kbdrecommended,t); 939 #define aa_recommendhimouse(t) aa_recommendhi(&aa_mouserecommended,t); 940 #define aa_recommendhidisplay(t) aa_recommendhi(&aa_displayrecommended,t); 941 #define aa_recommendlowkbd(t) aa_recommendlow(&aa_kbdrecommended,t); 942 #define aa_recommendlowmouse(t) aa_recommendlow(&aa_mouserecommended,t); 943 #define aa_recommendlowdisplay(t) aa_recommendlow(&aa_displayrecommended,t); 944 #define aa_scrwidth(a) ((a)->params.width) 945 #define aa_scrheight(a) ((a)->params.height) 946 #define aa_mmwidth(a) ((a)->params.mmwidth) 947 #define aa_mmheight(a) ((a)->params.mmheight) 948 #define aa_imgwidth(a) ((a)->imgwidth) 949 #define aa_imgheight(a) ((a)->imgheight) 950 #define aa_image(c) ((c)->imagebuffer) 951 #define aa_text(c) ((c)->textbuffer) 952 #define aa_attrs(c) ((c)->attrbuffer) 953 954 955 #ifdef __cplusplus 956 } 957 #endif 958 #endif 959