source: toilet/trunk/src/term.c @ 2263

Last change on this file since 2263 was 1461, checked in by Sam Hocevar, 16 years ago
  • Bwarf, typo in the no warranty clause.
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1/*
2 *  TOIlet        The Other Implementation’s letters
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: term.c 1461 2006-12-12 01:50:48Z sam $
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/*
16 * This file contains text to canvas rendering functions.
17 */
18
19#include "config.h"
20
21#if defined(HAVE_INTTYPES_H)
22#   include <inttypes.h>
23#endif
24#include <stdlib.h>
25#include <cucul.h>
26
27#include "toilet.h"
28#include "render.h"
29
30static int feed_tiny(context_t *, uint32_t, uint32_t);
31static int flush_tiny(context_t *);
32static int end_tiny(context_t *);
33
34int init_tiny(context_t *cx)
35{
36    cx->ew = 16;
37    cx->eh = 2;
38
39    cx->feed = feed_tiny;
40    cx->flush = flush_tiny;
41    cx->end = end_tiny;
42
43    return 0;
44}
45
46static int feed_tiny(context_t *cx, uint32_t ch, uint32_t attr)
47{
48    switch(ch)
49    {
50        case (uint32_t)'\r':
51            return 0;
52        case (uint32_t)'\n':
53            cx->x = 0;
54            cx->y++;
55            return 0;
56        case (uint32_t)'\t':
57            cx->x = (cx->x & ~7) + 8;
58            return 0;
59    }
60
61    /* Check whether we reached the end of the screen */
62    if(cx->x && cx->x + 1 > cx->term_width)
63    {
64        cx->x = 0;
65        cx->y++;
66    }
67
68    /* Check whether the current canvas is large enough */
69    if(cx->x + 1 > cx->w)
70    {
71        cx->w = cx->x + 1 < cx->term_width ? cx->x + 1 : cx->term_width;
72        if(cx->w > cx->ew)
73            cx->ew = cx->ew + cx->ew / 2;
74    }
75
76    if(cx->y + 1 > cx->h)
77    {
78        cx->h = cx->y + 1;
79        if(cx->h > cx->eh)
80            cx->eh = cx->eh + cx->eh / 2;
81    }
82
83    cucul_set_attr(cx->cv, attr);
84    cucul_set_canvas_size(cx->cv, cx->ew, cx->eh);
85
86    cucul_put_char(cx->cv, cx->x, cx->y, ch);
87    cx->x++;
88
89    return 0;
90}
91
92static int flush_tiny(context_t *cx)
93{
94    cx->torender = cx->cv;
95    cucul_set_canvas_size(cx->torender, cx->w, cx->h);
96
97    cx->ew = 16;
98    cx->eh = 2;
99    cx->x = cx->y = 0;
100    cx->w = cx->h = 0;
101    cx->cv = cucul_create_canvas(cx->ew, cx->eh);
102
103    return 0;
104}
105
106static int end_tiny(context_t *cx)
107{
108    return 0;
109}
110
Note: See TracBrowser for help on using the repository browser.