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.
 
 
 
 
 
 

118 lines
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. 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. 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. pig = new Cucul();
  57. pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
  58. pig->importMemory(pigstring, strlen(pigstring), "text");
  59. }
  60. catch(int e) {
  61. cerr << "Error while importing image (" << e << ")" << endl;
  62. return -1;
  63. }
  64. kk->setDisplayTime(20000);
  65. while(!kk->getEvent(Event::CACA_EVENT_KEY_PRESS, NULL, 0)) {
  66. /* In case of resize ...*/
  67. if((x + pig->getWidth())-1 >= qq->getWidth() || x < 0 )
  68. x = 0;
  69. if((y + pig->getHeight())-1 >= qq->getHeight() || y < 0 )
  70. y = 0;
  71. qq->Clear();
  72. /* Draw pig */
  73. qq->Blit(x, y, pig, NULL);
  74. /* printf works */
  75. qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK);
  76. qq->Printf(qq->getWidth() / 2 - 10, qq->getHeight() / 2,
  77. "Powered by libcaca %s", VERSION);
  78. /* Blit */
  79. kk->Display();
  80. x += ix;
  81. y += iy;
  82. if(x + pig->getWidth() >= qq->getWidth() || x < 0 )
  83. ix = -ix;
  84. if(y + pig->getHeight() >= qq->getHeight() || y < 0 )
  85. iy = -iy;
  86. }
  87. delete kk;
  88. delete qq;
  89. return 0;
  90. }