File: mactty.h

package info (click to toggle)
glhack 1.2-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 26,744 kB
  • ctags: 21,239
  • sloc: ansic: 208,571; cpp: 13,139; yacc: 2,005; makefile: 1,155; lex: 377; sh: 121; awk: 89; sed: 11
file content (347 lines) | stat: -rw-r--r-- 10,957 bytes parent folder | download | duplicates (22)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*	SCCS Id: @(#)mactty.h	3.4	1993/03/01	*/
/* Copyright (c) Jon W{tte 1993.					*/
/* NetHack may be freely redistributed.  See license for details.	*/

/*
 * This header is the supported external interface for the "tty" window
 * package. This package sports care-free handling of "dumb" tty windows
 * (preferrably using monospaced fonts) - it does NOT remember the strings
 * sent to it; rather, it uses an offscreen bitmap.
 *
 * For best performance, make sure it is aligned on a 32-pixel boundary
 * (or at least a 16-pixel one) in black & white. For 24bit color,
 * alignment doesn't matter, and for 8-bit color, alignment to every
 * fourth pixel is most efficient.
 *
 * (c) Copyright 1993 Jon W{tte
 */

/*
 * You should really not poke in the structures used by the tty window.
 * However, since it uses the wRefCon of windows (by calling GetWRefCon
 * and SetWRefCon) you lose that possibility. If you still want to store
 * information about a window, the FIRST location _pointed to_ by the
 * wRefCon will be a void * that you can use for whatever reasons. Don't
 * take the address of this variable and expect it to stay the same
 * across calls to the tty window.
 *
 * void * my_config_ptr = * ( void * * ) GetWRefCon ( tty_window ) ;
 */

/*
 * The library uses the window's port temporarily through SetPortBits;
 * that means you shouldn't do any funky things to the clipping region
 * etc. Actually, you shouldn't even resize the window, as that will clip
 * new drawing.
 *
 * Also, if you use this library under Pascal, remember that the string
 * passed to add_tty_string() is a "C" style string with NO length byte,
 * and a terminating zero byte at the end instead.
 */

#ifndef _H_tty_public
# define _H_tty_public
#undef red			/* undef internal color const strings from decl */
#undef green
#undef blue
#if !TARGET_API_MAC_CARBON
# include <windows.h>
#endif

/*
 * Error code returned when it's probably our fault, or
 * bad parameters.
 */
#define general_failure 1

/*
 * Base resource id's for window types
 */
#define WIN_BASE_RES 128
#define WIN_BASE_KIND 128

/*
 * Commonly used characters
 */
#define CHAR_ENTER ((char)3)
#define CHAR_BELL ((char)7)
#define CHAR_BS ((char)8)
#define CHAR_LF ((char)10)
#define CHAR_CR ((char)13)
#define CHAR_ESC ((char)27)
#define CHAR_BLANK ((char)32)
#define CHAR_DELETE ((char)127)

extern char game_active;	/* flag to window rendering routines not to use ppat */
/*
 * If you want some fancy operations that not a normal TTY device normally
 * supports, use EXTENDED_SUPPORT. For frames, area erases and area scrolls,
 * plus bitmap graphics - RESOLUTION DEPENDENT, be sure to call
 * get_tty_metrics and use those limits.
 */
#define EXTENDED_SUPPORT 0
/*
 * if you print a lot of single characters, accumulating each one in a
 * clipping region will take too much time. Instead, define this, which
 * will clip in rects.
 */
#define CLIP_RECT_ONLY 1

typedef enum tty_attrib {

/*
 * Flags relating to the general functioning of the window.
 * These flags are passed at create_tty time, and changing them
 * later will clear the screen.
 */
	TTY_ATTRIB_FLAGS ,
/*
 * When using proportional fonts, this will place each character
 * separately, ensuring aligned columns (but looking ugly and taking
 * time)
 */
# define TA_MOVE_EACH_CHAR 1L
/*
 * This means draw each change as it occurs instead of collecting the area
 * and draw it all at once at update_tty() - slower, but more reliable.
 */
# define TA_ALWAYS_REFRESH 2L
/*
 * When reaching the right end, we either just stop drawing, or wrap to the
 * next line.
 */
# define TA_WRAP_AROUND 4L
/*
 * Overstrike means that characters are added on top of each other; i e don't
 * clear the letter beneath. This is faster, using srcOr under QuickDraw
 */
# define TA_OVERSTRIKE 8L
/*
 * We may want the window not to scroll when we reach the end line,
 * but stop drawing instead.
 */
# define TA_INHIBIT_VERT_SCROLL 16L

/*
 * Foreground and background colors. These only affect characters
 * drawn by subsequent calls; not what's already there (but it does
 * affect clears)
 * On b/w screens these do nothing.
 */
	TTY_ATTRIB_FOREGROUND ,
	TTY_ATTRIB_BACKGROUND ,
# define TA_RGB_TO_TTY(r) ((((long)((r).red>>8)&0xff)<<16)+\
	(((long)((r).green>>8)&0xff)<<8)+((long)((r).blue>>8)&0xff))

/*
 * Attributes relating to the cursor, and character set mappings
 */
	TTY_ATTRIB_CURSOR ,
/*
 * Blinking cursor is more noticeable when it's idle
 */
# define TA_BLINKING_CURSOR 1L
/*
 * When handling input, do we echo characters as they are typed?
 */
# define TA_ECHO_INPUT 2L
/*
 * Do we return each character code separately, or map delete etc? Note
 * that non-raw input means getchar won't return anything until the user
 * has typed a return.
 */
# define TA_RAW_INPUT 4L
/*
 * Do we print every character as it is (including BS, NL and CR!) or do
 * do we interpret characters such as NL, BS and CR?
 */
# define TA_RAW_OUTPUT 8L
/*
 * When getting a NL, do we also move to the left?
 */
# define TA_NL_ADD_CR 16L
/*
 * When getting a CR, do we also move down?
 */
# define TA_CR_ADD_NL 32L
/*
 * Wait for input or return what we've got?
 */
# define TA_NONBLOCKING_IO 64L

/*
 * Use this macro to cast a function pointer to a tty attribute; this will help
 * portability to systems where a function pointer doesn't fit in a long
 */
# define TA_ATTRIB_FUNC(x) ((long)(x))

/*
 * This symbolic constant is used to check the number of attributes
 */
	TTY_NUMBER_ATTRIBUTES

} tty_attrib ;

