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