source: libcaca/trunk/examples/transform.c @ 3495

Last change on this file since 3495 was 3495, checked in by Sam Hocevar, 11 years ago

Add caca_export_area_to_memory() to export only a selected part of the
current canvas. This is useful to export dirty rectangles. Accordingly,
add caca_import_area_from_memory() and caca_import_area_from_file().

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1/*
2 *  unicode       libcaca Unicode rendering test program
3 *  Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  $Id: transform.c 3495 2009-05-21 20:55:21Z 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#endif
21
22#include "caca.h"
23
24static char const pig[] =
25    ",--.   ,--.\n"
26    "\\  /-~-\\  /\n"
27    " )' o O `(\n"
28    "(  ,---.  )\n"
29    " `(_o_o_)'\n"
30    "   )`-'(\n";
31
32static char const duck[] =
33    "                ,~~.\n"
34    "    __     ,   (  O )>\n"
35    "___( o)>   )`~~'   (\n"
36    "\\ <_. )   (  .__)   )\n"
37    " `---'     `-.____,'\n";
38
39int main(int argc, char *argv[])
40{
41    caca_canvas_t *cv, *image, *tmp, *sprite;
42    caca_display_t *dp;
43
44    cv = caca_create_canvas(0, 0);
45    if(cv == NULL)
46    {
47        printf("Can't created canvas\n");
48        return -1;
49    }
50    dp = caca_create_display(cv);
51    if(dp == NULL)
52    {
53        printf("Can't create display\n");
54        return -1;
55    }
56
57    image = caca_create_canvas(70, 6);
58    tmp = caca_create_canvas(70, 6);
59    sprite = caca_create_canvas(0, 0);
60
61    caca_set_color_ansi(sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
62    caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text");
63    caca_blit(image, 55, 0, sprite, NULL);
64
65    caca_set_color_ansi(sprite, CACA_LIGHTGREEN, CACA_BLACK);
66    caca_import_canvas_from_memory(sprite, duck, strlen(duck), "text");
67    caca_blit(image, 30, 1, sprite, NULL);
68
69    caca_set_color_ansi(image, CACA_LIGHTCYAN, CACA_BLACK);
70    caca_put_str(image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
71    caca_set_color_ansi(image, CACA_LIGHTRED, CACA_BLACK);
72    caca_put_char(image, 38, 1, '|');
73
74    caca_set_color_ansi(image, CACA_YELLOW, CACA_BLACK);
75    caca_put_str(image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
76
77    caca_set_color_ansi(image, CACA_WHITE, CACA_LIGHTRED);
78    caca_put_str(image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
79    caca_put_str(image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
80    caca_set_color_ansi(image, CACA_BLACK, CACA_LIGHTRED);
81    caca_put_str(image, 4, 3, "▓▒░");
82    caca_put_str(image, 4, 4, "▓▒░");
83    caca_put_str(image, 24, 3, "░▒▓");
84    caca_put_str(image, 24, 4, "░▒▓");
85
86    /* Blit the transformed canvas onto the main canvas */
87    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
88    caca_put_str(cv, 0, 0, "normal");
89    caca_blit(cv, 10, 0, image, NULL);
90
91    caca_put_str(cv, 0, 6, "flip");
92    caca_blit(tmp, 0, 0, image, NULL);
93    caca_flip(tmp);
94    caca_blit(cv, 10, 6, tmp, NULL);
95
96    caca_put_str(cv, 0, 12, "flop");
97    caca_blit(tmp, 0, 0, image, NULL);
98    caca_flop(tmp);
99    caca_blit(cv, 10, 12, tmp, NULL);
100
101    caca_put_str(cv, 0, 18, "rotate");
102    caca_blit(tmp, 0, 0, image, NULL);
103    caca_rotate_180(tmp);
104    caca_blit(cv, 10, 18, tmp, NULL);
105
106    caca_refresh_display(dp);
107
108    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
109
110    caca_free_display(dp);
111    caca_free_canvas(tmp);
112    caca_free_canvas(sprite);
113    caca_free_canvas(image);
114    caca_free_canvas(cv);
115
116    return 0;
117}
118
Note: See TracBrowser for help on using the repository browser.