No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

227 líneas
7.3 KiB

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