You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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