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

Last change on this file since 3904 was 3904, checked in by Sam Hocevar, 10 years ago

Move debugging methods to caca_debug.h.

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