functions to access its real data. This is a big API change that will
break your software, sorry :(
tags/v0.99.beta14
| @@ -53,64 +53,28 @@ typedef struct caca_event caca_event_t; | |||
| * The \e type field is always valid. */ | |||
| struct caca_event | |||
| { | |||
| /** \brief User event type enumeration. | |||
| * | |||
| * This enum serves two purposes: | |||
| * - Build listening masks for caca_get_event(). | |||
| * - Define the type of a \e caca_event_t. | |||
| */ | |||
| enum caca_event_type | |||
| { | |||
| CACA_EVENT_NONE = 0x0000, /**< No event. */ | |||
| CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */ | |||
| CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */ | |||
| CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */ | |||
| CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */ | |||
| CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */ | |||
| CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */ | |||
| CACA_EVENT_QUIT = 0x0040, /**< The user requested to quit. */ | |||
| CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */ | |||
| } | |||
| /** \brief User event type member. | |||
| * | |||
| * This field is always valid when caca_get_event() returns. | |||
| */ | |||
| type; | |||
| /** \brief User event data member. | |||
| * | |||
| * The validity of the \e data union depends on the value of the \e type | |||
| * field: | |||
| * - \c CACA_EVENT_NONE: no other field is valid. | |||
| * - \c CACA_EVENT_KEY_PRESS, \c CACA_EVENT_KEY_RELEASE: the | |||
| * \e data.key.ch field is valid and contains either the ASCII value for | |||
| * the key, or an \e enum \e caca_key value. If the value is a printable | |||
| * ASCII character, the \e data.key.utf32 and \e data.key.utf8 fields are | |||
| * also filled and contain respectively the UTF-32/UCS-4 and the UTF-8 | |||
| * representations of the character. Otherwise, their content is | |||
| * undefined. | |||
| * - \c CACA_EVENT_MOUSE_PRESS, \c CACA_EVENT_MOUSE_RELEASE: the | |||
| * \e data.mouse.button field is valid and contains the index of the | |||
| * mouse button that was pressed. | |||
| * - \c CACA_EVENT_MOUSE_MOTION: the \e data.mouse.x and \e data.mouse.y | |||
| * fields are valid and contain the mouse coordinates in character | |||
| * cells. | |||
| * - \c CACA_EVENT_RESIZE: the \e data.resize.w and \e data.resize.h | |||
| * fields are valid and contain the new width and height values of | |||
| * the \e libcucul canvas attached to \e libcaca. | |||
| * - \c CACA_EVENT_QUIT: no other field is valid. | |||
| * | |||
| * The result of accessing data members outside the above conditions is | |||
| * undefined. | |||
| */ | |||
| union | |||
| { | |||
| struct { unsigned int x, y, button; } mouse; | |||
| struct { unsigned int w, h; } resize; | |||
| struct { unsigned int ch; unsigned long int utf32; char utf8[8]; } key; | |||
| } data; | |||
| unsigned char opaque_structure[32]; | |||
| }; | |||
| /** \brief User event type enumeration. | |||
| * | |||
| * This enum serves two purposes: | |||
| * - Build listening masks for caca_get_event(). | |||
| * - Define the type of a \e caca_event_t. | |||
| */ | |||
| enum caca_event_type | |||
| { | |||
| CACA_EVENT_NONE = 0x0000, /**< No event. */ | |||
| CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */ | |||
| CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */ | |||
| CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */ | |||
| CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */ | |||
| CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */ | |||
| CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */ | |||
| CACA_EVENT_QUIT = 0x0040, /**< The user requested to quit. */ | |||
| CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */ | |||
| }; | |||
| /** \brief Special key values. | |||
| @@ -196,6 +160,8 @@ __extern unsigned int caca_get_display_time(caca_display_t const *); | |||
| __extern unsigned int caca_get_display_width(caca_display_t const *); | |||
| __extern unsigned int caca_get_display_height(caca_display_t const *); | |||
| __extern int caca_set_display_title(caca_display_t *, char const *); | |||
| __extern int caca_set_mouse(caca_display_t *, int); | |||
| __extern int caca_set_cursor(caca_display_t *, int); | |||
| /* @} */ | |||
| /** \defgroup caca_event libcaca event handling | |||
| @@ -208,8 +174,15 @@ __extern int caca_get_event(caca_display_t *, unsigned int, | |||
| caca_event_t *, int); | |||
| __extern unsigned int caca_get_mouse_x(caca_display_t const *); | |||
| __extern unsigned int caca_get_mouse_y(caca_display_t const *); | |||
| __extern int caca_set_mouse(caca_display_t *, int); | |||
| __extern int caca_set_cursor(caca_display_t *, int); | |||
| __extern enum caca_event_type caca_get_event_type(caca_event_t const *); | |||
| __extern unsigned int caca_get_event_key_ch(caca_event_t const *); | |||
| __extern unsigned long int caca_get_event_key_utf32(caca_event_t const *); | |||
| __extern int caca_get_event_key_utf8(caca_event_t const *, char *); | |||
| __extern unsigned int caca_get_event_mouse_button(caca_event_t const *); | |||
| __extern unsigned int caca_get_event_mouse_x(caca_event_t const *); | |||
| __extern unsigned int caca_get_event_mouse_y(caca_event_t const *); | |||
| __extern unsigned int caca_get_event_resize_width(caca_event_t const *); | |||
| __extern unsigned int caca_get_event_resize_height(caca_event_t const *); | |||
| /* @} */ | |||
| #ifdef __cplusplus | |||
| @@ -84,19 +84,19 @@ unsigned int __caca0_get_event(unsigned int m, int t) | |||
| if(!ret) | |||
| return 0x00000000; | |||
| switch(ev.type) | |||
| switch(caca_get_event_type(&ev)) | |||
| { | |||
| case CACA_EVENT_KEY_PRESS: | |||
| return 0x01000000 | ev.data.key.ch; | |||
| return 0x01000000 | caca_get_event_key_ch(&ev); | |||
| case CACA_EVENT_KEY_RELEASE: | |||
| return 0x02000000 | ev.data.key.ch; | |||
| return 0x02000000 | caca_get_event_key_ch(&ev); | |||
| case CACA_EVENT_MOUSE_PRESS: | |||
| return 0x04000000 | ev.data.mouse.button; | |||
| return 0x04000000 | caca_get_event_mouse_button(&ev); | |||
| case CACA_EVENT_MOUSE_RELEASE: | |||
| return 0x08000000 | ev.data.mouse.button; | |||
| return 0x08000000 | caca_get_event_mouse_button(&ev); | |||
| case CACA_EVENT_MOUSE_MOTION: | |||
| return 0x10000000 | ((ev.data.mouse.x & 0xfff) << 12) | |||
| | (ev.data.mouse.y & 0xfff); | |||
| return 0x10000000 | ((caca_get_event_mouse_x(&ev) & 0xfff) << 12) | |||
| | (caca_get_event_mouse_y(&ev) & 0xfff); | |||
| case CACA_EVENT_RESIZE: | |||
| return 0x20000000; | |||
| default: | |||
| @@ -20,6 +20,7 @@ | |||
| #endif | |||
| typedef struct caca_timer caca_timer_t; | |||
| typedef struct caca_privevent caca_privevent_t; | |||
| #if !defined(_DOXYGEN_SKIP_ME) | |||
| # define EVENTBUF_LEN 10 | |||
| @@ -89,6 +90,19 @@ struct caca_timer | |||
| int last_sec, last_usec; | |||
| }; | |||
| /* Private event structure */ | |||
| struct caca_privevent | |||
| { | |||
| enum caca_event_type type; | |||
| union | |||
| { | |||
| struct { unsigned int x, y, button; } mouse; | |||
| struct { unsigned int w, h; } resize; | |||
| struct { unsigned int ch; unsigned long int utf32; char utf8[8]; } key; | |||
| } data; | |||
| }; | |||
| /* Internal caca display context */ | |||
| struct caca_display | |||
| { | |||
| @@ -112,7 +126,7 @@ struct caca_display | |||
| unsigned int (* get_display_height) (caca_display_t const *); | |||
| void (* display) (caca_display_t *); | |||
| void (* handle_resize) (caca_display_t *); | |||
| int (* get_event) (caca_display_t *, caca_event_t *); | |||
| int (* get_event) (caca_display_t *, caca_privevent_t *); | |||
| void (* set_mouse) (caca_display_t *, int); | |||
| void (* set_cursor) (caca_display_t *, int); | |||
| } drv; | |||
| @@ -138,14 +152,14 @@ struct caca_display | |||
| struct events | |||
| { | |||
| #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | |||
| caca_event_t buf[EVENTBUF_LEN]; | |||
| caca_privevent_t buf[EVENTBUF_LEN]; | |||
| int queue; | |||
| #endif | |||
| #if defined(USE_SLANG) || defined(USE_NCURSES) | |||
| caca_timer_t key_timer; | |||
| unsigned int last_key_ticks; | |||
| unsigned int autorepeat_ticks; | |||
| caca_event_t last_key_event; | |||
| caca_privevent_t last_key_event; | |||
| #endif | |||
| #if defined(USE_WIN32) | |||
| unsigned char not_empty_struct; | |||
| @@ -160,8 +174,8 @@ extern unsigned int _caca_getticks(caca_timer_t *); | |||
| /* Internal event functions */ | |||
| extern void _caca_handle_resize(caca_display_t *); | |||
| #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | |||
| extern void _push_event(caca_display_t *, caca_event_t *); | |||
| extern int _pop_event(caca_display_t *, caca_event_t *); | |||
| extern void _push_event(caca_display_t *, caca_privevent_t *); | |||
| extern int _pop_event(caca_display_t *, caca_privevent_t *); | |||
| #endif | |||
| /* Internal window functions */ | |||
| @@ -130,10 +130,10 @@ static void conio_handle_resize(caca_display_t *dp) | |||
| dp->resize.h = dp->cv->height; | |||
| } | |||
| static int conio_get_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int conio_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| unsigned char ch; | |||
| caca_event_t release; | |||
| caca_privevent_t release; | |||
| if(!_conio_kbhit()) | |||
| { | |||
| @@ -322,7 +322,7 @@ static void gl_handle_resize(caca_display_t *dp) | |||
| glMatrixMode(GL_MODELVIEW); | |||
| } | |||
| static int gl_get_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int gl_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| #ifdef HAVE_GLUTCHECKLOOP | |||
| glutCheckLoop(); | |||
| @@ -384,7 +384,7 @@ static void ncurses_handle_resize(caca_display_t *dp) | |||
| dp->resize.h = dp->cv->height; | |||
| } | |||
| static int ncurses_get_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| int intkey; | |||
| @@ -83,7 +83,7 @@ static void raw_handle_resize(caca_display_t *dp) | |||
| ; | |||
| } | |||
| static int raw_get_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int raw_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| ev->type = CACA_EVENT_NONE; | |||
| return 0; | |||
| @@ -272,7 +272,7 @@ static void slang_handle_resize(caca_display_t *dp) | |||
| SLsmg_reinit_smg(); | |||
| } | |||
| static int slang_get_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| int intkey; | |||
| @@ -143,7 +143,7 @@ static void vga_handle_resize(caca_display_t *dp) | |||
| dp->resize.h = dp->cv->height; | |||
| } | |||
| static int vga_get_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int vga_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| /* FIXME */ | |||
| ev->type = CACA_EVENT_NONE; | |||
| @@ -244,7 +244,7 @@ static void win32_handle_resize(caca_display_t *dp) | |||
| dp->resize.h = dp->cv->height; | |||
| } | |||
| static int win32_get_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int win32_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| INPUT_RECORD rec; | |||
| DWORD num; | |||
| @@ -369,7 +369,7 @@ static void x11_handle_resize(caca_display_t *dp) | |||
| dp->drv.p->pixmap = new_pixmap; | |||
| } | |||
| static int x11_get_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int x11_get_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| XEvent xevent; | |||
| char key; | |||
| @@ -21,6 +21,7 @@ | |||
| #if !defined(__KERNEL__) | |||
| # include <stdio.h> | |||
| # include <string.h> | |||
| #endif | |||
| #include "cucul.h" | |||
| @@ -28,8 +29,8 @@ | |||
| #include "caca.h" | |||
| #include "caca_internals.h" | |||
| static int _get_next_event(caca_display_t *, caca_event_t *); | |||
| static int _lowlevel_event(caca_display_t *, caca_event_t *); | |||
| static int _get_next_event(caca_display_t *, caca_privevent_t *); | |||
| static int _lowlevel_event(caca_display_t *, caca_privevent_t *); | |||
| #if !defined(_DOXYGEN_SKIP_ME) | |||
| /* If no new key was pressed after AUTOREPEAT_THRESHOLD usec, assume the | |||
| @@ -67,7 +68,7 @@ static int _lowlevel_event(caca_display_t *, caca_event_t *); | |||
| int caca_get_event(caca_display_t *dp, unsigned int event_mask, | |||
| caca_event_t *ev, int timeout) | |||
| { | |||
| caca_event_t dummy_event; | |||
| caca_privevent_t privevent; | |||
| caca_timer_t timer; | |||
| int usec = 0; | |||
| @@ -77,16 +78,17 @@ int caca_get_event(caca_display_t *dp, unsigned int event_mask, | |||
| if(timeout > 0) | |||
| _caca_getticks(&timer); | |||
| if(ev == NULL) | |||
| ev = &dummy_event; | |||
| for( ; ; ) | |||
| { | |||
| int ret = _get_next_event(dp, ev); | |||
| int ret = _get_next_event(dp, &privevent); | |||
| /* If we got the event we wanted, return */ | |||
| if(ev->type & event_mask) | |||
| if(privevent.type & event_mask) | |||
| { | |||
| if(ev) | |||
| memcpy(ev, &privevent, sizeof(privevent)); | |||
| return ret; | |||
| } | |||
| /* If there is no timeout, sleep and try again. */ | |||
| if(timeout < 0) | |||
| @@ -98,7 +100,9 @@ int caca_get_event(caca_display_t *dp, unsigned int event_mask, | |||
| /* If we timeouted, return an empty event */ | |||
| if(usec >= timeout) | |||
| { | |||
| ev->type = CACA_EVENT_NONE; | |||
| privevent.type = CACA_EVENT_NONE; | |||
| if(ev) | |||
| memcpy(ev, &privevent, sizeof(privevent)); | |||
| return 0; | |||
| } | |||
| @@ -153,11 +157,170 @@ unsigned int caca_get_mouse_y(caca_display_t const *dp) | |||
| return dp->mouse.y; | |||
| } | |||
| /** \brief Return an event's type. | |||
| * | |||
| * Return the type of an event. This function may always be called on an | |||
| * event after caca_get_event() was called, and its return value indicates | |||
| * which other functions may be called: | |||
| * - \c CACA_EVENT_NONE: no other function may be called. | |||
| * - \c CACA_EVENT_KEY_PRESS, \c CACA_EVENT_KEY_RELEASE: | |||
| * caca_get_event_key_ch(), caca_get_event_key_utf32() and | |||
| * caca_get_event_key_utf8() may be called. | |||
| * - \c CACA_EVENT_MOUSE_PRESS, \c CACA_EVENT_MOUSE_RELEASE: | |||
| * caca_get_event_mouse_button() may be called. | |||
| * - \c CACA_EVENT_MOUSE_MOTION: caca_get_event_mouse_x() and | |||
| * caca_get_event_mouse_y() may be called. | |||
| * - \c CACA_EVENT_RESIZE: caca_get_event_resize_width() and | |||
| * caca_get_event_resize_height() may be called. | |||
| * - \c CACA_EVENT_QUIT: no other function may be called. | |||
| * | |||
| * This function never fails. | |||
| * | |||
| * \param ev The libcaca event. | |||
| * \return The event's type. | |||
| */ | |||
| enum caca_event_type caca_get_event_type(caca_event_t const *ev) | |||
| { | |||
| return ((caca_privevent_t const *)ev)->type; | |||
| } | |||
| /** \brief Return a key press or key release event's value | |||
| * | |||
| * Return either the ASCII value for an event's key, or if the key is not | |||
| * an ASCII character, an appropriate \e enum \e caca_key value. | |||
| * | |||
| * This function never fails, but must only be called with a valid event of | |||
| * type \c CACA_EVENT_KEY_PRESS or \c CACA_EVENT_KEY_RELEASE, or the results | |||
| * will be undefined. See caca_get_event_type() for more information. | |||
| * | |||
| * \param ev The libcaca event. | |||
| * \return The key value. | |||
| */ | |||
| unsigned int caca_get_event_key_ch(caca_event_t const *ev) | |||
| { | |||
| return ((caca_privevent_t const *)ev)->data.key.ch; | |||
| } | |||
| /** \brief Return a key press or key release event's Unicode value | |||
| * | |||
| * Return the UTF-32/UCS-4 value for an event's key if it resolves to a | |||
| * printable character. | |||
| * | |||
| * This function never fails, but must only be called with a valid event of | |||
| * type \c CACA_EVENT_KEY_PRESS or \c CACA_EVENT_KEY_RELEASE, or the results | |||
| * will be undefined. See caca_get_event_type() for more information. | |||
| * | |||
| * \param ev The libcaca event. | |||
| * \return The key's Unicode value. | |||
| */ | |||
| unsigned long int caca_get_event_key_utf32(caca_event_t const *ev) | |||
| { | |||
| return ((caca_privevent_t const *)ev)->data.key.utf32; | |||
| } | |||
| /** \brief Return a key press or key release event's UTF-8 value | |||
| * | |||
| * Write the UTF-8 value for an event's key if it resolves to a printable | |||
| * character. Up to 6 UTF-8 bytes and a null termination are written. | |||
| * | |||
| * This function never fails, but must only be called with a valid event of | |||
| * type \c CACA_EVENT_KEY_PRESS or \c CACA_EVENT_KEY_RELEASE, or the results | |||
| * will be undefined. See caca_get_event_type() for more information. | |||
| * | |||
| * \param ev The libcaca event. | |||
| * \return This function always returns 0. | |||
| */ | |||
| int caca_get_event_key_utf8(caca_event_t const *ev, char *utf8) | |||
| { | |||
| memcpy(utf8, ((caca_privevent_t const *)ev)->data.key.utf8, 8); | |||
| return 0; | |||
| } | |||
| /** \brief Return a mouse press or mouse release event's button | |||
| * | |||
| * Return the mouse button index for an event. | |||
| * | |||
| * This function never fails, but must only be called with a valid event of | |||
| * type \c CACA_EVENT_MOUSE_PRESS or \c CACA_EVENT_MOUSE_RELEASE, or the | |||
| * results will be undefined. See caca_get_event_type() for more information. | |||
| * | |||
| * \param ev The libcaca event. | |||
| * \return The event's mouse button. | |||
| */ | |||
| unsigned int caca_get_event_mouse_button(caca_event_t const *ev) | |||
| { | |||
| return ((caca_privevent_t const *)ev)->data.mouse.button; | |||
| } | |||
| /** \brief Return a mouse motion event's X coordinate. | |||
| * | |||
| * Return the X coordinate for a mouse motion event. | |||
| * | |||
| * This function never fails, but must only be called with a valid event of | |||
| * type \c CACA_EVENT_MOUSE_MOTION, or the results will be undefined. See | |||
| * caca_get_event_type() for more information. | |||
| * | |||
| * \param ev The libcaca event. | |||
| * \return The event's X mouse coordinate. | |||
| */ | |||
| unsigned int caca_get_event_mouse_x(caca_event_t const *ev) | |||
| { | |||
| return ((caca_privevent_t const *)ev)->data.mouse.x; | |||
| } | |||
| /** \brief Return a mouse motion event's Y coordinate. | |||
| * | |||
| * Return the Y coordinate for a mouse motion event. | |||
| * | |||
| * This function never fails, but must only be called with a valid event of | |||
| * type \c CACA_EVENT_MOUSE_MOTION, or the results will be undefined. See | |||
| * caca_get_event_type() for more information. | |||
| * | |||
| * \param ev The libcaca event. | |||
| * \return The event's Y mouse coordinate. | |||
| */ | |||
| unsigned int caca_get_event_mouse_y(caca_event_t const *ev) | |||
| { | |||
| return ((caca_privevent_t const *)ev)->data.mouse.y; | |||
| } | |||
| /** \brief Return a resize event's display width value. | |||
| * | |||
| * Return the width value for a display resize event. | |||
| * | |||
| * This function never fails, but must only be called with a valid event of | |||
| * type \c CACA_EVENT_RESIZE, or the results will be undefined. See | |||
| * caca_get_event_type() for more information. | |||
| * | |||
| * \param ev The libcaca event. | |||
| * \return The event's new display width value. | |||
| */ | |||
| unsigned int caca_get_event_resize_width(caca_event_t const *ev) | |||
| { | |||
| return ((caca_privevent_t const *)ev)->data.resize.w; | |||
| } | |||
| /** \brief Return a resize event's display height value. | |||
| * | |||
| * Return the height value for a display resize event. | |||
| * | |||
| * This function never fails, but must only be called with a valid event of | |||
| * type \c CACA_EVENT_RESIZE, or the results will be undefined. See | |||
| * caca_get_event_type() for more information. | |||
| * | |||
| * \param ev The libcaca event. | |||
| * \return The event's new display height value. | |||
| */ | |||
| unsigned int caca_get_event_resize_height(caca_event_t const *ev) | |||
| { | |||
| return ((caca_privevent_t const *)ev)->data.resize.h; | |||
| } | |||
| /* | |||
| * XXX: The following functions are local. | |||
| */ | |||
| static int _get_next_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int _get_next_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| #if defined(USE_SLANG) || defined(USE_NCURSES) | |||
| unsigned int ticks; | |||
| @@ -239,7 +402,7 @@ static int _get_next_event(caca_display_t *dp, caca_event_t *ev) | |||
| #endif | |||
| } | |||
| static int _lowlevel_event(caca_display_t *dp, caca_event_t *ev) | |||
| static int _lowlevel_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) | |||
| int ret = _pop_event(dp, ev); | |||
| @@ -252,7 +415,7 @@ static int _lowlevel_event(caca_display_t *dp, caca_event_t *ev) | |||
| } | |||
| #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) | |||
| void _push_event(caca_display_t *dp, caca_event_t *ev) | |||
| void _push_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| if(!ev->type || dp->events.queue == EVENTBUF_LEN) | |||
| return; | |||
| @@ -260,7 +423,7 @@ void _push_event(caca_display_t *dp, caca_event_t *ev) | |||
| dp->events.queue++; | |||
| } | |||
| int _pop_event(caca_display_t *dp, caca_event_t *ev) | |||
| int _pop_event(caca_display_t *dp, caca_privevent_t *ev) | |||
| { | |||
| int i; | |||
| @@ -272,7 +272,7 @@ game (void) | |||
| caca_event_t ev; | |||
| if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0)) | |||
| { | |||
| switch(ev.data.key.ch) | |||
| switch(caca_get_event_key_ch(&ev)) | |||
| { | |||
| case CACA_KEY_CTRL_C: | |||
| case CACA_KEY_CTRL_Z: | |||
| @@ -108,10 +108,10 @@ int main(int argc, char **argv) | |||
| while(caca_get_event(dp, CACA_EVENT_KEY_PRESS | |||
| | CACA_EVENT_QUIT, &ev, 0)) | |||
| { | |||
| if(ev.type == CACA_EVENT_QUIT) | |||
| if(caca_get_event_type(&ev) == CACA_EVENT_QUIT) | |||
| goto end; | |||
| switch(ev.data.key.ch) | |||
| switch(caca_get_event_key_ch(&ev)) | |||
| { | |||
| case CACA_KEY_ESCAPE: | |||
| case CACA_KEY_CTRL_C: | |||
| @@ -80,12 +80,12 @@ int main(int argc, char **argv) | |||
| while(caca_get_event(dp, CACA_EVENT_ANY, &ev, -1)) | |||
| { | |||
| switch(ev.type) | |||
| switch(caca_get_event_type(&ev)) | |||
| { | |||
| case CACA_EVENT_QUIT: | |||
| goto quit; | |||
| case CACA_EVENT_KEY_PRESS: | |||
| switch(ev.data.key.ch) | |||
| switch(caca_get_event_key_ch(&ev)) | |||
| { | |||
| case CACA_KEY_LEFT: dx -= 2; break; | |||
| case CACA_KEY_RIGHT: dx += 2; break; | |||
| @@ -71,7 +71,7 @@ int main(int argc, char **argv) | |||
| int ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, 0); | |||
| int eof = 0; | |||
| if(ret && ev.type & CACA_EVENT_KEY_PRESS) | |||
| if(ret && caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS) | |||
| break; | |||
| if(bytes == 0) | |||
| @@ -145,20 +145,21 @@ int main(int argc, char **argv) | |||
| while(event) | |||
| { | |||
| if(ev.type & CACA_EVENT_MOUSE_PRESS) | |||
| if(caca_get_event_type(&ev) & CACA_EVENT_MOUSE_PRESS) | |||
| { | |||
| if(ev.data.mouse.button == 1) | |||
| if(caca_get_event_mouse_button(&ev) == 1) | |||
| { | |||
| if(items) current = (current + 1) % items; | |||
| reload = 1; | |||
| } | |||
| else if(ev.data.mouse.button == 2) | |||
| if(caca_get_event_mouse_button(&ev) == 2) | |||
| { | |||
| if(items) current = (items + current - 1) % items; | |||
| reload = 1; | |||
| } | |||
| } | |||
| else if(ev.type & CACA_EVENT_KEY_PRESS) switch(ev.data.key.ch) | |||
| else if(caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS) | |||
| switch(caca_get_event_key_ch(&ev)) | |||
| { | |||
| case 'n': | |||
| case 'N': | |||
| @@ -286,15 +287,15 @@ int main(int argc, char **argv) | |||
| quit = 1; | |||
| break; | |||
| } | |||
| else if(ev.type == CACA_EVENT_RESIZE) | |||
| else if(caca_get_event_type(&ev) == CACA_EVENT_RESIZE) | |||
| { | |||
| caca_refresh_display(dp); | |||
| ww = ev.data.resize.w; | |||
| wh = ev.data.resize.h; | |||
| ww = caca_get_event_resize_width(&ev); | |||
| wh = caca_get_event_resize_height(&ev); | |||
| update = 1; | |||
| set_zoom(zoom); | |||
| } | |||
| else if(ev.type & CACA_EVENT_QUIT) | |||
| else if(caca_get_event_type(&ev) & CACA_EVENT_QUIT) | |||
| quit = 1; | |||
| if(status || new_status) | |||
| @@ -88,14 +88,14 @@ int main(int argc, char **argv) | |||
| while(caca_get_event(dp, CACA_EVENT_ANY, &ev, 0)) | |||
| { | |||
| if(demo && (ev.type & CACA_EVENT_KEY_PRESS)) | |||
| if(demo && (caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS)) | |||
| { | |||
| menu = 1; | |||
| demo = NULL; | |||
| } | |||
| else if(ev.type & CACA_EVENT_KEY_PRESS) | |||
| else if(caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS) | |||
| { | |||
| switch(ev.data.key.ch) | |||
| switch(caca_get_event_key_ch(&ev)) | |||
| { | |||
| case 'q': | |||
| case 'Q': | |||
| @@ -159,13 +159,13 @@ int main(int argc, char **argv) | |||
| cucul_clear_canvas(cv); | |||
| } | |||
| } | |||
| else if(ev.type & CACA_EVENT_MOUSE_MOTION) | |||
| else if(caca_get_event_type(&ev) & CACA_EVENT_MOUSE_MOTION) | |||
| { | |||
| mouse = 1; | |||
| xmouse = ev.data.mouse.x; | |||
| ymouse = ev.data.mouse.y; | |||
| xmouse = caca_get_event_mouse_x(&ev); | |||
| ymouse = caca_get_event_mouse_y(&ev); | |||
| } | |||
| else if(ev.type & CACA_EVENT_RESIZE) | |||
| else if(caca_get_event_type(&ev) & CACA_EVENT_RESIZE) | |||
| { | |||
| mouse = 1; /* old hack */ | |||
| } | |||
| @@ -72,9 +72,9 @@ int main(int argc, char **argv) | |||
| do | |||
| { | |||
| /* "quit" quits */ | |||
| if(ev.type & CACA_EVENT_KEY_PRESS) | |||
| if(caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS) | |||
| { | |||
| int key = ev.data.key.ch; | |||
| int key = caca_get_event_key_ch(&ev); | |||
| if((key == 'q' && quit == 0) || (key == 'u' && quit == 1) | |||
| || (key == 'i' && quit == 2) || (key == 't' && quit == 3)) | |||
| quit++; | |||
| @@ -104,7 +104,7 @@ int main(int argc, char **argv) | |||
| /* Print previous events */ | |||
| cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK); | |||
| for(i = 1; i < h && events[i].type; i++) | |||
| for(i = 1; i < h && caca_get_event_type(&events[i]); i++) | |||
| print_event(0, i, events + i); | |||
| caca_refresh_display(dp); | |||
| @@ -121,36 +121,37 @@ static void print_event(int x, int y, caca_event_t *ev) | |||
| { | |||
| int character; | |||
| switch(ev->type) | |||
| switch(caca_get_event_type(ev)) | |||
| { | |||
| case CACA_EVENT_NONE: | |||
| cucul_printf(cv, x, y, "CACA_EVENT_NONE"); | |||
| break; | |||
| case CACA_EVENT_KEY_PRESS: | |||
| character = ev->data.key.ch; | |||
| character = caca_get_event_key_ch(ev); | |||
| cucul_printf(cv, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character, | |||
| (character > 0x1f && character < 0x80) ? character : '?'); | |||
| break; | |||
| case CACA_EVENT_KEY_RELEASE: | |||
| character = ev->data.key.ch; | |||
| character = caca_get_event_key_ch(ev); | |||
| cucul_printf(cv, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character, | |||
| (character > 0x1f && character < 0x80) ? character : '?'); | |||
| break; | |||
| case CACA_EVENT_MOUSE_MOTION: | |||
| cucul_printf(cv, x, y, "CACA_EVENT_MOUSE_MOTION %u %u", | |||
| ev->data.mouse.x, ev->data.mouse.y); | |||
| caca_get_event_mouse_x(ev), caca_get_event_mouse_y(ev)); | |||
| break; | |||
| case CACA_EVENT_MOUSE_PRESS: | |||
| cucul_printf(cv, x, y, "CACA_EVENT_MOUSE_PRESS %u", | |||
| ev->data.mouse.button); | |||
| caca_get_event_mouse_button(ev)); | |||
| break; | |||
| case CACA_EVENT_MOUSE_RELEASE: | |||
| cucul_printf(cv, x, y, "CACA_EVENT_MOUSE_RELEASE %u", | |||
| ev->data.mouse.button); | |||
| caca_get_event_mouse_button(ev)); | |||
| break; | |||
| case CACA_EVENT_RESIZE: | |||
| cucul_printf(cv, x, y, "CACA_EVENT_RESIZE %u %u", | |||
| ev->data.resize.w, ev->data.resize.h); | |||
| caca_get_event_resize_width(ev), | |||
| caca_get_event_resize_height(ev)); | |||
| break; | |||
| case CACA_EVENT_QUIT: | |||
| cucul_printf(cv, x, y, "CACA_EVENT_QUIT"); | |||
| @@ -74,13 +74,13 @@ int main(int argc, char *argv[]) | |||
| if(ret) | |||
| { | |||
| if(ev.data.key.ch == CACA_KEY_LEFT) | |||
| if(caca_get_event_key_ch(&ev) == CACA_KEY_LEFT) | |||
| gam /= 1.03; | |||
| else if(ev.data.key.ch == CACA_KEY_RIGHT) | |||
| else if(caca_get_event_key_ch(&ev) == CACA_KEY_RIGHT) | |||
| gam *= 1.03; | |||
| else if(ev.data.key.ch == CACA_KEY_DOWN) | |||
| else if(caca_get_event_key_ch(&ev) == CACA_KEY_DOWN) | |||
| gam = 1.0; | |||
| else if(ev.data.key.ch == CACA_KEY_ESCAPE) | |||
| else if(caca_get_event_key_ch(&ev) == CACA_KEY_ESCAPE) | |||
| break; | |||
| } | |||
| @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) | |||
| if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1) == 0) | |||
| continue; | |||
| switch(ev.data.key.ch) | |||
| switch(caca_get_event_key_ch(&ev)) | |||
| { | |||
| case CACA_KEY_ESCAPE: | |||
| running = 0; | |||
| @@ -143,7 +143,8 @@ int main(int argc, char *argv[]) | |||
| memmove(entries[e].buffer + entries[e].cursor + 1, | |||
| entries[e].buffer + entries[e].cursor, | |||
| (entries[e].size - entries[e].cursor) * 4); | |||
| entries[e].buffer[entries[e].cursor] = ev.data.key.utf32; | |||
| entries[e].buffer[entries[e].cursor] = | |||
| caca_get_event_key_utf32(&ev); | |||
| entries[e].size++; | |||
| entries[e].cursor++; | |||
| } | |||
| @@ -66,7 +66,7 @@ int main(int argc, char **argv) | |||
| while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0)) | |||
| { | |||
| switch(ev.data.key.ch) | |||
| switch(caca_get_event_key_ch(&ev)) | |||
| { | |||
| case 0: | |||
| break; | |||
| @@ -83,7 +83,7 @@ int main(int argc, char **argv) | |||
| caca_event_t ev; | |||
| int ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, 0); | |||
| if(ret && ev.type & CACA_EVENT_KEY_PRESS) | |||
| if(ret && caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS) | |||
| break; | |||
| for(i = 0; i < 4; i++) | |||