1 | /* |
---|
2 | * libcaca Colour ASCII-Art library |
---|
3 | * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: caca.h 2043 2007-11-24 11:08:21Z sam $ |
---|
7 | * |
---|
8 | * This library is free software. It comes without any warranty, to |
---|
9 | * the extent permitted by applicable law. You can redistribute it |
---|
10 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
11 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
13 | */ |
---|
14 | |
---|
15 | /** \file caca.h |
---|
16 | * \version \$Id: caca.h 2043 2007-11-24 11:08:21Z sam $ |
---|
17 | * \author Sam Hocevar <sam@zoy.org> |
---|
18 | * \brief The \e libcaca public header. |
---|
19 | * |
---|
20 | * This header contains the public types and functions that applications |
---|
21 | * using \e libcaca may use. |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef __CACA_H__ |
---|
25 | #define __CACA_H__ |
---|
26 | |
---|
27 | #include <cucul.h> |
---|
28 | |
---|
29 | #if !defined(_DOXYGEN_SKIP_ME) |
---|
30 | # if defined(__WIN32__) && defined(__LIBCACA__) |
---|
31 | # define __extern extern __declspec(dllexport) |
---|
32 | # else |
---|
33 | # define __extern extern |
---|
34 | # endif |
---|
35 | #endif |
---|
36 | |
---|
37 | /** libcaca API version */ |
---|
38 | #define CACA_API_VERSION_1 |
---|
39 | |
---|
40 | #ifdef __cplusplus |
---|
41 | extern "C" |
---|
42 | { |
---|
43 | #endif |
---|
44 | |
---|
45 | /** \e libcaca display context */ |
---|
46 | typedef struct caca_display caca_display_t; |
---|
47 | /** \e libcaca event structure */ |
---|
48 | typedef struct caca_event caca_event_t; |
---|
49 | |
---|
50 | /** \brief Handling of user events. |
---|
51 | * |
---|
52 | * This structure is filled by caca_get_event() when an event is received. |
---|
53 | * The \e type field is always valid. */ |
---|
54 | struct caca_event |
---|
55 | { |
---|
56 | /** \brief User event type enumeration. |
---|
57 | * |
---|
58 | * This enum serves two purposes: |
---|
59 | * - Build listening masks for caca_get_event(). |
---|
60 | * - Define the type of a \e caca_event_t. |
---|
61 | */ |
---|
62 | enum caca_event_type |
---|
63 | { |
---|
64 | CACA_EVENT_NONE = 0x0000, /**< No event. */ |
---|
65 | |
---|
66 | CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */ |
---|
67 | CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */ |
---|
68 | CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */ |
---|
69 | CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */ |
---|
70 | CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */ |
---|
71 | CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */ |
---|
72 | CACA_EVENT_QUIT = 0x0040, /**< The user requested to quit. */ |
---|
73 | |
---|
74 | CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */ |
---|
75 | } |
---|
76 | /** \brief User event type member. |
---|
77 | * |
---|
78 | * This field is always valid when caca_get_event() returns. |
---|
79 | */ |
---|
80 | type; |
---|
81 | |
---|
82 | /** \brief User event data member. |
---|
83 | * |
---|
84 | * The validity of the \e data union depends on the value of the \e type |
---|
85 | * field: |
---|
86 | * - \c CACA_EVENT_NONE: no other field is valid. |
---|
87 | * - \c CACA_EVENT_KEY_PRESS, \c CACA_EVENT_KEY_RELEASE: the |
---|
88 | * \e data.key.ch field is valid and contains either the ASCII value for |
---|
89 | * the key, or an \e enum \e caca_key value. If the value is a printable |
---|
90 | * ASCII character, the \e data.key.utf32 and \e data.key.utf8 fields are |
---|
91 | * also filled and contain respectively the UTF-32/UCS-4 and the UTF-8 |
---|
92 | * representations of the character. Otherwise, their content is |
---|
93 | * undefined. |
---|
94 | * - \c CACA_EVENT_MOUSE_PRESS, \c CACA_EVENT_MOUSE_RELEASE: the |
---|
95 | * \e data.mouse.button field is valid and contains the index of the |
---|
96 | * mouse button that was pressed. |
---|
97 | * - \c CACA_EVENT_MOUSE_MOTION: the \e data.mouse.x and \e data.mouse.y |
---|
98 | * fields are valid and contain the mouse coordinates in character |
---|
99 | * cells. |
---|
100 | * - \c CACA_EVENT_RESIZE: the \e data.resize.w and \e data.resize.h |
---|
101 | * fields are valid and contain the new width and height values of |
---|
102 | * the \e libcucul canvas attached to \e libcaca. |
---|
103 | * - \c CACA_EVENT_QUIT: no other field is valid. |
---|
104 | * |
---|
105 | * The result of accessing data members outside the above conditions is |
---|
106 | * undefined. |
---|
107 | */ |
---|
108 | union |
---|
109 | { |
---|
110 | struct { unsigned int x, y, button; } mouse; |
---|
111 | struct { unsigned int w, h; } resize; |
---|
112 | struct { unsigned int ch; unsigned long int utf32; char utf8[8]; } key; |
---|
113 | } data; |
---|
114 | }; |
---|
115 | |
---|
116 | /** \brief Special key values. |
---|
117 | * |
---|
118 | * Special key values returned by caca_get_event() for which there is no |
---|
119 | * printable ASCII equivalent. |
---|
120 | */ |
---|
121 | enum caca_key |
---|
122 | { |
---|
123 | CACA_KEY_UNKNOWN = 0x00, /**< Unknown key. */ |
---|
124 | |
---|
125 | /* The following keys have ASCII equivalents */ |
---|
126 | CACA_KEY_CTRL_A = 0x01, /**< The Ctrl-A key. */ |
---|
127 | CACA_KEY_CTRL_B = 0x02, /**< The Ctrl-B key. */ |
---|
128 | CACA_KEY_CTRL_C = 0x03, /**< The Ctrl-C key. */ |
---|
129 | CACA_KEY_CTRL_D = 0x04, /**< The Ctrl-D key. */ |
---|
130 | CACA_KEY_CTRL_E = 0x05, /**< The Ctrl-E key. */ |
---|
131 | CACA_KEY_CTRL_F = 0x06, /**< The Ctrl-F key. */ |
---|
132 | CACA_KEY_CTRL_G = 0x07, /**< The Ctrl-G key. */ |
---|
133 | CACA_KEY_BACKSPACE = 0x08, /**< The backspace key. */ |
---|
134 | CACA_KEY_TAB = 0x09, /**< The tabulation key. */ |
---|
135 | CACA_KEY_CTRL_J = 0x0a, /**< The Ctrl-J key. */ |
---|
136 | CACA_KEY_CTRL_K = 0x0b, /**< The Ctrl-K key. */ |
---|
137 | CACA_KEY_CTRL_L = 0x0c, /**< The Ctrl-L key. */ |
---|
138 | CACA_KEY_RETURN = 0x0d, /**< The return key. */ |
---|
139 | CACA_KEY_CTRL_N = 0x0e, /**< The Ctrl-N key. */ |
---|
140 | CACA_KEY_CTRL_O = 0x0f, /**< The Ctrl-O key. */ |
---|
141 | CACA_KEY_CTRL_P = 0x10, /**< The Ctrl-P key. */ |
---|
142 | CACA_KEY_CTRL_Q = 0x11, /**< The Ctrl-Q key. */ |
---|
143 | CACA_KEY_CTRL_R = 0x12, /**< The Ctrl-R key. */ |
---|
144 | CACA_KEY_PAUSE = 0x13, /**< The pause key. */ |
---|
145 | CACA_KEY_CTRL_T = 0x14, /**< The Ctrl-T key. */ |
---|
146 | CACA_KEY_CTRL_U = 0x15, /**< The Ctrl-U key. */ |
---|
147 | CACA_KEY_CTRL_V = 0x16, /**< The Ctrl-V key. */ |
---|
148 | CACA_KEY_CTRL_W = 0x17, /**< The Ctrl-W key. */ |
---|
149 | CACA_KEY_CTRL_X = 0x18, /**< The Ctrl-X key. */ |
---|
150 | CACA_KEY_CTRL_Y = 0x19, /**< The Ctrl-Y key. */ |
---|
151 | CACA_KEY_CTRL_Z = 0x1a, /**< The Ctrl-Z key. */ |
---|
152 | CACA_KEY_ESCAPE = 0x1b, /**< The escape key. */ |
---|
153 | CACA_KEY_DELETE = 0x7f, /**< The delete key. */ |
---|
154 | |
---|
155 | /* The following keys do not have ASCII equivalents but have been |
---|
156 | * chosen to match the SDL equivalents */ |
---|
157 | CACA_KEY_UP = 0x111, /**< The up arrow key. */ |
---|
158 | CACA_KEY_DOWN = 0x112, /**< The down arrow key. */ |
---|
159 | CACA_KEY_LEFT = 0x113, /**< The left arrow key. */ |
---|
160 | CACA_KEY_RIGHT = 0x114, /**< The right arrow key. */ |
---|
161 | |
---|
162 | CACA_KEY_INSERT = 0x115, /**< The insert key. */ |
---|
163 | CACA_KEY_HOME = 0x116, /**< The home key. */ |
---|
164 | CACA_KEY_END = 0x117, /**< The end key. */ |
---|
165 | CACA_KEY_PAGEUP = 0x118, /**< The page up key. */ |
---|
166 | CACA_KEY_PAGEDOWN = 0x119, /**< The page down key. */ |
---|
167 | |
---|
168 | CACA_KEY_F1 = 0x11a, /**< The F1 key. */ |
---|
169 | CACA_KEY_F2 = 0x11b, /**< The F2 key. */ |
---|
170 | CACA_KEY_F3 = 0x11c, /**< The F3 key. */ |
---|
171 | CACA_KEY_F4 = 0x11d, /**< The F4 key. */ |
---|
172 | CACA_KEY_F5 = 0x11e, /**< The F5 key. */ |
---|
173 | CACA_KEY_F6 = 0x11f, /**< The F6 key. */ |
---|
174 | CACA_KEY_F7 = 0x120, /**< The F7 key. */ |
---|
175 | CACA_KEY_F8 = 0x121, /**< The F8 key. */ |
---|
176 | CACA_KEY_F9 = 0x122, /**< The F9 key. */ |
---|
177 | CACA_KEY_F10 = 0x123, /**< The F10 key. */ |
---|
178 | CACA_KEY_F11 = 0x124, /**< The F11 key. */ |
---|
179 | CACA_KEY_F12 = 0x125, /**< The F12 key. */ |
---|
180 | CACA_KEY_F13 = 0x126, /**< The F13 key. */ |
---|
181 | CACA_KEY_F14 = 0x127, /**< The F14 key. */ |
---|
182 | CACA_KEY_F15 = 0x128 /**< The F15 key. */ |
---|
183 | }; |
---|
184 | |
---|
185 | /** \defgroup libcaca libcaca basic functions |
---|
186 | * |
---|
187 | * These functions provide the basic \e libcaca routines for driver |
---|
188 | * initialisation, system information retrieval and configuration. |
---|
189 | * |
---|
190 | * @{ */ |
---|
191 | __extern caca_display_t * caca_create_display(cucul_canvas_t *); |
---|
192 | __extern int caca_free_display(caca_display_t *); |
---|
193 | __extern int caca_refresh_display(caca_display_t *); |
---|
194 | __extern int caca_set_display_time(caca_display_t *, unsigned int); |
---|
195 | __extern unsigned int caca_get_display_time(caca_display_t const *); |
---|
196 | __extern unsigned int caca_get_display_width(caca_display_t const *); |
---|
197 | __extern unsigned int caca_get_display_height(caca_display_t const *); |
---|
198 | __extern int caca_set_display_title(caca_display_t *, char const *); |
---|
199 | /* @} */ |
---|
200 | |
---|
201 | /** \defgroup caca_event libcaca event handling |
---|
202 | * |
---|
203 | * These functions handle user events such as keyboard input and mouse |
---|
204 | * clicks. |
---|
205 | * |
---|
206 | * @{ */ |
---|
207 | __extern int caca_get_event(caca_display_t *, unsigned int, |
---|
208 | caca_event_t *, int); |
---|
209 | __extern unsigned int caca_get_mouse_x(caca_display_t const *); |
---|
210 | __extern unsigned int caca_get_mouse_y(caca_display_t const *); |
---|
211 | __extern int caca_set_mouse(caca_display_t *, int); |
---|
212 | __extern int caca_set_cursor(caca_display_t *, int); |
---|
213 | /* @} */ |
---|
214 | |
---|
215 | #ifdef __cplusplus |
---|
216 | } |
---|
217 | #endif |
---|
218 | |
---|
219 | #if !defined(_DOXYGEN_SKIP_ME) |
---|
220 | # undef __extern |
---|
221 | #endif |
---|
222 | |
---|
223 | #endif /* __CACA_H__ */ |
---|