Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

blit.c 2.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * blit libcaca blit test program
  3. * Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
  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. #if !defined(__KERNEL__)
  16. # include <stdio.h>
  17. # include <string.h>
  18. #endif
  19. #include "caca.h"
  20. static char const pig[] =
  21. " ,__ __,\n"
  22. " \\)`\\_..._/`(/\n"
  23. " .' _ _ '.\n"
  24. " / o\\ /o \\\n"
  25. " | .-.-. | _\n"
  26. " | /() ()\\ | (,`)\n"
  27. " / \\ '-----' / \\ .'\n"
  28. "| '-..___..-' |\n"
  29. "| |\n"
  30. "| |\n"
  31. "; ;\n"
  32. " \\ / \\ /\n"
  33. " \\-..-/'-'\\-..-/\n"
  34. "jgs\\/\\/ \\/\\/\n";
  35. int main(int argc, char *argv[])
  36. {
  37. caca_canvas_t *cv, *sprite;
  38. caca_display_t *dp;
  39. cv = caca_create_canvas(80, 24);
  40. if(cv == NULL)
  41. {
  42. printf("Failed to create canvas\n");
  43. return 1;
  44. }
  45. dp = caca_create_display(cv);
  46. if(dp == NULL)
  47. {
  48. printf("Failed to create display\n");
  49. return 1;
  50. }
  51. sprite = caca_create_canvas(0, 0);
  52. caca_set_color_ansi(sprite, CACA_LIGHTRED, CACA_BLACK);
  53. caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text");
  54. caca_set_canvas_handle(sprite, caca_get_canvas_width(sprite) / 2,
  55. caca_get_canvas_height(sprite) / 2);
  56. caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
  57. caca_put_str(cv, 0, 0, "Centered sprite");
  58. caca_blit(cv, caca_get_canvas_width(cv) / 2,
  59. caca_get_canvas_height(cv) / 2, sprite, NULL);
  60. caca_refresh_display(dp);
  61. caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
  62. caca_free_display(dp);
  63. caca_free_canvas(sprite);
  64. caca_free_canvas(cv);
  65. return 0;
  66. }