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

Last change on this file since 2070 was 2070, checked in by Sam Hocevar, 12 years ago
  • Added MSVC project files for the C++ bindings and the C++ test.
  • 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 2070 2007-11-25 20:23:03Z 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 "config.h"
16
17#include <iostream>
18
19#include <cucul++.h>
20#include <caca++.h>
21
22using namespace std;
23
24
25static char const pigstring[] =
26    "                                   \n"
27    "                             _     \n"
28    "    _._ _..._ .-',     _.._(`))    \n"
29    "   '-. `     '  /-._.-'    ',/     \n"
30    "      )         \\            '.    \n"
31    "     / _    _    |             \\   \n"
32    "    |  a    a    /              |  \n"
33    "    \\   .-.                     ;  \n"
34    "     '-('' ).-'       ,'       ;   \n"
35    "        '-;           |      .'    \n"
36    "           \\           \\    /      \n"
37    "           | 7  .__  _.-\\   \\      \n"
38    "           | |  |  ``/  /`  /      \n"
39    "      jgs /,_|  |   /,_/   /       \n"
40    "             /,_/      '`-'        \n";
41
42int main(int argc, char *argv[])
43{
44    Cucul *qq, *pig;
45    Caca  *kk;
46
47    int x = 0, y = 0, ix = 1, iy = 1;
48
49    try {
50        qq = new Cucul();
51    }
52    catch (int e) {
53        cerr << "Error while initializing cucul (" << e << ")" << endl;
54        return -1;
55    }
56
57    try {
58        kk = new Caca(qq);
59    }
60    catch(int e) {
61        cerr << "Error while attaching cucul to caca (" << e << ")" << endl;
62        return -1;
63    }
64
65    try {
66        // Import buffer into a canvas
67        pig = new Cucul();
68        pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
69        pig->importMemory(pigstring, strlen(pigstring), "text");
70    }
71    catch(int e) {
72        cerr << "Error while importing image (" << e << ")" << endl;
73        return -1;
74    }
75
76    kk->setDisplayTime(20000);
77
78    while(!kk->getEvent(Event::CACA_EVENT_KEY_PRESS, NULL, 0))
79    {
80
81        /* In case of resize ...*/
82        if((x + pig->getWidth())-1 >= qq->getWidth() || x < 0 )
83            x = 0;
84        if((y + pig->getHeight())-1 >= qq->getHeight() || y < 0 )
85            y = 0;
86
87        qq->Clear();
88
89        /* Draw pig */
90        qq->Blit(x, y, pig, NULL);
91
92        /* printf works */
93        qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK);
94        qq->Printf(qq->getWidth() / 2 - 10, qq->getHeight() / 2,
95                   "Powered by libcaca %s", VERSION);
96
97        /* Blit */
98        kk->Display();
99
100        x += ix;
101        y += iy;
102
103        if(x + pig->getWidth() >= qq->getWidth() || x < 0 )
104            ix = -ix;
105        if(y + pig->getHeight() >= qq->getHeight() || y < 0 )
106            iy = -iy;
107
108    }
109
110    delete kk;
111    delete qq;
112
113    return 0;
114}
Note: See TracBrowser for help on using the repository browser.