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.
 
 
 
 
 
 

113 lines
2.3 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. void *buffer;
  56. unsigned long int len;
  57. buffer = cucul_export_memory(dp->cv, "caca", &len);
  58. if(!buffer)
  59. return;
  60. fwrite(buffer, len, 1, stdout);
  61. fflush(stdout);
  62. free(buffer);
  63. }
  64. static void raw_handle_resize(caca_display_t *dp)
  65. {
  66. ;
  67. }
  68. static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
  69. {
  70. ev->type = CACA_EVENT_NONE;
  71. return 0;
  72. }
  73. /*
  74. * Driver initialisation
  75. */
  76. int raw_install(caca_display_t *dp)
  77. {
  78. dp->drv.driver = CACA_DRIVER_RAW;
  79. dp->drv.init_graphics = raw_init_graphics;
  80. dp->drv.end_graphics = raw_end_graphics;
  81. dp->drv.set_display_title = raw_set_display_title;
  82. dp->drv.get_display_width = raw_get_display_width;
  83. dp->drv.get_display_height = raw_get_display_height;
  84. dp->drv.display = raw_display;
  85. dp->drv.handle_resize = raw_handle_resize;
  86. dp->drv.get_event = raw_get_event;
  87. dp->drv.set_mouse = NULL;
  88. return 0;
  89. }
  90. #endif /* !__KERNEL__ */