source: libcaca/trunk/doc/tutorial.dox @ 4300

Last change on this file since 4300 was 3473, checked in by Sam Hocevar, 11 years ago

A lot of documentation updates here and there, including bugfixes dating
back to the libcucul merge.

  • Property svn:keywords set to Id
File size: 1.7 KB
RevLine 
[836]1/* $Id: tutorial.dox 3473 2009-05-19 00:52:10Z sam $ */
2
[2824]3/** \page libcaca-tutorial A libcaca tutorial
[836]4
[2879]5First, a very simple working program, to check for basic libcaca
6functionalities.
[1279]7
[836]8\code
[1279]9
[836]10#include <caca.h>
11
12int main(void)
13{
[2824]14    caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
[2879]15
[2062]16    dp = caca_create_display(NULL);
[1946]17    if(!dp) return 1;
[2062]18    cv = caca_get_canvas(dp);
[2879]19
[836]20    caca_set_display_title(dp, "Hello!");
[2824]21    caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
22    caca_put_str(cv, 0, 0, "This is a message");
[923]23    caca_refresh_display(dp);
[836]24    caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
25    caca_free_display(dp);
26
27    return 0;
28}
[1279]29
[836]30\endcode
31
[2879]32What 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.
[3473]41 - Write the string \c "This is a message" onto the canvas, using the current
42   colour pair.
43 - Refresh the display, causing the text to be effectively displayed.
44 - Wait for an event of type \c CACA_EVENT_KEY_PRESS.
[2879]45 - Free the display (release memory). Since it was created together with the
46   display, the canvas will be automatically freed as well.
[1279]47
[2879]48You can then compile this code on an UNIX-like system using the following
[3473]49commans (requiring \c pkg-config and \c gcc):
[1280]50\code
[2824]51gcc `pkg-config --libs --cflags caca` example.c -o example
[1280]52\endcode
53
[836]54*/
Note: See TracBrowser for help on using the repository browser.