Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

111 строки
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. #include "common.h"
  18. #if !defined(__KERNEL__)
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include "caca.h"
  22. #include "caca_internals.h"
  23. #include "cucul.h"
  24. #include "cucul_internals.h"
  25. static int raw_init_graphics(caca_display_t *dp)
  26. {
  27. unsigned int width = dp->cv->width, height = dp->cv->height;
  28. char const *geometry;
  29. #if defined(HAVE_GETENV)
  30. geometry = getenv("CACA_GEOMETRY");
  31. if(geometry && *geometry)
  32. sscanf(geometry, "%ux%u", &width, &height);
  33. #endif
  34. _cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
  35. return 0;
  36. }
  37. static int raw_end_graphics(caca_display_t *dp)
  38. {
  39. return 0;
  40. }
  41. static int raw_set_display_title(caca_display_t *dp, char const *title)
  42. {
  43. return -1;
  44. }
  45. static unsigned int raw_get_display_width(caca_display_t *dp)
  46. {
  47. return 0;
  48. }
  49. static unsigned int raw_get_display_height(caca_display_t *dp)
  50. {
  51. return 0;
  52. }
  53. static void raw_display(caca_display_t *dp)
  54. {
  55. cucul_buffer_t *buffer;
  56. buffer = cucul_export_canvas(dp->cv, "caca");
  57. fwrite(cucul_get_buffer_data(buffer),
  58. cucul_get_buffer_size(buffer), 1, stdout);
  59. fflush(stdout);
  60. cucul_free_buffer(buffer);
  61. }
  62. static void raw_handle_resize(caca_display_t *dp)
  63. {
  64. ;
  65. }
  66. static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
  67. {
  68. ev->type = CACA_EVENT_NONE;
  69. return 0;
  70. }
  71. /*
  72. * Driver initialisation
  73. */
  74. int raw_install(caca_display_t *dp)
  75. {
  76. dp->drv.driver = CACA_DRIVER_RAW;
  77. dp->drv.init_graphics = raw_init_graphics;
  78. dp->drv.end_graphics = raw_end_graphics;
  79. dp->drv.set_display_title = raw_set_display_title;
  80. dp->drv.get_display_width = raw_get_display_width;
  81. dp->drv.get_display_height = raw_get_display_height;
  82. dp->drv.display = raw_display;
  83. dp->drv.handle_resize = raw_handle_resize;
  84. dp->drv.get_event = raw_get_event;
  85. dp->drv.set_mouse = NULL;
  86. return 0;
  87. }
  88. #endif /* !__KERNEL__ */