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

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

Start working on profiling.

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