source: libcaca/trunk/examples/spritedit.c @ 193

Last change on this file since 193 was 193, checked in by Sam Hocevar, 18 years ago
  • src/blit.c: + Added caca_set_dithering() (unused yet). + Added random dithering.
  • src/caca.h: + Renamed legacy EE_* enums to CACA_*.
  • examples/demo.c examples/caca.txt: + Added a default sprite for libcaca.
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/*
2 *   spritedit     sprite editor using libcaca
3 *   Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
4 *                 All Rights Reserved
5 *
6 *   $Id: spritedit.c 193 2003-11-16 15:20:17Z sam $
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU Lesser General Public
10 *   License as published by the Free Software Foundation; either
11 *   version 2 of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 *   Lesser General Public License for more details.
17 *
18 *   You should have received a copy of the GNU Lesser General Public
19 *   License along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 *   02111-1307  USA
22 */
23
24#include "config.h"
25
26#include <stdio.h>
27
28#include "caca.h"
29
30int main(int argc, char **argv)
31{
32    int quit = 0;
33    struct caca_sprite *sprite;
34    int frame = 0;
35
36    if(argc < 2)
37    {
38        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
39        return 1;
40    }
41
42    if(caca_init())
43        return 1;
44
45    sprite = caca_load_sprite(argv[1]);
46
47    if(!sprite)
48    {
49        caca_end();
50        fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
51        return 1;
52    }
53
54    /* Go ! */
55    while(!quit)
56    {
57        int xa, ya, xb, yb;
58        char buf[BUFSIZ];
59
60        switch(caca_get_key())
61        {
62        case 0:
63            break;
64        case 'q':
65            quit = 1;
66            break;
67        case '-':
68            if(frame > 0)
69                frame--;
70            break;
71        case '+':
72            if(frame < caca_get_sprite_frames(sprite) - 1)
73                frame++;
74            break;
75        }
76
77        caca_clear();
78
79        caca_set_color(CACA_COLOR_WHITE);
80        caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1);
81
82        caca_putstr(3, 0, "[ Sprite editor for libcaca ]");
83
84        sprintf(buf, "sprite `%s'", argv[1]);
85        caca_putstr(3, 2, buf);
86        sprintf(buf, "frame %i/%i", frame, caca_get_sprite_frames(sprite) - 1);
87        caca_putstr(3, 3, buf);
88
89        /* Crosshair */
90        caca_draw_thin_line(57, 2, 57, 18);
91        caca_draw_thin_line(37, 10, 77, 10);
92        caca_putchar(57, 10, '+');
93
94        /* Boxed sprite */
95        xa = -1 - caca_get_sprite_dx(sprite, frame);
96        ya = -1 - caca_get_sprite_dy(sprite, frame);
97        xb = xa + 1 + caca_get_sprite_width(sprite, frame);
98        yb = ya + 1 + caca_get_sprite_height(sprite, frame);
99        caca_set_color(CACA_COLOR_BLACK);
100        caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
101        caca_set_color(CACA_COLOR_WHITE);
102        caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
103        caca_draw_sprite(57, 10, sprite, frame);
104
105        /* Free sprite */
106        caca_draw_sprite(20, 10, sprite, frame);
107
108        caca_refresh();
109    }
110
111    /* Clean up */
112    caca_end();
113
114    return 0;
115}
116
Note: See TracBrowser for help on using the repository browser.