25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

cxxtest.cpp 3.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include "config.h"
  14. #include <iostream>
  15. #include <cucul++.h>
  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. Cucul *qq, *pig;
  37. Caca *kk;
  38. Event ev;
  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. Buffer *buf = new Buffer();
  57. buf->loadMemory((void *)pigstring, strlen(pigstring));
  58. pig = new Cucul(buf, "text");
  59. delete buf;
  60. // Change colour to magenta
  61. pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
  62. for(int y = 0; y < pig->getHeight(); y++)
  63. for(int x = 0; x < pig->getWidth(); x++)
  64. pig->putChar(x, y, pig->getChar(x, y));
  65. }
  66. catch(int e) {
  67. cerr << "Error while importing image (" << e << ")" << endl;
  68. return -1;
  69. }
  70. kk->setDisplayTime(20000);
  71. while(!kk->getEvent(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) {
  72. /* In case of resize ...*/
  73. if((x + pig->getWidth())-1 >= qq->getWidth() || x < 0 )
  74. x = 0;
  75. if((y + pig->getHeight())-1 >= qq->getHeight() || y < 0 )
  76. y = 0;
  77. qq->Clear();
  78. /* Draw pig */
  79. qq->Blit(x, y, pig, NULL);
  80. /* printf works */
  81. qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK);
  82. qq->Printf(qq->getWidth() / 2 - 10, qq->getHeight() / 2,
  83. "Powered by libcaca %s", VERSION);
  84. /* Blit */
  85. kk->Display();
  86. x += ix;
  87. y += iy;
  88. if(x + pig->getWidth() >= qq->getWidth() || x < 0 )
  89. ix = -ix;
  90. if(y + pig->getHeight() >= qq->getHeight() || y < 0 )
  91. iy = -iy;
  92. }
  93. delete kk;
  94. delete qq;
  95. return 0;
  96. }