Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

cxxtest.cpp 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. }