source: libcaca/trunk/examples/spritedit.c @ 2111

Last change on this file since 2111 was 2101, checked in by Sam Hocevar, 13 years ago
  • Rename "test" to "examples". The former will become a real testsuite.
  • Autodetect zzuf in the configure step. It might become handy.
  • Property svn:keywords set to Id
File size: 3.6 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 2101 2007-11-30 23:48:39Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16#include "common.h"
17#if !defined(__KERNEL__)
18#   include <stdio.h>
19#endif
20#include "cucul.h"
21#include "caca.h"
22
23#define MYDELAY 100
24
25int main(int argc, char **argv)
26{
27#if 0
28    cucul_canvas_t *cv;
29    caca_display_t *dp;
30
31    int quit = 0;
32    cucul_sprite_t *sprite;
33    int frame = 0;
34    unsigned char play = 0;
35    unsigned int delay = 0;
36
37    if(argc < 2)
38    {
39        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
40        return 1;
41    }
42
43    cv = cucul_create_canvas(0, 0);
44    if(!cv)
45        return 1;
46    dp = caca_create_display(cv);
47    if(!dp)
48        return 1;
49
50    sprite = cucul_load_sprite(argv[1]);
51
52    if(!sprite)
53    {
54        caca_free_display(dp);
55        cucul_free_canvas(cv);
56        fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
57        return 1;
58    }
59
60    /* Go ! */
61    while(!quit)
62    {
63        caca_event_t ev;
64        int xa, ya, xb, yb;
65        char buf[BUFSIZ];
66
67        while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
68        {
69            switch(caca_get_event_key_ch(&ev))
70            {
71            case 0:
72                break;
73            case 'q':
74                quit = 1;
75                break;
76            case '-':
77                if(frame > 0)
78                    frame--;
79                break;
80            case '+':
81                if(frame < cucul_get_sprite_frames(sprite) - 1)
82                    frame++;
83                break;
84            case 'p':
85                play=!play;
86
87            }
88        }
89
90        if(play) {
91            if(!delay) {
92                if(frame < cucul_get_sprite_frames(sprite) - 1) {
93                    frame++;
94                }
95                else {
96                    frame = 0;
97                }
98            }
99            delay++;
100            if(delay>=MYDELAY) {
101                delay = 0;
102            }
103        }
104
105
106        cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
107        cucul_clear_canvas(cv);
108
109        cucul_draw_thin_box(cv, 0, 0, cucul_get_canvas_width(cv) - 1,
110                            cucul_get_canvas_height(cv) - 1);
111
112        cucul_put_str(cv, 3, 0, "[ Sprite editor for libcaca ]");
113
114        sprintf(buf, "sprite `%s'", argv[1]);
115        cucul_put_str(cv, 3, 2, buf);
116        sprintf(buf, "frame %i/%i", frame, cucul_get_sprite_frames(sprite) - 1);
117        cucul_put_str(cv, 3, 3, buf);
118
119        /* Crosshair */
120        cucul_draw_thin_line(cv, 57, 2, 57, 18);
121        cucul_draw_thin_line(cv, 37, 10, 77, 10);
122        cucul_put_char(cv, 57, 10, '+');
123
124        /* Boxed sprite */
125        xa = -1 - cucul_get_sprite_dx(sprite, frame);
126        ya = -1 - cucul_get_sprite_dy(sprite, frame);
127        xb = xa + 1 + cucul_get_sprite_width(sprite, frame);
128        yb = ya + 1 + cucul_get_sprite_height(sprite, frame);
129        cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_BLACK);
130        cucul_fill_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb, " ");
131        cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
132        cucul_draw_thin_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb);
133        cucul_draw_sprite(cv, 57, 10, sprite, frame);
134
135        /* Free sprite */
136        cucul_draw_sprite(cv, 20, 10, sprite, frame);
137
138        caca_refresh_display(dp);
139    }
140
141    /* Clean up */
142    caca_free_display(dp);
143    cucul_free_canvas(cv);
144#endif
145
146    return 0;
147}
148
Note: See TracBrowser for help on using the repository browser.