Changeset 2049 for libcaca/trunk/caca
- Timestamp:
- Nov 25, 2007, 12:11:54 PM (13 years ago)
- Location:
- libcaca/trunk/caca
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/caca.h
r2043 r2049 54 54 struct caca_event 55 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. */ 56 unsigned char opaque_structure[32]; 57 }; 65 58 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. */ 59 /** \brief User event type enumeration. 60 * 61 * This enum serves two purposes: 62 * - Build listening masks for caca_get_event(). 63 * - Define the type of a \e caca_event_t. 64 */ 65 enum caca_event_type 66 { 67 CACA_EVENT_NONE = 0x0000, /**< No event. */ 73 68 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;69 CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */ 70 CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */ 71 CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */ 72 CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */ 73 CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */ 74 CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */ 75 CACA_EVENT_QUIT = 0x0040, /**< The user requested to quit. */ 81 76 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; 77 CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */ 114 78 }; 115 79 … … 197 161 __extern unsigned int caca_get_display_height(caca_display_t const *); 198 162 __extern int caca_set_display_title(caca_display_t *, char const *); 163 __extern int caca_set_mouse(caca_display_t *, int); 164 __extern int caca_set_cursor(caca_display_t *, int); 199 165 /* @} */ 200 166 … … 209 175 __extern unsigned int caca_get_mouse_x(caca_display_t const *); 210 176 __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); 177 __extern enum caca_event_type caca_get_event_type(caca_event_t const *); 178 __extern unsigned int caca_get_event_key_ch(caca_event_t const *); 179 __extern unsigned long int caca_get_event_key_utf32(caca_event_t const *); 180 __extern int caca_get_event_key_utf8(caca_event_t const *, char *); 181 __extern unsigned int caca_get_event_mouse_button(caca_event_t const *); 182 __extern unsigned int caca_get_event_mouse_x(caca_event_t const *); 183 __extern unsigned int caca_get_event_mouse_y(caca_event_t const *); 184 __extern unsigned int caca_get_event_resize_width(caca_event_t const *); 185 __extern unsigned int caca_get_event_resize_height(caca_event_t const *); 213 186 /* @} */ 214 187 -
libcaca/trunk/caca/caca0.c
r1882 r2049 85 85 return 0x00000000; 86 86 87 switch( ev.type)87 switch(caca_get_event_type(&ev)) 88 88 { 89 89 case CACA_EVENT_KEY_PRESS: 90 return 0x01000000 | ev.data.key.ch;90 return 0x01000000 | caca_get_event_key_ch(&ev); 91 91 case CACA_EVENT_KEY_RELEASE: 92 return 0x02000000 | ev.data.key.ch;92 return 0x02000000 | caca_get_event_key_ch(&ev); 93 93 case CACA_EVENT_MOUSE_PRESS: 94 return 0x04000000 | ev.data.mouse.button;94 return 0x04000000 | caca_get_event_mouse_button(&ev); 95 95 case CACA_EVENT_MOUSE_RELEASE: 96 return 0x08000000 | ev.data.mouse.button;96 return 0x08000000 | caca_get_event_mouse_button(&ev); 97 97 case CACA_EVENT_MOUSE_MOTION: 98 return 0x10000000 | (( ev.data.mouse.x& 0xfff) << 12)99 | ( ev.data.mouse.y& 0xfff);98 return 0x10000000 | ((caca_get_event_mouse_x(&ev) & 0xfff) << 12) 99 | (caca_get_event_mouse_y(&ev) & 0xfff); 100 100 case CACA_EVENT_RESIZE: 101 101 return 0x20000000; -
libcaca/trunk/caca/caca_internals.h
r2043 r2049 21 21 22 22 typedef struct caca_timer caca_timer_t; 23 typedef struct caca_privevent caca_privevent_t; 23 24 24 25 #if !defined(_DOXYGEN_SKIP_ME) … … 90 91 }; 91 92 93 /* Private event structure */ 94 struct caca_privevent 95 { 96 enum caca_event_type type; 97 98 union 99 { 100 struct { unsigned int x, y, button; } mouse; 101 struct { unsigned int w, h; } resize; 102 struct { unsigned int ch; unsigned long int utf32; char utf8[8]; } key; 103 } data; 104 }; 105 92 106 /* Internal caca display context */ 93 107 struct caca_display … … 113 127 void (* display) (caca_display_t *); 114 128 void (* handle_resize) (caca_display_t *); 115 int (* get_event) (caca_display_t *, caca_ event_t *);129 int (* get_event) (caca_display_t *, caca_privevent_t *); 116 130 void (* set_mouse) (caca_display_t *, int); 117 131 void (* set_cursor) (caca_display_t *, int); … … 139 153 { 140 154 #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) 141 caca_ event_t buf[EVENTBUF_LEN];155 caca_privevent_t buf[EVENTBUF_LEN]; 142 156 int queue; 143 157 #endif … … 146 160 unsigned int last_key_ticks; 147 161 unsigned int autorepeat_ticks; 148 caca_ event_t last_key_event;162 caca_privevent_t last_key_event; 149 163 #endif 150 164 #if defined(USE_WIN32) … … 161 175 extern void _caca_handle_resize(caca_display_t *); 162 176 #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) 163 extern void _push_event(caca_display_t *, caca_ event_t *);164 extern int _pop_event(caca_display_t *, caca_ event_t *);177 extern void _push_event(caca_display_t *, caca_privevent_t *); 178 extern int _pop_event(caca_display_t *, caca_privevent_t *); 165 179 #endif 166 180 -
libcaca/trunk/caca/driver_conio.c
r2043 r2049 131 131 } 132 132 133 static int conio_get_event(caca_display_t *dp, caca_ event_t *ev)133 static int conio_get_event(caca_display_t *dp, caca_privevent_t *ev) 134 134 { 135 135 unsigned char ch; 136 caca_ event_t release;136 caca_privevent_t release; 137 137 138 138 if(!_conio_kbhit()) -
libcaca/trunk/caca/driver_gl.c
r2043 r2049 323 323 } 324 324 325 static int gl_get_event(caca_display_t *dp, caca_ event_t *ev)325 static int gl_get_event(caca_display_t *dp, caca_privevent_t *ev) 326 326 { 327 327 #ifdef HAVE_GLUTCHECKLOOP -
libcaca/trunk/caca/driver_ncurses.c
r2043 r2049 385 385 } 386 386 387 static int ncurses_get_event(caca_display_t *dp, caca_ event_t *ev)387 static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev) 388 388 { 389 389 int intkey; -
libcaca/trunk/caca/driver_raw.c
r2043 r2049 84 84 } 85 85 86 static int raw_get_event(caca_display_t *dp, caca_ event_t *ev)86 static int raw_get_event(caca_display_t *dp, caca_privevent_t *ev) 87 87 { 88 88 ev->type = CACA_EVENT_NONE; -
libcaca/trunk/caca/driver_slang.c
r2043 r2049 273 273 } 274 274 275 static int slang_get_event(caca_display_t *dp, caca_ event_t *ev)275 static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev) 276 276 { 277 277 int intkey; -
libcaca/trunk/caca/driver_vga.c
r2043 r2049 144 144 } 145 145 146 static int vga_get_event(caca_display_t *dp, caca_ event_t *ev)146 static int vga_get_event(caca_display_t *dp, caca_privevent_t *ev) 147 147 { 148 148 /* FIXME */ -
libcaca/trunk/caca/driver_win32.c
r2043 r2049 245 245 } 246 246 247 static int win32_get_event(caca_display_t *dp, caca_ event_t *ev)247 static int win32_get_event(caca_display_t *dp, caca_privevent_t *ev) 248 248 { 249 249 INPUT_RECORD rec; -
libcaca/trunk/caca/driver_x11.c
r2043 r2049 370 370 } 371 371 372 static int x11_get_event(caca_display_t *dp, caca_ event_t *ev)372 static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) 373 373 { 374 374 XEvent xevent; -
libcaca/trunk/caca/event.c
r2043 r2049 22 22 #if !defined(__KERNEL__) 23 23 # include <stdio.h> 24 # include <string.h> 24 25 #endif 25 26 … … 29 30 #include "caca_internals.h" 30 31 31 static int _get_next_event(caca_display_t *, caca_ event_t *);32 static int _lowlevel_event(caca_display_t *, caca_ event_t *);32 static int _get_next_event(caca_display_t *, caca_privevent_t *); 33 static int _lowlevel_event(caca_display_t *, caca_privevent_t *); 33 34 34 35 #if !defined(_DOXYGEN_SKIP_ME) … … 68 69 caca_event_t *ev, int timeout) 69 70 { 70 caca_ event_t dummy_event;71 caca_privevent_t privevent; 71 72 caca_timer_t timer; 72 73 int usec = 0; … … 78 79 _caca_getticks(&timer); 79 80 80 if(ev == NULL)81 ev = &dummy_event;82 83 81 for( ; ; ) 84 82 { 85 int ret = _get_next_event(dp, ev);83 int ret = _get_next_event(dp, &privevent); 86 84 87 85 /* If we got the event we wanted, return */ 88 if(ev->type & event_mask) 86 if(privevent.type & event_mask) 87 { 88 if(ev) 89 memcpy(ev, &privevent, sizeof(privevent)); 89 90 return ret; 91 } 90 92 91 93 /* If there is no timeout, sleep and try again. */ … … 99 101 if(usec >= timeout) 100 102 { 101 ev->type = CACA_EVENT_NONE; 103 privevent.type = CACA_EVENT_NONE; 104 if(ev) 105 memcpy(ev, &privevent, sizeof(privevent)); 102 106 return 0; 103 107 } … … 154 158 } 155 159 160 /** \brief Return an event's type. 161 * 162 * Return the type of an event. This function may always be called on an 163 * event after caca_get_event() was called, and its return value indicates 164 * which other functions may be called: 165 * - \c CACA_EVENT_NONE: no other function may be called. 166 * - \c CACA_EVENT_KEY_PRESS, \c CACA_EVENT_KEY_RELEASE: 167 * caca_get_event_key_ch(), caca_get_event_key_utf32() and 168 * caca_get_event_key_utf8() may be called. 169 * - \c CACA_EVENT_MOUSE_PRESS, \c CACA_EVENT_MOUSE_RELEASE: 170 * caca_get_event_mouse_button() may be called. 171 * - \c CACA_EVENT_MOUSE_MOTION: caca_get_event_mouse_x() and 172 * caca_get_event_mouse_y() may be called. 173 * - \c CACA_EVENT_RESIZE: caca_get_event_resize_width() and 174 * caca_get_event_resize_height() may be called. 175 * - \c CACA_EVENT_QUIT: no other function may be called. 176 * 177 * This function never fails. 178 * 179 * \param ev The libcaca event. 180 * \return The event's type. 181 */ 182 enum caca_event_type caca_get_event_type(caca_event_t const *ev) 183 { 184 return ((caca_privevent_t const *)ev)->type; 185 } 186 187 /** \brief Return a key press or key release event's value 188 * 189 * Return either the ASCII value for an event's key, or if the key is not 190 * an ASCII character, an appropriate \e enum \e caca_key value. 191 * 192 * This function never fails, but must only be called with a valid event of 193 * type \c CACA_EVENT_KEY_PRESS or \c CACA_EVENT_KEY_RELEASE, or the results 194 * will be undefined. See caca_get_event_type() for more information. 195 * 196 * \param ev The libcaca event. 197 * \return The key value. 198 */ 199 unsigned int caca_get_event_key_ch(caca_event_t const *ev) 200 { 201 return ((caca_privevent_t const *)ev)->data.key.ch; 202 } 203 204 /** \brief Return a key press or key release event's Unicode value 205 * 206 * Return the UTF-32/UCS-4 value for an event's key if it resolves to a 207 * printable character. 208 * 209 * This function never fails, but must only be called with a valid event of 210 * type \c CACA_EVENT_KEY_PRESS or \c CACA_EVENT_KEY_RELEASE, or the results 211 * will be undefined. See caca_get_event_type() for more information. 212 * 213 * \param ev The libcaca event. 214 * \return The key's Unicode value. 215 */ 216 unsigned long int caca_get_event_key_utf32(caca_event_t const *ev) 217 { 218 return ((caca_privevent_t const *)ev)->data.key.utf32; 219 } 220 221 /** \brief Return a key press or key release event's UTF-8 value 222 * 223 * Write the UTF-8 value for an event's key if it resolves to a printable 224 * character. Up to 6 UTF-8 bytes and a null termination are written. 225 * 226 * This function never fails, but must only be called with a valid event of 227 * type \c CACA_EVENT_KEY_PRESS or \c CACA_EVENT_KEY_RELEASE, or the results 228 * will be undefined. See caca_get_event_type() for more information. 229 * 230 * \param ev The libcaca event. 231 * \return This function always returns 0. 232 */ 233 int caca_get_event_key_utf8(caca_event_t const *ev, char *utf8) 234 { 235 memcpy(utf8, ((caca_privevent_t const *)ev)->data.key.utf8, 8); 236 return 0; 237 } 238 239 /** \brief Return a mouse press or mouse release event's button 240 * 241 * Return the mouse button index for an event. 242 * 243 * This function never fails, but must only be called with a valid event of 244 * type \c CACA_EVENT_MOUSE_PRESS or \c CACA_EVENT_MOUSE_RELEASE, or the 245 * results will be undefined. See caca_get_event_type() for more information. 246 * 247 * \param ev The libcaca event. 248 * \return The event's mouse button. 249 */ 250 unsigned int caca_get_event_mouse_button(caca_event_t const *ev) 251 { 252 return ((caca_privevent_t const *)ev)->data.mouse.button; 253 } 254 255 /** \brief Return a mouse motion event's X coordinate. 256 * 257 * Return the X coordinate for a mouse motion event. 258 * 259 * This function never fails, but must only be called with a valid event of 260 * type \c CACA_EVENT_MOUSE_MOTION, or the results will be undefined. See 261 * caca_get_event_type() for more information. 262 * 263 * \param ev The libcaca event. 264 * \return The event's X mouse coordinate. 265 */ 266 unsigned int caca_get_event_mouse_x(caca_event_t const *ev) 267 { 268 return ((caca_privevent_t const *)ev)->data.mouse.x; 269 } 270 271 /** \brief Return a mouse motion event's Y coordinate. 272 * 273 * Return the Y coordinate for a mouse motion event. 274 * 275 * This function never fails, but must only be called with a valid event of 276 * type \c CACA_EVENT_MOUSE_MOTION, or the results will be undefined. See 277 * caca_get_event_type() for more information. 278 * 279 * \param ev The libcaca event. 280 * \return The event's Y mouse coordinate. 281 */ 282 unsigned int caca_get_event_mouse_y(caca_event_t const *ev) 283 { 284 return ((caca_privevent_t const *)ev)->data.mouse.y; 285 } 286 287 /** \brief Return a resize event's display width value. 288 * 289 * Return the width value for a display resize event. 290 * 291 * This function never fails, but must only be called with a valid event of 292 * type \c CACA_EVENT_RESIZE, or the results will be undefined. See 293 * caca_get_event_type() for more information. 294 * 295 * \param ev The libcaca event. 296 * \return The event's new display width value. 297 */ 298 unsigned int caca_get_event_resize_width(caca_event_t const *ev) 299 { 300 return ((caca_privevent_t const *)ev)->data.resize.w; 301 } 302 303 /** \brief Return a resize event's display height value. 304 * 305 * Return the height value for a display resize event. 306 * 307 * This function never fails, but must only be called with a valid event of 308 * type \c CACA_EVENT_RESIZE, or the results will be undefined. See 309 * caca_get_event_type() for more information. 310 * 311 * \param ev The libcaca event. 312 * \return The event's new display height value. 313 */ 314 unsigned int caca_get_event_resize_height(caca_event_t const *ev) 315 { 316 return ((caca_privevent_t const *)ev)->data.resize.h; 317 } 318 156 319 /* 157 320 * XXX: The following functions are local. 158 321 */ 159 322 160 static int _get_next_event(caca_display_t *dp, caca_ event_t *ev)323 static int _get_next_event(caca_display_t *dp, caca_privevent_t *ev) 161 324 { 162 325 #if defined(USE_SLANG) || defined(USE_NCURSES) … … 240 403 } 241 404 242 static int _lowlevel_event(caca_display_t *dp, caca_ event_t *ev)405 static int _lowlevel_event(caca_display_t *dp, caca_privevent_t *ev) 243 406 { 244 407 #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) … … 253 416 254 417 #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) 255 void _push_event(caca_display_t *dp, caca_ event_t *ev)418 void _push_event(caca_display_t *dp, caca_privevent_t *ev) 256 419 { 257 420 if(!ev->type || dp->events.queue == EVENTBUF_LEN) … … 261 424 } 262 425 263 int _pop_event(caca_display_t *dp, caca_ event_t *ev)426 int _pop_event(caca_display_t *dp, caca_privevent_t *ev) 264 427 { 265 428 int i;
Note: See TracChangeset
for help on using the changeset viewer.