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

Last change on this file since 2988 was 2988, checked in by Sam Hocevar, 12 years ago

Port toilet to the unified libcaca 0.99.beta15 API.

  • Property svn:keywords set to Id
File size: 2.3 KB
RevLine 
[1084]1/*
[1087]2 *  TOIlet        The Other Implementation’s letters
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
[1084]5 *
[1087]6 *  $Id: term.c 2988 2008-10-18 21:36:17Z sam $
[1084]7 *
[1461]8 *  This program is free software. It comes without any warranty, to
[1451]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
[1087]12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
[1084]13 */
14
[1102]15/*
16 * This file contains text to canvas rendering functions.
17 */
18
[1084]19#include "config.h"
20
[1087]21#if defined(HAVE_INTTYPES_H)
22#   include <inttypes.h>
23#endif
24#include <stdlib.h>
[2988]25#include <caca.h>
[1084]26
[1193]27#include "toilet.h"
[1100]28#include "render.h"
[1087]29
[1385]30static int feed_tiny(context_t *, uint32_t, uint32_t);
[1241]31static int flush_tiny(context_t *);
[1193]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;
[1241]40    cx->flush = flush_tiny;
[1193]41    cx->end = end_tiny;
42
43    return 0;
44}
45
[1385]46static int feed_tiny(context_t *cx, uint32_t ch, uint32_t attr)
[1193]47{
[1195]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
[1194]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    }
[1193]67
[1194]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    {
[1193]78        cx->h = cx->y + 1;
[1194]79        if(cx->h > cx->eh)
80            cx->eh = cx->eh + cx->eh / 2;
81    }
[1193]82
[2988]83    caca_set_attr(cx->cv, attr);
84    caca_set_canvas_size(cx->cv, cx->ew, cx->eh);
[1194]85
[2988]86    caca_put_char(cx->cv, cx->x, cx->y, ch);
[1195]87    cx->x++;
[1193]88
89    return 0;
90}
91
[1241]92static int flush_tiny(context_t *cx)
[1193]93{
[1241]94    cx->torender = cx->cv;
[2988]95    caca_set_canvas_size(cx->torender, cx->w, cx->h);
[1193]96
[1241]97    cx->ew = 16;
98    cx->eh = 2;
[1194]99    cx->x = cx->y = 0;
100    cx->w = cx->h = 0;
[2988]101    cx->cv = caca_create_canvas(cx->ew, cx->eh);
[1087]102
[1194]103    return 0;
104}
[1087]105
[1241]106static int end_tiny(context_t *cx)
[1194]107{
108    return 0;
[1087]109}
110
Note: See TracBrowser for help on using the repository browser.