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

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