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

Last change on this file since 1269 was 1269, checked in by Sam Hocevar, 13 years ago
  • Got rid of cucul_ansi_to_str(), it's really useless.
  • Partial update of the C++ bindings.
  • Updated documentation.
  • Property svn:keywords set to Id
File size: 2.4 KB
RevLine 
[784]1/*
2 *  cpptest       libcaca++ rendering test
3 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
[1269]6 *  $Id: cxxtest.cpp 1269 2006-10-31 14:04:22Z sam $
[784]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
[827]14#include "config.h"
15
[781]16#include <iostream>
17
18#include <cucul++.h>
19#include <caca++.h>
20
21using namespace std;
22
23
24static char const *pig[]= {
[785]25    "                                   ",
26    "                             _     ",
27    "    _._ _..._ .-',     _.._(`))    ",
28    "   '-. `     '  /-._.-'    ',/     ",
[797]29    "      )         \\            '.    ",
[785]30    "     / _    _    |             \\   ",
31    "    |  a    a    /              |  ",
[797]32    "    \\   .-.                     ;  " ,
[785]33    "     '-('' ).-'       ,'       ;   ",
34    "        '-;           |      .'    ",
35    "           \\           \\    /      ",
36    "           | 7  .__  _.-\\   \\      ",
37    "           | |  |  ``/  /`  /      ",
38    "      jgs /,_|  |   /,_/   /       ",
39    "             /,_/      '`-'        ",
40    "                                   ",
[781]41 NULL
42};
43
44int main(int argc, char *argv[])
45{
46    Cucul *qq;
47    Caca  *kk;
[796]48    Event ev;
49
[785]50    int x = 0, y = 0, ix = 1, iy = 1;
[781]51
[785]52
53
[781]54    try {
[782]55        qq = new Cucul();
[892]56    }
[781]57    catch (int e) {
58        cerr << "Error while initializing cucul (" << e << ")" << endl;
59        return -1;
60    }
[892]61
[782]62    try {
63        kk = new Caca(qq);
64    }
65    catch(int e) {
66        cerr << "Error while attaching cucul to caca (" << e << ")" << endl;
67        return -1;
68    }
[781]69
[1002]70    kk->setDisplayTime(20000);
[781]71
[897]72    while(!kk->getEvent(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) {
[892]73
[785]74        /* Draw pig */
[1269]75        qq->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_BLACK);
[892]76
[785]77        for(int i = 0; pig[i]; i++)
[892]78            qq->putStr(x, y+i, (char*)pig[i]);
79
[785]80        /* printf works */
[1269]81        qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK);
[892]82        qq->Printf(30,15, "Powered by libcaca %s", VERSION);
83
[785]84        /* Blit */
[897]85        kk->Display();
[781]86
[785]87        x+=ix;
88        y+=iy;
[781]89
[892]90        if(x>=(qq->getWidth()-35)  || x<0 )
[785]91            ix=-ix;
[892]92        if(y>=(qq->getHeight()-15)   || y<0 )
[785]93            iy=-iy;
94
95
96    }
97
98
[781]99    delete kk;
100    delete qq;
101
102    return 0;
103}
Note: See TracBrowser for help on using the repository browser.