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

Last change on this file since 2304 was 2136, checked in by Sam Hocevar, 12 years ago
  • Add #include <cstring> to fix gcc-4.3 build.
  • 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 2136 2007-12-14 16:23:14Z 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    Cucul *cv, *pig;
44    Caca  *dp;
45
46    int x = 0, y = 0, ix = 1, iy = 1;
47
48    try {
49        cv = new Cucul();
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 Cucul();
67        pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_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(CUCUL_LIGHTBLUE, CUCUL_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.