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

Last change on this file since 2101 was 2101, checked in by Sam Hocevar, 12 years ago
  • Rename "test" to "examples". The former will become a real testsuite.
  • Autodetect zzuf in the configure step. It might become handy.
  • Property svn:keywords set to Id
File size: 2.5 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 2101 2007-11-30 23:48:39Z 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#include "common.h"
17#if !defined(__KERNEL__)
18#   if defined(HAVE_INTTYPES_H)
19#      include <inttypes.h>
20#   endif
21#   include <stdio.h>
22#   include <string.h>
23#   include <stdlib.h>
24#endif
25#include "cucul.h"
26
27#define STRING \
28  "              |_| \n" \
29  "   _,----._   | | \n" \
30  "  (/ @  @ \\)   __ \n" \
31  "   |  OO  |   |_  \n" \
32  "   \\ `--' /   |__ \n" \
33  "    `----'        \n" \
34  "              |_| \n" \
35  " Hello world!  |  \n" \
36  "                  \n"
37
38int main(int argc, char *argv[])
39{
40    cucul_canvas_t *cv, *pig;
41    void *buffer;
42    unsigned long int len;
43    unsigned int i, j;
44
45    pig = cucul_create_canvas(0, 0);
46    cucul_import_memory(pig, STRING, strlen(STRING), "text");
47
48    cv = cucul_create_canvas(cucul_get_canvas_width(pig) * 2,
49                             cucul_get_canvas_height(pig) * 2);
50
51    if(cv == NULL || pig == NULL)
52    {
53        printf("Can't created canvas\n");
54        return -1;
55    }
56
57    cucul_blit(cv, 0, 0, pig, NULL);
58    cucul_flip(pig);
59    cucul_blit(cv, cucul_get_canvas_width(pig), 0, pig, NULL);
60    cucul_flip(pig);
61    cucul_flop(pig);
62    cucul_blit(cv, 0, cucul_get_canvas_height(pig), pig, NULL);
63    cucul_flop(pig);
64    cucul_rotate_180(pig);
65    cucul_blit(cv, cucul_get_canvas_width(pig),
66                   cucul_get_canvas_height(pig), pig, NULL);
67
68    for(j = 0; j < cucul_get_canvas_height(cv); j++)
69    {
70        for(i = 0; i < cucul_get_canvas_width(cv); i += 2)
71        {
72            unsigned long int a;
73            cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE + (i + j) % 6,
74                                 CUCUL_DEFAULT);
75            a = cucul_get_attr(cv, -1, -1);
76            cucul_put_attr(cv, i, j, a);
77            cucul_put_attr(cv, i + 1, j, a);
78        }
79    }
80
81    buffer = cucul_export_memory(cv, "utf8", &len);
82    fwrite(buffer, len, 1, stdout);
83    free(buffer);
84
85    cucul_rotate_left(cv);
86    buffer = cucul_export_memory(cv, "utf8", &len);
87    fwrite(buffer, len, 1, stdout);
88    free(buffer);
89
90    cucul_free_canvas(pig);
91    cucul_free_canvas(cv);
92
93    return 0;
94}
95
Note: See TracBrowser for help on using the repository browser.