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

Last change on this file since 677 was 677, checked in by Sam Hocevar, 15 years ago
  • Renamed cucul_init()/cucul_end() into cucul_create()/cucul_free().
  • Property svn:keywords set to Id
File size: 3.0 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 677 2006-03-23 13:12:56Z 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
21int main(int argc, char **argv)
22{
23    cucul_t *qq;
24    caca_t *kk;
25
26    int quit = 0;
27    struct cucul_sprite *sprite;
28    int frame = 0;
29
30    if(argc < 2)
31    {
32        fprintf(stderr, "%s: missing argument (filename).\n", argv[0]);
33        return 1;
34    }
35
36    qq = cucul_create(0, 0);
37    if(!qq)
38        return 1;
39    kk = caca_attach(qq);
40    if(!kk)
41        return 1;
42
43    sprite = cucul_load_sprite(qq, argv[1]);
44
45    if(!sprite)
46    {
47        caca_detach(kk);
48        cucul_free(qq);
49        fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
50        return 1;
51    }
52
53    /* Go ! */
54    while(!quit)
55    {
56        int xa, ya, xb, yb;
57        char buf[BUFSIZ];
58        int event;
59
60        while((event = caca_get_event(kk, CACA_EVENT_KEY_PRESS)))
61        {
62            switch(event & 0x00ffffff)
63            {
64            case 0:
65                break;
66            case 'q':
67                quit = 1;
68                break;
69            case '-':
70                if(frame > 0)
71                    frame--;
72                break;
73            case '+':
74                if(frame < cucul_get_sprite_frames(qq, sprite) - 1)
75                    frame++;
76                break;
77            }
78        }
79
80        cucul_clear(qq);
81
82        cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
83        cucul_draw_thin_box(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1);
84
85        cucul_putstr(qq, 3, 0, "[ Sprite editor for libcaca ]");
86
87        sprintf(buf, "sprite `%s'", argv[1]);
88        cucul_putstr(qq, 3, 2, buf);
89        sprintf(buf, "frame %i/%i", frame, cucul_get_sprite_frames(qq, sprite) - 1);
90        cucul_putstr(qq, 3, 3, buf);
91
92        /* Crosshair */
93        cucul_draw_thin_line(qq, 57, 2, 57, 18);
94        cucul_draw_thin_line(qq, 37, 10, 77, 10);
95        cucul_putchar(qq, 57, 10, '+');
96
97        /* Boxed sprite */
98        xa = -1 - cucul_get_sprite_dx(qq, sprite, frame);
99        ya = -1 - cucul_get_sprite_dy(qq, sprite, frame);
100        xb = xa + 1 + cucul_get_sprite_width(qq, sprite, frame);
101        yb = ya + 1 + cucul_get_sprite_height(qq, sprite, frame);
102        cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);
103        cucul_fill_box(qq, 57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
104        cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
105        cucul_draw_thin_box(qq, 57 + xa, 10 + ya, 57 + xb, 10 + yb);
106        cucul_draw_sprite(qq, 57, 10, sprite, frame);
107
108        /* Free sprite */
109        cucul_draw_sprite(qq, 20, 10, sprite, frame);
110
111        caca_display(kk);
112    }
113
114    /* Clean up */
115    caca_detach(kk);
116    cucul_free(qq);
117
118    return 0;
119}
120
Note: See TracBrowser for help on using the repository browser.