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

Last change on this file since 4369 was 4369, checked in by Sam Hocevar, 12 years ago

Add the copyright unit test and update copyright information everywhere.

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