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.
 
 
 
 
 
 

64 lines
2.1 KiB

  1. /* $Id$ */
  2. /** \page libcaca-tutorial A libcaca tutorial
  3. First, a working program, very simple, to check you can compile and run it:
  4. \code
  5. #include <caca.h>
  6. #include <caca.h>
  7. int main(void)
  8. {
  9. /* Initialise libcaca */
  10. caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
  11. dp = caca_create_display(NULL);
  12. if(!dp) return 1;
  13. cv = caca_get_canvas(dp);
  14. /* Set window title */
  15. caca_set_display_title(dp, "Hello!");
  16. /* Choose drawing colours */
  17. caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
  18. /* Draw a string at coordinates (0, 0) */
  19. caca_put_str(cv, 0, 0, "This is a message");
  20. /* Refresh display */
  21. caca_refresh_display(dp);
  22. /* Wait for a key press event */
  23. caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
  24. /* Clean up library */
  25. caca_free_display(dp);
  26. return 0;
  27. }
  28. \endcode
  29. What does it do ? (we skip variable definitions, guessing you have a brain) :
  30. - Create a caca canvas. A canvas is where everything happens. Writing characters, sprites, strings, images, everything. It is mandatory and is the reason of libcacas' beeing. Size is there a width of 0 pixels, and a height of 0 pixels. It'll be resized according to contents you put in it.
  31. - Create a caca display. This is basically the window. Physically it can be a window (most of the displays), a console (ncurses, slang) or a real display (VGA).
  32. - Set the window name of our display (only available in windowed displays, does nothing otherwise). (so this is libcaca related)
  33. - Set current colors to black background, and white foreground of our canvas (so this is libcaca related)
  34. - Put a string "This is a message" with current colors in our libcaca canvas.
  35. - Refresh our caca display, whish was firstly attached to our canvas
  36. - Wait for an event of type "CACA_EVENT_KEY_PRESS", which seems obvious.
  37. - Free display (release memory)
  38. - Free canvas (release memory and close window if any)
  39. You can then compile this code under UNIX-like systems with following command : (you'll need pkg-config and gcc)
  40. \code
  41. gcc `pkg-config --libs --cflags caca` example.c -o example
  42. \endcode
  43. */