您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

191 行
6.3 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(cv, CUCUL_COLOR_BLACK,
  49. CUCUL_COLOR_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 Function equivalence list
  69. \subsection bar1 Basic functions
  70. - \b caca_init(): use cucul_create_canvas() to create a \e libcucul canvas,
  71. followed by caca_create_display() to attach a \e libcaca display to it.
  72. - \b caca_set_delay(): unchanged.
  73. - \b caca_get_feature(): deprecated.
  74. - \b caca_set_feature(): deprecated, see cucul_set_dither_antialias(),
  75. cucul_set_dither_color() and cucul_set_dither_mode() instead.
  76. - \b caca_get_feature_name(): deprecated, see cucul_get_dither_mode_list(),
  77. cucul_get_dither_antialias_list() and cucul_get_dither_color_list()
  78. instead.
  79. - \b caca_get_rendertime(): unchanged.
  80. - \b caca_get_width(): use cucul_get_canvas_width().
  81. - \b caca_get_height(): use cucul_get_canvas_height().
  82. - \b caca_set_window_title(): use caca_set_display_title().
  83. - \b caca_get_window_width(): use caca_get_display_width().
  84. - \b caca_get_window_height(): use caca_get_display_height().
  85. - \b caca_refresh(): use caca_refresh_display().
  86. - \b caca_end(): use caca_free_display() to detach the \e libcaca display,
  87. followed by cucul_free_canvas() to free the underlying \e libcucul canvas.
  88. \subsection bar2 Event handling
  89. - \b caca_get_event(): unchanged, but the event information retrieval
  90. changed a lot.
  91. - \b caca_wait_event(): use caca_get_event() with a \c timeout argument
  92. of \b -1.
  93. - \b caca_get_mouse_x(): unchanged.
  94. - \b caca_get_mouse_y(): unchanged.
  95. \subsection bar3 Character printing
  96. - \b caca_set_color(): use cucul_set_color() or cucul_set_truecolor().
  97. - \b caca_get_fg_color(): deprecated.
  98. - \b caca_get_bg_color(): deprecated.
  99. - \b caca_get_color_name(): use cucul_get_color_name().
  100. - \b caca_putchar(): use cucul_putchar().
  101. - \b caca_putstr(): use cucul_putstr().
  102. - \b caca_printf(): use cucul_printf().
  103. - \b caca_clear(): use cucul_clear_canvas().
  104. \subsection bar4 Primitives drawing
  105. These functions are almost unchanged, except for Unicode support and the
  106. fact that they now act on a given canvas.
  107. - \b caca_draw_line(): use cucul_draw_line().
  108. - \b caca_draw_polyline(): use cucul_draw_polyline().
  109. - \b caca_draw_thin_line(): use cucul_draw_thin_line().
  110. - \b caca_draw_thin_polyline(): use cucul_draw_thin_polyline().
  111. - \b caca_draw_circle(): use cucul_draw_circle().
  112. - \b caca_draw_ellipse(): use cucul_draw_ellipse().
  113. - \b caca_draw_thin_ellipse(): use cucul_draw_thin_ellipse().
  114. - \b caca_fill_ellipse(): use cucul_fill_ellipse().
  115. - \b caca_draw_box(): use cucul_draw_box().
  116. - \b caca_draw_thin_box(): use cucul_draw_thin_box().
  117. - \b caca_fill_box(): use cucul_fill_box().
  118. - \b caca_draw_triangle(): use cucul_draw_triangle().
  119. - \b caca_draw_thin_triangle(): use cucul_draw_thin_triangle().
  120. - \b caca_fill_triangle(): use cucul_fill_triangle().
  121. \subsection bar5 Mathematical functions
  122. - \b caca_rand(): use cucul_rand(). The second argument is different, make
  123. sure you take that into account.
  124. - \b caca_sqrt(): this function is now deprecated, use your system's
  125. \b sqrt() call instead.
  126. \subsection bar6 Sprite handling
  127. The newly introduced canvases can have several frames. Sprites are hence
  128. completely deprecated.
  129. - \b caca_load_sprite(): use cucul_import_canvas().
  130. - \b caca_get_sprite_frames(): use cucul_get_canvas_frame_count().
  131. - \b caca_get_sprite_width(): use cucul_get_canvas_width().
  132. - \b caca_get_sprite_height(): use cucul_get_canvas_height().
  133. - \b caca_get_sprite_dx(): this function is now deprecated.
  134. - \b caca_get_sprite_dy(): this function is now deprecated.
  135. - \b caca_draw_sprite(): use cucul_set_canvas_frame() and cucul_blit().
  136. - \b caca_free_sprite(): use cucul_free_canvas().
  137. \subsection bar7 Bitmap handling
  138. Bitmaps have been renamed to dithers, because these objects do not in fact
  139. store any pixels, they just have information on how bitmaps will be dithered.
  140. - \b caca_create_bitmap(): use cucul_create_dither().
  141. - \b caca_set_bitmap_palette(): use cucul_set_dither_palette().
  142. - \b caca_draw_bitmap(): use cucul_dither_bitmap().
  143. - \b caca_free_bitmap(): use cucul_free_dither().
  144. \section foo3 Compilation
  145. The \c caca-config utility is deprecated in favour of the standard
  146. \c pkg-config interface:
  147. \code
  148. gcc -c foobar.c -o foobar.o `pkg-config --cflags caca`
  149. gcc foobar.o -o foobar `pkg-config --libs caca`
  150. \endcode
  151. \c caca-config is still provided as a convenience tool but will be removed
  152. in the future.
  153. */