/*
 * Character returned by end-of-file condition
 */
# define TTY_EOF -1


/*
 * Create the window according to a resource WIND template.
 * The window pointer pointed to by window should be NULL to
 * allocate the window record dynamically, or point to a
 * WindowRecord structure already allocated.
 *
 * Passing in_color means you have to be sure there's color support;
 * on the Mac, this means 32bit QuickDraw present, else it will
 * crash. Not passing in_color means everything's rendered in
 * black & white.
 */
extern short create_tty ( WindowPtr * window , short resource_id ,
	Boolean in_color ) ;

/*
 * Use init_tty_name or init_tty_number to initialize a window
 * once allocated by create_tty. Size parameters are in characters.
 */

extern short init_tty_number ( WindowPtr window , short font_number ,
	short font_size , short x_size , short y_size ) ;

/*
 * Close and deallocate a window and its data
 */
extern short destroy_tty ( WindowPtr window ) ;

/*
 * Change the font and font size used in the window for drawing after
 * the calls are made. To change the coordinate system, be sure to call
 * force_tty_coordinate_system_recalc() - else it may look strange if
 * the new font doesn't match the old one.
 */
extern short set_tty_font_name (winid window_type , char * name ) ;
extern short force_tty_coordinate_system_recalc ( WindowPtr window ) ;

/*
 * Getting some metrics about the tty and its drawing.
 */
