source: libcaca/trunk/examples/blit.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: 2.1 KB
Line 
1/*
2 *  blit          libcaca blit test program
3 *  Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  $Id: blit.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    "   .'  _   _  '.\n"
28    "  /    o\\ /o   \\\n"
29    "  |    .-.-.    |  _\n"
30    "  |   /() ()\\   | (,`)\n"
31    " / \\  '-----'  / \\ .'\n"
32    "|   '-..___..-'   |\n"
33    "|                 |\n"
34    "|                 |\n"
35    ";                 ;\n"
36    " \\      / \\      /\n"
37    "  \\-..-/'-'\\-..-/\n"
38    "jgs\\/\\/     \\/\\/\n";
39
40int main(int argc, char *argv[])
41{
42    caca_canvas_t *cv, *sprite;
43    caca_display_t *dp;
44
45    cv = caca_create_canvas(80, 24);
46    if(cv == NULL)
47    {
48        printf("Failed to create canvas\n");
49        return 1;
50    }
51
52    dp = caca_create_display(cv);
53    if(dp == NULL)
54    {
55        printf("Failed to create display\n");
56        return 1;
57    }
58
59    sprite = caca_create_canvas(0, 0);
60    caca_set_color_ansi(sprite, CACA_LIGHTRED, CACA_BLACK);
61    caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text");
62    caca_set_canvas_handle(sprite, caca_get_canvas_width(sprite) / 2,
63                                    caca_get_canvas_height(sprite) / 2);
64
65    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
66    caca_put_str(cv, 0, 0, "Centered sprite");
67
68    caca_blit(cv, caca_get_canvas_width(cv) / 2,
69                   caca_get_canvas_height(cv) / 2, sprite, NULL);
70
71    caca_refresh_display(dp);
72
73    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
74
75    caca_free_display(dp);
76    caca_free_canvas(sprite);
77    caca_free_canvas(cv);
78
79    return 0;
80}
81
Note: See TracBrowser for help on using the repository browser.