Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

222 рядки
7.0 KiB

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