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

Last change on this file since 2821 was 2821, checked in by Sam Hocevar, 11 years ago

Starting refactoring to get rid of libcucul. The initial reason for the
split is rendered moot by the plugin system: when enabled, binaries do
not link directly with libX11 or libGL. I hope this is a step towards
more consisteny and clarity.

  • Property svn:keywords set to Id
File size: 5.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 2821 2008-09-27 13:12:46Z 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#include "stubs.h"
19
20typedef struct caca_timer caca_timer_t;
21typedef struct caca_privevent caca_privevent_t;
22typedef struct caca_figfont caca_figfont_t;
23
24#if !defined(_DOXYGEN_SKIP_ME)
25#   define EVENTBUF_LEN 10
26#endif
27
28struct caca_frame
29{
30    /* Frame size */
31    int width, height;
32
33    /* Cell information */
34    uint32_t *chars;
35    uint32_t *attrs;
36
37    /* Painting context */
38    int x, y;
39    int handlex, handley;
40    uint32_t curattr;
41
42    /* Frame name */
43    char *name;
44};
45
46struct caca_canvas
47{
48    /* XXX: look at caca_set_canvas_boundaries() before adding anything
49     * to this structure. The function is quite hacky. */
50
51    /* Frame information */
52    int frame, framecount;
53    struct caca_frame *frames;
54
55    /* Canvas management */
56    int refcount;
57    int autoinc;
58    int (*resize_callback)(void *);
59    void *resize_data;
60
61    /* Shortcut to the active frame information */
62    int width, height;
63    uint32_t *chars;
64    uint32_t *attrs;
65    uint32_t curattr;
66
67    /* FIGfont management */
68    caca_figfont_t *ff;
69};
70
71/* Graphics driver */
72enum caca_driver
73{
74    CACA_DRIVER_NONE = 0,
75    CACA_DRIVER_RAW = 1,
76#if defined(USE_COCOA)
77    CACA_DRIVER_COCOA = 2,
78#endif
79#if defined(USE_CONIO)
80    CACA_DRIVER_CONIO = 3,
81#endif
82#if defined(USE_GL)
83    CACA_DRIVER_GL = 4,
84#endif
85#if defined(USE_NCURSES)
86    CACA_DRIVER_NCURSES = 5,
87#endif
88#if defined(USE_SLANG)
89    CACA_DRIVER_SLANG = 6,
90#endif
91#if defined(USE_VGA)
92    CACA_DRIVER_VGA = 7,
93#endif
94#if defined(USE_WIN32)
95    CACA_DRIVER_WIN32 = 8,
96#endif
97#if defined(USE_X11)
98    CACA_DRIVER_X11 = 9,
99#endif
100};
101
102/* Available external drivers */
103#if defined(USE_COCOA)
104int cocoa_install(caca_display_t *);
105#endif
106#if defined(USE_CONIO)
107int conio_install(caca_display_t *);
108#endif
109#if defined(USE_GL)
110int gl_install(caca_display_t *);
111#endif
112#if defined(USE_NCURSES)
113int ncurses_install(caca_display_t *);
114#endif
115int raw_install(caca_display_t *);
116#if defined(USE_SLANG)
117int slang_install(caca_display_t *);
118#endif
119#if defined(USE_VGA)
120int vga_install(caca_display_t *);
121#endif
122#if defined(USE_WIN32)
123int win32_install(caca_display_t *);
124#endif
125#if defined(USE_X11)
126int x11_install(caca_display_t *);
127#endif
128
129/* Timer structure */
130struct caca_timer
131{
132    int last_sec, last_usec;
133};
134
135/* Private event structure */
136struct caca_privevent
137{
138    enum caca_event_type type;
139
140    union
141    {
142        struct { int x, y, button; } mouse;
143        struct { int w, h; } resize;
144        struct { int ch; uint32_t utf32; char utf8[8]; } key;
145    } data;
146};
147
148/* Internal caca display context */
149struct caca_display
150{
151    /* A link to our caca canvas */
152    caca_canvas_t *cv;
153    int autorelease;
154
155#if defined(USE_PLUGINS)
156    void *plugin;
157#endif
158
159    /* Device-specific functions */
160    struct drv
161    {
162        char const * driver;
163        enum caca_driver id;
164        struct driver_private *p;
165
166        int (* init_graphics) (caca_display_t *);
167        int (* end_graphics) (caca_display_t *);
168        int (* set_display_title) (caca_display_t *, char const *);
169        int (* get_display_width) (caca_display_t const *);
170        int (* get_display_height) (caca_display_t const *);
171        void (* display) (caca_display_t *);
172        void (* handle_resize) (caca_display_t *);
173        int (* get_event) (caca_display_t *, caca_privevent_t *);
174        void (* set_mouse) (caca_display_t *, int);
175        void (* set_cursor) (caca_display_t *, int);
176    } drv;
177
178    /* Mouse position */
179    struct mouse
180    {
181        int x, y;
182    } mouse;
183
184    /* Window resize handling */
185    struct resize
186    {
187        int resized;   /* A resize event was requested */
188        int allow;     /* The display driver allows resizing */
189        int w, h; /* Requested width and height */
190    } resize;
191
192    /* Framerate handling */
193    int delay, rendertime;
194    caca_timer_t timer;
195    int lastticks;
196
197    struct events
198    {
199#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
200        caca_privevent_t buf[EVENTBUF_LEN];
201        int queue;
202#endif
203#if defined(USE_SLANG) || defined(USE_NCURSES)
204        caca_timer_t key_timer;
205        int last_key_ticks;
206        int autorepeat_ticks;
207        caca_privevent_t last_key_event;
208#endif
209#if defined(USE_WIN32)
210        uint8_t not_empty_struct;
211#endif
212    } events;
213};
214
215/* Colour functions */
216extern uint32_t _caca_attr_to_rgb24fg(uint32_t);
217extern uint32_t _caca_attr_to_rgb24bg(uint32_t);
218
219/* Frames functions */
220extern void _caca_save_frame_info(caca_canvas_t *);
221extern void _caca_load_frame_info(caca_canvas_t *);
222
223/* Internal timer functions */
224extern void _caca_sleep(int);
225extern int _caca_getticks(caca_timer_t *);
226
227/* Internal event functions */
228extern void _caca_handle_resize(caca_display_t *);
229#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
230extern void _push_event(caca_display_t *, caca_privevent_t *);
231extern int _pop_event(caca_display_t *, caca_privevent_t *);
232#endif
233
234/* Internal window functions */
235extern void _caca_set_term_title(char const *);
236
237#endif /* __CACA_INTERNALS_H__ */
Note: See TracBrowser for help on using the repository browser.