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 199 2003-11-19 17:32:10Z 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 | |
---|
30 | int 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())) |
---|
62 | { |
---|
63 | if(event & CACA_EVENT_KEY_PRESS) |
---|
64 | switch(event & 0xff) |
---|
65 | { |
---|
66 | case 0: |
---|
67 | break; |
---|
68 | case 'q': |
---|
69 | quit = 1; |
---|
70 | break; |
---|
71 | case '-': |
---|
72 | if(frame > 0) |
---|
73 | frame--; |
---|
74 | break; |
---|
75 | case '+': |
---|
76 | if(frame < caca_get_sprite_frames(sprite) - 1) |
---|
77 | frame++; |
---|
78 | break; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | caca_clear(); |
---|
83 | |
---|
84 | caca_set_color(CACA_COLOR_WHITE); |
---|
85 | caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1); |
---|
86 | |
---|
87 | caca_putstr(3, 0, "[ Sprite editor for libcaca ]"); |
---|
88 | |
---|
89 | sprintf(buf, "sprite `%s'", argv[1]); |
---|
90 | caca_putstr(3, 2, buf); |
---|
91 | sprintf(buf, "frame %i/%i", frame, caca_get_sprite_frames(sprite) - 1); |
---|
92 | caca_putstr(3, 3, buf); |
---|
93 | |
---|
94 | /* Crosshair */ |
---|
95 | caca_draw_thin_line(57, 2, 57, 18); |
---|
96 | caca_draw_thin_line(37, 10, 77, 10); |
---|
97 | caca_putchar(57, 10, '+'); |
---|
98 | |
---|
99 | /* Boxed sprite */ |
---|
100 | xa = -1 - caca_get_sprite_dx(sprite, frame); |
---|
101 | ya = -1 - caca_get_sprite_dy(sprite, frame); |
---|
102 | xb = xa + 1 + caca_get_sprite_width(sprite, frame); |
---|
103 | yb = ya + 1 + caca_get_sprite_height(sprite, frame); |
---|
104 | caca_set_color(CACA_COLOR_BLACK); |
---|
105 | caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' '); |
---|
106 | caca_set_color(CACA_COLOR_WHITE); |
---|
107 | caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb); |
---|
108 | caca_draw_sprite(57, 10, sprite, frame); |
---|
109 | |
---|
110 | /* Free sprite */ |
---|
111 | caca_draw_sprite(20, 10, sprite, frame); |
---|
112 | |
---|
113 | caca_refresh(); |
---|
114 | } |
---|
115 | |
---|
116 | /* Clean up */ |
---|
117 | caca_end(); |
---|
118 | |
---|
119 | return 0; |
---|
120 | } |
---|
121 | |
---|