Changeset 1282 for libcaca/trunk/cxx/cxxtest.cpp
- Timestamp:
- Nov 5, 2006, 10:59:26 PM (14 years ago)
- Location:
- libcaca/trunk/cxx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cxx
- Property svn:ignore
-
old new 6 6 *.pc 7 7 *.exe 8 c pptest8 cxxtest
-
- Property svn:ignore
-
libcaca/trunk/cxx/cxxtest.cpp
r1275 r1282 22 22 23 23 24 static char const *pig[]= { 25 " ", 26 " _ ", 27 " _._ _..._ .-', _.._(`)) ", 28 " '-. ` ' /-._.-' ',/ ", 29 " ) \\ '. ", 30 " / _ _ | \\ ", 31 " | a a / | ", 32 " \\ .-. ; " , 33 " '-('' ).-' ,' ; ", 34 " '-; | .' ", 35 " \\ \\ / ", 36 " | 7 .__ _.-\\ \\ ", 37 " | | | ``/ /` / ", 38 " jgs /,_| | /,_/ / ", 39 " /,_/ '`-' ", 40 " ", 41 NULL 42 }; 24 static char const pigstring[] = 25 " \n" 26 " _ \n" 27 " _._ _..._ .-', _.._(`)) \n" 28 " '-. ` ' /-._.-' ',/ \n" 29 " ) \\ '. \n" 30 " / _ _ | \\ \n" 31 " | a a / | \n" 32 " \\ .-. ; \n" 33 " '-('' ).-' ,' ; \n" 34 " '-; | .' \n" 35 " \\ \\ / \n" 36 " | 7 .__ _.-\\ \\ \n" 37 " | | | ``/ /` / \n" 38 " jgs /,_| | /,_/ / \n" 39 " /,_/ '`-' \n"; 43 40 44 41 int main(int argc, char *argv[]) 45 42 { 46 Cucul *qq ;43 Cucul *qq, *pig; 47 44 Caca *kk; 48 45 Event ev; 49 46 50 47 int x = 0, y = 0, ix = 1, iy = 1; 51 52 53 48 54 49 try { … … 68 63 } 69 64 65 try { 66 // Import buffer into a canvas 67 Buffer *buf = new Buffer(); 68 buf->loadMemory((void *)pigstring, strlen(pigstring)); 69 pig = new Cucul(buf, "text"); 70 delete buf; 71 // Change colour to magenta 72 pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT); 73 for(int y = 0; y < pig->getHeight(); y++) 74 for(int x = 0; x < pig->getWidth(); x++) 75 pig->putChar(x, y, pig->getChar(x, y)); 76 } 77 catch(int e) { 78 cerr << "Error while importing image (" << e << ")" << endl; 79 return -1; 80 } 81 70 82 kk->setDisplayTime(20000); 71 83 72 84 while(!kk->getEvent(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) { 73 85 86 qq->Clear(); 87 74 88 /* Draw pig */ 75 qq->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_BLACK); 76 77 for(int i = 0; pig[i]; i++) 78 qq->putStr(x, y+i, (char*)pig[i]); 89 qq->Blit(x, y, pig, NULL); 79 90 80 91 /* printf works */ 81 92 qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK); 82 qq->Printf((qq->getWidth()/2) - 10 ,qq->getHeight()/2, "Powered by libcaca %s", VERSION); 93 qq->Printf(qq->getWidth() / 2 - 10, qq->getHeight() / 2, 94 "Powered by libcaca %s", VERSION); 83 95 84 96 /* Blit */ 85 97 kk->Display(); 86 qq->Clear();87 98 88 x +=ix;89 y +=iy;99 x += ix; 100 y += iy; 90 101 91 if(x>=(qq->getWidth()-35) || x<0 ) 92 ix=-ix; 93 if(y>=(qq->getHeight()-15) || y<0 ) 94 iy=-iy; 95 96 102 if(x + pig->getWidth() >= qq->getWidth() || x < 0 ) 103 ix = -ix; 104 if(y + pig->getHeight() >= qq->getHeight() || y < 0 ) 105 iy = -iy; 97 106 } 98 99 107 100 108 delete kk;
Note: See TracChangeset
for help on using the changeset viewer.