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

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