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

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

Finish the dirty rectangle architecture. They are now reliable in the sense
that anything outside the dirty rectangle is guaranteed to be unchanged, but
we currently mark far too many cells as dirty. This must be optimised.

  • Property svn:keywords set to Id
File size: 5.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 3448 2009-05-14 00:18:23Z 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
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    /* Dirty rectangle */
62    int dirty_xmin, dirty_xmax, dirty_ymin, dirty_ymax;
63
64    /* Shortcut to the active frame information */
65    int width, height;
66    uint32_t *chars;
67    uint32_t *attrs;
68    uint32_t curattr;
69
70    /* FIGfont management */
71    caca_figfont_t *ff;
72};
73
74/* Graphics driver */
75enum caca_driver
76{
77    CACA_DRIVER_NONE = 0,
78    CACA_DRIVER_RAW = 1,
79#if defined(USE_COCOA)
80    CACA_DRIVER_COCOA = 2,
81#endif
82#if defined(USE_CONIO)
83    CACA_DRIVER_CONIO = 3,
84#endif
85#if defined(USE_GL)
86    CACA_DRIVER_GL = 4,
87#endif
88#if defined(USE_NCURSES)
89    CACA_DRIVER_NCURSES = 5,
90#endif
91#if defined(USE_SLANG)
92    CACA_DRIVER_SLANG = 6,
93#endif
94#if defined(USE_VGA)
95    CACA_DRIVER_VGA = 7,
96#endif
97#if defined(USE_WIN32)
98    CACA_DRIVER_WIN32 = 8,
99#endif
100#if defined(USE_X11)
101    CACA_DRIVER_X11 = 9,
102#endif
103};
104
105/* Available external drivers */
106#if defined(USE_COCOA)
107int cocoa_install(caca_display_t *);
108#endif
109#if defined(USE_CONIO)
110int conio_install(caca_display_t *);
111#endif
112#if defined(USE_GL)
113int gl_install(caca_display_t *);
114#endif
115#if defined(USE_NCURSES)
116int ncurses_install(caca_display_t *);
117#endif
118int raw_install(caca_display_t *);
119#if defined(USE_SLANG)
120int slang_install(caca_display_t *);
121#endif
122#if defined(USE_VGA)
123int vga_install(caca_display_t *);
124#endif
125#if defined(USE_WIN32)
126int win32_install(caca_display_t *);
127#endif
128#if defined(USE_X11)
129int x11_install(caca_display_t *);
130#endif
131
132/* Timer structure */
133struct caca_timer
134{
135    int last_sec, last_usec;
136};
137
138/* Private event structure */
139struct caca_privevent
140{
141    enum caca_event_type type;
142
143    union
144    {
145        struct { int x, y, button; } mouse;
146        struct { int w, h; } resize;
147        struct { int ch; uint32_t utf32; char utf8[8]; } key;
148    } data;
149};
150
151/* Internal caca display context */
152struct caca_display
153{
154    /* A link to our caca canvas */
155    caca_canvas_t *cv;
156    int autorelease;
157
158#if defined(USE_PLUGINS)
159    void *plugin;
160#endif
161
162    /* Device-specific functions */
163    struct drv
164    {
165        char const * driver;
166        enum caca_driver id;
167        struct driver_private *p;
168
169        int (* init_graphics) (caca_display_t *);
170        int (* end_graphics) (caca_display_t *);
171        int (* set_display_title) (caca_display_t *, char const *);
172        int (* get_display_width) (caca_display_t const *);
173        int (* get_display_height) (caca_display_t const *);
174        void (* display) (caca_display_t *);
175        void (* handle_resize) (caca_display_t *);
176        int (* get_event) (caca_display_t *, caca_privevent_t *);
177        void (* set_mouse) (caca_display_t *, int);
178        void (* set_cursor) (caca_display_t *, int);
179    } drv;
180
181    /* Mouse position */
182    struct mouse
183    {
184        int x, y;
185    } mouse;
186
187    /* Window resize handling */
188    struct resize
189    {
190        int resized;   /* A resize event was requested */
191        int allow;     /* The display driver allows resizing */
192        int w, h; /* Requested width and height */
193    } resize;
194
195    /* Framerate handling */
196    int delay, rendertime;
197    caca_timer_t timer;
198    int lastticks;
199
200    struct events
201    {
202#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
203        caca_privevent_t buf[EVENTBUF_LEN];
204        int queue;
205#endif
206#if defined(USE_SLANG) || defined(USE_NCURSES)
207        caca_timer_t key_timer;
208        int last_key_ticks;
209        int autorepeat_ticks;
210        caca_privevent_t last_key_event;
211#endif
212#if defined(USE_WIN32)
213        uint8_t not_empty_struct;
214#endif
215    } events;
216};
217
218/* Colour functions */
219extern uint32_t _caca_attr_to_rgb24fg(uint32_t);
220extern uint32_t _caca_attr_to_rgb24bg(uint32_t);
221
222/* Frames functions */
223extern void _caca_save_frame_info(caca_canvas_t *);
224extern void _caca_load_frame_info(caca_canvas_t *);
225
226/* Internal timer functions */
227extern void _caca_sleep(int);
228extern int _caca_getticks(caca_timer_t *);
229
230/* Internal event functions */
231extern void _caca_handle_resize(caca_display_t *);
232#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
233extern void _push_event(caca_display_t *, caca_privevent_t *);
234extern int _pop_event(caca_display_t *, caca_privevent_t *);
235#endif
236
237/* Internal window functions */
238extern void _caca_set_term_title(char const *);
239
240#endif /* __CACA_INTERNALS_H__ */
Note: See TracBrowser for help on using the repository browser.