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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 "config.h"
  15. #include <iostream>
  16. #include <cucul++.h>
  17. #include <caca++.h>
  18. using namespace std;
  19. static char const pigstring[] =
  20. " \n"
  21. " _ \n"
  22. " _._ _..._ .-', _.._(`)) \n"
  23. " '-. ` ' /-._.-' ',/ \n"
  24. " ) \\ '. \n"
  25. " / _ _ | \\ \n"
  26. " | a a / | \n"
  27. " \\ .-. ; \n"
  28. " '-('' ).-' ,' ; \n"
  29. " '-; | .' \n"
  30. " \\ \\ / \n"
  31. " | 7 .__ _.-\\ \\ \n"
  32. " | | | ``/ /` / \n"
  33. " jgs /,_| | /,_/ / \n"
  34. " /,_/ '`-' \n";
  35. int main(int argc, char *argv[])
  36. {
  37. Cucul *qq, *pig;
  38. Caca *kk;
  39. Event ev;
  40. int x = 0, y = 0, ix = 1, iy = 1;
  41. try {
  42. qq = new Cucul();
  43. }
  44. catch (int e) {
  45. cerr << "Error while initializing cucul (" << e << ")" << endl;
  46. return -1;
  47. }
  48. try {
  49. kk = new Caca(qq);
  50. }
  51. catch(int e) {
  52. cerr << "Error while attaching cucul to caca (" << e << ")" << endl;
  53. return -1;
  54. }
  55. try {
  56. // Import buffer into a canvas
  57. pig = new Cucul();
  58. pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
  59. pig->importMemory(pigstring, strlen(pigstring), "text");
  60. }
  61. catch(int e) {
  62. cerr << "Error while importing image (" << e << ")" << endl;
  63. return -1;
  64. }
  65. kk->setDisplayTime(20000);
  66. while(!kk->getEvent(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) {
  67. /* In case of resize ...*/
  68. if((x + pig->getWidth())-1 >= qq->getWidth() || x < 0 )
  69. x = 0;
  70. if((y + pig->getHeight())-1 >= qq->getHeight() || y < 0 )
  71. y = 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. }