Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

tutorial.dox 1.7 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /** \page libcaca-tutorial A libcaca tutorial
  2. First, a very simple working program, to check for basic libcaca
  3. functionalities.
  4. \code
  5. #include <caca.h>
  6. int main(void)
  7. {
  8. caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
  9. dp = caca_create_display(NULL);
  10. if(!dp) return 1;
  11. cv = caca_get_canvas(dp);
  12. caca_set_display_title(dp, "Hello!");
  13. caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
  14. caca_put_str(cv, 0, 0, "This is a message");
  15. caca_refresh_display(dp);
  16. caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
  17. caca_free_display(dp);
  18. return 0;
  19. }
  20. \endcode
  21. What does it do?
  22. - Create a display. Physically, the display is either a window or a context
  23. in a terminal (ncurses, slang) or even the whole screen (VGA).
  24. - Get the display's associated canvas. A canvas is the surface where
  25. everything happens: writing characters, sprites, strings, images... It is
  26. unavoidable. Here the size of the canvas is set by the display.
  27. - Set the display's window name (only available in windowed displays, does
  28. nothing otherwise).
  29. - Set the current canvas colours to black background and white foreground.
  30. - Write the string \c "This is a message" onto the canvas, using the current
  31. colour pair.
  32. - Refresh the display, causing the text to be effectively displayed.
  33. - Wait for an event of type \c CACA_EVENT_KEY_PRESS.
  34. - Free the display (release memory). Since it was created together with the
  35. display, the canvas will be automatically freed as well.
  36. You can then compile this code on an UNIX-like system using the following
  37. commans (requiring \c pkg-config and \c gcc):
  38. \code
  39. gcc `pkg-config --libs --cflags caca` example.c -o example
  40. \endcode
  41. */