source: libcaca/trunk/test/event.c @ 330

Last change on this file since 330 was 330, checked in by Sam Hocevar, 17 years ago
  • test/event.c: + Display at least two digits for keycodes.
  • configure.ac: + ScreenUpdate? is actually mandatory for our conio driver.
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1/*
2 *  event         event lister for libcaca
3 *  Copyright (c) 2004 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: event.c 330 2004-01-08 18:40:29Z sam $
7 *
8 *  This program is free software; you can redistribute it and/or
9 *  modify it under the terms of the GNU Lesser General Public
10 *  License as published by the Free Software Foundation; either
11 *  version 2 of the License, or (at your option) any later version.
12 *
13 *  This program is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 *  Lesser General Public License for more details.
17 *
18 *  You should have received a copy of the GNU Lesser General Public
19 *  License along with this program; if not, write to the Free Software
20 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 *  02111-1307  USA
22 */
23
24#include "config.h"
25
26#include <stdio.h>
27#include <string.h>
28
29#include "caca.h"
30
31static void print_event(int, int, unsigned int);
32
33int main(int argc, char **argv)
34{
35    int *events;
36    int i, h;
37
38    if(caca_init())
39        return 1;
40
41    caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
42    caca_draw_line(0, 0, caca_get_width() - 1, 0, ' ');
43
44    caca_refresh();
45
46    h = caca_get_height();
47
48    events = malloc(h * sizeof(int));
49    memset(events, 0, h * sizeof(int));
50
51    for( ; ; )
52    {
53        unsigned int event = caca_wait_event(CACA_EVENT_ANY);
54
55        if(!event)
56            continue;
57
58        memmove(events + 1, events, (h - 1) * sizeof(int));
59        events[0] = event;
60
61        caca_clear();
62
63        /* Print current event */
64        caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
65        caca_draw_line(0, 0, caca_get_width() - 1, 0, ' ');
66        print_event(0, 0, event);
67
68        /* Print previous events */
69        caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
70        for(i = 1; i < h && events[i]; i++)
71            print_event(0, i, events[i]);
72
73        /* q quits */
74        if(event == (CACA_EVENT_KEY_PRESS | 'q'))
75            break;
76
77        caca_refresh();
78    }
79
80    /* Clean up */
81    caca_end();
82
83    return 0;
84}
85
86static void print_event(int x, int y, unsigned int event)
87{
88    switch(event & 0xff000000)
89    {
90    case CACA_EVENT_NONE:
91        caca_printf(x, y, "CACA_EVENT_NONE");
92        break;
93    case CACA_EVENT_KEY_PRESS:
94        caca_printf(x, y, "CACA_EVENT_KEY_PRESS 0x%02x",
95                    event & 0x00ffffff);
96        break;
97    case CACA_EVENT_KEY_RELEASE:
98        caca_printf(x, y, "CACA_EVENT_KEY_RELEASE 0x2%x",
99                    event & 0x00ffffff);
100        break;
101    case CACA_EVENT_MOUSE_MOTION:
102        caca_printf(x, y, "CACA_EVENT_MOUSE_MOTION %u %u",
103                    (event & 0x00fff000) >> 12, event & 0x00000fff);
104        break;
105    case CACA_EVENT_MOUSE_PRESS:
106        caca_printf(x, y, "CACA_EVENT_MOUSE_PRESS %u",
107                    event & 0x00ffffff);
108        break;
109    case CACA_EVENT_MOUSE_RELEASE:
110        caca_printf(x, y, "CACA_EVENT_MOUSE_RELEASE %u",
111                    event & 0x00ffffff);
112        break;
113    default:
114        caca_printf(x, y, "CACA_EVENT_UNKNOWN");
115    }
116}
117
Note: See TracBrowser for help on using the repository browser.