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.
 
 
 
 
 
 

112 regels
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. free(buffer);
  62. }
  63. static void raw_handle_resize(caca_display_t *dp)
  64. {
  65. ;
  66. }
  67. static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
  68. {
  69. ev->type = CACA_EVENT_NONE;
  70. return 0;
  71. }
  72. /*
  73. * Driver initialisation
  74. */
  75. int raw_install(caca_display_t *dp)
  76. {
  77. dp->drv.driver = CACA_DRIVER_RAW;
  78. dp->drv.init_graphics = raw_init_graphics;
  79. dp->drv.end_graphics = raw_end_graphics;
  80. dp->drv.set_display_title = raw_set_display_title;
  81. dp->drv.get_display_width = raw_get_display_width;
  82. dp->drv.get_display_height = raw_get_display_height;
  83. dp->drv.display = raw_display;
  84. dp->drv.handle_resize = raw_handle_resize;
  85. dp->drv.get_event = raw_get_event;
  86. dp->drv.set_mouse = NULL;
  87. return 0;
  88. }
  89. #endif /* !__KERNEL__ */