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

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

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