1 | /* |
---|
2 | * cpptest libcaca++ rendering test |
---|
3 | * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: cpptest.cpp 796 2006-04-17 13:23:28Z jylam $ |
---|
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 <iostream> |
---|
15 | |
---|
16 | #include <cucul++.h> |
---|
17 | #include <caca++.h> |
---|
18 | |
---|
19 | using namespace std; |
---|
20 | |
---|
21 | |
---|
22 | static char const *pig[]= { |
---|
23 | " ", |
---|
24 | " _ ", |
---|
25 | " _._ _..._ .-', _.._(`)) ", |
---|
26 | " '-. ` ' /-._.-' ',/ ", |
---|
27 | " ) \ '. ", |
---|
28 | " / _ _ | \\ ", |
---|
29 | " | a a / | ", |
---|
30 | " \ .-. ; " , |
---|
31 | " '-('' ).-' ,' ; ", |
---|
32 | " '-; | .' ", |
---|
33 | " \\ \\ / ", |
---|
34 | " | 7 .__ _.-\\ \\ ", |
---|
35 | " | | | ``/ /` / ", |
---|
36 | " jgs /,_| | /,_/ / ", |
---|
37 | " /,_/ '`-' ", |
---|
38 | " ", |
---|
39 | NULL |
---|
40 | }; |
---|
41 | |
---|
42 | int main(int argc, char *argv[]) |
---|
43 | { |
---|
44 | Cucul *qq; |
---|
45 | Caca *kk; |
---|
46 | Event ev; |
---|
47 | |
---|
48 | int x = 0, y = 0, ix = 1, iy = 1; |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | try { |
---|
53 | qq = new Cucul(); |
---|
54 | } |
---|
55 | catch (int e) { |
---|
56 | cerr << "Error while initializing cucul (" << e << ")" << endl; |
---|
57 | return -1; |
---|
58 | } |
---|
59 | |
---|
60 | try { |
---|
61 | kk = new Caca(qq); |
---|
62 | } |
---|
63 | catch(int e) { |
---|
64 | cerr << "Error while attaching cucul to caca (" << e << ")" << endl; |
---|
65 | return -1; |
---|
66 | } |
---|
67 | |
---|
68 | kk->set_delay(20000); |
---|
69 | |
---|
70 | while(!kk->get_event(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) { |
---|
71 | |
---|
72 | /* Draw pig */ |
---|
73 | qq->set_color(CUCUL_COLOR_LIGHTMAGENTA, CUCUL_COLOR_BLACK); |
---|
74 | |
---|
75 | for(int i = 0; pig[i]; i++) |
---|
76 | qq->putstr(x, y+i, (char*)pig[i]); |
---|
77 | |
---|
78 | /* printf works */ |
---|
79 | qq->set_color(CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLACK); |
---|
80 | qq->printf(30,15, "Powered by libcaca %s", VERSION); |
---|
81 | |
---|
82 | /* Blit */ |
---|
83 | kk->display(); |
---|
84 | |
---|
85 | x+=ix; |
---|
86 | y+=iy; |
---|
87 | |
---|
88 | if(x>=(qq->get_width()-35) || x<0 ) |
---|
89 | ix=-ix; |
---|
90 | if(y>=(qq->get_height()-15) || y<0 ) |
---|
91 | iy=-iy; |
---|
92 | |
---|
93 | |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | delete kk; |
---|
98 | delete qq; |
---|
99 | |
---|
100 | return 0; |
---|
101 | } |
---|