source: libcaca/trunk/examples/text.c @ 2299

Last change on this file since 2299 was 2299, checked in by Sam Hocevar, 12 years ago
  • Remove #include <stdint.h> etc. from "common.h". Instead, make sure that <cucul.h> will provide the C99 types, even if libcaca has been installed.
  • Rename what's left of "common.h" to "stubs.h".
  • Remove all references to erroneous <inttypes.h> from source files.
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1/*
2 *  text          canvas text import/export
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: text.c 2299 2008-04-19 12:42:50Z 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#include "config.h"
16
17#if !defined(__KERNEL__)
18#   include <stdio.h>
19#   include <string.h>
20#   include <stdlib.h>
21#endif
22
23#include "cucul.h"
24
25#define STRING \
26  "              |_| \n" \
27  "   _,----._   | | \n" \
28  "  (/ @  @ \\)   __ \n" \
29  "   |  OO  |   |_  \n" \
30  "   \\ `--' /   |__ \n" \
31  "    `----'        \n" \
32  "              |_| \n" \
33  " Hello world!  |  \n" \
34  "                  \n"
35
36int main(int argc, char *argv[])
37{
38    cucul_canvas_t *cv, *pig;
39    void *buffer;
40    unsigned long int len;
41    unsigned int i, j;
42
43    pig = cucul_create_canvas(0, 0);
44    cucul_import_memory(pig, STRING, strlen(STRING), "text");
45
46    cv = cucul_create_canvas(cucul_get_canvas_width(pig) * 2,
47                             cucul_get_canvas_height(pig) * 2);
48
49    if(cv == NULL || pig == NULL)
50    {
51        printf("Can't created canvas\n");
52        return -1;
53    }
54
55    cucul_blit(cv, 0, 0, pig, NULL);
56    cucul_flip(pig);
57    cucul_blit(cv, cucul_get_canvas_width(pig), 0, pig, NULL);
58    cucul_flip(pig);
59    cucul_flop(pig);
60    cucul_blit(cv, 0, cucul_get_canvas_height(pig), pig, NULL);
61    cucul_flop(pig);
62    cucul_rotate_180(pig);
63    cucul_blit(cv, cucul_get_canvas_width(pig),
64                   cucul_get_canvas_height(pig), pig, NULL);
65
66    for(j = 0; j < cucul_get_canvas_height(cv); j++)
67    {
68        for(i = 0; i < cucul_get_canvas_width(cv); i += 2)
69        {
70            unsigned long int a;
71            cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE + (i + j) % 6,
72                                 CUCUL_DEFAULT);
73            a = cucul_get_attr(cv, -1, -1);
74            cucul_put_attr(cv, i, j, a);
75            cucul_put_attr(cv, i + 1, j, a);
76        }
77    }
78
79    buffer = cucul_export_memory(cv, "utf8", &len);
80    fwrite(buffer, len, 1, stdout);
81    free(buffer);
82
83    cucul_rotate_left(cv);
84    buffer = cucul_export_memory(cv, "utf8", &len);
85    fwrite(buffer, len, 1, stdout);
86    free(buffer);
87
88    cucul_free_canvas(pig);
89    cucul_free_canvas(cv);
90
91    return 0;
92}
93
Note: See TracBrowser for help on using the repository browser.