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