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 | |
---|
20 | typedef struct caca_timer caca_timer_t; |
---|
21 | typedef struct caca_privevent caca_privevent_t; |
---|
22 | typedef struct caca_figfont caca_figfont_t; |
---|
23 | |
---|
24 | #if !defined(_DOXYGEN_SKIP_ME) |
---|
25 | # define EVENTBUF_LEN 10 |
---|
26 | #endif |
---|
27 | |
---|
28 | struct 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 | |
---|
46 | struct 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 */ |
---|
76 | enum 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) |
---|
108 | int cocoa_install(caca_display_t *); |
---|
109 | #endif |
---|
110 | #if defined(USE_CONIO) |
---|
111 | int conio_install(caca_display_t *); |
---|
112 | #endif |
---|
113 | #if defined(USE_GL) |
---|
114 | int gl_install(caca_display_t *); |
---|
115 | #endif |
---|
116 | #if defined(USE_NCURSES) |
---|
117 | int ncurses_install(caca_display_t *); |
---|
118 | #endif |
---|
119 | int raw_install(caca_display_t *); |
---|
120 | #if defined(USE_SLANG) |
---|
121 | int slang_install(caca_display_t *); |
---|
122 | #endif |
---|
123 | #if defined(USE_VGA) |
---|
124 | int vga_install(caca_display_t *); |
---|
125 | #endif |
---|
126 | #if defined(USE_WIN32) |
---|
127 | int win32_install(caca_display_t *); |
---|
128 | #endif |
---|
129 | #if defined(USE_X11) |
---|
130 | int x11_install(caca_display_t *); |
---|
131 | #endif |
---|
132 | |
---|
133 | /* Timer structure */ |
---|
134 | struct caca_timer |
---|
135 | { |
---|
136 | int last_sec, last_usec; |
---|
137 | }; |
---|
138 | |
---|
139 | /* Private event structure */ |
---|
140 | struct 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 */ |
---|
153 | struct 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 */ |
---|
220 | extern uint32_t _caca_attr_to_rgb24fg(uint32_t); |
---|
221 | extern uint32_t _caca_attr_to_rgb24bg(uint32_t); |
---|
222 | |
---|
223 | /* Frames functions */ |
---|
224 | extern void _caca_save_frame_info(caca_canvas_t *); |
---|
225 | extern void _caca_load_frame_info(caca_canvas_t *); |
---|
226 | |
---|
227 | /* Internal timer functions */ |
---|
228 | extern void _caca_sleep(int); |
---|
229 | extern int _caca_getticks(caca_timer_t *); |
---|
230 | |
---|
231 | /* Internal event functions */ |
---|
232 | extern void _caca_handle_resize(caca_display_t *); |
---|
233 | #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) |
---|
234 | extern void _push_event(caca_display_t *, caca_privevent_t *); |
---|
235 | extern int _pop_event(caca_display_t *, caca_privevent_t *); |
---|
236 | #endif |
---|
237 | |
---|
238 | /* Internal window functions */ |
---|
239 | extern void _caca_set_term_title(char const *); |
---|
240 | |
---|
241 | #endif /* __CACA_INTERNALS_H__ */ |
---|