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

Last change on this file since 1452 was 1452, checked in by Sam Hocevar, 14 years ago
  • Add a no warranty clause to the code.
  • 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 1452 2006-12-11 15:48:46Z sam $
7 *
8 *  This program is free software. It commes 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    Event ev;
47
48    int x = 0, y = 0, ix = 1, iy = 1;
49
50    try {
51        qq = new Cucul();
52    }
53    catch (int e) {
54        cerr << "Error while initializing cucul (" << e << ")" << endl;
55        return -1;
56    }
57
58    try {
59        kk = new Caca(qq);
60    }
61    catch(int e) {
62        cerr << "Error while attaching cucul to caca (" << e << ")" << endl;
63        return -1;
64    }
65
66    try {
67        // Import buffer into a canvas
68        pig = new Cucul();
69        pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
70        pig->importMemory(pigstring, strlen(pigstring), "text");
71    }
72    catch(int e) {
73        cerr << "Error while importing image (" << e << ")" << endl;
74        return -1;
75    }
76
77    kk->setDisplayTime(20000);
78
79    while(!kk->getEvent(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) {
80
81
82        /* In case of resize ...*/
83        if((x + pig->getWidth())-1 >= qq->getWidth() || x < 0 )
84            x = 0;
85        if((y + pig->getHeight())-1 >= qq->getHeight() || y < 0 )
86            y = 0;
87
88
89
90
91        qq->Clear();
92
93        /* Draw pig */
94        qq->Blit(x, y, pig, NULL);
95
96        /* printf works */
97        qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK);
98        qq->Printf(qq->getWidth() / 2 - 10, qq->getHeight() / 2,
99                   "Powered by libcaca %s", VERSION);
100
101        /* Blit */
102        kk->Display();
103
104        x += ix;
105        y += iy;
106
107        if(x + pig->getWidth() >= qq->getWidth() || x < 0 )
108            ix = -ix;
109        if(y + pig->getHeight() >= qq->getHeight() || y < 0 )
110            iy = -iy;
111
112    }
113
114    delete kk;
115    delete qq;
116
117    return 0;
118}
Note: See TracBrowser for help on using the repository browser.