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.
 
 
 
 
 
 

109 lines
2.2 KiB

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