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

Last change on this file since 1388 was 1388, checked in by Sam Hocevar, 14 years ago
  • Updated C++ bindings so that they build, at least.
  • Property svn:keywords set to Id
File size: 2.8 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 1388 2006-11-13 21:42:15Z sam $
7 *
8 *  This program is free software; you can redistribute it and/or
9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14#include "config.h"
15
16#include <iostream>
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 *qq, *pig;
44    Caca  *kk;
45    Event ev;
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(ev.CACA_EVENT_KEY_PRESS, &ev, 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
88
89
90        qq->Clear();
91
92        /* Draw pig */
93        qq->Blit(x, y, pig, NULL);
94
95        /* printf works */
96        qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK);
97        qq->Printf(qq->getWidth() / 2 - 10, qq->getHeight() / 2,
98                   "Powered by libcaca %s", VERSION);
99
100        /* Blit */
101        kk->Display();
102
103        x += ix;
104        y += iy;
105
106        if(x + pig->getWidth() >= qq->getWidth() || x < 0 )
107            ix = -ix;
108        if(y + pig->getHeight() >= qq->getHeight() || y < 0 )
109            iy = -iy;
110
111    }
112
113    delete kk;
114    delete qq;
115
116    return 0;
117}
Note: See TracBrowser for help on using the repository browser.