Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

113 linhas
2.9 KiB

  1. /*
  2. * cpptest libcaca++ rendering test
  3. * Copyright (c) 2006-2007 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * 2009-2010 Sam Hocevar <sam@hocevar.net>
  5. * All Rights Reserved
  6. *
  7. * This program is free software. It comes without any warranty, to
  8. * the extent permitted by applicable law. You can redistribute it
  9. * and/or modify it under the terms of the Do What The Fuck You Want
  10. * To Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include <iostream>
  14. #include <cstring>
  15. #include <caca++.h>
  16. using namespace std;
  17. static char const pigstring[] =
  18. " \n"
  19. " _ \n"
  20. " _._ _..._ .-', _.._(`)) \n"
  21. " '-. ` ' /-._.-' ',/ \n"
  22. " ) \\ '. \n"
  23. " / _ _ | \\ \n"
  24. " | a a / | \n"
  25. " \\ .-. ; \n"
  26. " '-('' ).-' ,' ; \n"
  27. " '-; | .' \n"
  28. " \\ \\ / \n"
  29. " | 7 .__ _.-\\ \\ \n"
  30. " | | | ``/ /` / \n"
  31. " jgs /,_| | /,_/ / \n"
  32. " /,_/ '`-' \n";
  33. int main(int argc, char *argv[])
  34. {
  35. Canvas *cv, *pig;
  36. Caca *dp;
  37. int x = 0, y = 0, ix = 1, iy = 1;
  38. try {
  39. cv = new Canvas();
  40. }
  41. catch (int e) {
  42. cerr << "Error while creating canvas (" << e << ")" << endl;
  43. return -1;
  44. }
  45. try {
  46. dp = new Caca(cv);
  47. }
  48. catch(int e) {
  49. cerr << "Error while attaching canvas to display (" << e << ")" << endl;
  50. return -1;
  51. }
  52. try {
  53. // Import buffer into a canvas
  54. pig = new Canvas();
  55. pig->setColorANSI(CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
  56. pig->importFromMemory(pigstring, strlen(pigstring), "text");
  57. }
  58. catch(int e) {
  59. cerr << "Error while importing image (" << e << ")" << endl;
  60. return -1;
  61. }
  62. dp->setDisplayTime(20000);
  63. while(!dp->getEvent(Event::CACA_EVENT_KEY_PRESS, NULL, 0))
  64. {
  65. /* In case of resize ...*/
  66. if((x + pig->getWidth())-1 >= cv->getWidth() || x < 0 )
  67. x = 0;
  68. if((y + pig->getHeight())-1 >= cv->getHeight() || y < 0 )
  69. y = 0;
  70. cv->Clear();
  71. /* Draw pig */
  72. cv->Blit(x, y, pig, NULL);
  73. /* printf works */
  74. cv->setColorANSI(CACA_LIGHTBLUE, CACA_BLACK);
  75. cv->Printf(cv->getWidth() / 2 - 10, cv->getHeight() / 2,
  76. "Powered by libcaca %s", dp->getVersion());
  77. /* Blit */
  78. dp->Display();
  79. x += ix;
  80. y += iy;
  81. if(x + pig->getWidth() >= cv->getWidth() || x < 0 )
  82. ix = -ix;
  83. if(y + pig->getHeight() >= cv->getHeight() || y < 0 )
  84. iy = -iy;
  85. }
  86. delete dp;
  87. delete pig;
  88. delete cv;
  89. return 0;
  90. }