Source:NetHack 3.2.0/mactty.h

Below is the full text to mactty.h from the source code of NetHack 3.2.0. To link to a particular line, write [[NetHack 3.2.0/mactty.h#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)mactty.h	3.2	93/03/01	*/ 2.   /* Copyright (c) Jon W{tte 1993. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    /*  6.     * This header is the supported external interface for the "tty" window 7.    * package. This package sports care-free handling of "dumb" tty windows 8.    * (preferrably using monospaced fonts) - it does NOT remember the strings 9.    * sent to it; rather, it uses an offscreen bitmap. 10.   *  11.    * For best performance, make sure it is aligned on a 32-pixel boundary 12.   * (or at least a 16-pixel one) in black & white. For 24bit color, 13.   * alignment doesn't matter, and for 8-bit color, alignment to every 14.   * fourth pixel is most efficient. 15.   *  16.    * (c) Copyright 1993 Jon W{tte 17.   */  18.    19.   /*  20.    * You should really not poke in the structures used by the tty window. 21.   * However, since it uses the wRefCon of windows (by calling GetWRefCon  22.    * and SetWRefCon) you lose that possibility. If you still want to store 23.   * information about a window, the FIRST location _pointed to_ by the 24.   * wRefCon will be a void * that you can use for whatever reasons. Don't 25. * take the address of this variable and expect it to stay the same 26.   * across calls to the tty window. 27.   *  28.    * void * my_config_ptr = * ( void * * ) GetWRefCon ( tty_window ) ; 29.   */  30.    31.   /*  32.    * The library uses the window's port temporarily through SetPortBits; 33.   * that means you shouldn't do any funky things to the clipping region 34.   * etc. Actually, you shouldn't even resize the window, as that will clip 35.   * new drawing. 36.   *  37.    * Also, if you use this library under Pascal, remember that the string 38.   * passed to add_tty_string is a "C" style string with NO length byte, 39.   * and a terminating zero byte at the end instead. 40.   */  41.    42.   #ifndef _H_tty_public 43.  # define _H_tty_public 44.   45.   #include   46. #include  47. #include  48. #include  49. #include  50. #include  51. #include  52. #include  53. #include  54. #include  55. #include  56. 57.   58.   /*  59.    * If you export this library to Pascal, which doesn't have vsprintf 60.   * to rely on, you will need to change this define to 0 61.   */  62.   #define PRINTF_TTY 1 63.  /*  64.    * If you want the functions getchar_tty and gets_tty, you have to define 65.   * this. Currently not supported. 66.   */  67.   #define TTY_INPUT 0 68.  /*  69.    * If you want some fancy operations that not a normal TTY device normally 70.   * supports, use EXTENDED_SUPPORT. For frames, area erases and area scrolls, 71.   * plus bitmap graphics - RESOLUTION DEPENDENT, be sure to call 72.   * get_tty_metrics and use those limits. 73.   */  74.   #define EXTENDED_SUPPORT 1 75.  /*  76.    * if you print a lot of single characters, accumulating each one in a  77. * clipping region will take too much time. Instead, define this, which 78.   * will clip in rects. 79.   */  80.   #define CLIP_RECT_ONLY 1 81.   82.   typedef enum tty_attrib { 83.   84.   /*  85.    * Flags relating to the general functioning of the window. 86.   * These flags are passed at create_tty time, and changing them 87.   * later will clear the screen. 88.   */  89.   	TTY_ATTRIB_FLAGS , 90.  /*  91.    * When using proportional fonts, this will place each character 92.   * separately, ensuring aligned columns (but looking ugly and taking  93.    * time) 94.   */  95.   # define TA_MOVE_EACH_CHAR 1L 96.  /*  97.    * This means draw each change as it occurs instead of collecting the area 98.   * and draw it all at once at update_tty - slower, but more reliable. 99.   */  100.  # define TA_ALWAYS_REFRESH 2L 101. /*  102.   * When reaching the right end, we either just stop drawing, or wrap to the 103.  * next line. 104.  */  105.  # define TA_WRAP_AROUND 4L 106. /*  107.   * Overstrike means that characters are added on top of each other; i e don't  108. * clear the letter beneath. This is faster, using srcOr under QuickDraw 109.  */  110.  # define TA_OVERSTRIKE 8L 111. /*  112.   * We may want the window not to scroll when we reach the end line, 113.  * but stop drawing instead. 114.  */  115.  # define TA_INHIBIT_VERT_SCROLL 16L 116.  117.  /*  118.   * Foreground and background colors. These only affect characters 119.  * drawn by subsequent calls; not what's already there (but it does  120.   * affect clears) 121.  * On b/w screens these do nothing. 122.  */  123.  	TTY_ATTRIB_FOREGROUND , 124. 	TTY_ATTRIB_BACKGROUND , 125. # define TA_RGB_TO_TTY(r) ((((long)((r).red>>8)&0xff)<<16)+\  126.  	(((long)((r).green>>8)&0xff)<<8)+((long)((r).blue>>8)&0xff)) 127.  128.  /*  129.   * Attributes relating to the cursor, and character set mappings 130.  */  131.  	TTY_ATTRIB_CURSOR , 132. /*  133.   * Blinking cursor is more noticeable when it's idle 134.  */  135.  # define TA_BLINKING_CURSOR 1L 136. /*  137.   * When handling input, do we echo characters as they are typed? 138.  */  139.  # define TA_ECHO_INPUT 2L 140. /*  141.   * Do we return each character code separately, or map delete etc? Note 142.  * that non-raw input means getchar won't return anything until the user 143.  * has typed a return. 144.  */  145.  # define TA_RAW_INPUT 4L 146. /*  147.   * Do we print every character as it is (including BS, NL and CR!) or do  148. * do we interpret characters such as NL, BS and CR? 149.  */  150.  # define TA_RAW_OUTPUT 8L 151. /*  152.   * When getting a NL, do we also move to the left? 153.  */  154.  # define TA_NL_ADD_CR 16L 155. /*  156.   * When getting a CR, do we also move down? 157.  */  158.  # define TA_CR_ADD_NL 32L 159. /*  160.   * Wait for input or return what we've got? 161.  */  162.  # define TA_NONBLOCKING_IO 64L 163.  164.  /*  165.   * A callback function for command keys entered when locked in an input loop. 166.  * Calling convention: 167.  * pascal void callback_function ( EventRecord * event, WindowPtr window ) ; 168.  */  169.  	TTY_COMMAND_KEY_CALLBACK , 170. /*  171.   * This function is called to allocate memory for the window. Note that 172.  * create_tty doesn't create any memory (except that created by GetNewWindow) 173.  * but init_tty_name and init_tty_number do allocate memory. 174.  * Calling convention: 175.  * pascal short allocate_memory ( WindowPtr window, void * * to_alloc ,  176.   *     long size ) ; 177.  * should return 0 for success, and error code for fail. 178.  */  179.  	TTY_ALLOCATE_MEMORY_FUNCTION , 180. /*  181.   * This is the counterpart to the allocate function, called to free memory. 182.  * Calling convention: 183.  * pascal short free_memory ( WindowPtr window, void * to_free ) ; 184.  * should return 0 for success, and error code for fail. 185.  */  186.  	TTY_FREE_MEMORY_FUNCTION , 187. /*  188.   * Use this function to beep, for instance for too large buffer or for 189.  * printing a bell character in non-RAW mode. 190.  * pascal void ( * tty_beep ) ( WindowPtr window ) ; 191.  */  192.   	TTY_BEEP_FUNCTION , 193. /*  194.   * Use this macro to cast a function pointer to a tty attribute; this will help 195.  * portability to systems where a function pointer doesn't fit in a long 196.  */  197.  # define TA_ATTRIB_FUNC(x) ((long)(x)) 198.  199.  /*  200.   * This symbolic constant is used to check the number of attributes 201.  */  202.  	TTY_NUMBER_ATTRIBUTES 203.  204.  } tty_attrib ; 205.  206.  /*  207.   * Character returned by end-of-file condition 208.  */  209.  # define TTY_EOF -1 210.  211.   212.  /*  213.   * Create the window according to a resource WIND template. 214.  * The window pointer pointed to by window should be NULL to  215. * allocate the window record dynamically, or point to a 216. * WindowRecord structure already allocated. 217.  *  218.   * Passing in_color means you have to be sure there's color support; 219.  * on the Mac, this means 32bit QuickDraw present, else it will 220.  * crash. Not passing in_color means everything's rendered in 221. * black & white. 222.  */  223.  extern pascal short create_tty ( WindowPtr * window, short resource_id ,  224.  	Boolean in_color ) ; 225.  226.  /*  227.   * Use init_tty_name or init_tty_number to initialize a window 228.  * once allocated by create_tty. Size parameters are in characters. 229.  */  230.  extern pascal short init_tty_name ( WindowPtr window,  231.  	unsigned char * font_name , short font_size , short x_size ,  232.  	short y_size ) ; 233. extern pascal short init_tty_number ( WindowPtr window, short font_number ,  234.  	short font_size , short x_size , short y_size ) ; 235.  236.  /*  237.   * Close and deallocate a window and its data 238.  */  239.  extern pascal short destroy_tty ( WindowPtr window ) ; 240.  241.  /*  242.   * Change the font and font size used in the window for drawing after 243.  * the calls are made. To change the coordinate system, be sure to call 244.  * force_tty_coordinate_system_recalc - else it may look strange if  245. * the new font doesn't match the old one. 246.  */  247.  extern pascal short set_tty_font_name ( WindowPtr window,  248.  	unsigned char * name ) ; 249. extern pascal short set_tty_font_number ( WindowPtr window, short number ) ; 250. extern pascal short set_tty_font_size ( WindowPtr window, short size ) ; 251. extern pascal short force_tty_coordinate_system_recalc ( WindowPtr window ) ; 252.  253.  /*  254.   * Getting some metrics about the tty and its drawing. 255.  */  256.  extern pascal short get_tty_metrics ( WindowPtr window, short * x_size ,  257.  	short * y_size , short * x_size_pixels , short * y_size_pixels ,  258.  	short * font_number , short * font_size ,  259.  	short * char_width , short * row_height ) ; 260.  261.  /*  262.   * The basic move cursor function. 0,0 is topleft. 263.  */  264.  extern pascal short move_tty_cursor ( WindowPtr window, short x_pos ,  265.  	short y_pos ) ; 266.  267.  /*  268.   * Return the location of the tty cursor 269.  */  270.  extern pascal short get_tty_cursor ( WindowPtr window, short * x_pos ,  271.  	short * y_pos ) ; 272.  273.  /*  274.   * Flush all changes done to a tty to the screen (see TA_ALWAYS_UPDATE above) 275.  */  276.  extern pascal short update_tty ( WindowPtr window ) ; 277.  278.  /*  279.   * Add a character to the tty and update the cursor position 280.  */  281.  extern pascal short add_tty_char ( WindowPtr window, short character ) ; 282.  283.  /*  284.   * Add a string of characters to the tty and update the cursor 285.  * position. The string is 0-terminated! 286.  */  287.  extern pascal short add_tty_string ( WindowPtr window, const char * string ) ; 288.  289.  #if PRINTF_TTY 290. /*  291.   * The cool, standard C printf function, here for convenience. Requires 292.  * vsprintf in the libraries. Change the PRINTF_TTY define to remove it. 293.  */  294.  extern short printf_tty ( WindowPtr window, const char * format , ... ) ; 295. #endif 296.  297.  /*  298.   * Change or read an attribute of the tty. Note that some attribute changes 299.  * may clear the screen. See the above enum and defines for values. 300.  * Attributes can be both function pointers and special flag values. 301.  */  302.  extern pascal short get_tty_attrib ( WindowPtr window, tty_attrib attrib ,  303.  	long * value ) ; 304. extern pascal short set_tty_attrib ( WindowPtr window, tty_attrib attrib ,  305.  	long value ) ; 306.  307.  /*  308.   * Scroll the actual TTY image, in characters, positive means up/left 309.  * scroll_tty ( my_tty, 0 , 1 ) means a linefeed. Is always carried out 310.  * directly, regardless of the wait-update setting. Does updates before 311.  * scrolling. 312.  */  313.  extern pascal short scroll_tty ( WindowPtr window, short delta_x ,  314.  	short delta_y ) ; 315.  316.  /*  317.   * Erase the offscreen bitmap and move the cursor to 0,0. Re-init some window 318.  * values (font etc) Is always carried out directly on-screen, regardless of  319. * the wait-for-update setting. Clears update area. 320.  */  321.  extern pascal short clear_tty ( WindowPtr window ) ; 322.  323.  /*  324.   * We changed our mind about the size we want to draw in - in characters. 325.  * You need to change the window size separately with SizeWindow. 326.  */  327.  extern pascal short resize_tty_area ( WindowPtr window, short x_size ,  328.  	short y_size ) ; 329.  330.  /*  331.   * Call this function after calling WaitNextEvent in your program. It will 332.  * return 0 if this was an event handled by the tty window, and you can go  333. * right back to calling WaitNextEvent. Non-0 means you handle the event. 334.  */  335.  extern pascal short handle_tty_event ( WindowPtr window,  336.  	EventRecord * event ) ; 337.  338.  /*  339.   * For screen dumps, open the printer port and call this function. Can be used 340.  * for clipboard as well (only for a PICT, though; this library doesn't concern  341.   * itself with characters, just bitmaps) 342.  */  343.  extern pascal short image_tty ( WindowPtr window ) ; 344.  345.  #if TTY_INPUT 346. /*  347.   * Enter an internal event loop to read a character, that is returned in the 348.  * character parameter. Note that several callback attributes may be called 349.  * here to handle events the tty cannot handle itself. To handle command keys, 350.  * you can install a command key handler. Note that if input isn't raw, you 351.  * will not get any input until return is pressed. 352.  */  353.  extern pascal short getchar_tty ( WindowPtr window, short * character ) ; 354.  355.  /*  356.   * Read an entire string, bounded by the length specified. 357.  */  358.  extern pascal short gets_tty ( WindowPtr window, char * buffer ,  359.  	short buffer_length ) ; 360.  361.  #endif /* TTY_INPUT */ 362.  363.  #if EXTENDED_SUPPORT 364.  365.  /*  366.   * Various versions of delete character/s, insert line/s etc can be handled by  367. * this general-purpose function. Negative num_ means delete, positive means 368.  * insert, and you can never be sure which of row and col operations come first 369.  * if you specify both...  370. */ 371.  extern pascal short mangle_tty_rows_columns ( WindowPtr window,  372.  	short from_row , short num_rows , short from_col , short num_cols ) ; 373.  374.  /*  375.   * For erasing just an area of characters 376.  */  377.  extern pascal short clear_tty_window ( WindowPtr window, short from_row ,  378.  	short from_col , short to_row , short to_col ) ; 379.  380.  /*  381.   * For framing an area without using grahpics characters. 382.  * Note that the given limits are those used for framing, you should not 383.  * draw in them. frame_fatness should typically be 1-5, and may be clipped 384.  * if it is too large. 385.  */  386.  extern pascal short frame_tty_window ( WindowPtr window, short from_row ,  387.  	short from_col , short to_row , short to_col , short frame_fatness ) ; 388.  389.  /*  390.   * For inverting specific characters after the fact. May look funny in color. 391.  */  392.  extern pascal short invert_tty_window ( WindowPtr window, short from_row ,  393.  	short from_col , short to_row , short to_col ) ; 394.  395.  /*  396.   * For drawing lines on the tty - VERY DEVICE DEPENDENT. Use get_tty_metrics. 397.  */  398.  extern pascal short draw_tty_line ( WindowPtr window, short from_x ,  399.  	short from_y , short to_x , short to_y ) ; 400.  401.  #endif /* EXTENDED_SUPPORT */ 402.  403.  #endif /* _H_tty_public */