選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

114 行
2.4 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library 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. /*
  14. * This file contains the libcaca raw input and output driver
  15. */
  16. #include "config.h"
  17. #if !defined(__KERNEL__)
  18. # include <stdio.h>
  19. #endif
  20. #include "caca.h"
  21. #include "caca_internals.h"
  22. #include "cucul.h"
  23. #include "cucul_internals.h"
  24. static int raw_init_graphics(caca_t *kk)
  25. {
  26. return 0;
  27. }
  28. static int raw_end_graphics(caca_t *kk)
  29. {
  30. return 0;
  31. }
  32. static int raw_set_window_title(caca_t *kk, char const *title)
  33. {
  34. return 0;
  35. }
  36. static unsigned int raw_get_window_width(caca_t *kk)
  37. {
  38. return 0;
  39. }
  40. static unsigned int raw_get_window_height(caca_t *kk)
  41. {
  42. return 0;
  43. }
  44. static void raw_display(caca_t *kk)
  45. {
  46. uint32_t *attr = kk->qq->attr;
  47. uint32_t *chars = kk->qq->chars;
  48. uint32_t w, h;
  49. unsigned int n;
  50. w = kk->qq->width;
  51. h = kk->qq->height;
  52. fprintf(stdout, "CACA%c%c%c%c%c%c%c%c",
  53. (w >> 24), (w >> 16) & 0xff, (w >> 8) & 0xff, w & 0xff,
  54. (h >> 24), (h >> 16) & 0xff, (h >> 8) & 0xff, h & 0xff);
  55. for(n = kk->qq->height * kk->qq->width; n--; )
  56. {
  57. uint32_t c = *chars++;
  58. uint32_t a = *attr++;
  59. fprintf(stdout, "%c%c%c%c%c%c%c%c",
  60. (c >> 24), (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff,
  61. (a >> 24), (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff);
  62. }
  63. fprintf(stdout, "ACAC");
  64. fflush(stdout);
  65. }
  66. static void raw_handle_resize(caca_t *kk)
  67. {
  68. ;
  69. }
  70. static int raw_get_event(caca_t *kk, caca_event_t *ev)
  71. {
  72. ev->type = CACA_EVENT_NONE;
  73. return 0;
  74. }
  75. /*
  76. * Driver initialisation
  77. */
  78. int raw_install(caca_t *kk)
  79. {
  80. kk->drv.driver = CACA_DRIVER_RAW;
  81. kk->drv.init_graphics = raw_init_graphics;
  82. kk->drv.end_graphics = raw_end_graphics;
  83. kk->drv.set_window_title = raw_set_window_title;
  84. kk->drv.get_window_width = raw_get_window_width;
  85. kk->drv.get_window_height = raw_get_window_height;
  86. kk->drv.display = raw_display;
  87. kk->drv.handle_resize = raw_handle_resize;
  88. kk->drv.get_event = raw_get_event;
  89. kk->drv.set_mouse = NULL;
  90. return 0;
  91. }