1 | /* $Id: tutorial.dox 2824 2008-09-27 14:29:11Z sam $ */ |
---|
2 | |
---|
3 | /** \page libcaca-tutorial A libcaca tutorial |
---|
4 | |
---|
5 | First, a working program, very simple, to check you can compile and run it: |
---|
6 | |
---|
7 | \code |
---|
8 | |
---|
9 | #include <caca.h> |
---|
10 | #include <caca.h> |
---|
11 | |
---|
12 | int main(void) |
---|
13 | { |
---|
14 | /* Initialise libcaca */ |
---|
15 | caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev; |
---|
16 | dp = caca_create_display(NULL); |
---|
17 | if(!dp) return 1; |
---|
18 | cv = caca_get_canvas(dp); |
---|
19 | /* Set window title */ |
---|
20 | caca_set_display_title(dp, "Hello!"); |
---|
21 | /* Choose drawing colours */ |
---|
22 | caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE); |
---|
23 | /* Draw a string at coordinates (0, 0) */ |
---|
24 | caca_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 | |
---|
32 | return 0; |
---|
33 | } |
---|
34 | |
---|
35 | \endcode |
---|
36 | |
---|
37 | |
---|
38 | What does it do ? (we skip variable definitions, guessing you have a brain) : |
---|
39 | - 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. |
---|
40 | |
---|
41 | - 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). |
---|
42 | |
---|
43 | - Set the window name of our display (only available in windowed displays, does nothing otherwise). (so this is libcaca related) |
---|
44 | |
---|
45 | - Set current colors to black background, and white foreground of our canvas (so this is libcaca related) |
---|
46 | |
---|
47 | - Put a string "This is a message" with current colors in our libcaca canvas. |
---|
48 | |
---|
49 | - Refresh our caca display, whish was firstly attached to our canvas |
---|
50 | |
---|
51 | - Wait for an event of type "CACA_EVENT_KEY_PRESS", which seems obvious. |
---|
52 | |
---|
53 | - Free display (release memory) |
---|
54 | |
---|
55 | - Free canvas (release memory and close window if any) |
---|
56 | |
---|
57 | |
---|
58 | You can then compile this code under UNIX-like systems with following command : (you'll need pkg-config and gcc) |
---|
59 | \code |
---|
60 | gcc `pkg-config --libs --cflags caca` example.c -o example |
---|
61 | \endcode |
---|
62 | |
---|
63 | */ |
---|