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 2050 2007-11-25 11:11:59Z 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 "config.h" |
---|
16 | |
---|
17 | #include <iostream> |
---|
18 | |
---|
19 | #include <cucul++.h> |
---|
20 | #include <caca++.h> |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | |
---|
24 | |
---|
25 | static char const pigstring[] = |
---|
26 | " \n" |
---|
27 | " _ \n" |
---|
28 | " _._ _..._ .-', _.._(`)) \n" |
---|
29 | " '-. ` ' /-._.-' ',/ \n" |
---|
30 | " ) \\ '. \n" |
---|
31 | " / _ _ | \\ \n" |
---|
32 | " | a a / | \n" |
---|
33 | " \\ .-. ; \n" |
---|
34 | " '-('' ).-' ,' ; \n" |
---|
35 | " '-; | .' \n" |
---|
36 | " \\ \\ / \n" |
---|
37 | " | 7 .__ _.-\\ \\ \n" |
---|
38 | " | | | ``/ /` / \n" |
---|
39 | " jgs /,_| | /,_/ / \n" |
---|
40 | " /,_/ '`-' \n"; |
---|
41 | |
---|
42 | int main(int argc, char *argv[]) |
---|
43 | { |
---|
44 | Cucul *qq, *pig; |
---|
45 | Caca *kk; |
---|
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(Event::CACA_EVENT_KEY_PRESS, NULL, 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 | } |
---|