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

Revision 4350, 2.3 KB checked in by sam, 3 years ago (diff)

Get rid of $Id$ keywords.

  • Property svn:keywords set to Id
Line 
1/*
2 *  TOIlet        The Other Implementation’s letters
3 *  Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  This program is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13/*
14 * This file contains text to canvas rendering functions.
15 */
16
17#include "config.h"
18
19#if defined(HAVE_INTTYPES_H)
20#   include <inttypes.h>
21#endif
22#include <stdlib.h>
23#include <caca.h>
24
25#include "toilet.h"
26#include "render.h"
27
28static int feed_tiny(context_t *, uint32_t, uint32_t);
29static int flush_tiny(context_t *);
30static int end_tiny(context_t *);
31
32int init_tiny(context_t *cx)
33{
34    cx->ew = 16;
35    cx->eh = 2;
36
37    cx->feed = feed_tiny;
38    cx->flush = flush_tiny;
39    cx->end = end_tiny;
40
41    return 0;
42}
43
44static int feed_tiny(context_t *cx, uint32_t ch, uint32_t attr)
45{
46    switch(ch)
47    {
48        case (uint32_t)'\r':
49            return 0;
50        case (uint32_t)'\n':
51            cx->x = 0;
52            cx->y++;
53            return 0;
54        case (uint32_t)'\t':
55            cx->x = (cx->x & ~7) + 8;
56            return 0;
57    }
58
59    /* Check whether we reached the end of the screen */
60    if(cx->x && cx->x + 1 > cx->term_width)
61    {
62        cx->x = 0;
63        cx->y++;
64    }
65
66    /* Check whether the current canvas is large enough */
67    if(cx->x + 1 > cx->w)
68    {
69        cx->w = cx->x + 1 < cx->term_width ? cx->x + 1 : cx->term_width;
70        if(cx->w > cx->ew)
71            cx->ew = cx->ew + cx->ew / 2;
72    }
73
74    if(cx->y + 1 > cx->h)
75    {
76        cx->h = cx->y + 1;
77        if(cx->h > cx->eh)
78            cx->eh = cx->eh + cx->eh / 2;
79    }
80
81    caca_set_attr(cx->cv, attr);
82    caca_set_canvas_size(cx->cv, cx->ew, cx->eh);
83
84    caca_put_char(cx->cv, cx->x, cx->y, ch);
85    cx->x++;
86
87    return 0;
88}
89
90static int flush_tiny(context_t *cx)
91{
92    cx->torender = cx->cv;
93    caca_set_canvas_size(cx->torender, cx->w, cx->h);
94
95    cx->ew = 16;
96    cx->eh = 2;
97    cx->x = cx->y = 0;
98    cx->w = cx->h = 0;
99    cx->cv = caca_create_canvas(cx->ew, cx->eh);
100
101    return 0;
102}
103
104static int end_tiny(context_t *cx)
105{
106    return 0;
107}
108
Note: See TracBrowser for help on using the repository browser.