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

Last change on this file since 2824 was 2824, checked in by Sam Hocevar, 11 years ago

Continuing the libcucul-libcaca merge.

  • Property svn:keywords set to Id
File size: 2.9 KB
RevLine 
[784]1/*
2 *  cpptest       libcaca++ rendering test
3 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
[1275]6 *  $Id: cxxtest.cpp 2824 2008-09-27 14:29:11Z sam $
[784]7 *
[1462]8 *  This program is free software. It comes without any warranty, to
[1452]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
[784]12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
[781]15#include <iostream>
[2136]16#include <cstring>
[781]17
18#include <caca++.h>
19
20using namespace std;
21
22
[1282]23static char const pigstring[] =
24    "                                   \n"
25    "                             _     \n"
26    "    _._ _..._ .-',     _.._(`))    \n"
27    "   '-. `     '  /-._.-'    ',/     \n"
28    "      )         \\            '.    \n"
29    "     / _    _    |             \\   \n"
30    "    |  a    a    /              |  \n"
31    "    \\   .-.                     ;  \n"
32    "     '-('' ).-'       ,'       ;   \n"
33    "        '-;           |      .'    \n"
34    "           \\           \\    /      \n"
35    "           | 7  .__  _.-\\   \\      \n"
36    "           | |  |  ``/  /`  /      \n"
37    "      jgs /,_|  |   /,_/   /       \n"
38    "             /,_/      '`-'        \n";
[781]39
40int main(int argc, char *argv[])
41{
[2821]42    Canvas *cv, *pig;
[2074]43    Caca  *dp;
[796]44
[785]45    int x = 0, y = 0, ix = 1, iy = 1;
[781]46
47    try {
[2821]48        cv = new Canvas();
[892]49    }
[781]50    catch (int e) {
[2824]51        cerr << "Error while creating canvas (" << e << ")" << endl;
[781]52        return -1;
53    }
[892]54
[782]55    try {
[2074]56        dp = new Caca(cv);
[782]57    }
58    catch(int e) {
[2824]59        cerr << "Error while attaching canvas to display (" << e << ")" << endl;
[782]60        return -1;
61    }
[781]62
[1282]63    try {
64        // Import buffer into a canvas
[2821]65        pig = new Canvas();
66        pig->setColorANSI(CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
[1388]67        pig->importMemory(pigstring, strlen(pigstring), "text");
[1282]68    }
69    catch(int e) {
70        cerr << "Error while importing image (" << e << ")" << endl;
71        return -1;
72    }
73
[2074]74    dp->setDisplayTime(20000);
[781]75
[2074]76    while(!dp->getEvent(Event::CACA_EVENT_KEY_PRESS, NULL, 0))
[2070]77    {
[892]78
[1310]79        /* In case of resize ...*/
[2074]80        if((x + pig->getWidth())-1 >= cv->getWidth() || x < 0 )
[1310]81            x = 0;
[2074]82        if((y + pig->getHeight())-1 >= cv->getHeight() || y < 0 )
[1310]83            y = 0;
84
[2074]85        cv->Clear();
[1282]86
[785]87        /* Draw pig */
[2074]88        cv->Blit(x, y, pig, NULL);
[892]89
[785]90        /* printf works */
[2821]91        cv->setColorANSI(CACA_LIGHTBLUE, CACA_BLACK);
[2074]92        cv->Printf(cv->getWidth() / 2 - 10, cv->getHeight() / 2,
93                   "Powered by libcaca %s", dp->getVersion());
[892]94
[785]95        /* Blit */
[2074]96        dp->Display();
[781]97
[1282]98        x += ix;
99        y += iy;
[781]100
[2074]101        if(x + pig->getWidth() >= cv->getWidth() || x < 0 )
[1282]102            ix = -ix;
[2074]103        if(y + pig->getHeight() >= cv->getHeight() || y < 0 )
[1282]104            iy = -iy;
[1310]105
[785]106    }
107
[2074]108    delete dp;
[2075]109    delete pig;
[2074]110    delete cv;
[781]111
112    return 0;
113}
Note: See TracBrowser for help on using the repository browser.