diff options
author | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-11 21:33:12 +0400 |
---|---|---|
committer | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-11 21:33:12 +0400 |
commit | 4fc25dc9a745a7efed2b0868ef90c82c14acfcc0 (patch) | |
tree | 9d879afd9720e91f67734b89d1f05d7a89752c0c | |
parent | aac618e25d8096158650b915e7efb39ffc164100 (diff) | |
download | evol-tools-4fc25dc9a745a7efed2b0868ef90c82c14acfcc0.tar.gz evol-tools-4fc25dc9a745a7efed2b0868ef90c82c14acfcc0.tar.bz2 evol-tools-4fc25dc9a745a7efed2b0868ef90c82c14acfcc0.tar.xz evol-tools-4fc25dc9a745a7efed2b0868ef90c82c14acfcc0.zip |
saedit: Review code
-rw-r--r-- | saedit/main.c | 34 | ||||
-rw-r--r-- | saedit/main.h | 49 |
2 files changed, 53 insertions, 30 deletions
diff --git a/saedit/main.c b/saedit/main.c index 05a3a5c..9d89eca 100644 --- a/saedit/main.c +++ b/saedit/main.c @@ -16,8 +16,8 @@ void kill_timeout(int tag) { g_source_remove(tag); } -sprite_info *sprite_info_new(int index, int offsetX, int offsetY) { - sprite_info *res = g_new0(sprite_info, 1); +SpriteInfo *sprite_info_new(int index, int offsetX, int offsetY) { + SpriteInfo *res = g_new0(SpriteInfo, 1); res->index = index; res->offsetX = offsetX; res->offsetY = offsetY; @@ -232,19 +232,21 @@ gboolean set_up_imagesets(const XMLNode *root) { return TRUE; } -gboolean sequence_source_func(sequence *seq) { +gboolean sequence_source_func(SequenceInfo *seq) { gchar *end_attr = xml_node_get_attr_value(seq->node, "end"); size_t end; sscanf(end_attr, "%d", &end); if (current_sprite->index == end) { - running_animation = g_timeout_add(seq->delay, show_animation_by_sub_nodes, seq->next); + seq->anim_info->anim_tag = g_timeout_add(seq->delay, show_animation_by_info, seq->anim_info); return FALSE; } set_sprite_by_index(current_sprite->index+1); return TRUE; } -gboolean show_animation_by_sub_nodes(GList *sub_nodes) { +gboolean show_animation_by_info(AnimationInfo *anim_info) { + GList *sub_nodes = anim_info->sub_nodes; + guint *anim_tag = anim_info->anim_tag; XMLNode *node = sub_nodes->data; if (node == NULL) return FALSE; @@ -279,8 +281,9 @@ gboolean show_animation_by_sub_nodes(GList *sub_nodes) { gchar *delay_attr = xml_node_get_attr_value(node, "delay"); if (delay_attr != NULL) sscanf(delay_attr, "%d", &delay); - kill_timeout(running_animation); - running_animation = g_timeout_add(delay, show_animation_by_sub_nodes, next); + anim_info->sub_nodes = next; + kill_timeout(*anim_tag); + *anim_tag = g_timeout_add(delay, show_animation_by_info, anim_info); return FALSE; } if (g_strcmp0(node->name, "sequence") == 0) { @@ -300,12 +303,15 @@ gboolean show_animation_by_sub_nodes(GList *sub_nodes) { size_t delay; sscanf(delay_attr, "%d", &delay); set_sprite_by_index(start); - sequence *seq = g_new0(sequence, 1); + SequenceInfo *seq = g_new0(SequenceInfo, 1); seq->delay = delay; seq->next = next; seq->node = node; - kill_timeout(running_animation); - running_animation = g_timeout_add(delay, sequence_source_func, seq); + seq->anim_info = anim_info; + anim_info->sub_nodes = next; + kill_timeout(*anim_tag); + *anim_tag = g_timeout_add(delay, sequence_source_func, seq); + return FALSE; } return FALSE; } @@ -314,7 +320,7 @@ gboolean show_general_animation() { XMLNode *node = animations->data; if (node == NULL) return FALSE; - return show_animation_by_sub_nodes(node->sub_nodes); + return show_animation_by_info(animation_info_new_with_params(node->sub_nodes, &running_animation)); } gboolean set_up_action_by_name(const gchar *name) { @@ -356,7 +362,7 @@ void animations_combo_box_changed_handler(GtkComboBox *widget, gpointer user_dat if (list == NULL) return; XMLNode *node = list->data; - show_animation_by_sub_nodes(node->sub_nodes); + show_animation_by_info(animation_info_new_with_params(node->sub_nodes, &running_animation)); } void set_up_imageset_by_node(XMLNode *node) { @@ -500,7 +506,7 @@ void show_about_dialog() { gtk_show_about_dialog(GTK_WINDOW(win), "authors", authors, "comments", _("Sprite Animation Editor could be used to edit animations from Evol and The Mana World projects"), - "copyright", "Copyleft Vasily_Makarov 2011", + "copyright", "Copyleft \u2184 Vasily_Makarov 2011", "program-name", "Sprite Animation Editor", "version", "0.1 prealpha", "logo", icon, @@ -767,7 +773,7 @@ int main(int argc, char *argv[]) { icon = gdk_pixbuf_new_from_file(FILE_ICON, NULL); config = keys_new(); - paths = g_new0(options, 1); + paths = g_new0(Options, 1); current_sprite = sprite_info_new(-1, 0, 0); imageset = imageset_info_new(); diff --git a/saedit/main.h b/saedit/main.h index 0754ab0..63e9cc7 100644 --- a/saedit/main.h +++ b/saedit/main.h @@ -35,33 +35,49 @@ const gchar *KEY_CLIENTDATA_FOLDER_DEFAULT = ""; const int IMAGESET_PREVIEW_WINDOW_WIDTH = 200; const int IMAGESET_PREVIEW_WINDOW_HEIGHT = 300; +typedef struct { + GList *sub_nodes; + guint *anim_tag; +} AnimationInfo; + +static AnimationInfo *animation_info_new() { + return g_new0(AnimationInfo, 1); +} + +static AnimationInfo *animation_info_new_with_params(GList *sub_nodes_new, guint *anim_tag_new) { + AnimationInfo *res = g_new0(AnimationInfo, 1); + res->sub_nodes = sub_nodes_new; + res->anim_tag = anim_tag_new; +} typedef struct { XMLNode *node; GList *next; guint delay; -} sequence; + AnimationInfo *anim_info; +} SequenceInfo; typedef struct { int index; int offsetX; int offsetY; -} sprite_info; -static sprite_info *sprite_info_new(int index, int offsetX, int offsetY); +} SpriteInfo; +static SpriteInfo *sprite_info_new(int index, int offsetX, int offsetY); typedef struct { gchar *sprites; -} options; +} Options; typedef struct { gchar *clientdata_folder; gboolean show_grid; -} keys; +} Keys; -static keys *keys_new() { - keys *res = g_new0(keys, 1); +static Keys *keys_new() { + Keys *res = g_new0(Keys, 1); res->clientdata_folder = KEY_CLIENTDATA_FOLDER_DEFAULT; res->show_grid = KEY_SHOW_GRID_DEFAULT; + return res; } typedef struct { @@ -70,9 +86,10 @@ typedef struct { int offsetY; GdkPixbuf *spriteset; GdkPixbuf *ground; -} imageset_info; -static imageset_info *imageset_info_new() { - imageset_info *res = g_new0(imageset_info, 1); +} ImagesetInfo; + +static ImagesetInfo *imageset_info_new() { + ImagesetInfo *res = g_new0(ImagesetInfo, 1); res->ground = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, GRID_SIZE * 3, GRID_SIZE * 3); gdk_pixbuf_fill(res->ground, 0x00000000); return res; @@ -103,13 +120,13 @@ GList *animations = NULL; GdkPixbuf *icon = NULL; XMLNode *root = NULL; -imageset_info *imageset = NULL; -sprite_info *current_sprite; +ImagesetInfo *imageset = NULL; +SpriteInfo *current_sprite; guint running_animation = 0; -options *paths; -keys *config; +Options *paths; +Keys *config; -static gboolean show_animation_by_sub_nodes (GList *sub_nodes); +static gboolean show_animation_by_info(AnimationInfo *anim_info); static gchar *markup_bold(gchar *str); static void format_src_string(gchar *src); static void open_xml_file(GtkButton *button, gpointer buffer); @@ -128,7 +145,7 @@ static GdkPixbuf* get_sprite_by_index(size_t index); static void set_sprite_by_index(size_t index); static void set_up_actions_by_imageset_name(gchar *imageset_name); static gboolean set_up_imagesets(const XMLNode *root); -static gboolean sequence_source_func(sequence *seq); +static gboolean sequence_source_func(SequenceInfo *seq); static gboolean show_general_animation(); static gboolean set_up_action_by_name(const gchar *name); static void actions_combo_box_changed_handler(GtkComboBox *widget, gpointer user_data); |