25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

tutorial.dox 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* $Id$ */
  2. /** \page libcaca-tutorial A libcucul and libcaca tutorial
  3. Before writing your first libcaca application, you need to know the difference between libcucul and libcaca :
  4. - libcucul is the text rendering library. It will do all the work you actually need. From imports (text, ANSI, caca internal format, all of this supporting n-bytes unicode), to exports (sames formats, adding SVG, PostScript, TGA, HTML (both 3 and 4), IRC), it'll cover all your needs.
  5. - libcaca handle everything that can be hardware related. It includes display (RAW, X11, OpenGL, Windows (GDI), conio (DOS), ncurses, slang, text VGA (IMB-Compatible)), keyboard (same drivers but RAW), mouse (same drivers but RAW and VGA), time and resize events (on windowed drivers).
  6. So, you can write a libcucul only program, but you <b>can't</b> write a libcaca only program, it'll be nonsense. Period.
  7. First, a working program, very simple, to check you can compile and run it:
  8. \code
  9. #include <cucul.h>
  10. #include <caca.h>
  11. int main(void)
  12. {
  13. /* Initialise libcaca */
  14. cucul_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
  15. cv = cucul_create_canvas(0, 0);
  16. if(!cv) return 1;
  17. dp = caca_create_display(cv);
  18. if(!dp) return 1;
  19. /* Set window title */
  20. caca_set_display_title(dp, "Hello!");
  21. /* Choose drawing colours */
  22. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  23. /* Draw a string at coordinates (0, 0) */
  24. cucul_put_str(cv, 0, 0, "This is a message");
  25. /* Refresh display */
  26. caca_refresh_display(dp);
  27. /* Wait for a key press event */
  28. caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
  29. /* Clean up library */
  30. caca_free_display(dp);
  31. cucul_free_canvas(cv);
  32. return 0;
  33. }
  34. \endcode
  35. What does it do ? (we skip variable definitions, guessing you have a brain) :
  36. - Create a cucul canvas. A canvas is where everything happens. Writing characters, sprites, strings, images, everything. It is mandatory and is the reason of libcuculs' 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.
  37. - 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).
  38. - Set the window name of our display (only available in windowed displays, does nothing otherwise). (so this is libcaca related)
  39. - Set current colors to black background, and white foreground of our canvas (so this is libcucul related)
  40. - Put a string "This is a message" with current colors in our libcucul canvas.
  41. - Refresh our caca display, whish was firstly attached to our canvas
  42. - Wait for an event of type "CACA_EVENT_KEY_PRESS", which seems obvious.
  43. - Free display (release memory)
  44. - Free canvas (release memory and close window if any)
  45. You can then compile this code under UNIX-like systems with following command : (you'll need pkg-config and gcc)
  46. \code
  47. gcc `pkg-config --libs --cflags cucul caca` example.c -o example
  48. \endcode
  49. */