source: libcaca/trunk/caca/caca_internals.h @ 2049

Last change on this file since 2049 was 2049, checked in by Sam Hocevar, 12 years ago
  • Made the caca_event_t structure opaque and created a whole bunch of functions to access its real data. This is a big API change that will break your software, sorry :(
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: caca_internals.h 2049 2007-11-25 11:11:54Z sam $
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#ifndef __CACA_INTERNALS_H__
16#define __CACA_INTERNALS_H__
17
18#if defined(HAVE_INTTYPES_H) && !defined(__KERNEL__)
19#   include <inttypes.h>
20#endif
21
22typedef struct caca_timer caca_timer_t;
23typedef struct caca_privevent caca_privevent_t;
24
25#if !defined(_DOXYGEN_SKIP_ME)
26#   define EVENTBUF_LEN 10
27#endif
28
29/* Graphics driver */
30enum caca_driver
31{
32    CACA_DRIVER_NONE = 0,
33    CACA_DRIVER_RAW = 1,
34#if defined(USE_COCOA)
35    CACA_DRIVER_COCOA = 2,
36#endif
37#if defined(USE_CONIO)
38    CACA_DRIVER_CONIO = 3,
39#endif
40#if defined(USE_GL)
41    CACA_DRIVER_GL = 4,
42#endif
43#if defined(USE_NCURSES)
44    CACA_DRIVER_NCURSES = 5,
45#endif
46#if defined(USE_SLANG)
47    CACA_DRIVER_SLANG = 6,
48#endif
49#if defined(USE_VGA)
50    CACA_DRIVER_VGA = 7,
51#endif
52#if defined(USE_WIN32)
53    CACA_DRIVER_WIN32 = 8,
54#endif
55#if defined(USE_X11)
56    CACA_DRIVER_X11 = 9,
57#endif
58};
59
60/* Available external drivers */
61#if defined(USE_COCOA)
62int cocoa_install(caca_display_t *);
63#endif
64#if defined(USE_CONIO)
65int conio_install(caca_display_t *);
66#endif
67#if defined(USE_GL)
68int gl_install(caca_display_t *);
69#endif
70#if defined(USE_NCURSES)
71int ncurses_install(caca_display_t *);
72#endif
73int raw_install(caca_display_t *);
74#if defined(USE_SLANG)
75int slang_install(caca_display_t *);
76#endif
77#if defined(USE_VGA)
78int vga_install(caca_display_t *);
79#endif
80#if defined(USE_WIN32)
81int win32_install(caca_display_t *);
82#endif
83#if defined(USE_X11)
84int x11_install(caca_display_t *);
85#endif
86
87/* Timer structure */
88struct caca_timer
89{
90    int last_sec, last_usec;
91};
92
93/* Private event structure */
94struct 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
106/* Internal caca display context */
107struct caca_display
108{
109    /* A link to our cucul canvas */
110    cucul_canvas_t *cv;
111
112#if defined(USE_PLUGINS)
113    void *plugin;
114#endif
115
116    /* Device-specific functions */
117    struct drv
118    {
119        enum caca_driver driver;
120        struct driver_private *p;
121
122        int (* init_graphics) (caca_display_t *);
123        int (* end_graphics) (caca_display_t *);
124        int (* set_display_title) (caca_display_t *, char const *);
125        unsigned int (* get_display_width) (caca_display_t const *);
126        unsigned int (* get_display_height) (caca_display_t const *);
127        void (* display) (caca_display_t *);
128        void (* handle_resize) (caca_display_t *);
129        int (* get_event) (caca_display_t *, caca_privevent_t *);
130        void (* set_mouse) (caca_display_t *, int);
131        void (* set_cursor) (caca_display_t *, int);
132    } drv;
133
134    /* Mouse position */
135    struct mouse
136    {
137        unsigned int x, y;
138    } mouse;
139
140    /* Window resize handling */
141    struct resize
142    {
143        int resized;   /* A resize event was requested */
144        unsigned w, h; /* Requested width and height */
145    } resize;
146
147    /* Framerate handling */
148    unsigned int delay, rendertime;
149    caca_timer_t timer;
150    int lastticks;
151
152    struct events
153    {
154#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
155        caca_privevent_t buf[EVENTBUF_LEN];
156        int queue;
157#endif
158#if defined(USE_SLANG) || defined(USE_NCURSES)
159        caca_timer_t key_timer;
160        unsigned int last_key_ticks;
161        unsigned int autorepeat_ticks;
162        caca_privevent_t last_key_event;
163#endif
164#if defined(USE_WIN32)
165        unsigned char not_empty_struct;
166#endif
167    } events;
168};
169
170/* Internal timer functions */
171extern void _caca_sleep(unsigned int);
172extern unsigned int _caca_getticks(caca_timer_t *);
173
174/* Internal event functions */
175extern void _caca_handle_resize(caca_display_t *);
176#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
177extern void _push_event(caca_display_t *, caca_privevent_t *);
178extern int _pop_event(caca_display_t *, caca_privevent_t *);
179#endif
180
181/* Internal window functions */
182extern void _caca_set_term_title(char const *);
183
184#endif /* __CACA_INTERNALS_H__ */
Note: See TracBrowser for help on using the repository browser.