25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cxxtest.cpp 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. #include <iostream>
  15. #include <cstring>
  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. Canvas *cv, *pig;
  37. Caca *dp;
  38. int x = 0, y = 0, ix = 1, iy = 1;
  39. try {
  40. cv = new Canvas();
  41. }
  42. catch (int e) {
  43. cerr << "Error while creating canvas (" << e << ")" << endl;
  44. return -1;
  45. }
  46. try {
  47. dp = new Caca(cv);
  48. }
  49. catch(int e) {
  50. cerr << "Error while attaching canvas to display (" << e << ")" << endl;
  51. return -1;
  52. }
  53. try {
  54. // Import buffer into a canvas
  55. pig = new Canvas();
  56. pig->setColorANSI(CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
  57. pig->importFromMemory(pigstring, strlen(pigstring), "text");
  58. }
  59. catch(int e) {
  60. cerr << "Error while importing image (" << e << ")" << endl;
  61. return -1;
  62. }
  63. dp->setDisplayTime(20000);
  64. while(!dp->getEvent(Event::CACA_EVENT_KEY_PRESS, NULL, 0))
  65. {
  66. /* In case of resize ...*/
  67. if((x + pig->getWidth())-1 >= cv->getWidth() || x < 0 )
  68. x = 0;
  69. if((y + pig->getHeight())-1 >= cv->getHeight() || y < 0 )
  70. y = 0;
  71. cv->Clear();
  72. /* Draw pig */
  73. cv->Blit(x, y, pig, NULL);
  74. /* printf works */
  75. cv->setColorANSI(CACA_LIGHTBLUE, CACA_BLACK);
  76. cv->Printf(cv->getWidth() / 2 - 10, cv->getHeight() / 2,
  77. "Powered by libcaca %s", dp->getVersion());
  78. /* Blit */
  79. dp->Display();
  80. x += ix;
  81. y += iy;
  82. if(x + pig->getWidth() >= cv->getWidth() || x < 0 )
  83. ix = -ix;
  84. if(y + pig->getHeight() >= cv->getHeight() || y < 0 )
  85. iy = -iy;
  86. }
  87. delete dp;
  88. delete pig;
  89. delete cv;
  90. return 0;
  91. }