source: libcaca/trunk/test/spritedit.c @ 185

Last change on this file since 185 was 185, checked in by Sam Hocevar, 20 years ago
  • Renamed libee to libcaca. Far less collisions.
  • 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 185 2003-11-16 00:33:35Z sam $
7 *
8 *   This program is free software; you can redistribute it and/or modify
9 *   it under the terms of the GNU General Public License as published by
10 *   the Free Software Foundation; either version 2 of the License, or
11 *   (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
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include "config.h"
24
25#include <stdio.h>
26
27#include "caca.h"
28
29int main(int argc, char **argv)
30{
31    int quit = 0;
32    struct caca_sprite *sprite;
33    int frame = 0;
34
35    if(argc < 2)
36    {
37        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
38        return 1;
39    }
40
41    if(caca_init())
42        return 1;
43
44    sprite = caca_load_sprite(argv[1]);
45
46    if(!sprite)
47    {
48        caca_end();
49        fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
50        return 1;
51    }
52
53    /* Go ! */
54    while(!quit)
55    {
56        int xa, ya, xb, yb;
57        char buf[BUFSIZ];
58
59        switch(caca_get_key())
60        {
61        case 0:
62            break;
63        case 'q':
64            quit = 1;
65            break;
66        case '-':
67            if(frame > 0)
68                frame--;
69            break;
70        case '+':
71            if(frame < caca_get_sprite_frames(sprite) - 1)
72                frame++;
73            break;
74        }
75
76        caca_clear();
77
78        caca_set_color(EE_WHITE);
79        caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1);
80
81        caca_putstr(3, 0, "[ Sprite editor for libcaca ]");
82
83        sprintf(buf, "sprite `%s'", argv[1]);
84        caca_putstr(3, 2, buf);
85        sprintf(buf, "frame %i/%i", frame, caca_get_sprite_frames(sprite) - 1);
86        caca_putstr(3, 3, buf);
87
88        /* Crosshair */
89        caca_draw_thin_line(57, 2, 57, 18);
90        caca_draw_thin_line(37, 10, 77, 10);
91        caca_putchar(57, 10, '+');
92
93        /* Boxed sprite */
94        xa = -1 - caca_get_sprite_dx(sprite, frame);
95        ya = -1 - caca_get_sprite_dy(sprite, frame);
96        xb = xa + 1 + caca_get_sprite_width(sprite, frame);
97        yb = ya + 1 + caca_get_sprite_height(sprite, frame);
98        caca_set_color(EE_BLACK);
99        caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
100        caca_set_color(EE_WHITE);
101        caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
102        caca_draw_sprite(57, 10, sprite, frame);
103
104        /* Free sprite */
105        caca_draw_sprite(20, 10, sprite, frame);
106
107        caca_refresh();
108    }
109
110    /* Clean up */
111    caca_end();
112
113    return 0;
114}
115
Note: See TracBrowser for help on using the repository browser.