Changeset 332


Ignore:
Timestamp:
Jan 10, 2004, 8:29:12 PM (17 years ago)
Author:
Sam Hocevar
Message:
  • src/graphics: + Initialise the char buffers in the X11 driver.
  • src/io.c: + caca_get_event() and caca_wait_event() immediately return zero if

event_mask is zero.

+ Added support for the Home, End, PgUp? and PgDown? keys.
+ In the S-Lang driver, added a call to SLang_getkey() before the call to

SLkp_getkey(), otherwise a single Escape call will not be interpreted.

  • test/event.c: + The "quit" sequence now quits the program, instead of "q" alone. + Added a status bar below.
Location:
libcaca/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/caca.h

    r322 r332  
    192192enum caca_key
    193193{
     194    CACA_KEY_UNKNOWN = 0, /**< Unknown key. */
     195
     196    /* The following keys have ASCII equivalents */
     197    CACA_KEY_BACKSPACE = 8, /**< The backspace key. */
     198    CACA_KEY_TAB = 9, /**< The tabulation key. */
     199    CACA_KEY_RETURN = 13, /**< The return key. */
     200    CACA_KEY_PAUSE = 19, /**< The pause key. */
     201    CACA_KEY_ESCAPE = 27, /**< The escape key. */
     202    CACA_KEY_DELETE = 127, /**< The delete key. */
     203
     204    /* The following keys do not have ASCII equivalents but have been
     205     * chosen to match the SDL equivalents */
    194206    CACA_KEY_UP = 273, /**< The up arrow key. */
    195207    CACA_KEY_DOWN = 274, /**< The down arrow key. */
    196208    CACA_KEY_LEFT = 275, /**< The left arrow key. */
    197209    CACA_KEY_RIGHT = 276, /**< The right arrow key. */
     210
     211    CACA_KEY_INSERT = 277, /**< The insert key. */
     212    CACA_KEY_HOME = 278, /**< The home key. */
     213    CACA_KEY_END = 279, /**< The end key. */
     214    CACA_KEY_PAGEUP = 280, /**< The page up key. */
     215    CACA_KEY_PAGEDOWN = 281, /**< The page down key. */
    198216
    199217    CACA_KEY_F1 = 282, /**< The F1 key. */
  • libcaca/trunk/src/graphics.c

    r331 r332  
    633633        }
    634634
     635        memset(x11_char, 0, _caca_width * _caca_height * sizeof(int));
     636        memset(x11_attr, 0, _caca_width * _caca_height * sizeof(int));
     637
    635638        x11_dpy = XOpenDisplay(NULL);
    636639        if(x11_dpy == NULL)
  • libcaca/trunk/src/io.c

    r331 r332  
    7979 *  This function polls the event queue for mouse or keyboard events matching
    8080 *  the event mask and returns the first matching event. Non-matching events
    81  *  are discarded. It is non-blocking and returns zero if no more events are
    82  *  pending in the queue. See also caca_wait_event() for a blocking version
    83  *  of this function.
     81 *  are discarded. \c event_mask must have a non-zero value. This function is
     82 *  non-blocking and returns zero if no more events are pending in the queue.
     83 *  See also caca_wait_event() for a blocking version of this function.
    8484 *
    8585 * \param event_mask Bitmask of requested events.
     
    8888unsigned int caca_get_event(unsigned int event_mask)
    8989{
     90    if(!event_mask)
     91        return CACA_EVENT_NONE;
     92
    9093    for( ; ; )
    9194    {
     
    101104 *  This function returns the first mouse or keyboard event in the queue
    102105 *  that matches the event mask. If no event is pending, it blocks until a
    103  *  matching event is received. See also caca_get_event() for a non-blocking
    104  *  version of this function.
     106 *  matching event is received. \c event_mask must have a non-zero value.
     107 *  See also caca_get_event() for a non-blocking version of this function.
    105108 *
    106109 *  \param event_mask Bitmask of requested events.
     
    109112unsigned int caca_wait_event(unsigned int event_mask)
    110113{
     114    if(!event_mask)
     115        return CACA_EVENT_NONE;
     116
    111117    for( ; ; )
    112118    {
     
    280286            case XK_Up:    return event | CACA_KEY_UP;
    281287            case XK_Down:  return event | CACA_KEY_DOWN;
    282             default:       return 0;
     288            default:       return CACA_EVENT_NONE;
    283289            }
    284290        }
    285291
    286         return 0;
     292        return CACA_EVENT_NONE;
    287293    }
    288294    else
     
    293299        int intkey = getch();
    294300        if(intkey == ERR)
    295             return 0;
     301            return CACA_EVENT_NONE;
    296302
    297303        if(intkey < 0x100)
     
    422428        }
    423429
     430        event = CACA_EVENT_KEY_PRESS;
     431
    424432        switch(intkey)
    425433        {
    426             case KEY_UP: event = CACA_KEY_UP; break;
    427             case KEY_DOWN: event = CACA_KEY_DOWN; break;
    428             case KEY_LEFT: event = CACA_KEY_LEFT; break;
    429             case KEY_RIGHT: event = CACA_KEY_RIGHT; break;
    430 
    431             case KEY_F(1): event = CACA_KEY_F1; break;
    432             case KEY_F(2): event = CACA_KEY_F2; break;
    433             case KEY_F(3): event = CACA_KEY_F3; break;
    434             case KEY_F(4): event = CACA_KEY_F4; break;
    435             case KEY_F(5): event = CACA_KEY_F5; break;
    436             case KEY_F(6): event = CACA_KEY_F6; break;
    437             case KEY_F(7): event = CACA_KEY_F7; break;
    438             case KEY_F(8): event = CACA_KEY_F8; break;
    439             case KEY_F(9): event = CACA_KEY_F9; break;
    440             case KEY_F(10): event = CACA_KEY_F10; break;
    441             case KEY_F(11): event = CACA_KEY_F11; break;
    442             case KEY_F(12): event = CACA_KEY_F12; break;
    443         }
    444 
    445         return CACA_EVENT_KEY_PRESS | event;
     434            case KEY_UP: return event | CACA_KEY_UP;
     435            case KEY_DOWN: return event | CACA_KEY_DOWN;
     436            case KEY_LEFT: return event | CACA_KEY_LEFT;
     437            case KEY_RIGHT: return event | CACA_KEY_RIGHT;
     438
     439            case KEY_IC: return event | CACA_KEY_INSERT;
     440            case KEY_DC: return event | CACA_KEY_DELETE;
     441            case KEY_HOME: return event | CACA_KEY_HOME;
     442            case KEY_END: return event | CACA_KEY_END;
     443            case KEY_PPAGE: return event | CACA_KEY_PAGEUP;
     444            case KEY_NPAGE: return event | CACA_KEY_PAGEDOWN;
     445
     446            case KEY_F(1): return event | CACA_KEY_F1;
     447            case KEY_F(2): return event | CACA_KEY_F2;
     448            case KEY_F(3): return event | CACA_KEY_F3;
     449            case KEY_F(4): return event | CACA_KEY_F4;
     450            case KEY_F(5): return event | CACA_KEY_F5;
     451            case KEY_F(6): return event | CACA_KEY_F6;
     452            case KEY_F(7): return event | CACA_KEY_F7;
     453            case KEY_F(8): return event | CACA_KEY_F8;
     454            case KEY_F(9): return event | CACA_KEY_F9;
     455            case KEY_F(10): return event | CACA_KEY_F10;
     456            case KEY_F(11): return event | CACA_KEY_F11;
     457            case KEY_F(12): return event | CACA_KEY_F12;
     458        }
     459
     460        return CACA_EVENT_NONE;
    446461    }
    447462    else
     
    453468
    454469        if(!SLang_input_pending(0))
    455             return 0;
    456 
    457         intkey = SLkp_getkey();
    458 
     470            return CACA_EVENT_NONE;
     471
     472        /* We first use SLang_getkey() to see whether Esc was pressed
     473         * alone, then (if it wasn't) we unget the key and use SLkp_getkey()
     474         * instead, so that escape sequences are interpreted. */
     475        intkey = SLang_getkey();
     476
     477        if(intkey != 0x1b /* Esc */ || SLang_input_pending(0))
     478        {
     479            SLang_ungetkey(intkey);
     480            intkey = SLkp_getkey();
     481        }
     482
     483        /* If the key was ASCII, return it immediately */
    459484        if(intkey < 0x100)
    460485        {
     
    472497        }
    473498
     499        event = CACA_EVENT_KEY_PRESS;
     500
    474501        switch(intkey)
    475502        {
    476             case SL_KEY_UP: event = CACA_KEY_UP; break;
    477             case SL_KEY_DOWN: event = CACA_KEY_DOWN; break;
    478             case SL_KEY_LEFT: event = CACA_KEY_LEFT; break;
    479             case SL_KEY_RIGHT: event = CACA_KEY_RIGHT; break;
    480 
    481             case SL_KEY_F(1): event = CACA_KEY_F1; break;
    482             case SL_KEY_F(2): event = CACA_KEY_F2; break;
    483             case SL_KEY_F(3): event = CACA_KEY_F3; break;
    484             case SL_KEY_F(4): event = CACA_KEY_F4; break;
    485             case SL_KEY_F(5): event = CACA_KEY_F5; break;
    486             case SL_KEY_F(6): event = CACA_KEY_F6; break;
    487             case SL_KEY_F(7): event = CACA_KEY_F7; break;
    488             case SL_KEY_F(8): event = CACA_KEY_F8; break;
    489             case SL_KEY_F(9): event = CACA_KEY_F9; break;
    490             case SL_KEY_F(10): event = CACA_KEY_F10; break;
    491             case SL_KEY_F(11): event = CACA_KEY_F11; break;
    492             case SL_KEY_F(12): event = CACA_KEY_F12; break;
    493         }
    494 
    495         return CACA_EVENT_KEY_PRESS | event;
     503            case SL_KEY_UP: return event | CACA_KEY_UP;
     504            case SL_KEY_DOWN: return event | CACA_KEY_DOWN;
     505            case SL_KEY_LEFT: return event | CACA_KEY_LEFT;
     506            case SL_KEY_RIGHT: return event | CACA_KEY_RIGHT;
     507
     508            case SL_KEY_IC: return event | CACA_KEY_INSERT;
     509            case SL_KEY_DELETE: return event | CACA_KEY_DELETE;
     510            case SL_KEY_HOME: return event | CACA_KEY_HOME;
     511            case SL_KEY_END: return event | CACA_KEY_END;
     512            case SL_KEY_PPAGE: return event | CACA_KEY_PAGEUP;
     513            case SL_KEY_NPAGE: return event | CACA_KEY_PAGEDOWN;
     514
     515            case SL_KEY_F(1): return event | CACA_KEY_F1;
     516            case SL_KEY_F(2): return event | CACA_KEY_F2;
     517            case SL_KEY_F(3): return event | CACA_KEY_F3;
     518            case SL_KEY_F(4): return event | CACA_KEY_F4;
     519            case SL_KEY_F(5): return event | CACA_KEY_F5;
     520            case SL_KEY_F(6): return event | CACA_KEY_F6;
     521            case SL_KEY_F(7): return event | CACA_KEY_F7;
     522            case SL_KEY_F(8): return event | CACA_KEY_F8;
     523            case SL_KEY_F(9): return event | CACA_KEY_F9;
     524            case SL_KEY_F(10): return event | CACA_KEY_F10;
     525            case SL_KEY_F(11): return event | CACA_KEY_F11;
     526            case SL_KEY_F(12): return event | CACA_KEY_F12;
     527        }
     528
     529        return CACA_EVENT_NONE;
    496530    }
    497531    else
     
    501535    {
    502536        if(!_conio_kbhit())
    503             return 0;
     537            return CACA_EVENT_NONE;
    504538
    505539        event = getch();
     
    513547    }
    514548
    515     return 0;
     549    return CACA_EVENT_NONE;
    516550}
    517551
     
    530564
    531565    if(events == 0)
    532         return 0;
     566        return CACA_EVENT_NONE;
    533567
    534568    event = eventbuf[0];
  • libcaca/trunk/test/event.c

    r331 r332  
    3939        return 1;
    4040
     41    h = caca_get_height() - 1;
     42
    4143    caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
    4244    caca_draw_line(0, 0, caca_get_width() - 1, 0, ' ');
    4345
     46    caca_draw_line(0, h, caca_get_width() - 1, h, ' ');
     47    caca_putstr(0, h, "type \"quit\" to exit");
     48
    4449    caca_refresh();
    45 
    46     h = caca_get_height();
    4750
    4851    events = malloc(h * sizeof(int));
    4952    memset(events, 0, h * sizeof(int));
    5053
    51     for(quit = 0; !quit; )
     54    for(quit = 0; quit < 4; )
    5255    {
     56        static char const * quit_string[] = { "", "q", "qu", "qui", "quit" };
    5357        unsigned int event = caca_wait_event(CACA_EVENT_ANY);
    5458
     
    5862        do
    5963        {
    60             /* q quits */
    61             if(event == (CACA_EVENT_KEY_PRESS | 'q'))
    62                 quit = 1;
     64            /* "quit" quits */
     65            if(event & CACA_EVENT_KEY_PRESS)
     66            {
     67                int key = event & ~CACA_EVENT_KEY_PRESS;
     68                if((key == 'q' && quit == 0) || (key == 'u' && quit == 1)
     69                    || (key == 'i' && quit == 2) || (key == 't' && quit == 3))
     70                    quit++;
     71                else if(key == 'q')
     72                    quit = 1;
     73                else
     74                    quit = 0;
     75            }
    6376
    6477            memmove(events + 1, events, (h - 1) * sizeof(int));
     
    7588        caca_draw_line(0, 0, caca_get_width() - 1, 0, ' ');
    7689        print_event(0, 0, events[0]);
     90
     91        caca_draw_line(0, h, caca_get_width() - 1, h, ' ');
     92        caca_printf(0, h, "type \"quit\" to exit: %s", quit_string[quit]);
    7793
    7894        /* Print previous events */
Note: See TracChangeset for help on using the changeset viewer.