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

Last change on this file since 183 was 153, checked in by Sam Hocevar, 20 years ago
  • libee/graphics.c: + Renamed ee_color() to ee_set_color(), wrote ee_get_color().
  • libee/line.c: + Implemented draw_polyline() and draw_thin_polyline().
  • libee/sprite.c: + Removed the f member of struct ee_sprite. + Implemented ee_get_sprite_{width|height|dx|dy}(). + Restore the color fater ee_draw_sprite() is called.
  • libee/box.c: + Fixed a bug causing improper box clipping at the right and the bottom.
  • data/foo_fighter: + Fixed bugs in the sprite.
  • src/intro.c: + Test effects for the future game's intro.
  • test/spritedit.c: + Added stuff to the sprite editor. We can now navigate through frames.
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/*
2 *   spritedit     sprite editor using libee
3 *   Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
4 *                 All Rights Reserved
5 *
6 *   $Id: spritedit.c 153 2003-11-12 01:48:58Z 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 "ee.h"
28
29int main(int argc, char **argv)
30{
31    int quit = 0;
32    struct ee_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(ee_init())
42        return 1;
43
44    sprite = ee_load_sprite(argv[1]);
45
46    if(!sprite)
47    {
48        ee_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(ee_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 < ee_get_sprite_frames(sprite) - 1)
72                frame++;
73            break;
74        }
75
76        ee_clear();
77
78        ee_set_color(EE_WHITE);
79        ee_draw_thin_box(0, 0, ee_get_width() - 1, ee_get_height() - 1);
80
81        ee_putstr(3, 0, "[ Sprite editor for libee ]");
82
83        sprintf(buf, "sprite `%s'", argv[1]);
84        ee_putstr(3, 2, buf);
85        sprintf(buf, "frame %i/%i", frame, ee_get_sprite_frames(sprite) - 1);
86        ee_putstr(3, 3, buf);
87
88        /* Crosshair */
89        ee_draw_thin_line(57, 2, 57, 18);
90        ee_draw_thin_line(37, 10, 77, 10);
91        ee_putchar(57, 10, '+');
92
93        /* Boxed sprite */
94        xa = -1 - ee_get_sprite_dx(sprite, frame);
95        ya = -1 - ee_get_sprite_dy(sprite, frame);
96        xb = xa + 1 + ee_get_sprite_width(sprite, frame);
97        yb = ya + 1 + ee_get_sprite_height(sprite, frame);
98        ee_set_color(EE_BLACK);
99        ee_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
100        ee_set_color(EE_WHITE);
101        ee_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
102        ee_draw_sprite(57, 10, sprite, frame);
103
104        /* Free sprite */
105        ee_draw_sprite(20, 10, sprite, frame);
106
107        ee_refresh();
108    }
109
110    /* Clean up */
111    ee_end();
112
113    return 0;
114}
115
Note: See TracBrowser for help on using the repository browser.