Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * TOIlet The Other Implementation’s letters
  3. * Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program 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 text to canvas rendering functions.
  16. */
  17. #include "config.h"
  18. #if defined(HAVE_INTTYPES_H)
  19. # include <inttypes.h>
  20. #endif
  21. #include <stdlib.h>
  22. #include <caca.h>
  23. #include "toilet.h"
  24. #include "render.h"
  25. static int feed_tiny(context_t *, uint32_t, uint32_t);
  26. static int flush_tiny(context_t *);
  27. static int end_tiny(context_t *);
  28. int init_tiny(context_t *cx)
  29. {
  30. cx->ew = 16;
  31. cx->eh = 2;
  32. cx->feed = feed_tiny;
  33. cx->flush = flush_tiny;
  34. cx->end = end_tiny;
  35. return 0;
  36. }
  37. static int feed_tiny(context_t *cx, uint32_t ch, uint32_t attr)
  38. {
  39. switch(ch)
  40. {
  41. case (uint32_t)'\r':
  42. return 0;
  43. case (uint32_t)'\n':
  44. cx->x = 0;
  45. cx->y++;
  46. return 0;
  47. case (uint32_t)'\t':
  48. cx->x = (cx->x & ~7) + 8;
  49. return 0;
  50. }
  51. /* Check whether we reached the end of the screen */
  52. if(cx->x && cx->x + 1 > cx->term_width)
  53. {
  54. cx->x = 0;
  55. cx->y++;
  56. }
  57. /* Check whether the current canvas is large enough */
  58. if(cx->x + 1 > cx->w)
  59. {
  60. cx->w = cx->x + 1 < cx->term_width ? cx->x + 1 : cx->term_width;
  61. if(cx->w > cx->ew)
  62. cx->ew = cx->ew + cx->ew / 2;
  63. }
  64. if(cx->y + 1 > cx->h)
  65. {
  66. cx->h = cx->y + 1;
  67. if(cx->h > cx->eh)
  68. cx->eh = cx->eh + cx->eh / 2;
  69. }
  70. caca_set_attr(cx->cv, attr);
  71. caca_set_canvas_size(cx->cv, cx->ew, cx->eh);
  72. caca_put_char(cx->cv, cx->x, cx->y, ch);
  73. cx->x++;
  74. return 0;
  75. }
  76. static int flush_tiny(context_t *cx)
  77. {
  78. cx->torender = cx->cv;
  79. caca_set_canvas_size(cx->torender, cx->w, cx->h);
  80. cx->ew = 16;
  81. cx->eh = 2;
  82. cx->x = cx->y = 0;
  83. cx->w = cx->h = 0;
  84. cx->cv = caca_create_canvas(cx->ew, cx->eh);
  85. return 0;
  86. }
  87. static int end_tiny(context_t *cx)
  88. {
  89. return 0;
  90. }