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

Last change on this file since 3514 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
RevLine 
[675]1/*
2 *  unicode       libcaca Unicode rendering test program
[3495]3 *  Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
[675]4 *                All Rights Reserved
5 *
6 *  $Id: transform.c 3495 2009-05-21 20:55:21Z sam $
7 *
[1462]8 *  This program is free software. It comes without any warranty, to
[1452]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
[675]12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
[2299]16
[1048]17#if !defined(__KERNEL__)
18#   include <stdio.h>
[1344]19#   include <string.h>
[675]20#endif
21
22#include "caca.h"
23
[1344]24static char const pig[] =
25    ",--.   ,--.\n"
26    "\\  /-~-\\  /\n"
27    " )' o O `(\n"
28    "(  ,---.  )\n"
29    " `(_o_o_)'\n"
30    "   )`-'(\n";
[675]31
[1344]32static char const duck[] =
33    "                ,~~.\n"
34    "    __     ,   (  O )>\n"
35    "___( o)>   )`~~'   (\n"
36    "\\ <_. )   (  .__)   )\n"
37    " `---'     `-.____,'\n";
[675]38
[1048]39int main(int argc, char *argv[])
[675]40{
[2821]41    caca_canvas_t *cv, *image, *tmp, *sprite;
[811]42    caca_display_t *dp;
[675]43
[2821]44    cv = caca_create_canvas(0, 0);
[1753]45    if(cv == NULL)
46    {
47        printf("Can't created canvas\n");
48        return -1;
49    }
[819]50    dp = caca_create_display(cv);
[1753]51    if(dp == NULL)
52    {
53        printf("Can't create display\n");
54        return -1;
55    }
[675]56
[2821]57    image = caca_create_canvas(70, 6);
58    tmp = caca_create_canvas(70, 6);
59    sprite = caca_create_canvas(0, 0);
[675]60
[2821]61    caca_set_color_ansi(sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
[3495]62    caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text");
[2821]63    caca_blit(image, 55, 0, sprite, NULL);
[675]64
[2821]65    caca_set_color_ansi(sprite, CACA_LIGHTGREEN, CACA_BLACK);
[3495]66    caca_import_canvas_from_memory(sprite, duck, strlen(duck), "text");
[2821]67    caca_blit(image, 30, 1, sprite, NULL);
[675]68
[2821]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, '|');
[675]73
[2821]74    caca_set_color_ansi(image, CACA_YELLOW, CACA_BLACK);
75    caca_put_str(image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
[675]76
[2821]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, "░▒▓");
[675]85
86    /* Blit the transformed canvas onto the main canvas */
[2821]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);
[1344]90
[2821]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);
[1344]95
[2821]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);
[1344]100
[2821]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);
[675]105
[819]106    caca_refresh_display(dp);
[675]107
[849]108    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
[675]109
[819]110    caca_free_display(dp);
[2821]111    caca_free_canvas(tmp);
112    caca_free_canvas(sprite);
113    caca_free_canvas(image);
114    caca_free_canvas(cv);
[675]115
116    return 0;
117}
118
Note: See TracBrowser for help on using the repository browser.