Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

113 строки
2.9 KiB

  1. /*
  2. * cpptest libcaca++ rendering test
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  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. #include "config.h"
  14. #include <iostream>
  15. #include <cucul++.h>
  16. #include <caca++.h>
  17. using namespace std;
  18. static char const pigstring[] =
  19. " \n"
  20. " _ \n"
  21. " _._ _..._ .-', _.._(`)) \n"
  22. " '-. ` ' /-._.-' ',/ \n"
  23. " ) \\ '. \n"
  24. " / _ _ | \\ \n"
  25. " | a a / | \n"
  26. " \\ .-. ; \n"
  27. " '-('' ).-' ,' ; \n"
  28. " '-; | .' \n"
  29. " \\ \\ / \n"
  30. " | 7 .__ _.-\\ \\ \n"
  31. " | | | ``/ /` / \n"
  32. " jgs /,_| | /,_/ / \n"
  33. " /,_/ '`-' \n";
  34. int main(int argc, char *argv[])
  35. {
  36. Cucul *qq, *pig;
  37. Caca *kk;
  38. Event ev;
  39. int x = 0, y = 0, ix = 1, iy = 1;
  40. try {
  41. qq = new Cucul();
  42. }
  43. catch (int e) {
  44. cerr << "Error while initializing cucul (" << e << ")" << endl;
  45. return -1;
  46. }
  47. try {
  48. kk = new Caca(qq);
  49. }
  50. catch(int e) {
  51. cerr << "Error while attaching cucul to caca (" << e << ")" << endl;
  52. return -1;
  53. }
  54. try {
  55. // Import buffer into a canvas
  56. Buffer *buf = new Buffer();
  57. buf->loadMemory((void *)pigstring, strlen(pigstring));
  58. pig = new Cucul(buf, "text");
  59. delete buf;
  60. // Change colour to magenta
  61. pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
  62. for(int y = 0; y < pig->getHeight(); y++)
  63. for(int x = 0; x < pig->getWidth(); x++)
  64. pig->putChar(x, y, pig->getChar(x, y));
  65. }
  66. catch(int e) {
  67. cerr << "Error while importing image (" << e << ")" << endl;
  68. return -1;
  69. }
  70. kk->setDisplayTime(20000);
  71. while(!kk->getEvent(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) {
  72. qq->Clear();
  73. /* Draw pig */
  74. qq->Blit(x, y, pig, NULL);
  75. /* printf works */
  76. qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK);
  77. qq->Printf(qq->getWidth() / 2 - 10, qq->getHeight() / 2,
  78. "Powered by libcaca %s", VERSION);
  79. /* Blit */
  80. kk->Display();
  81. x += ix;
  82. y += iy;
  83. if(x + pig->getWidth() >= qq->getWidth() || x < 0 )
  84. ix = -ix;
  85. if(y + pig->getHeight() >= qq->getHeight() || y < 0 )
  86. iy = -iy;
  87. }
  88. delete kk;
  89. delete qq;
  90. return 0;
  91. }