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

Last change on this file since 1282 was 1282, checked in by Sam Hocevar, 13 years ago
  • Use the import function to load the pig image in cxxtest.
  • 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 1282 2006-11-05 21:59:26Z 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        Buffer *buf = new Buffer();
68        buf->loadMemory((void *)pigstring, strlen(pigstring));
69        pig = new Cucul(buf, "text");
70        delete buf;
71        // Change colour to magenta
72        pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
73        for(int y = 0; y < pig->getHeight(); y++)
74            for(int x = 0; x < pig->getWidth(); x++)
75                pig->putChar(x, y, pig->getChar(x, y));
76    }
77    catch(int e) {
78        cerr << "Error while importing image (" << e << ")" << endl;
79        return -1;
80    }
81
82    kk->setDisplayTime(20000);
83
84    while(!kk->getEvent(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) {
85
86        qq->Clear();
87
88        /* Draw pig */
89        qq->Blit(x, y, pig, NULL);
90
91        /* printf works */
92        qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK);
93        qq->Printf(qq->getWidth() / 2 - 10, qq->getHeight() / 2,
94                   "Powered by libcaca %s", VERSION);
95
96        /* Blit */
97        kk->Display();
98
99        x += ix;
100        y += iy;
101
102        if(x + pig->getWidth() >= qq->getWidth() || x < 0 )
103            ix = -ix;
104        if(y + pig->getHeight() >= qq->getHeight() || y < 0 )
105            iy = -iy;
106    }
107
108    delete kk;
109    delete qq;
110
111    return 0;
112}
Note: See TracBrowser for help on using the repository browser.