Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-release > by-pkgid > 2a9a0500ba8dfb95025148f22d49b751 > files > 77

lib64caca-devel-0.99-0.beta18.13.mga6.x86_64.rpm

<!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>
<!-- Generated by Doxygen 1.8.11 -->
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">A libcaca tutorial </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>First, a very simple working program, to check for basic libcaca functionalities.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="caca_8h.html">caca.h</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">    <a class="code" href="caca_8h.html#aae0f6938d08e6e0abbcd5a8c06504ab8">caca_canvas_t</a> *cv; <a class="code" href="caca_8h.html#ada5af7a20f3e2f6c103078181b07393e">caca_display_t</a> *dp; <a class="code" href="structcaca__event.html">caca_event_t</a> ev;</div><div class="line"></div><div class="line">    dp = <a class="code" href="group__caca__display.html#gac393d4446d813f6e4ba93d2b583c1edb">caca_create_display</a>(NULL);</div><div class="line">    <span class="keywordflow">if</span>(!dp) <span class="keywordflow">return</span> 1;</div><div class="line">    cv = <a class="code" href="group__caca__display.html#ga65670cdec61ba57879b893c997cd26da">caca_get_canvas</a>(dp);</div><div class="line"></div><div class="line">    <a class="code" href="group__caca__display.html#gadab2bf1e8d0bf5c3cfb3e29ab07d5641">caca_set_display_title</a>(dp, <span class="stringliteral">&quot;Hello!&quot;</span>);</div><div class="line">    <a class="code" href="group__caca__attributes.html#ga1cd39df80cc6b537a4df18415a8605cf">caca_set_color_ansi</a>(cv, <a class="code" href="group__caca__attr.html#gga9db83488c6f07a5f7d773c380b3126a9a9280adda765037612d94743bdc3f346d">CACA_BLACK</a>, <a class="code" href="group__caca__attr.html#gga9db83488c6f07a5f7d773c380b3126a9a1bd1244f952d10b9599fb314e41862ad">CACA_WHITE</a>);</div><div class="line">    <a class="code" href="group__caca__canvas.html#gac9370c0854f358b88d0cb8caf07fb6d3">caca_put_str</a>(cv, 0, 0, <span class="stringliteral">&quot;This is a message&quot;</span>);</div><div class="line">    <a class="code" href="group__caca__display.html#ga8c710eac721d05d807491a1534d1cbe7">caca_refresh_display</a>(dp);</div><div class="line">    <a class="code" href="group__caca__event.html#ga98e74dedbe1629c0fc9460761696e050">caca_get_event</a>(dp, <a class="code" href="caca_8h.html#a40754185ca237fc44a95357afba34aeaab1da825755a2ac3593cca73721b77e22">CACA_EVENT_KEY_PRESS</a>, &amp;ev, -1);</div><div class="line">    <a class="code" href="group__caca__display.html#gac1b5b4540a500dd59eaa673d784fab1f">caca_free_display</a>(dp);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --><p>What does it do?</p><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 <code>"This is a message"</code> onto the canvas, using the current colour pair.</li>
<li>Refresh the display, causing the text to be effectively displayed.</li>
<li>Wait for an event of type <code>CACA_EVENT_KEY_PRESS</code>.</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 commans (requiring <code>pkg-config</code> and <code>gcc</code>): </p><div class="fragment"><div class="line">gcc `pkg-config --libs --cflags caca` example.c -o example</div></div><!-- fragment --> </div></div><!-- contents -->
  </body>
</html>