You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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