25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
2.4 KiB

  1. /*
  2. * frames canvas frame switching features
  3. * Copyright (c) 2006-2012 Sam Hocevar <sam@hocevar.net>
  4. * All Rights Reserved
  5. *
  6. * This program is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What the Fuck You Want
  9. * to Public License, Version 2, as published by Sam Hocevar. See
  10. * http://www.wtfpl.net/ for more details.
  11. */
  12. #include "config.h"
  13. #if !defined(__KERNEL__)
  14. # include <stdio.h>
  15. #endif
  16. #include "caca.h"
  17. int main(int argc, char *argv[])
  18. {
  19. caca_canvas_t *cv;
  20. caca_display_t *dp;
  21. int n, frame;
  22. /* Create a canvas with 200 frames */
  23. cv = caca_create_canvas(0, 0);
  24. if(cv == NULL)
  25. {
  26. printf("Can't create canvas\n");
  27. return -1;
  28. }
  29. for(frame = 1; frame < 200; frame++)
  30. caca_create_frame(cv, frame);
  31. fprintf(stderr, "canvas created, size is %ix%i\n",
  32. caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  33. /* Resize it to 150 x 80 (around 19MB) */
  34. caca_set_canvas_size(cv, 150, 80);
  35. fprintf(stderr, "canvas expanded, size is %ix%i\n",
  36. caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  37. /* Fill the first 16 frames with a different colour */
  38. for(frame = 0; frame < 16; frame++)
  39. {
  40. caca_set_frame(cv, frame);
  41. caca_set_color_ansi(cv, CACA_WHITE, frame);
  42. caca_fill_box(cv, 0, 0, 40, 15, ':');
  43. caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
  44. caca_put_str(cv, frame * 5 / 2, frame, "カカ");
  45. caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
  46. }
  47. /* Resize it to a more decent size */
  48. caca_set_canvas_size(cv, 41, 16);
  49. fprintf(stderr, "canvas shrinked, size is %ix%i\n",
  50. caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  51. dp = caca_create_display(cv);
  52. caca_set_display_time(dp, 50000);
  53. fprintf(stderr, "display attached, size is %ix%i\n",
  54. caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  55. n = 0;
  56. while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 0))
  57. {
  58. caca_set_frame(cv, n % 16);
  59. caca_refresh_display(dp);
  60. n++;
  61. }
  62. caca_free_display(dp);
  63. /* It is possible, though not necessary, to free all additional frames
  64. * separately. */
  65. caca_free_canvas(cv);
  66. return 0;
  67. }