1 /*
2  * TilEm II
3  *
4  * Copyright (c) 2011 Benjamin Moody
5  *
6  * This program is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation, either version 3 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <gtk/gtk.h>
21 
22 G_BEGIN_DECLS
23 
24 #define TILEM_TYPE_ANIMATION           (tilem_animation_get_type())
25 #define TILEM_ANIMATION(obj)           (G_TYPE_CHECK_INSTANCE_CAST((obj), TILEM_TYPE_ANIMATION, TilemAnimation))
26 #define TILEM_ANIMATION_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST((cls), TILEM_TYPE_ANIMATION, TilemAnimationClass))
27 #define TILEM_IS_ANIMATION(obj)        (G_TYPE_CHECK_INSTANCE_TYPE((obj), TILEM_TYPE_ANIMATION))
28 #define TILEM_IS_ANIMATION_CLASS(cls)  (G_TYPE_CHECK_CLASS_TYPE((cls), TILEM_TYPE_ANIMATION))
29 #define TILEM_ANIMATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TILEM_TYPE_ANIMATION, TilemAnimationClass))
30 
31 typedef struct _TilemAnimation TilemAnimation;
32 typedef struct _TilemAnimationClass TilemAnimationClass;
33 typedef struct _TilemAnimFrame TilemAnimFrame;
34 
35 GType tilem_animation_get_type(void) G_GNUC_CONST;
36 
37 /* Create a new TilemAnimation for the given display dimensions. */
38 TilemAnimation * tilem_animation_new(int display_width,
39                                      int display_height);
40 
41 /* Add a frame to the animation.  BUF holds the LCD contents, DURATION
42    is the length of time this frame should be displayed (in
43    milliseconds.) */
44 gboolean tilem_animation_append_frame(TilemAnimation *anim,
45                                       const TilemLCDBuffer *buf,
46                                       int duration);
47 
48 /* Set output image size. */
49 void tilem_animation_set_size(TilemAnimation *anim, int width, int height);
50 
51 /* Set output image colors. */
52 void tilem_animation_set_colors(TilemAnimation *anim,
53                                 const GdkColor *foreground,
54                                 const GdkColor *background);
55 
56 /* Set animation speed factor */
57 void tilem_animation_set_speed(TilemAnimation *anim, gdouble factor);
58 
59 /* Get animation speed factor */
60 gdouble tilem_animation_get_speed(TilemAnimation *anim);
61 
62 /* Retrieve the next frame of the animation.  If FRM is NULL, retrieve
63    the first frame.  If FRM is non-null, it must be a frame belonging
64    to this animation. */
65 TilemAnimFrame *tilem_animation_next_frame(TilemAnimation *anim,
66                                            TilemAnimFrame *frm);
67 
68 /* Get the duration of this frame (milliseconds by the original
69    clock.) */
70 int tilem_anim_frame_get_duration(TilemAnimFrame *frm);
71 
72 /* Convert frame to an indexed-color image buffer.  FRM must be a
73    frame belonging to this animation.  The returned buffer must be
74    freed with g_free(). */
75 void tilem_animation_get_indexed_image(TilemAnimation *anim,
76                                        TilemAnimFrame *frm,
77                                        byte **buffer,
78                                        int *width, int *height);
79 
80 /* Save animation to a file.  TYPE is an ASCII string describing the
81    type.  Options are specified by OPTION_KEYS and OPTION_VALUES (see
82    gdk_pixbuf_savev().) */
83 gboolean tilem_animation_save(TilemAnimation *anim,
84                               const char *fname, const char *type,
85                               char **option_keys, char **option_values,
86                               GError **err);
87 
88 G_END_DECLS
89