Ignore:
Timestamp:
Apr 18, 2006, 5:11:25 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Renamed caca_t into caca_display_t.
  • Renamed canvas handle variables from "c" to "cv". Eh ouais mon gros.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/event.c

    r810 r811  
    2727#include "caca_internals.h"
    2828
    29 static int _get_next_event(caca_t *, caca_event_t *);
    30 static int _lowlevel_event(caca_t *, caca_event_t *);
     29static int _get_next_event(caca_display_t *, caca_event_t *);
     30static int _lowlevel_event(caca_display_t *, caca_event_t *);
    3131
    3232#if !defined(_DOXYGEN_SKIP_ME)
     
    5151 *  function to wait indefinitely until a matching event is received.
    5252 *
    53  *  \param kk The libcaca graphical context.
     53 *  \param dp The libcaca graphical context.
    5454 *  \param event_mask Bitmask of requested events.
    5555 *  \param timeout A timeout value in microseconds
     
    5757 *  \return The next matching event in the queue, or 0 if no event is pending.
    5858 */
    59 int caca_get_event(caca_t *kk, unsigned int event_mask,
     59int caca_get_event(caca_display_t *dp, unsigned int event_mask,
    6060                   caca_event_t *ev, int timeout)
    6161{
     
    7171    for( ; ; )
    7272    {
    73         int ret = _get_next_event(kk, ev);
     73        int ret = _get_next_event(dp, ev);
    7474
    7575        /* If we got the event we wanted, return */
     
    109109 *  the mouse is clicked. Other drivers such as X11 work well.
    110110 *
    111  *  \param kk The libcaca graphical context.
     111 *  \param dp The libcaca graphical context.
    112112 *  \return The X mouse coordinate.
    113113 */
    114 unsigned int caca_get_mouse_x(caca_t *kk)
    115 {
    116     if(kk->mouse.x >= kk->c->width)
    117         kk->mouse.x = kk->c->width - 1;
    118 
    119     return kk->mouse.x;
     114unsigned int caca_get_mouse_x(caca_display_t *dp)
     115{
     116    if(dp->mouse.x >= dp->cv->width)
     117        dp->mouse.x = dp->cv->width - 1;
     118
     119    return dp->mouse.x;
    120120}
    121121
     
    127127 *  the mouse is clicked. Other drivers such as X11 work well.
    128128 *
    129  *  \param kk The libcaca graphical context.
     129 *  \param dp The libcaca graphical context.
    130130 *  \return The Y mouse coordinate.
    131131 */
    132 unsigned int caca_get_mouse_y(caca_t *kk)
    133 {
    134     if(kk->mouse.y >= kk->c->height)
    135         kk->mouse.y = kk->c->height - 1;
    136 
    137     return kk->mouse.y;
     132unsigned int caca_get_mouse_y(caca_display_t *dp)
     133{
     134    if(dp->mouse.y >= dp->cv->height)
     135        dp->mouse.y = dp->cv->height - 1;
     136
     137    return dp->mouse.y;
    138138}
    139139
     
    142142 */
    143143
    144 static int _get_next_event(caca_t *kk, caca_event_t *ev)
     144static int _get_next_event(caca_display_t *dp, caca_event_t *ev)
    145145{
    146146#if defined(USE_SLANG) || defined(USE_NCURSES)
     
    150150
    151151    /* If we are about to return a resize event, acknowledge it */
    152     if(kk->resize.resized)
    153     {
    154         kk->resize.resized = 0;
    155         _caca_handle_resize(kk);
     152    if(dp->resize.resized)
     153    {
     154        dp->resize.resized = 0;
     155        _caca_handle_resize(dp);
    156156        ev->type = CACA_EVENT_RESIZE;
    157         ev->data.resize.w = kk->c->width;
    158         ev->data.resize.h = kk->c->height;
     157        ev->data.resize.w = dp->cv->width;
     158        ev->data.resize.h = dp->cv->height;
    159159        return 1;
    160160    }
    161161
    162     ret = _lowlevel_event(kk, ev);
     162    ret = _lowlevel_event(dp, ev);
    163163
    164164#if defined(USE_SLANG)
    165     if(kk->drv.driver != CACA_DRIVER_SLANG)
     165    if(dp->drv.driver != CACA_DRIVER_SLANG)
    166166#endif
    167167#if defined(USE_NCURSES)
    168     if(kk->drv.driver != CACA_DRIVER_NCURSES)
     168    if(dp->drv.driver != CACA_DRIVER_NCURSES)
    169169#endif
    170170    return ret;
     
    172172#if defined(USE_SLANG) || defined(USE_NCURSES)
    173173    /* Simulate long keypresses using autorepeat features */
    174     ticks = _caca_getticks(&kk->events.key_timer);
    175     kk->events.last_key_ticks += ticks;
    176     kk->events.autorepeat_ticks += ticks;
     174    ticks = _caca_getticks(&dp->events.key_timer);
     175    dp->events.last_key_ticks += ticks;
     176    dp->events.autorepeat_ticks += ticks;
    177177
    178178    /* Handle autorepeat */
    179     if(kk->events.last_key_event.type
    180            && kk->events.autorepeat_ticks > AUTOREPEAT_TRIGGER
    181            && kk->events.autorepeat_ticks > AUTOREPEAT_THRESHOLD
    182            && kk->events.autorepeat_ticks > AUTOREPEAT_RATE)
    183     {
    184         _push_event(kk, ev);
    185         kk->events.autorepeat_ticks -= AUTOREPEAT_RATE;
    186         *ev = kk->events.last_key_event;
     179    if(dp->events.last_key_event.type
     180           && dp->events.autorepeat_ticks > AUTOREPEAT_TRIGGER
     181           && dp->events.autorepeat_ticks > AUTOREPEAT_THRESHOLD
     182           && dp->events.autorepeat_ticks > AUTOREPEAT_RATE)
     183    {
     184        _push_event(dp, ev);
     185        dp->events.autorepeat_ticks -= AUTOREPEAT_RATE;
     186        *ev = dp->events.last_key_event;
    187187        return 1;
    188188    }
     
    191191     * this event and return the next one by calling ourselves. */
    192192    if(ev->type == CACA_EVENT_KEY_PRESS
    193         && kk->events.last_key_event.type
    194         && ev->data.key.ch == kk->events.last_key_event.data.key.ch
    195         && ev->data.key.ucs4 == kk->events.last_key_event.data.key.ucs4)
    196     {
    197         kk->events.last_key_ticks = 0;
    198         return _get_next_event(kk, ev);
     193        && dp->events.last_key_event.type
     194        && ev->data.key.ch == dp->events.last_key_event.data.key.ch
     195        && ev->data.key.ucs4 == dp->events.last_key_event.data.key.ucs4)
     196    {
     197        dp->events.last_key_ticks = 0;
     198        return _get_next_event(dp, ev);
    199199    }
    200200
    201201    /* We are in autorepeat mode, but key has expired or a new key was
    202202     * pressed - store our event and return a key release event first */
    203     if(kk->events.last_key_event.type
    204           && (kk->events.last_key_ticks > AUTOREPEAT_THRESHOLD
     203    if(dp->events.last_key_event.type
     204          && (dp->events.last_key_ticks > AUTOREPEAT_THRESHOLD
    205205               || (ev->type & CACA_EVENT_KEY_PRESS)))
    206206    {
    207         _push_event(kk, ev);
    208         *ev = kk->events.last_key_event;
     207        _push_event(dp, ev);
     208        *ev = dp->events.last_key_event;
    209209        ev->type = CACA_EVENT_KEY_RELEASE;
    210         kk->events.last_key_event.type = CACA_EVENT_NONE;
     210        dp->events.last_key_event.type = CACA_EVENT_NONE;
    211211        return 1;
    212212    }
     
    215215    if(ev->type & CACA_EVENT_KEY_PRESS)
    216216    {
    217         kk->events.last_key_ticks = 0;
    218         kk->events.autorepeat_ticks = 0;
    219         kk->events.last_key_event = *ev;
     217        dp->events.last_key_ticks = 0;
     218        dp->events.autorepeat_ticks = 0;
     219        dp->events.last_key_event = *ev;
    220220    }
    221221
     
    224224}
    225225
    226 static int _lowlevel_event(caca_t *kk, caca_event_t *ev)
     226static int _lowlevel_event(caca_display_t *dp, caca_event_t *ev)
    227227{
    228228#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
    229     int ret = _pop_event(kk, ev);
     229    int ret = _pop_event(dp, ev);
    230230
    231231    if(ret)
     
    233233#endif
    234234
    235     return kk->drv.get_event(kk, ev);
     235    return dp->drv.get_event(dp, ev);
    236236}
    237237
    238238#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
    239 void _push_event(caca_t *kk, caca_event_t *ev)
    240 {
    241     if(!ev->type || kk->events.queue == EVENTBUF_LEN)
     239void _push_event(caca_display_t *dp, caca_event_t *ev)
     240{
     241    if(!ev->type || dp->events.queue == EVENTBUF_LEN)
    242242        return;
    243     kk->events.buf[kk->events.queue] = *ev;
    244     kk->events.queue++;
    245 }
    246 
    247 int _pop_event(caca_t *kk, caca_event_t *ev)
     243    dp->events.buf[dp->events.queue] = *ev;
     244    dp->events.queue++;
     245}
     246
     247int _pop_event(caca_display_t *dp, caca_event_t *ev)
    248248{
    249249    int i;
    250250
    251     if(kk->events.queue == 0)
     251    if(dp->events.queue == 0)
    252252        return 0;
    253253
    254     *ev = kk->events.buf[0];
    255     for(i = 1; i < kk->events.queue; i++)
    256         kk->events.buf[i - 1] = kk->events.buf[i];
    257     kk->events.queue--;
     254    *ev = dp->events.buf[0];
     255    for(i = 1; i < dp->events.queue; i++)
     256        dp->events.buf[i - 1] = dp->events.buf[i];
     257    dp->events.queue--;
    258258
    259259    return 1;
Note: See TracChangeset for help on using the changeset viewer.