source: libcaca/branches/0.9/test/spritedit.c @ 3273

Last change on this file since 3273 was 323, checked in by Sam Hocevar, 17 years ago
  • test/spritedit.c: + Moved spritedit to the test/ directory, because it is not mature enough.
  • libcaca.spec debian/control debian/rules: + Do not install caca-spritedit.
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1/*
2 *  spritedit     sprite editor for libcaca
3 *  Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: spritedit.c 323 2004-01-07 13:06:06Z 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        int event;
60
61        while((event = caca_get_event(CACA_EVENT_KEY_PRESS)))
62        {
63            switch(event & 0x00ffffff)
64            {
65            case 0:
66                break;
67            case 'q':
68                quit = 1;
69                break;
70            case '-':
71                if(frame > 0)
72                    frame--;
73                break;
74            case '+':
75                if(frame < caca_get_sprite_frames(sprite) - 1)
76                    frame++;
77                break;
78            }
79        }
80
81        caca_clear();
82
83        caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
84        caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1);
85
86        caca_putstr(3, 0, "[ Sprite editor for libcaca ]");
87
88        sprintf(buf, "sprite `%s'", argv[1]);
89        caca_putstr(3, 2, buf);
90        sprintf(buf, "frame %i/%i", frame, caca_get_sprite_frames(sprite) - 1);
91        caca_putstr(3, 3, buf);
92
93        /* Crosshair */
94        caca_draw_thin_line(57, 2, 57, 18);
95        caca_draw_thin_line(37, 10, 77, 10);
96        caca_putchar(57, 10, '+');
97
98        /* Boxed sprite */
99        xa = -1 - caca_get_sprite_dx(sprite, frame);
100        ya = -1 - caca_get_sprite_dy(sprite, frame);
101        xb = xa + 1 + caca_get_sprite_width(sprite, frame);
102        yb = ya + 1 + caca_get_sprite_height(sprite, frame);
103        caca_set_color(CACA_COLOR_BLACK, CACA_COLOR_BLACK);
104        caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
105        caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
106        caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
107        caca_draw_sprite(57, 10, sprite, frame);
108
109        /* Free sprite */
110        caca_draw_sprite(20, 10, sprite, frame);
111
112        caca_refresh();
113    }
114
115    /* Clean up */
116    caca_end();
117
118    return 0;
119}
120
Note: See TracBrowser for help on using the repository browser.