| 1 | /* |
|---|
| 2 | * libcaca Colour ASCII-Art library |
|---|
| 3 | * Copyright (c) 2002-2006 Sam Hocevar <sam@hocevar.net> |
|---|
| 4 | * All Rights Reserved |
|---|
| 5 | * |
|---|
| 6 | * $Id$ |
|---|
| 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 | # define MAX_DIRTY_COUNT 8 |
|---|
| 27 | #endif |
|---|
| 28 | |
|---|
| 29 | struct 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 | |
|---|
| 47 | struct 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, dirty_disabled; |
|---|
| 64 | struct |
|---|
| 65 | { |
|---|
| 66 | int xmin, ymin, xmax, ymax; |
|---|
| 67 | } |
|---|
| 68 | dirty[MAX_DIRTY_COUNT + 1]; |
|---|
| 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 */ |
|---|
| 81 | enum caca_driver |
|---|
| 82 | { |
|---|
| 83 | CACA_DRIVER_NULL = 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) |
|---|
| 113 | int cocoa_install(caca_display_t *); |
|---|
| 114 | #endif |
|---|
| 115 | #if defined(USE_CONIO) |
|---|
| 116 | int conio_install(caca_display_t *); |
|---|
| 117 | #endif |
|---|
| 118 | #if defined(USE_GL) |
|---|
| 119 | int gl_install(caca_display_t *); |
|---|
| 120 | #endif |
|---|
| 121 | #if defined(USE_NCURSES) |
|---|
| 122 | int ncurses_install(caca_display_t *); |
|---|
| 123 | #endif |
|---|
| 124 | int null_install(caca_display_t *); |
|---|
| 125 | int raw_install(caca_display_t *); |
|---|
| 126 | #if defined(USE_SLANG) |
|---|
| 127 | int slang_install(caca_display_t *); |
|---|
| 128 | #endif |
|---|
| 129 | #if defined(USE_VGA) |
|---|
| 130 | int vga_install(caca_display_t *); |
|---|
| 131 | #endif |
|---|
| 132 | #if defined(USE_WIN32) |
|---|
| 133 | int win32_install(caca_display_t *); |
|---|
| 134 | #endif |
|---|
| 135 | #if defined(USE_X11) |
|---|
| 136 | int x11_install(caca_display_t *); |
|---|
| 137 | #endif |
|---|
| 138 | |
|---|
| 139 | /* Timer structure */ |
|---|
| 140 | struct caca_timer |
|---|
| 141 | { |
|---|
| 142 | int last_sec, last_usec; |
|---|
| 143 | }; |
|---|
| 144 | |
|---|
| 145 | /* Private event structure */ |
|---|
| 146 | struct caca_privevent |
|---|
| 147 | { |
|---|
| 148 | enum caca_event_type type; |
|---|
| 149 | |
|---|
| 150 | union |
|---|
| 151 | { |
|---|
| 152 | struct { int x, y, button; } mouse; |
|---|
| 153 | struct { int w, h; } resize; |
|---|
| 154 | struct { int ch; uint32_t utf32; char utf8[8]; } key; |
|---|
| 155 | } data; |
|---|
| 156 | }; |
|---|
| 157 | |
|---|
| 158 | /* Internal caca display context */ |
|---|
| 159 | struct caca_display |
|---|
| 160 | { |
|---|
| 161 | /* A link to our caca canvas */ |
|---|
| 162 | caca_canvas_t *cv; |
|---|
| 163 | int autorelease; |
|---|
| 164 | |
|---|
| 165 | #if defined(USE_PLUGINS) |
|---|
| 166 | void *plugin; |
|---|
| 167 | #endif |
|---|
| 168 | |
|---|
| 169 | /* Device-specific functions */ |
|---|
| 170 | struct drv |
|---|
| 171 | { |
|---|
| 172 | char const * driver; |
|---|
| 173 | enum caca_driver id; |
|---|
| 174 | struct driver_private *p; |
|---|
| 175 | |
|---|
| 176 | int (* init_graphics) (caca_display_t *); |
|---|
| 177 | int (* end_graphics) (caca_display_t *); |
|---|
| 178 | int (* set_display_title) (caca_display_t *, char const *); |
|---|
| 179 | int (* get_display_width) (caca_display_t const *); |
|---|
| 180 | int (* get_display_height) (caca_display_t const *); |
|---|
| 181 | void (* display) (caca_display_t *); |
|---|
| 182 | void (* handle_resize) (caca_display_t *); |
|---|
| 183 | int (* get_event) (caca_display_t *, caca_privevent_t *); |
|---|
| 184 | void (* set_mouse) (caca_display_t *, int); |
|---|
| 185 | void (* set_cursor) (caca_display_t *, int); |
|---|
| 186 | } drv; |
|---|
| 187 | |
|---|
| 188 | /* Mouse position */ |
|---|
| 189 | struct mouse |
|---|
| 190 | { |
|---|
| 191 | int x, y; |
|---|
| 192 | } mouse; |
|---|
| 193 | |
|---|
| 194 | /* Window resize handling */ |
|---|
| 195 | struct resize |
|---|
| 196 | { |
|---|
| 197 | int resized; /* A resize event was requested */ |
|---|
| 198 | int allow; /* The display driver allows resizing */ |
|---|
| 199 | int w, h; /* Requested width and height */ |
|---|
| 200 | } resize; |
|---|
| 201 | |
|---|
| 202 | /* Framerate handling */ |
|---|
| 203 | int delay, rendertime; |
|---|
| 204 | caca_timer_t timer; |
|---|
| 205 | int lastticks; |
|---|
| 206 | |
|---|
| 207 | struct events |
|---|
| 208 | { |
|---|
| 209 | #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) |
|---|
| 210 | caca_privevent_t buf[EVENTBUF_LEN]; |
|---|
| 211 | int queue; |
|---|
| 212 | #endif |
|---|
| 213 | #if defined(USE_SLANG) || defined(USE_NCURSES) |
|---|
| 214 | caca_timer_t key_timer; |
|---|
| 215 | int last_key_ticks; |
|---|
| 216 | int autorepeat_ticks; |
|---|
| 217 | caca_privevent_t last_key_event; |
|---|
| 218 | #endif |
|---|
| 219 | #if defined(USE_WIN32) |
|---|
| 220 | uint8_t not_empty_struct; |
|---|
| 221 | #endif |
|---|
| 222 | } events; |
|---|
| 223 | }; |
|---|
| 224 | |
|---|
| 225 | /* Dirty rectangle functions */ |
|---|
| 226 | extern void _caca_clip_dirty_rect_list(caca_canvas_t *); |
|---|
| 227 | |
|---|
| 228 | /* Colour functions */ |
|---|
| 229 | extern uint32_t _caca_attr_to_rgb24fg(uint32_t); |
|---|
| 230 | extern uint32_t _caca_attr_to_rgb24bg(uint32_t); |
|---|
| 231 | |
|---|
| 232 | /* Frames functions */ |
|---|
| 233 | extern void _caca_save_frame_info(caca_canvas_t *); |
|---|
| 234 | extern void _caca_load_frame_info(caca_canvas_t *); |
|---|
| 235 | |
|---|
| 236 | /* Internal timer functions */ |
|---|
| 237 | extern void _caca_sleep(int); |
|---|
| 238 | extern int _caca_getticks(caca_timer_t *); |
|---|
| 239 | |
|---|
| 240 | /* Internal event functions */ |
|---|
| 241 | extern void _caca_handle_resize(caca_display_t *); |
|---|
| 242 | #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) |
|---|
| 243 | extern void _push_event(caca_display_t *, caca_privevent_t *); |
|---|
| 244 | extern int _pop_event(caca_display_t *, caca_privevent_t *); |
|---|
| 245 | #endif |
|---|
| 246 | |
|---|
| 247 | /* Internal window functions */ |
|---|
| 248 | extern void _caca_set_term_title(char const *); |
|---|
| 249 | |
|---|
| 250 | #endif /* __CACA_INTERNALS_H__ */ |
|---|