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

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

Store dirty rectangles in a structure list. For now there is still only
one dirty rectangle, but this is the first step to improvement.

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