<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>libcaca documentation</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head> <body> <!-- $Id$ --> <!-- Generated by Doxygen 1.5.9 --> <div class="contents"> <h1><a class="anchor" name="libcaca-tutorial">A libcaca tutorial </a></h1>First, a very simple working program, to check for basic libcaca functionalities.<p> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="caca_8h.html" title="The libcaca public header.">caca.h</a>></span> <span class="keywordtype">int</span> main(<span class="keywordtype">void</span>) { <a class="code" href="caca_8h.html#ae0f6938d08e6e0abbcd5a8c06504ab8">caca_canvas_t</a> *cv; <a class="code" href="caca_8h.html#da5af7a20f3e2f6c103078181b07393e">caca_display_t</a> *dp; <a class="code" href="structcaca__event.html" title="Handling of user events.">caca_event_t</a> ev; dp = <a class="code" href="group__caca__display.html#gc393d4446d813f6e4ba93d2b583c1edb" title="Attach a caca graphical context to a caca canvas.">caca_create_display</a>(NULL); <span class="keywordflow">if</span>(!dp) <span class="keywordflow">return</span> 1; cv = <a class="code" href="group__caca__display.html#g65670cdec61ba57879b893c997cd26da" title="Get the canvas attached to a caca graphical context.">caca_get_canvas</a>(dp); <a class="code" href="group__caca__display.html#gdab2bf1e8d0bf5c3cfb3e29ab07d5641" title="Set the display title.">caca_set_display_title</a>(dp, <span class="stringliteral">"Hello!"</span>); <a class="code" href="group__caca__attributes.html#g1cd39df80cc6b537a4df18415a8605cf" title="Set the default colour pair for text (ANSI version).">caca_set_color_ansi</a>(cv, <a class="code" href="group__caca__attr.html#g14a182c346372cdd6fcaa54cf2a84f05">CACA_BLACK</a>, <a class="code" href="group__caca__attr.html#gdf659290c774e7aa588cfad292dae73f">CACA_WHITE</a>); <a class="code" href="group__caca__canvas.html#gc9370c0854f358b88d0cb8caf07fb6d3" title="Print a string.">caca_put_str</a>(cv, 0, 0, <span class="stringliteral">"This is a message"</span>); <a class="code" href="group__caca__display.html#g8c710eac721d05d807491a1534d1cbe7" title="Flush pending changes and redraw the screen.">caca_refresh_display</a>(dp); <a class="code" href="group__caca__event.html#g98e74dedbe1629c0fc9460761696e050" title="Get the next mouse or keyboard input event.">caca_get_event</a>(dp, <a class="code" href="caca_8h.html#40754185ca237fc44a95357afba34aeab1da825755a2ac3593cca73721b77e22">CACA_EVENT_KEY_PRESS</a>, &ev, -1); <a class="code" href="group__caca__display.html#gc1b5b4540a500dd59eaa673d784fab1f" title="Detach a caca graphical context from a caca backend context.">caca_free_display</a>(dp); <span class="keywordflow">return</span> 0; } </pre></div><p> What does it do?<ul> <li>Create a display. Physically, the display is either a window or a context in a terminal (ncurses, slang) or even the whole screen (VGA).</li><li>Get the display's associated canvas. A canvas is the surface where everything happens: writing characters, sprites, strings, images... It is unavoidable. Here the size of the canvas is set by the display.</li><li>Set the display's window name (only available in windowed displays, does nothing otherwise).</li><li>Set the current canvas colours to black background and white foreground.</li><li>Write the string "This is a message" using the current colors onto the canvas.</li><li>Refresh the display.</li><li>Wait for an event of type "CACA_EVENT_KEY_PRESS".</li><li>Free the display (release memory). Since it was created together with the display, the canvas will be automatically freed as well.</li></ul> <p> You can then compile this code on an UNIX-like system using the following comman (requiring pkg-config and gcc): <div class="fragment"><pre class="fragment">gcc `pkg-config --libs --cflags caca` example.c -o example </pre></div> </div> <!-- $Id$ --> </body> </html>