source: libcaca/trunk/cxx/cxxtest.cpp @ 2821

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

Starting refactoring to get rid of libcucul. The initial reason for the
split is rendered moot by the plugin system: when enabled, binaries do
not link directly with libX11 or libGL. I hope this is a step towards
more consisteny and clarity.

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/*
2 *  cpptest       libcaca++ rendering test
3 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
6 *  $Id: cxxtest.cpp 2821 2008-09-27 13:12:46Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include <iostream>
16#include <cstring>
17
18#include <cucul++.h>
19#include <caca++.h>
20
21using namespace std;
22
23
24static char const pigstring[] =
25    "                                   \n"
26    "                             _     \n"
27    "    _._ _..._ .-',     _.._(`))    \n"
28    "   '-. `     '  /-._.-'    ',/     \n"
29    "      )         \\            '.    \n"
30    "     / _    _    |             \\   \n"
31    "    |  a    a    /              |  \n"
32    "    \\   .-.                     ;  \n"
33    "     '-('' ).-'       ,'       ;   \n"
34    "        '-;           |      .'    \n"
35    "           \\           \\    /      \n"
36    "           | 7  .__  _.-\\   \\      \n"
37    "           | |  |  ``/  /`  /      \n"
38    "      jgs /,_|  |   /,_/   /       \n"
39    "             /,_/      '`-'        \n";
40
41int main(int argc, char *argv[])
42{
43    Canvas *cv, *pig;
44    Caca  *dp;
45
46    int x = 0, y = 0, ix = 1, iy = 1;
47
48    try {
49        cv = new Canvas();
50    }
51    catch (int e) {
52        cerr << "Error while initializing cucul (" << e << ")" << endl;
53        return -1;
54    }
55
56    try {
57        dp = new Caca(cv);
58    }
59    catch(int e) {
60        cerr << "Error while attaching cucul to caca (" << e << ")" << endl;
61        return -1;
62    }
63
64    try {
65        // Import buffer into a canvas
66        pig = new Canvas();
67        pig->setColorANSI(CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
68        pig->importMemory(pigstring, strlen(pigstring), "text");
69    }
70    catch(int e) {
71        cerr << "Error while importing image (" << e << ")" << endl;
72        return -1;
73    }
74
75    dp->setDisplayTime(20000);
76
77    while(!dp->getEvent(Event::CACA_EVENT_KEY_PRESS, NULL, 0))
78    {
79
80        /* In case of resize ...*/
81        if((x + pig->getWidth())-1 >= cv->getWidth() || x < 0 )
82            x = 0;
83        if((y + pig->getHeight())-1 >= cv->getHeight() || y < 0 )
84            y = 0;
85
86        cv->Clear();
87
88        /* Draw pig */
89        cv->Blit(x, y, pig, NULL);
90
91        /* printf works */
92        cv->setColorANSI(CACA_LIGHTBLUE, CACA_BLACK);
93        cv->Printf(cv->getWidth() / 2 - 10, cv->getHeight() / 2,
94                   "Powered by libcaca %s", dp->getVersion());
95
96        /* Blit */
97        dp->Display();
98
99        x += ix;
100        y += iy;
101
102        if(x + pig->getWidth() >= cv->getWidth() || x < 0 )
103            ix = -ix;
104        if(y + pig->getHeight() >= cv->getHeight() || y < 0 )
105            iy = -iy;
106
107    }
108
109    delete dp;
110    delete pig;
111    delete cv;
112
113    return 0;
114}
Note: See TracBrowser for help on using the repository browser.