extern short get_tty_metrics ( WindowPtr window , short * x_size ,
	short * y_size , short * x_size_pixels , short * y_size_pixels ,
	short * font_number , short * font_size ,
	short * char_width , short * row_height ) ;

/*
 * The basic move cursor function. 0,0 is topleft.
 */
extern short move_tty_cursor ( WindowPtr window , short x_pos ,
	short y_pos ) ;

/*
 * Flush all changes done to a tty to the screen (see TA_ALWAYS_UPDATE above)
 */
extern short update_tty ( WindowPtr window ) ;

/*
 * Add a character to the tty and update the cursor position
 */
extern short add_tty_char ( WindowPtr window , short character ) ;

/*
 * Add a string of characters to the tty and update the cursor
 * position. The string is 0-terminated!
 */
extern short add_tty_string ( WindowPtr window , const char * string ) ;

/*
 * Change or read an attribute of the tty. Note that some attribute changes
 * may clear the screen. See the above enum and defines for values.
 * Attributes can be both function pointers and special flag values.
 */
extern short get_tty_attrib ( WindowPtr window , tty_attrib attrib ,
	long * value ) ;
extern short set_tty_attrib ( WindowPtr window , tty_attrib attrib ,
	long value ) ;

/*
 * Scroll the actual TTY image, in characters, positive means up/left
 * scroll_tty ( my_tty , 0 , 1 ) means a linefeed. Is always carried out
 * directly, regardless of the wait-update setting. Does updates before
 * scrolling.
 */
extern short scroll_tty ( WindowPtr window , short delta_x ,
	short delta_y ) ;

/*
 * Erase the offscreen bitmap and move the cursor to 0,0. Re-init some window
 * values (font etc) Is always carried out directly on-screen, regardless of
 * the wait-for-update setting. Clears update area.
 */
extern short clear_tty ( WindowPtr window ) ;

/*
 * Call this routine with a window (always _mt_window) and a time (usually
 * from most recent event) to determine if cursor in window should be blinked
 */
extern short blink_cursor ( WindowPtr window , long when ) ;

/*
 * For screen dumps, open the printer port and call this function. Can be used
 * for clipboard as well (only for a PICT, though; this library doesn't concern
 * itself with characters, just bitmaps)
 */
extern short image_tty ( EventRecord *theEvent, WindowPtr window ) ;

/*
 * For erasing just an area of characters
 */
extern short clear_tty_window ( WindowPtr window , short from_row ,
	short from_col , short to_row , short to_col ) ;

/*
 * get and set the invalid region of the main window
 */
 extern short get_invalid_region (WindowPtr window, Rect *inval_rect);
 extern short set_invalid_region (WindowPtr window, Rect *inval_rect);
 
/*
 * Now in macsnd.c, which seemed like a good place
 */
extern void tty_nhbell ();

#if EXTENDED_SUPPORT

/*
 * Various versions of delete character/s, insert line/s etc can be handled by
 * this general-purpose function. Negative num_ means delete, positive means
 * insert, and you can never be sure which of row and col operations come first
 * if you specify both...
 */
extern short mangle_tty_rows_columns ( WindowPtr window ,
	short from_row , short num_rows , short from_col , short num_cols ) ;

/*
 * For framing an area without using grahpics characters.
 * Note that the given limits are those used for framing, you should not
 * draw in them. frame_fatness should typically be 1-5, and may be clipped
 * if it is too large.
 */
extern short frame_tty_window ( WindowPtr window , short from_row ,
	short from_col , short to_row , short to_col , short frame_fatness ) ;

/*
 * For inverting specific characters after the fact. May look funny in color.
 */
extern short invert_tty_window ( WindowPtr window , short from_row ,
	short from_col , short to_row , short to_col ) ;

/*
 * For drawing lines on the tty - VERY DEVICE DEPENDENT. Use get_tty_metrics.
 */
extern short draw_tty_line ( WindowPtr window , short from_x ,
	short from_y , short to_x , short to_y ) ;

#endif /* EXTENDED_SUPPORT */

#endif /* _H_tty_public */