mactty.h

Go to the documentation of this file.
00001 /*      SCCS Id: @(#)mactty.h   3.4     1993/03/01      */
00002 /* Copyright (c) Jon W{tte 1993.                                        */
00003 /* NetHack may be freely redistributed.  See license for details.       */
00004 
00005 /*
00006  * This header is the supported external interface for the "tty" window
00007  * package. This package sports care-free handling of "dumb" tty windows
00008  * (preferrably using monospaced fonts) - it does NOT remember the strings
00009  * sent to it; rather, it uses an offscreen bitmap.
00010  *
00011  * For best performance, make sure it is aligned on a 32-pixel boundary
00012  * (or at least a 16-pixel one) in black & white. For 24bit color,
00013  * alignment doesn't matter, and for 8-bit color, alignment to every
00014  * fourth pixel is most efficient.
00015  *
00016  * (c) Copyright 1993 Jon W{tte
00017  */
00018 
00019 /*
00020  * You should really not poke in the structures used by the tty window.
00021  * However, since it uses the wRefCon of windows (by calling GetWRefCon
00022  * and SetWRefCon) you lose that possibility. If you still want to store
00023  * information about a window, the FIRST location _pointed to_ by the
00024  * wRefCon will be a void * that you can use for whatever reasons. Don't
00025  * take the address of this variable and expect it to stay the same
00026  * across calls to the tty window.
00027  *
00028  * void * my_config_ptr = * ( void * * ) GetWRefCon ( tty_window ) ;
00029  */
00030 
00031 /*
00032  * The library uses the window's port temporarily through SetPortBits;
00033  * that means you shouldn't do any funky things to the clipping region
00034  * etc. Actually, you shouldn't even resize the window, as that will clip
00035  * new drawing.
00036  *
00037  * Also, if you use this library under Pascal, remember that the string
00038  * passed to add_tty_string() is a "C" style string with NO length byte,
00039  * and a terminating zero byte at the end instead.
00040  */
00041 
00042 #ifndef _H_tty_public
00043 # define _H_tty_public
00044 #undef red                      /* undef internal color const strings from decl */
00045 #undef green
00046 #undef blue
00047 #if !TARGET_API_MAC_CARBON
00048 # include <windows.h>
00049 #endif
00050 
00051 /*
00052  * Error code returned when it's probably our fault, or
00053  * bad parameters.
00054  */
00055 #define general_failure 1
00056 
00057 /*
00058  * Base resource id's for window types
00059  */
00060 #define WIN_BASE_RES 128
00061 #define WIN_BASE_KIND 128
00062 
00063 /*
00064  * Commonly used characters
00065  */
00066 #define CHAR_ENTER ((char)3)
00067 #define CHAR_BELL ((char)7)
00068 #define CHAR_BS ((char)8)
00069 #define CHAR_LF ((char)10)
00070 #define CHAR_CR ((char)13)
00071 #define CHAR_ESC ((char)27)
00072 #define CHAR_BLANK ((char)32)
00073 #define CHAR_DELETE ((char)127)
00074 
00075 extern char game_active;        /* flag to window rendering routines not to use ppat */
00076 /*
00077  * If you want some fancy operations that not a normal TTY device normally
00078  * supports, use EXTENDED_SUPPORT. For frames, area erases and area scrolls,
00079  * plus bitmap graphics - RESOLUTION DEPENDENT, be sure to call
00080  * get_tty_metrics and use those limits.
00081  */
00082 #define EXTENDED_SUPPORT 0
00083 /*
00084  * if you print a lot of single characters, accumulating each one in a
00085  * clipping region will take too much time. Instead, define this, which
00086  * will clip in rects.
00087  */
00088 #define CLIP_RECT_ONLY 1
00089 
00090 typedef enum tty_attrib {
00091 
00092 /*
00093  * Flags relating to the general functioning of the window.
00094  * These flags are passed at create_tty time, and changing them
00095  * later will clear the screen.
00096  */
00097         TTY_ATTRIB_FLAGS ,
00098 /*
00099  * When using proportional fonts, this will place each character
00100  * separately, ensuring aligned columns (but looking ugly and taking
00101  * time)
00102  */
00103 # define TA_MOVE_EACH_CHAR 1L
00104 /*
00105  * This means draw each change as it occurs instead of collecting the area
00106  * and draw it all at once at update_tty() - slower, but more reliable.
00107  */
00108 # define TA_ALWAYS_REFRESH 2L
00109 /*
00110  * When reaching the right end, we either just stop drawing, or wrap to the
00111  * next line.
00112  */
00113 # define TA_WRAP_AROUND 4L
00114 /*
00115  * Overstrike means that characters are added on top of each other; i e don't
00116  * clear the letter beneath. This is faster, using srcOr under QuickDraw
00117  */
00118 # define TA_OVERSTRIKE 8L
00119 /*
00120  * We may want the window not to scroll when we reach the end line,
00121  * but stop drawing instead.
00122  */
00123 # define TA_INHIBIT_VERT_SCROLL 16L
00124 
00125 /*
00126  * Foreground and background colors. These only affect characters
00127  * drawn by subsequent calls; not what's already there (but it does
00128  * affect clears)
00129  * On b/w screens these do nothing.
00130  */
00131         TTY_ATTRIB_FOREGROUND ,
00132         TTY_ATTRIB_BACKGROUND ,
00133 # define TA_RGB_TO_TTY(r) ((((long)((r).red>>8)&0xff)<<16)+\
00134         (((long)((r).green>>8)&0xff)<<8)+((long)((r).blue>>8)&0xff))
00135 
00136 /*
00137  * Attributes relating to the cursor, and character set mappings
00138  */
00139         TTY_ATTRIB_CURSOR ,
00140 /*
00141  * Blinking cursor is more noticeable when it's idle
00142  */
00143 # define TA_BLINKING_CURSOR 1L
00144 /*
00145  * When handling input, do we echo characters as they are typed?
00146  */
00147 # define TA_ECHO_INPUT 2L
00148 /*
00149  * Do we return each character code separately, or map delete etc? Note
00150  * that non-raw input means getchar won't return anything until the user
00151  * has typed a return.
00152  */
00153 # define TA_RAW_INPUT 4L
00154 /*
00155  * Do we print every character as it is (including BS, NL and CR!) or do
00156  * do we interpret characters such as NL, BS and CR?
00157  */
00158 # define TA_RAW_OUTPUT 8L
00159 /*
00160  * When getting a NL, do we also move to the left?
00161  */
00162 # define TA_NL_ADD_CR 16L
00163 /*
00164  * When getting a CR, do we also move down?
00165  */
00166 # define TA_CR_ADD_NL 32L
00167 /*
00168  * Wait for input or return what we've got?
00169  */
00170 # define TA_NONBLOCKING_IO 64L
00171 
00172 /*
00173  * Use this macro to cast a function pointer to a tty attribute; this will help
00174  * portability to systems where a function pointer doesn't fit in a long
00175  */
00176 # define TA_ATTRIB_FUNC(x) ((long)(x))
00177 
00178 /*
00179  * This symbolic constant is used to check the number of attributes
00180  */
00181         TTY_NUMBER_ATTRIBUTES
00182 
00183 } tty_attrib ;
00184 
00185 /*
00186  * Character returned by end-of-file condition
00187  */
00188 # define TTY_EOF -1
00189 
00190 
00191 /*
00192  * Create the window according to a resource WIND template.
00193  * The window pointer pointed to by window should be NULL to
00194  * allocate the window record dynamically, or point to a
00195  * WindowRecord structure already allocated.
00196  *
00197  * Passing in_color means you have to be sure there's color support;
00198  * on the Mac, this means 32bit QuickDraw present, else it will
00199  * crash. Not passing in_color means everything's rendered in
00200  * black & white.
00201  */
00202 extern short create_tty ( WindowPtr * window , short resource_id ,
00203         Boolean in_color ) ;
00204 
00205 /*
00206  * Use init_tty_name or init_tty_number to initialize a window
00207  * once allocated by create_tty. Size parameters are in characters.
00208  */
00209 
00210 extern short init_tty_number ( WindowPtr window , short font_number ,
00211         short font_size , short x_size , short y_size ) ;
00212 
00213 /*
00214  * Close and deallocate a window and its data
00215  */
00216 extern short destroy_tty ( WindowPtr window ) ;
00217 
00218 /*
00219  * Change the font and font size used in the window for drawing after
00220  * the calls are made. To change the coordinate system, be sure to call
00221  * force_tty_coordinate_system_recalc() - else it may look strange if
00222  * the new font doesn't match the old one.
00223  */
00224 extern short set_tty_font_name (winid window_type , char * name ) ;
00225 extern short force_tty_coordinate_system_recalc ( WindowPtr window ) ;
00226 
00227 /*
00228  * Getting some metrics about the tty and its drawing.
00229  */
00230 extern short get_tty_metrics ( WindowPtr window , short * x_size ,
00231         short * y_size , short * x_size_pixels , short * y_size_pixels ,
00232         short * font_number , short * font_size ,
00233         short * char_width , short * row_height ) ;
00234 
00235 /*
00236  * The basic move cursor function. 0,0 is topleft.
00237  */
00238 extern short move_tty_cursor ( WindowPtr window , short x_pos ,
00239         short y_pos ) ;
00240 
00241 /*
00242  * Flush all changes done to a tty to the screen (see TA_ALWAYS_UPDATE above)
00243  */
00244 extern short update_tty ( WindowPtr window ) ;
00245 
00246 /*
00247  * Add a character to the tty and update the cursor position
00248  */
00249 extern short add_tty_char ( WindowPtr window , short character ) ;
00250 
00251 /*
00252  * Add a string of characters to the tty and update the cursor
00253  * position. The string is 0-terminated!
00254  */
00255 extern short add_tty_string ( WindowPtr window , const char * string ) ;
00256 
00257 /*
00258  * Change or read an attribute of the tty. Note that some attribute changes
00259  * may clear the screen. See the above enum and defines for values.
00260  * Attributes can be both function pointers and special flag values.
00261  */
00262 extern short get_tty_attrib ( WindowPtr window , tty_attrib attrib ,
00263         long * value ) ;
00264 extern short set_tty_attrib ( WindowPtr window , tty_attrib attrib ,
00265         long value ) ;
00266 
00267 /*
00268  * Scroll the actual TTY image, in characters, positive means up/left
00269  * scroll_tty ( my_tty , 0 , 1 ) means a linefeed. Is always carried out
00270  * directly, regardless of the wait-update setting. Does updates before
00271  * scrolling.
00272  */
00273 extern short scroll_tty ( WindowPtr window , short delta_x ,
00274         short delta_y ) ;
00275 
00276 /*
00277  * Erase the offscreen bitmap and move the cursor to 0,0. Re-init some window
00278  * values (font etc) Is always carried out directly on-screen, regardless of
00279  * the wait-for-update setting. Clears update area.
00280  */
00281 extern short clear_tty ( WindowPtr window ) ;
00282 
00283 /*
00284  * Call this routine with a window (always _mt_window) and a time (usually
00285  * from most recent event) to determine if cursor in window should be blinked
00286  */
00287 extern short blink_cursor ( WindowPtr window , long when ) ;
00288 
00289 /*
00290  * For screen dumps, open the printer port and call this function. Can be used
00291  * for clipboard as well (only for a PICT, though; this library doesn't concern
00292  * itself with characters, just bitmaps)
00293  */
00294 extern short image_tty ( EventRecord *theEvent, WindowPtr window ) ;
00295 
00296 /*
00297  * For erasing just an area of characters
00298  */
00299 extern short clear_tty_window ( WindowPtr window , short from_row ,
00300         short from_col , short to_row , short to_col ) ;
00301 
00302 /*
00303  * get and set the invalid region of the main window
00304  */
00305  extern short get_invalid_region (WindowPtr window, Rect *inval_rect);
00306  extern short set_invalid_region (WindowPtr window, Rect *inval_rect);
00307  
00308 /*
00309  * Now in macsnd.c, which seemed like a good place
00310  */
00311 extern void tty_nhbell ();
00312 
00313 #if EXTENDED_SUPPORT
00314 
00315 /*
00316  * Various versions of delete character/s, insert line/s etc can be handled by
00317  * this general-purpose function. Negative num_ means delete, positive means
00318  * insert, and you can never be sure which of row and col operations come first
00319  * if you specify both...
00320  */
00321 extern short mangle_tty_rows_columns ( WindowPtr window ,
00322         short from_row , short num_rows , short from_col , short num_cols ) ;
00323 
00324 /*
00325  * For framing an area without using grahpics characters.
00326  * Note that the given limits are those used for framing, you should not
00327  * draw in them. frame_fatness should typically be 1-5, and may be clipped
00328  * if it is too large.
00329  */
00330 extern short frame_tty_window ( WindowPtr window , short from_row ,
00331         short from_col , short to_row , short to_col , short frame_fatness ) ;
00332 
00333 /*
00334  * For inverting specific characters after the fact. May look funny in color.
00335  */
00336 extern short invert_tty_window ( WindowPtr window , short from_row ,
00337         short from_col , short to_row , short to_col ) ;
00338 
00339 /*
00340  * For drawing lines on the tty - VERY DEVICE DEPENDENT. Use get_tty_metrics.
00341  */
00342 extern short draw_tty_line ( WindowPtr window , short from_x ,
00343         short from_y , short to_x , short to_y ) ;
00344 
00345 #endif /* EXTENDED_SUPPORT */
00346 
00347 #endif /* _H_tty_public */