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 2075 2007-11-26 01:04:34Z sam $ |
---|
7 | * |
---|
8 | * This program is free software. It comes 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 <iostream> |
---|
16 | |
---|
17 | #include <cucul++.h> |
---|
18 | #include <caca++.h> |
---|
19 | |
---|
20 | using namespace std; |
---|
21 | |
---|
22 | |
---|
23 | static 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"; |
---|
39 | |
---|
40 | int main(int argc, char *argv[]) |
---|
41 | { |
---|
42 | Cucul *cv, *pig; |
---|
43 | Caca *dp; |
---|
44 | |
---|
45 | int x = 0, y = 0, ix = 1, iy = 1; |
---|
46 | |
---|
47 | try { |
---|
48 | cv = new Cucul(); |
---|
49 | } |
---|
50 | catch (int e) { |
---|
51 | cerr << "Error while initializing cucul (" << e << ")" << endl; |
---|
52 | return -1; |
---|
53 | } |
---|
54 | |
---|
55 | try { |
---|
56 | dp = new Caca(cv); |
---|
57 | } |
---|
58 | catch(int e) { |
---|
59 | cerr << "Error while attaching cucul to caca (" << e << ")" << endl; |
---|
60 | return -1; |
---|
61 | } |
---|
62 | |
---|
63 | try { |
---|
64 | // Import buffer into a canvas |
---|
65 | pig = new Cucul(); |
---|
66 | pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT); |
---|
67 | pig->importMemory(pigstring, strlen(pigstring), "text"); |
---|
68 | } |
---|
69 | catch(int e) { |
---|
70 | cerr << "Error while importing image (" << e << ")" << endl; |
---|
71 | return -1; |
---|
72 | } |
---|
73 | |
---|
74 | dp->setDisplayTime(20000); |
---|
75 | |
---|
76 | while(!dp->getEvent(Event::CACA_EVENT_KEY_PRESS, NULL, 0)) |
---|
77 | { |
---|
78 | |
---|
79 | /* In case of resize ...*/ |
---|
80 | if((x + pig->getWidth())-1 >= cv->getWidth() || x < 0 ) |
---|
81 | x = 0; |
---|
82 | if((y + pig->getHeight())-1 >= cv->getHeight() || y < 0 ) |
---|
83 | y = 0; |
---|
84 | |
---|
85 | cv->Clear(); |
---|
86 | |
---|
87 | /* Draw pig */ |
---|
88 | cv->Blit(x, y, pig, NULL); |
---|
89 | |
---|
90 | /* printf works */ |
---|
91 | cv->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK); |
---|
92 | cv->Printf(cv->getWidth() / 2 - 10, cv->getHeight() / 2, |
---|
93 | "Powered by libcaca %s", dp->getVersion()); |
---|
94 | |
---|
95 | /* Blit */ |
---|
96 | dp->Display(); |
---|
97 | |
---|
98 | x += ix; |
---|
99 | y += iy; |
---|
100 | |
---|
101 | if(x + pig->getWidth() >= cv->getWidth() || x < 0 ) |
---|
102 | ix = -ix; |
---|
103 | if(y + pig->getHeight() >= cv->getHeight() || y < 0 ) |
---|
104 | iy = -iy; |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | delete dp; |
---|
109 | delete pig; |
---|
110 | delete cv; |
---|
111 | |
---|
112 | return 0; |
---|
113 | } |
---|