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

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

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  This library is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13#ifndef __CACA_INTERNALS_H__
14#define __CACA_INTERNALS_H__
15
16#include "caca_stubs.h"
17#include "caca_debug.h"
18#include "caca_prof.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 STAT_VALUES 32
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/* Statistic structure for profiling */
147struct caca_stat
148{
149    int itable[STAT_VALUES];
150    int64_t imean;
151    char *name;
152};
153
154/* Private event structure */
155struct caca_privevent
156{
157    enum caca_event_type type;
158
159    union
160    {
161        struct { int x, y, button; } mouse;
162        struct { int w, h; } resize;
163        struct { int ch; uint32_t utf32; char utf8[8]; } key;
164    } data;
165};
166
167/* Internal caca display context */
168struct caca_display
169{
170    /* A link to our caca canvas */
171    caca_canvas_t *cv;
172    int autorelease;
173
174#if defined(USE_PLUGINS)
175    void *plugin;
176#endif
177
178    /* Device-specific functions */
179    struct drv
180    {
181        char const * driver;
182        enum caca_driver id;
183        struct driver_private *p;
184
185        int (* init_graphics) (caca_display_t *);
186        int (* end_graphics) (caca_display_t *);
187        int (* set_display_title) (caca_display_t *, char const *);
188        int (* get_display_width) (caca_display_t const *);
189        int (* get_display_height) (caca_display_t const *);
190        void (* display) (caca_display_t *);
191        void (* handle_resize) (caca_display_t *);
192        int (* get_event) (caca_display_t *, caca_privevent_t *);
193        void (* set_mouse) (caca_display_t *, int);
194        void (* set_cursor) (caca_display_t *, int);
195    } drv;
196
197    /* Mouse position */
198    struct mouse
199    {
200        int x, y;
201    } mouse;
202
203    /* Window resize handling */
204    struct resize
205    {
206        int resized;   /* A resize event was requested */
207        int allow;     /* The display driver allows resizing */
208        int w, h; /* Requested width and height */
209    } resize;
210
211    /* Framerate handling */
212    int delay, rendertime;
213    caca_timer_t timer;
214#if defined PROF
215    struct caca_stat display_stat, wait_stat;
216    struct caca_stat ev_sys_stat, ev_wait_stat;
217#endif
218    int lastticks;
219
220    struct events
221    {
222#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
223        caca_privevent_t buf[EVENTBUF_LEN];
224        int queue;
225#endif
226#if defined(USE_SLANG) || defined(USE_NCURSES)
227        caca_timer_t key_timer;
228        int last_key_ticks;
229        int autorepeat_ticks;
230        caca_privevent_t last_key_event;
231#endif
232#if defined(USE_WIN32)
233        uint8_t not_empty_struct;
234#endif
235    } events;
236};
237
238/* Dirty rectangle functions */
239extern void _caca_clip_dirty_rect_list(caca_canvas_t *);
240
241/* Colour functions */
242extern uint32_t _caca_attr_to_rgb24fg(uint32_t);
243extern uint32_t _caca_attr_to_rgb24bg(uint32_t);
244
245/* Frames functions */
246extern void _caca_save_frame_info(caca_canvas_t *);
247extern void _caca_load_frame_info(caca_canvas_t *);
248
249/* Internal timer functions */
250extern void _caca_sleep(int);
251extern int _caca_getticks(caca_timer_t *);
252
253/* Internal event functions */
254extern void _caca_handle_resize(caca_display_t *);
255#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
256extern void _push_event(caca_display_t *, caca_privevent_t *);
257extern int _pop_event(caca_display_t *, caca_privevent_t *);
258#endif
259
260/* Internal window functions */
261extern void _caca_set_term_title(char const *);
262
263/* Profiling functions */
264#if defined PROF
265extern void _caca_dump_stats(void);
266extern void _caca_init_stat(struct caca_stat *, char const *, ...);
267extern void _caca_fini_stat(struct caca_stat *);
268#endif
269
270#endif /* __CACA_INTERNALS_H__ */
Note: See TracBrowser for help on using the repository browser.