[824] | 1 | /* $Id: migrating.dox 3482 2009-05-19 20:42:28Z sam $ */ |
---|
| 2 | |
---|
[1879] | 3 | /** \page libcaca-migrating Migrating from libcaca 0.x to the 1.0 API |
---|
[824] | 4 | |
---|
[836] | 5 | This section will guide you through the migration of a \e libcaca 0.x |
---|
[824] | 6 | application to the latest API version. |
---|
| 7 | |
---|
| 8 | \section foo1 Overview |
---|
| 9 | |
---|
[2824] | 10 | The most important change in the 1.0 API of \e libcaca is the |
---|
| 11 | object-oriented design. See these two examples for a rough idea of |
---|
| 12 | what changed: |
---|
[824] | 13 | |
---|
[845] | 14 | <table border="0"><tr><td valign="top"> |
---|
[824] | 15 | \code |
---|
| 16 | #include <caca.h> |
---|
| 17 | |
---|
[848] | 18 | /* libcaca program - 0.x API */ |
---|
[824] | 19 | int main(void) |
---|
| 20 | { |
---|
| 21 | /* Initialise libcaca */ |
---|
| 22 | caca_init(); |
---|
| 23 | /* Set window title */ |
---|
[845] | 24 | caca_set_window_title("Window"); |
---|
[824] | 25 | /* Choose drawing colours */ |
---|
[845] | 26 | caca_set_color(CACA_COLOR_BLACK, |
---|
| 27 | CACA_COLOR_WHITE); |
---|
| 28 | /* Draw a string at (0, 0) */ |
---|
| 29 | caca_putstr(0, 0, "Hello world!"); |
---|
[824] | 30 | /* Refresh display */ |
---|
| 31 | caca_refresh(); |
---|
| 32 | /* Wait for a key press event */ |
---|
| 33 | caca_wait_event(CACA_EVENT_KEY_PRESS); |
---|
| 34 | /* Clean up library */ |
---|
| 35 | caca_end(); |
---|
| 36 | |
---|
| 37 | return 0; |
---|
| 38 | } |
---|
| 39 | \endcode |
---|
[845] | 40 | </td><td> |
---|
[824] | 41 | \code |
---|
| 42 | #include <caca.h> |
---|
| 43 | |
---|
[848] | 44 | /* libcaca program - 1.0 API */ |
---|
[824] | 45 | int main(void) |
---|
| 46 | { |
---|
| 47 | /* Initialise libcaca */ |
---|
[2824] | 48 | caca_canvas_t *cv; |
---|
[849] | 49 | caca_display_t *dp; |
---|
[3473] | 50 | dp = caca_create_display(NULL); |
---|
[2062] | 51 | cv = caca_get_canvas(dp); |
---|
[824] | 52 | /* Set window title */ |
---|
[845] | 53 | caca_set_display_title(dp, "Window"); |
---|
[824] | 54 | /* Choose drawing colours */ |
---|
[2824] | 55 | caca_set_color_ansi(cv, CACA_BLACK, |
---|
| 56 | CACA_WHITE); |
---|
[845] | 57 | /* Draw a string at (0, 0) */ |
---|
[2824] | 58 | caca_put_str(cv, 0, 0, "Hello world!"); |
---|
[824] | 59 | /* Refresh display */ |
---|
| 60 | caca_refresh_display(); |
---|
| 61 | /* Wait for a key press event */ |
---|
[845] | 62 | caca_get_event(dp, CACA_EVENT_KEY_PRESS, |
---|
[849] | 63 | NULL, -1); |
---|
[824] | 64 | /* Clean up library */ |
---|
| 65 | caca_free_display(dp); |
---|
| 66 | |
---|
| 67 | return 0; |
---|
| 68 | } |
---|
| 69 | \endcode |
---|
[845] | 70 | </td></tr></table> |
---|
[824] | 71 | |
---|
| 72 | Note the following important things: |
---|
| 73 | |
---|
[3473] | 74 | - Most functions now take an object handle as their first argument. |
---|
[824] | 75 | |
---|
[1016] | 76 | \section foo2 Migration strategy |
---|
[824] | 77 | |
---|
[1016] | 78 | You have two ways to migrate your application to use \e libcaca 1.x: |
---|
| 79 | |
---|
| 80 | - Port your code using the function equivalence list. This is the preferred |
---|
| 81 | way because new functions are thread safe and offer much more features |
---|
| 82 | to both the programmer and the end user. |
---|
| 83 | - Use the legacy compatibility layer. |
---|
| 84 | |
---|
| 85 | Using the compatibility layer is as easy as adding the following three lines: |
---|
| 86 | |
---|
| 87 | <table border="0"><tr><td valign="top"> |
---|
| 88 | \code |
---|
| 89 | #include <caca.h> |
---|
| 90 | |
---|
| 91 | /* libcaca program - 0.x API */ |
---|
| 92 | ... |
---|
| 93 | \endcode |
---|
| 94 | </td><td> |
---|
| 95 | \code |
---|
| 96 | #include <caca.h> |
---|
[1017] | 97 | #ifdef CACA_API_VERSION_1 |
---|
[1016] | 98 | # include <caca0.h> |
---|
| 99 | #endif |
---|
| 100 | |
---|
| 101 | /* libcaca program - 0.x API */ |
---|
| 102 | ... |
---|
| 103 | \endcode |
---|
| 104 | </td></tr></table> |
---|
| 105 | |
---|
[3473] | 106 | The modified code is guaranteed to build both with \e libcaca 0.x and |
---|
| 107 | \e libcaca 1.0. |
---|
| 108 | |
---|
[1016] | 109 | \section foo3 Function equivalence list |
---|
| 110 | |
---|
[824] | 111 | \subsection bar1 Basic functions |
---|
| 112 | |
---|
[2824] | 113 | - \b caca_init(): use caca_create_canvas() to create a \e libcaca canvas, |
---|
[824] | 114 | followed by caca_create_display() to attach a \e libcaca display to it. |
---|
[1016] | 115 | - \b caca_set_delay(): use caca_set_display_time(). |
---|
[824] | 116 | - \b caca_get_feature(): deprecated. |
---|
[2824] | 117 | - \b caca_set_feature(): deprecated, see caca_set_dither_antialias(), |
---|
| 118 | caca_set_dither_color() and caca_set_dither_mode() instead. |
---|
| 119 | - \b caca_get_feature_name(): deprecated, see caca_get_dither_mode_list(), |
---|
| 120 | caca_get_dither_antialias_list() and caca_get_dither_color_list() |
---|
[824] | 121 | instead. |
---|
[1016] | 122 | - \b caca_get_rendertime(): use caca_get_display_time(). |
---|
[2824] | 123 | - \b caca_get_width(): use caca_get_canvas_width(). |
---|
| 124 | - \b caca_get_height(): use caca_get_canvas_height(). |
---|
[824] | 125 | - \b caca_set_window_title(): use caca_set_display_title(). |
---|
| 126 | - \b caca_get_window_width(): use caca_get_display_width(). |
---|
| 127 | - \b caca_get_window_height(): use caca_get_display_height(). |
---|
| 128 | - \b caca_refresh(): use caca_refresh_display(). |
---|
| 129 | - \b caca_end(): use caca_free_display() to detach the \e libcaca display, |
---|
[2824] | 130 | followed by caca_free_canvas() to free the underlying \e libcaca canvas. |
---|
[824] | 131 | |
---|
| 132 | \subsection bar2 Event handling |
---|
| 133 | |
---|
[845] | 134 | - \b caca_get_event(): unchanged, but the event information retrieval |
---|
| 135 | changed a lot. |
---|
[824] | 136 | - \b caca_wait_event(): use caca_get_event() with a \c timeout argument |
---|
| 137 | of \b -1. |
---|
| 138 | - \b caca_get_mouse_x(): unchanged. |
---|
| 139 | - \b caca_get_mouse_y(): unchanged. |
---|
| 140 | |
---|
| 141 | \subsection bar3 Character printing |
---|
| 142 | |
---|
[2824] | 143 | - \b caca_set_color(): use caca_set_color_ansi() or caca_set_color_argb(). |
---|
| 144 | - \b caca_get_fg_color(): use caca_get_attr(). |
---|
| 145 | - \b caca_get_bg_color(): use caca_get_attr(). |
---|
[1269] | 146 | - \b caca_get_color_name(): this function is now deprecated due to major |
---|
| 147 | uselessness. |
---|
[2824] | 148 | - \b caca_putchar(): use caca_put_char(). |
---|
| 149 | - \b caca_putstr(): use caca_put_str(). |
---|
[3473] | 150 | - \b caca_printf(): unchanged. |
---|
[2824] | 151 | - \b caca_clear(): use caca_clear_canvas(). |
---|
[824] | 152 | |
---|
| 153 | \subsection bar4 Primitives drawing |
---|
| 154 | |
---|
[845] | 155 | These functions are almost unchanged, except for Unicode support and the |
---|
| 156 | fact that they now act on a given canvas. |
---|
| 157 | |
---|
[3473] | 158 | - \b caca_draw_line(): unchanged. |
---|
| 159 | - \b caca_draw_polyline(): unchanged. |
---|
| 160 | - \b caca_draw_thin_line(): unchanged. |
---|
| 161 | - \b caca_draw_thin_polyline(): unchanged. |
---|
[824] | 162 | |
---|
[3473] | 163 | - \b caca_draw_circle(): unchanged. |
---|
| 164 | - \b caca_draw_ellipse(): unchanged. |
---|
| 165 | - \b caca_draw_thin_ellipse(): unchanged. |
---|
| 166 | - \b caca_fill_ellipse(): unchanged. |
---|
[824] | 167 | |
---|
[3482] | 168 | - \b caca_draw_box(): unchanged, but the argument meaning changed (width |
---|
| 169 | and height instead of corner coordinates). |
---|
| 170 | - \b caca_draw_thin_box(): use caca_draw_thin_box() or caca_draw_cp437_box(), |
---|
| 171 | also the argument meaning changed (width |
---|
| 172 | and height instead of corner coordinates). |
---|
| 173 | - \b caca_fill_box(): unchanged, but the argument meaning changed (width |
---|
| 174 | and height instead of corner coordinates). |
---|
[824] | 175 | |
---|
[3473] | 176 | - \b caca_draw_triangle(): unchanged. |
---|
| 177 | - \b caca_draw_thin_triangle(): unchanged. |
---|
| 178 | - \b caca_fill_triangle(): unchanged. |
---|
[824] | 179 | |
---|
| 180 | \subsection bar5 Mathematical functions |
---|
| 181 | |
---|
[3473] | 182 | - \b caca_rand(): unchanged, but the second argument is different, make |
---|
[845] | 183 | sure you take that into account. |
---|
| 184 | - \b caca_sqrt(): this function is now deprecated, use your system's |
---|
| 185 | \b sqrt() call instead. |
---|
[824] | 186 | |
---|
| 187 | \subsection bar6 Sprite handling |
---|
| 188 | |
---|
[845] | 189 | The newly introduced canvases can have several frames. Sprites are hence |
---|
| 190 | completely deprecated. |
---|
[824] | 191 | |
---|
[2824] | 192 | - \b caca_load_sprite(): use caca_import_file(). |
---|
| 193 | - \b caca_get_sprite_frames(): use caca_get_frame_count(). |
---|
| 194 | - \b caca_get_sprite_width(): use caca_get_canvas_width(). |
---|
| 195 | - \b caca_get_sprite_height(): use caca_get_canvas_height(). |
---|
| 196 | - \b caca_get_sprite_dx(): use caca_get_canvas_handle_x(). |
---|
| 197 | - \b caca_get_sprite_dy(): use caca_get_canvas_handle_y(). |
---|
| 198 | - \b caca_draw_sprite(): use caca_set_frame() and caca_blit(). |
---|
| 199 | - \b caca_free_sprite(): use caca_free_canvas(). |
---|
[845] | 200 | |
---|
[824] | 201 | \subsection bar7 Bitmap handling |
---|
| 202 | |
---|
[845] | 203 | Bitmaps have been renamed to dithers, because these objects do not in fact |
---|
| 204 | store any pixels, they just have information on how bitmaps will be dithered. |
---|
| 205 | |
---|
[2824] | 206 | - \b caca_create_bitmap(): use caca_create_dither(). |
---|
| 207 | - \b caca_set_bitmap_palette(): use caca_set_dither_palette(). |
---|
| 208 | - \b caca_draw_bitmap(): use caca_dither_bitmap(). |
---|
| 209 | - \b caca_free_bitmap(): use caca_free_dither(). |
---|
[824] | 210 | |
---|
[1016] | 211 | \section foo4 Compilation |
---|
[824] | 212 | |
---|
| 213 | The \c caca-config utility is deprecated in favour of the standard |
---|
| 214 | \c pkg-config interface: |
---|
| 215 | |
---|
| 216 | \code |
---|
| 217 | gcc -c foobar.c -o foobar.o `pkg-config --cflags caca` |
---|
| 218 | gcc foobar.o -o foobar `pkg-config --libs caca` |
---|
| 219 | \endcode |
---|
| 220 | |
---|
[1369] | 221 | \c caca-config is still provided as a convenience tool but may be removed |
---|
[824] | 222 | in the future. |
---|
| 223 | |
---|
| 224 | */ |
---|