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

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

Optimise the dirty rectangle handling by keeping track of the number of
currently dirty rectangles.

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