source: libcaca/trunk/caca/caca0.h @ 1013

Last change on this file since 1013 was 1013, checked in by Sam Hocevar, 13 years ago
  • Added an emulation layer for pre-1.0 libcaca API. Legacy applications just need to include <caca0.h> instead of <caca.h> and should be source- compatible with old versions of libcaca.

Most of the old API works, except features and caca_sqrt(). Sprites do
work API-wise but due to the new format they are no longer working in
the same way.

  • Property svn:keywords set to Id
File size: 7.0 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: caca0.h 1013 2006-09-09 15:38:06Z sam $
7 *
8 *  This library is free software; you can redistribute it and/or
9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14/*
15 *  This header contains glue code for applications using the pre-1.0
16 *  libcaca API.
17 */
18
19#ifndef __CACA0_H__
20#define __CACA0_H__
21
22#include <caca.h>
23
24#ifdef __cplusplus
25extern "C"
26{
27#endif
28
29/* Function emulation */
30extern int __caca0_init(void);
31extern void __caca0_end(void);
32extern unsigned int __caca0_get_event(unsigned int, int);
33extern int __caca0_get_feature(int);
34extern void __caca0_set_feature(int);
35extern char const *__caca0_get_feature_name(int);
36extern cucul_canvas_t *__caca0_load_sprite(char const *);
37
38/* These variables are needed to emulate old non-thread safe behaviour */
39extern cucul_canvas_t *__caca0_cv;
40extern caca_display_t *__caca0_dp;
41extern unsigned char __caca0_fg;
42extern unsigned char __caca0_bg;
43extern char __caca0_utf8[];
44
45/* These enums and macros changed names or values */
46enum caca_color
47{
48    CACA_COLOR_BLACK = CUCUL_COLOR_BLACK,
49    CACA_COLOR_BLUE = CUCUL_COLOR_BLUE,
50    CACA_COLOR_GREEN = CUCUL_COLOR_GREEN,
51    CACA_COLOR_CYAN = CUCUL_COLOR_CYAN,
52    CACA_COLOR_RED = CUCUL_COLOR_RED,
53    CACA_COLOR_MAGENTA = CUCUL_COLOR_MAGENTA,
54    CACA_COLOR_BROWN = CUCUL_COLOR_BROWN,
55    CACA_COLOR_LIGHTGRAY = CUCUL_COLOR_LIGHTGRAY,
56    CACA_COLOR_DARKGRAY = CUCUL_COLOR_DARKGRAY,
57    CACA_COLOR_LIGHTBLUE = CUCUL_COLOR_LIGHTBLUE,
58    CACA_COLOR_LIGHTGREEN = CUCUL_COLOR_LIGHTGREEN,
59    CACA_COLOR_LIGHTCYAN = CUCUL_COLOR_LIGHTCYAN,
60    CACA_COLOR_LIGHTRED = CUCUL_COLOR_LIGHTRED,
61    CACA_COLOR_LIGHTMAGENTA = CUCUL_COLOR_LIGHTMAGENTA,
62    CACA_COLOR_YELLOW = CUCUL_COLOR_YELLOW,
63    CACA_COLOR_WHITE = CUCUL_COLOR_WHITE,
64};
65
66enum caca_feature
67{
68    CACA_BACKGROUND       = 0x10,
69    CACA_BACKGROUND_BLACK = 0x11,
70    CACA_BACKGROUND_SOLID = 0x12,
71#define CACA_BACKGROUND_MIN 0x11
72#define CACA_BACKGROUND_MAX 0x12
73    CACA_ANTIALIASING           = 0x20,
74    CACA_ANTIALIASING_NONE      = 0x21,
75    CACA_ANTIALIASING_PREFILTER = 0x22,
76#define CACA_ANTIALIASING_MIN     0x21
77#define CACA_ANTIALIASING_MAX     0x22
78    CACA_DITHERING          = 0x30,
79    CACA_DITHERING_NONE     = 0x31,
80    CACA_DITHERING_ORDERED2 = 0x32,
81    CACA_DITHERING_ORDERED4 = 0x33,
82    CACA_DITHERING_ORDERED8 = 0x34,
83    CACA_DITHERING_RANDOM   = 0x35,
84#define CACA_DITHERING_MIN    0x31
85#define CACA_DITHERING_MAX    0x35
86    CACA_FEATURE_UNKNOWN = 0xffff
87};
88
89#define CACA_EVENT_NONE          0x00000000
90#define CACA_EVENT_KEY_PRESS     0x01000000
91#define CACA_EVENT_KEY_RELEASE   0x02000000
92#define CACA_EVENT_MOUSE_PRESS   0x04000000
93#define CACA_EVENT_MOUSE_RELEASE 0x08000000
94#define CACA_EVENT_MOUSE_MOTION  0x10000000
95#define CACA_EVENT_RESIZE        0x20000000
96#define CACA_EVENT_ANY           0xff000000
97
98/* Backwards compatibility macros for even older shit */
99#define caca_dithering caca_feature
100#define caca_set_dithering caca_set_feature
101#define caca_get_dithering_name caca_get_feature_name
102#define CACA_DITHER_NONE    CACA_DITHERING_NONE
103#define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8
104#define CACA_DITHER_RANDOM  CACA_DITHERING_RANDOM
105
106/* Macros to redefine all the shit */
107#define caca_init __caca0_init
108#define caca_set_delay(x) caca_set_display_time(__caca0_dp, x)
109#define caca_get_feature __caca0_get_feature
110#define caca_set_feature __caca0_set_feature
111#define caca_get_feature_name __caca0_get_feature_name
112#define caca_get_rendertime() caca_get_display_time(__caca0_dp)
113#define caca_get_width() cucul_get_canvas_width(__caca0_cv)
114#define caca_get_height() cucul_get_canvas_height(__caca0_cv)
115#define caca_set_window_title(s) caca_set_display_title(__caca0_dp, s)
116#define caca_get_window_width() caca_get_display_width(__caca0_dp)
117#define caca_get_window_height() caca_get_display_height(__caca0_dp)
118#define caca_refresh() caca_refresh_display(__caca0_dp)
119#define caca_end __caca0_end
120
121#define caca_get_event(x) __caca0_get_event(x, 0)
122#define caca_wait_event(x) __caca0_get_event(x, -1)
123#define caca_get_mouse_x() caca_get_mouse_x(__caca0_dp)
124#define caca_get_mouse_y() caca_get_mouse_y(__caca0_dp)
125
126#define caca_set_color(x, y) cucul_set_color(__caca0_cv, x, y)
127#define caca_get_color_name cucul_get_color_name
128#define caca_putchar(x, y, c) cucul_putchar(__caca0_cv, x, y, c)
129#define caca_putstr(x, y, s) cucul_putstr(__caca0_cv, x, y, s)
130#define caca_printf(x, y, f, z...) cucul_printf(__caca0_cv, x, y, f, ##z)
131#define caca_clear() cucul_clear_canvas(__caca0_cv)
132
133#define caca_draw_line(x, y, z, t, c) \
134    (__caca0_utf8[0] = c, \
135     cucul_draw_line(__caca0_cv, x, y, z, t, __caca0_utf8))
136#define caca_draw_polyline(x, y, z, c) \
137    (__caca0_utf8[0] = c, \
138     cucul_draw_polyline(__caca0_cv, x, y, z, __caca0_utf8))
139#define caca_draw_thin_line(x, y, z, t) \
140    cucul_draw_thin_line(__caca0_cv, x, y, z, t)
141#define caca_draw_thin_polyline(x, y, z) \
142    cucul_draw_thin_polyline(__caca0_cv, x, y, z)
143#define caca_draw_circle(x, y, z, c) \
144    (__caca0_utf8[0] = c, cucul_draw_circle(__caca0_cv, x, y, z, __caca0_utf8))
145#define caca_draw_ellipse(x, y, z, t, c) \
146    (__caca0_utf8[0] = c, \
147     cucul_draw_ellipse(__caca0_cv, x, y, z, t, __caca0_utf8))
148#define caca_draw_thin_ellipse(x, y, z, t) \
149    cucul_draw_thin_ellipse(__caca0_cv, x, y, z, t)
150#define caca_fill_ellipse(x, y, z, t, c) \
151    (__caca0_utf8[0] = c, \
152     cucul_fill_ellipse(__caca0_cv, x, y, z, t, __caca0_utf8))
153#define caca_draw_box(x, y, z, t, c) \
154    (__caca0_utf8[0] = c, cucul_draw_box(__caca0_cv, x, y, z, t, __caca0_utf8))
155#define caca_draw_thin_box(x, y, z, t) \
156    cucul_draw_thin_box(__caca0_cv, x, y, z, t)
157#define caca_fill_box(x, y, z, t, c) \
158    (__caca0_utf8[0] = c, cucul_fill_box(__caca0_cv, x, y, z, t, __caca0_utf8))
159#define caca_draw_triangle(x, y, z, t, u, v, c) \
160    (__caca0_utf8[0] = c, \
161     cucul_draw_triangle(__caca0_cv, x, y, z, t, u, v, __caca0_utf8))
162#define caca_draw_thin_triangle(x, y, z, t, u, v) \
163    cucul_draw_thin_triangle(__caca0_cv, x, y, z, t, u, v)
164#define caca_fill_triangle(x, y, z, t, u, v, c) \
165    (__caca0_utf8[0] = c, \
166     cucul_fill_triangle(__caca0_cv, x, y, z, t, u, v, __caca0_utf8))
167
168#define caca_rand(a, b) cucul_rand(a, (b)+1)
169
170#define caca_sprite cucul_canvas
171#define caca_load_sprite __caca0_load_sprite
172#define caca_get_sprite_frames(c) 0
173#define caca_get_sprite_width(c, f) cucul_get_canvas_width(c)
174#define caca_get_sprite_height(c, f) cucul_get_canvas_height(c)
175#define caca_get_sprite_dx(c, f) 0
176#define caca_get_sprite_dx(c, f) 0
177#define caca_draw_sprite(x, y, c, f) cucul_blit(__caca0_cv, x, y, c, NULL)
178#define caca_free_sprite cucul_free_canvas
179
180#define caca_bitmap cucul_dither
181#define caca_create_bitmap cucul_create_dither
182#define caca_set_bitmap_palette cucul_set_dither_palette
183#define caca_draw_bitmap(x, y, z, t, b, p) \
184    cucul_dither_bitmap(__caca0_cv, x, y, z, t, b, p)
185#define caca_free_bitmap cucul_free_dither
186
187#ifdef __cplusplus
188}
189#endif
190
191#endif /* __CACA0_H__ */
Note: See TracBrowser for help on using the repository browser.