4 /* glk.h: Header file for Glk API, version 0.7.0.
5 Designed by Andrew Plotkin <erkyrath@eblong.com>
6 http://www.eblong.com/zarf/glk/index.html
8 This file is copyright 1998-2004 by Andrew Plotkin. You may copy,
9 distribute, and incorporate it into your own programs, by any means
10 and under any conditions, as long as you do not modify it. You may
11 also modify this file, incorporate it into your own programs,
12 and distribute the modified version, as long as you retain a notice
13 in your program or documentation which mentions my name and the URL
17 /* You may have to edit the definition of glui32 to make sure it's really a
18 32-bit unsigned integer type, and glsi32 to make sure it's really a
19 32-bit signed integer type. If they're not, horrible things will happen. */
21 typedef uint32_t glui32;
22 typedef int32_t glsi32;
24 /* These are the compile-time conditionals that reveal various Glk optional
26 #define GLK_MODULE_UNICODE
27 #define GLK_MODULE_IMAGE
28 #define GLK_MODULE_SOUND
29 #define GLK_MODULE_HYPERLINKS
31 /* These types are opaque object identifiers. They're pointers to opaque
32 C structures, which are defined differently by each library. */
33 typedef struct glk_window_struct *winid_t;
34 typedef struct glk_stream_struct *strid_t;
35 typedef struct glk_fileref_struct *frefid_t;
36 typedef struct glk_schannel_struct *schanid_t;
38 #define gestalt_Version (0)
39 #define gestalt_CharInput (1)
40 #define gestalt_LineInput (2)
41 #define gestalt_CharOutput (3)
42 #define gestalt_CharOutput_CannotPrint (0)
43 #define gestalt_CharOutput_ApproxPrint (1)
44 #define gestalt_CharOutput_ExactPrint (2)
45 #define gestalt_MouseInput (4)
46 #define gestalt_Timer (5)
47 #define gestalt_Graphics (6)
48 #define gestalt_DrawImage (7)
49 #define gestalt_Sound (8)
50 #define gestalt_SoundVolume (9)
51 #define gestalt_SoundNotify (10)
52 #define gestalt_Hyperlinks (11)
53 #define gestalt_HyperlinkInput (12)
54 #define gestalt_SoundMusic (13)
55 #define gestalt_GraphicsTransparency (14)
56 #define gestalt_Unicode (15)
58 #define evtype_None (0)
59 #define evtype_Timer (1)
60 #define evtype_CharInput (2)
61 #define evtype_LineInput (3)
62 #define evtype_MouseInput (4)
63 #define evtype_Arrange (5)
64 #define evtype_Redraw (6)
65 #define evtype_SoundNotify (7)
66 #define evtype_Hyperlink (8)
68 typedef struct event_struct {
74 #define keycode_Unknown (0xffffffff)
75 #define keycode_Left (0xfffffffe)
76 #define keycode_Right (0xfffffffd)
77 #define keycode_Up (0xfffffffc)
78 #define keycode_Down (0xfffffffb)
79 #define keycode_Return (0xfffffffa)
80 #define keycode_Delete (0xfffffff9)
81 #define keycode_Escape (0xfffffff8)
82 #define keycode_Tab (0xfffffff7)
83 #define keycode_PageUp (0xfffffff6)
84 #define keycode_PageDown (0xfffffff5)
85 #define keycode_Home (0xfffffff4)
86 #define keycode_End (0xfffffff3)
87 #define keycode_Func1 (0xffffffef)
88 #define keycode_Func2 (0xffffffee)
89 #define keycode_Func3 (0xffffffed)
90 #define keycode_Func4 (0xffffffec)
91 #define keycode_Func5 (0xffffffeb)
92 #define keycode_Func6 (0xffffffea)
93 #define keycode_Func7 (0xffffffe9)
94 #define keycode_Func8 (0xffffffe8)
95 #define keycode_Func9 (0xffffffe7)
96 #define keycode_Func10 (0xffffffe6)
97 #define keycode_Func11 (0xffffffe5)
98 #define keycode_Func12 (0xffffffe4)
99 /* The last keycode is always (0x100000000 - keycode_MAXVAL) */
100 #define keycode_MAXVAL (28)
102 #define style_Normal (0)
103 #define style_Emphasized (1)
104 #define style_Preformatted (2)
105 #define style_Header (3)
106 #define style_Subheader (4)
107 #define style_Alert (5)
108 #define style_Note (6)
109 #define style_BlockQuote (7)
110 #define style_Input (8)
111 #define style_User1 (9)
112 #define style_User2 (10)
113 #define style_NUMSTYLES (11)
115 typedef struct stream_result_struct {
120 #define wintype_AllTypes (0)
121 #define wintype_Pair (1)
122 #define wintype_Blank (2)
123 #define wintype_TextBuffer (3)
124 #define wintype_TextGrid (4)
125 #define wintype_Graphics (5)
127 #define winmethod_Left (0x00)
128 #define winmethod_Right (0x01)
129 #define winmethod_Above (0x02)
130 #define winmethod_Below (0x03)
131 #define winmethod_DirMask (0x0f)
133 #define winmethod_Fixed (0x10)
134 #define winmethod_Proportional (0x20)
135 #define winmethod_DivisionMask (0xf0)
137 #define fileusage_Data (0x00)
138 #define fileusage_SavedGame (0x01)
139 #define fileusage_Transcript (0x02)
140 #define fileusage_InputRecord (0x03)
141 #define fileusage_TypeMask (0x0f)
143 #define fileusage_TextMode (0x100)
144 #define fileusage_BinaryMode (0x000)
146 #define filemode_Write (0x01)
147 #define filemode_Read (0x02)
148 #define filemode_ReadWrite (0x03)
149 #define filemode_WriteAppend (0x05)
151 #define seekmode_Start (0)
152 #define seekmode_Current (1)
153 #define seekmode_End (2)
155 #define stylehint_Indentation (0)
156 #define stylehint_ParaIndentation (1)
157 #define stylehint_Justification (2)
158 #define stylehint_Size (3)
159 #define stylehint_Weight (4)
160 #define stylehint_Oblique (5)
161 #define stylehint_Proportional (6)
162 #define stylehint_TextColor (7)
163 #define stylehint_BackColor (8)
164 #define stylehint_ReverseColor (9)
165 #define stylehint_NUMHINTS (10)
167 #define stylehint_just_LeftFlush (0)
168 #define stylehint_just_LeftRight (1)
169 #define stylehint_just_Centered (2)
170 #define stylehint_just_RightFlush (3)
172 /* glk_main() is the top-level function which you define. The Glk library
174 extern void glk_main(void);
176 extern void glk_exit(void);
177 extern void glk_set_interrupt_handler(void (*func)(void));
178 extern void glk_tick(void);
180 extern glui32 glk_gestalt(glui32 sel, glui32 val);
181 extern glui32 glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr,
184 extern unsigned char glk_char_to_lower(unsigned char ch);
185 extern unsigned char glk_char_to_upper(unsigned char ch);
187 extern winid_t glk_window_get_root(void);
188 extern winid_t glk_window_open(winid_t split, glui32 method, glui32 size,
189 glui32 wintype, glui32 rock);
190 extern void glk_window_close(winid_t win, stream_result_t *result);
191 extern void glk_window_get_size(winid_t win, glui32 *widthptr,
193 extern void glk_window_set_arrangement(winid_t win, glui32 method,
194 glui32 size, winid_t keywin);
195 extern void glk_window_get_arrangement(winid_t win, glui32 *methodptr,
196 glui32 *sizeptr, winid_t *keywinptr);
197 extern winid_t glk_window_iterate(winid_t win, glui32 *rockptr);
198 extern glui32 glk_window_get_rock(winid_t win);
199 extern glui32 glk_window_get_type(winid_t win);
200 extern winid_t glk_window_get_parent(winid_t win);
201 extern winid_t glk_window_get_sibling(winid_t win);
202 extern void glk_window_clear(winid_t win);
203 extern void glk_window_move_cursor(winid_t win, glui32 xpos, glui32 ypos);
205 extern strid_t glk_window_get_stream(winid_t win);
206 extern void glk_window_set_echo_stream(winid_t win, strid_t str);
207 extern strid_t glk_window_get_echo_stream(winid_t win);
208 extern void glk_set_window(winid_t win);
210 extern strid_t glk_stream_open_file(frefid_t fileref, glui32 fmode,
212 extern strid_t glk_stream_open_memory(char *buf, glui32 buflen, glui32 fmode,
214 extern void glk_stream_close(strid_t str, stream_result_t *result);
215 extern strid_t glk_stream_iterate(strid_t str, glui32 *rockptr);
216 extern glui32 glk_stream_get_rock(strid_t str);
217 extern void glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekmode);
218 extern glui32 glk_stream_get_position(strid_t str);
219 extern void glk_stream_set_current(strid_t str);
220 extern strid_t glk_stream_get_current(void);
222 extern void glk_put_char(unsigned char ch);
223 extern void glk_put_char_stream(strid_t str, unsigned char ch);
224 extern void glk_put_string(char *s);
225 extern void glk_put_string_stream(strid_t str, char *s);
226 extern void glk_put_buffer(char *buf, glui32 len);
227 extern void glk_put_buffer_stream(strid_t str, char *buf, glui32 len);
228 extern void glk_set_style(glui32 styl);
229 extern void glk_set_style_stream(strid_t str, glui32 styl);
231 extern glsi32 glk_get_char_stream(strid_t str);
232 extern glui32 glk_get_line_stream(strid_t str, char *buf, glui32 len);
233 extern glui32 glk_get_buffer_stream(strid_t str, char *buf, glui32 len);
235 extern void glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint,
237 extern void glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint);
238 extern glui32 glk_style_distinguish(winid_t win, glui32 styl1, glui32 styl2);
239 extern glui32 glk_style_measure(winid_t win, glui32 styl, glui32 hint,
242 extern frefid_t glk_fileref_create_temp(glui32 usage, glui32 rock);
243 extern frefid_t glk_fileref_create_by_name(glui32 usage, char *name,
245 extern frefid_t glk_fileref_create_by_prompt(glui32 usage, glui32 fmode,
247 extern frefid_t glk_fileref_create_from_fileref(glui32 usage, frefid_t fref,
249 extern void glk_fileref_destroy(frefid_t fref);
250 extern frefid_t glk_fileref_iterate(frefid_t fref, glui32 *rockptr);
251 extern glui32 glk_fileref_get_rock(frefid_t fref);
252 extern void glk_fileref_delete_file(frefid_t fref);
253 extern glui32 glk_fileref_does_file_exist(frefid_t fref);
255 extern void glk_select(event_t *event);
256 extern void glk_select_poll(event_t *event);
258 extern void glk_request_timer_events(glui32 millisecs);
260 extern void glk_request_line_event(winid_t win, char *buf, glui32 maxlen,
262 extern void glk_request_char_event(winid_t win);
263 extern void glk_request_mouse_event(winid_t win);
265 extern void glk_cancel_line_event(winid_t win, event_t *event);
266 extern void glk_cancel_char_event(winid_t win);
267 extern void glk_cancel_mouse_event(winid_t win);
269 #ifdef GLK_MODULE_UNICODE
271 extern glui32 glk_buffer_to_lower_case_uni(glui32 *buf, glui32 len,
273 extern glui32 glk_buffer_to_upper_case_uni(glui32 *buf, glui32 len,
275 extern glui32 glk_buffer_to_title_case_uni(glui32 *buf, glui32 len,
276 glui32 numchars, glui32 lowerrest);
278 extern void glk_put_char_uni(glui32 ch);
279 extern void glk_put_string_uni(glui32 *s);
280 extern void glk_put_buffer_uni(glui32 *buf, glui32 len);
281 extern void glk_put_char_stream_uni(strid_t str, glui32 ch);
282 extern void glk_put_string_stream_uni(strid_t str, glui32 *s);
283 extern void glk_put_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len);
285 extern glsi32 glk_get_char_stream_uni(strid_t str);
286 extern glui32 glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len);
287 extern glui32 glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len);
289 extern strid_t glk_stream_open_file_uni(frefid_t fileref, glui32 fmode,
291 extern strid_t glk_stream_open_memory_uni(glui32 *buf, glui32 buflen,
292 glui32 fmode, glui32 rock);
294 extern void glk_request_char_event_uni(winid_t win);
295 extern void glk_request_line_event_uni(winid_t win, glui32 *buf,
296 glui32 maxlen, glui32 initlen);
298 #endif /* GLK_MODULE_UNICODE */
300 #ifdef GLK_MODULE_IMAGE
302 #define imagealign_InlineUp (0x01)
303 #define imagealign_InlineDown (0x02)
304 #define imagealign_InlineCenter (0x03)
305 #define imagealign_MarginLeft (0x04)
306 #define imagealign_MarginRight (0x05)
308 extern glui32 glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2);
309 extern glui32 glk_image_draw_scaled(winid_t win, glui32 image,
310 glsi32 val1, glsi32 val2, glui32 width, glui32 height);
311 extern glui32 glk_image_get_info(glui32 image, glui32 *width, glui32 *height);
313 extern void glk_window_flow_break(winid_t win);
315 extern void glk_window_erase_rect(winid_t win,
316 glsi32 left, glsi32 top, glui32 width, glui32 height);
317 extern void glk_window_fill_rect(winid_t win, glui32 color,
318 glsi32 left, glsi32 top, glui32 width, glui32 height);
319 extern void glk_window_set_background_color(winid_t win, glui32 color);
321 #endif /* GLK_MODULE_IMAGE */
323 #ifdef GLK_MODULE_SOUND
325 extern schanid_t glk_schannel_create(glui32 rock);
326 extern void glk_schannel_destroy(schanid_t chan);
327 extern schanid_t glk_schannel_iterate(schanid_t chan, glui32 *rockptr);
328 extern glui32 glk_schannel_get_rock(schanid_t chan);
330 extern glui32 glk_schannel_play(schanid_t chan, glui32 snd);
331 extern glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats,
333 extern void glk_schannel_stop(schanid_t chan);
334 extern void glk_schannel_set_volume(schanid_t chan, glui32 vol);
336 extern void glk_sound_load_hint(glui32 snd, glui32 flag);
338 #endif /* GLK_MODULE_SOUND */
340 #ifdef GLK_MODULE_HYPERLINKS
342 extern void glk_set_hyperlink(glui32 linkval);
343 extern void glk_set_hyperlink_stream(strid_t str, glui32 linkval);
344 extern void glk_request_hyperlink_event(winid_t win);
345 extern void glk_cancel_hyperlink_event(winid_t win);
347 #endif /* GLK_MODULE_HYPERLINKS */