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

Last change on this file since 2138 was 2138, checked in by Sam Hocevar, 12 years ago
  • Implement caca_create_display_with_driver() to specify an output driver without using environment variables..
  • Implement caca_get_display_driver() to return the current display's output driver.
  • Add a simple example program to test caca_create_display_with_driver().
  • Property svn:keywords set to Id
File size: 4.6 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 2138 2007-12-16 01:50:41Z 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    int autorelease;
112
113#if defined(USE_PLUGINS)
114    void *plugin;
115#endif
116
117    /* Device-specific functions */
118    struct drv
119    {
120        char const * driver;
121        enum caca_driver id;
122        struct driver_private *p;
123
124        int (* init_graphics) (caca_display_t *);
125        int (* end_graphics) (caca_display_t *);
126        int (* set_display_title) (caca_display_t *, char const *);
127        unsigned int (* get_display_width) (caca_display_t const *);
128        unsigned int (* get_display_height) (caca_display_t const *);
129        void (* display) (caca_display_t *);
130        void (* handle_resize) (caca_display_t *);
131        int (* get_event) (caca_display_t *, caca_privevent_t *);
132        void (* set_mouse) (caca_display_t *, int);
133        void (* set_cursor) (caca_display_t *, int);
134    } drv;
135
136    /* Mouse position */
137    struct mouse
138    {
139        unsigned int x, y;
140    } mouse;
141
142    /* Window resize handling */
143    struct resize
144    {
145        int resized;   /* A resize event was requested */
146        int allow;     /* The display driver allows resizing */
147        unsigned w, h; /* Requested width and height */
148    } resize;
149
150    /* Framerate handling */
151    unsigned int delay, rendertime;
152    caca_timer_t timer;
153    int lastticks;
154
155    struct events
156    {
157#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
158        caca_privevent_t buf[EVENTBUF_LEN];
159        int queue;
160#endif
161#if defined(USE_SLANG) || defined(USE_NCURSES)
162        caca_timer_t key_timer;
163        unsigned int last_key_ticks;
164        unsigned int autorepeat_ticks;
165        caca_privevent_t last_key_event;
166#endif
167#if defined(USE_WIN32)
168        unsigned char not_empty_struct;
169#endif
170    } events;
171};
172
173/* Internal timer functions */
174extern void _caca_sleep(unsigned int);
175extern unsigned int _caca_getticks(caca_timer_t *);
176
177/* Internal event functions */
178extern void _caca_handle_resize(caca_display_t *);
179#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
180extern void _push_event(caca_display_t *, caca_privevent_t *);
181extern int _pop_event(caca_display_t *, caca_privevent_t *);
182#endif
183
184/* Internal window functions */
185extern void _caca_set_term_title(char const *);
186
187#endif /* __CACA_INTERNALS_H__ */
Note: See TracBrowser for help on using the repository browser.