source: libcaca/trunk/examples/transform.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: 3.5 KB
Line 
1/*
2 *  unicode       libcaca Unicode rendering test program
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: transform.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#endif
24
25#include "cucul.h"
26#include "caca.h"
27
28static char const pig[] =
29    ",--.   ,--.\n"
30    "\\  /-~-\\  /\n"
31    " )' o O `(\n"
32    "(  ,---.  )\n"
33    " `(_o_o_)'\n"
34    "   )`-'(\n";
35
36static char const duck[] =
37    "                ,~~.\n"
38    "    __     ,   (  O )>\n"
39    "___( o)>   )`~~'   (\n"
40    "\\ <_. )   (  .__)   )\n"
41    " `---'     `-.____,'\n";
42
43int main(int argc, char *argv[])
44{
45    cucul_canvas_t *cv, *image, *tmp, *sprite;
46    caca_display_t *dp;
47
48    cv = cucul_create_canvas(0, 0);
49    if(cv == NULL)
50    {
51        printf("Can't created canvas\n");
52        return -1;
53    }
54    dp = caca_create_display(cv);
55    if(dp == NULL)
56    {
57        printf("Can't create display\n");
58        return -1;
59    }
60
61    image = cucul_create_canvas(70, 6);
62    tmp = cucul_create_canvas(70, 6);
63    sprite = cucul_create_canvas(0, 0);
64
65    cucul_set_color_ansi(sprite, CUCUL_LIGHTMAGENTA, CUCUL_BLACK);
66    cucul_import_memory(sprite, pig, strlen(pig), "text");
67    cucul_blit(image, 55, 0, sprite, NULL);
68
69    cucul_set_color_ansi(sprite, CUCUL_LIGHTGREEN, CUCUL_BLACK);
70    cucul_import_memory(sprite, duck, strlen(duck), "text");
71    cucul_blit(image, 30, 1, sprite, NULL);
72
73    cucul_set_color_ansi(image, CUCUL_LIGHTCYAN, CUCUL_BLACK);
74    cucul_put_str(image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
75    cucul_set_color_ansi(image, CUCUL_LIGHTRED, CUCUL_BLACK);
76    cucul_put_char(image, 38, 1, '|');
77
78    cucul_set_color_ansi(image, CUCUL_YELLOW, CUCUL_BLACK);
79    cucul_put_str(image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
80
81    cucul_set_color_ansi(image, CUCUL_WHITE, CUCUL_LIGHTRED);
82    cucul_put_str(image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
83    cucul_put_str(image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
84    cucul_set_color_ansi(image, CUCUL_BLACK, CUCUL_LIGHTRED);
85    cucul_put_str(image, 4, 3, "▓▒░");
86    cucul_put_str(image, 4, 4, "▓▒░");
87    cucul_put_str(image, 24, 3, "░▒▓");
88    cucul_put_str(image, 24, 4, "░▒▓");
89
90    /* Blit the transformed canvas onto the main canvas */
91    cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
92    cucul_put_str(cv, 0, 0, "normal");
93    cucul_blit(cv, 10, 0, image, NULL);
94
95    cucul_put_str(cv, 0, 6, "flip");
96    cucul_blit(tmp, 0, 0, image, NULL);
97    cucul_flip(tmp);
98    cucul_blit(cv, 10, 6, tmp, NULL);
99
100    cucul_put_str(cv, 0, 12, "flop");
101    cucul_blit(tmp, 0, 0, image, NULL);
102    cucul_flop(tmp);
103    cucul_blit(cv, 10, 12, tmp, NULL);
104
105    cucul_put_str(cv, 0, 18, "rotate");
106    cucul_blit(tmp, 0, 0, image, NULL);
107    cucul_rotate_180(tmp);
108    cucul_blit(cv, 10, 18, tmp, NULL);
109
110    caca_refresh_display(dp);
111
112    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
113
114    caca_free_display(dp);
115    cucul_free_canvas(tmp);
116    cucul_free_canvas(sprite);
117    cucul_free_canvas(image);
118    cucul_free_canvas(cv);
119
120    return 0;
121}
122
Note: See TracBrowser for help on using the repository browser.