You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

116 lines
2.5 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library 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. /*
  15. * This file contains the libcaca raw input and output driver
  16. */
  17. #include "config.h"
  18. #if !defined(__KERNEL__)
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include "caca.h"
  22. #include "caca_internals.h"
  23. static int raw_init_graphics(caca_display_t *dp)
  24. {
  25. int width = caca_get_canvas_width(dp->cv);
  26. int height = caca_get_canvas_height(dp->cv);
  27. char const *geometry;
  28. #if defined(HAVE_GETENV)
  29. geometry = getenv("CACA_GEOMETRY");
  30. if(geometry && *geometry)
  31. sscanf(geometry, "%ux%u", &width, &height);
  32. #endif
  33. dp->resize.allow = 1;
  34. caca_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
  35. dp->resize.allow = 0;
  36. return 0;
  37. }
  38. static int raw_end_graphics(caca_display_t *dp)
  39. {
  40. return 0;
  41. }
  42. static int raw_set_display_title(caca_display_t *dp, char const *title)
  43. {
  44. return -1;
  45. }
  46. static int raw_get_display_width(caca_display_t const *dp)
  47. {
  48. return 0;
  49. }
  50. static int raw_get_display_height(caca_display_t const *dp)
  51. {
  52. return 0;
  53. }
  54. static void raw_display(caca_display_t *dp)
  55. {
  56. void *buffer;
  57. size_t len;
  58. buffer = caca_export_canvas_to_memory(dp->cv, "caca", &len);
  59. if(!buffer)
  60. return;
  61. fwrite(buffer, len, 1, stdout);
  62. fflush(stdout);
  63. free(buffer);
  64. }
  65. static void raw_handle_resize(caca_display_t *dp)
  66. {
  67. ;
  68. }
  69. static int raw_get_event(caca_display_t *dp, caca_privevent_t *ev)
  70. {
  71. ev->type = CACA_EVENT_NONE;
  72. return 0;
  73. }
  74. /*
  75. * Driver initialisation
  76. */
  77. int raw_install(caca_display_t *dp)
  78. {
  79. dp->drv.id = CACA_DRIVER_RAW;
  80. dp->drv.driver = "raw";
  81. dp->drv.init_graphics = raw_init_graphics;
  82. dp->drv.end_graphics = raw_end_graphics;
  83. dp->drv.set_display_title = raw_set_display_title;
  84. dp->drv.get_display_width = raw_get_display_width;
  85. dp->drv.get_display_height = raw_get_display_height;
  86. dp->drv.display = raw_display;
  87. dp->drv.handle_resize = raw_handle_resize;
  88. dp->drv.get_event = raw_get_event;
  89. dp->drv.set_mouse = NULL;
  90. dp->drv.set_cursor = NULL;
  91. return 0;
  92. }
  93. #endif /* !__KERNEL__ */