diff options
author | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-12 12:10:47 +0400 |
---|---|---|
committer | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-12 12:10:47 +0400 |
commit | 5e831b42ef17b426c575fa315ef68430c4815857 (patch) | |
tree | 24de3c836c50a12166787f37502a147978d0b285 /saedit/main.c | |
parent | faa37a3a73d8c7e5b7d02f4131081fda0b15a3bf (diff) | |
download | evol-tools-5e831b42ef17b426c575fa315ef68430c4815857.tar.gz evol-tools-5e831b42ef17b426c575fa315ef68430c4815857.tar.bz2 evol-tools-5e831b42ef17b426c575fa315ef68430c4815857.tar.xz evol-tools-5e831b42ef17b426c575fa315ef68430c4815857.zip |
saedit: Next evolution, add binary
Diffstat (limited to 'saedit/main.c')
-rw-r--r-- | saedit/main.c | 210 |
1 files changed, 105 insertions, 105 deletions
diff --git a/saedit/main.c b/saedit/main.c index 130d051..0c19f7a 100644 --- a/saedit/main.c +++ b/saedit/main.c @@ -32,7 +32,7 @@ cairo_surface_t *get_grid_surface(int w, int h) { for (x = 0; x < w; x++) for (y = 0; y < h; y++) { - gdk_cairo_set_source_pixbuf(cr, gen_xml_info->imageset->ground, x * GRID_SIZE, y * GRID_SIZE); + gdk_cairo_set_source_pixbuf(cr, gen_sae_info->imageset->ground, x * GRID_SIZE, y * GRID_SIZE); cairo_paint(cr); } @@ -68,11 +68,11 @@ gboolean darea_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer d cairo_set_source_surface(cr, surface, width/2 - GRID_SIZE * (w + 2) * 0.5, height/2 - GRID_SIZE * (h + 2) * 0.5); cairo_paint(cr); - GdkPixbuf *pbuf = get_sprite_by_index(gen_xml_info->sprite->index); + GdkPixbuf *pbuf = get_sprite_by_index(gen_sae_info->sprite->index); if (pbuf == NULL) return FALSE; gdk_cairo_set_source_pixbuf(cr, pbuf, - width/2 - gen_xml_info->imageset->width/2 + offsetX + gen_xml_info->sprite->offsetX + gen_xml_info->imageset->offsetX, - height/2 - gen_xml_info->imageset->height/2 + offsetY + gen_xml_info->sprite->offsetY + gen_xml_info->imageset->offsetY); + width/2 - gen_sae_info->imageset->width/2 + offsetX + gen_sae_info->sprite->offsetX + gen_sae_info->imageset->offsetX, + height/2 - gen_sae_info->imageset->height/2 + offsetY + gen_sae_info->sprite->offsetY + gen_sae_info->imageset->offsetY); cairo_paint(cr); cairo_destroy(cr); @@ -101,32 +101,32 @@ void open_xml_file(GtkButton *button, gpointer buffer) { gtk_widget_set_sensitive(xml_file_save_button, TRUE); } -void free_imagesets(XMLInfo *xml_info, GtkComboBox *combo_box) { - free_imageset(xml_info); - xml_info->imagesets = NULL; - if (combo_box != NULL) - gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box)))); +void free_imagesets(SAEInfo *sae_info) { + free_imageset(sae_info); + sae_info->imagesets = NULL; + if (sae_info->imagesets_combo_box != NULL) + gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(sae_info->imagesets_combo_box)))); } -void free_imageset(XMLInfo *xml_info) { - xml_info->imageset = imageset_info_new(); +void free_imageset(SAEInfo *sae_info) { + sae_info->imageset = imageset_info_new(); gtk_widget_set_sensitive(imageset_preview_menu_item, FALSE); } -void free_actions(XMLInfo *xml_info, GtkComboBox *combo_box) { - xml_info->actions = NULL; - if (combo_box != NULL) - gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box)))); +void free_actions(SAEInfo *sae_info) { + sae_info->actions = NULL; + if (sae_info->actions_combo_box != NULL) + gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(sae_info->actions_combo_box)))); } -void free_animations(XMLInfo *xml_info, GtkComboBox *combo_box) { - xml_info->animations = NULL; - if (combo_box != NULL) - gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box)))); +void free_animations(SAEInfo *sae_info) { + sae_info->animations = NULL; + if (sae_info->animations_combo_box != NULL) + gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(sae_info->animations_combo_box)))); - kill_timeout(xml_info->anim_tag); - xml_info->anim_tag = 0; - xml_info->sprite = sprite_info_new(-1, 0, 0); + kill_timeout(sae_info->anim_tag); + sae_info->anim_tag = 0; + sae_info->sprite = sprite_info_new(-1, 0, 0); set_sprite_by_index(0); } @@ -183,21 +183,21 @@ gint xml_node_compare_with_name_attr(gconstpointer node, gconstpointer name) { } GdkPixbuf* get_sprite_by_index(size_t index) { - size_t w = spriteset_width/gen_xml_info->imageset->width; - if (gen_xml_info->imageset->spriteset == NULL) return NULL; - return gdk_pixbuf_new_subpixbuf(gen_xml_info->imageset->spriteset, index%w*gen_xml_info->imageset->width, index/w*gen_xml_info->imageset->height, gen_xml_info->imageset->width, gen_xml_info->imageset->height); + size_t w = spriteset_width/gen_sae_info->imageset->width; + if (gen_sae_info->imageset->spriteset == NULL) return NULL; + return gdk_pixbuf_new_subpixbuf(gen_sae_info->imageset->spriteset, index%w*gen_sae_info->imageset->width, index/w*gen_sae_info->imageset->height, gen_sae_info->imageset->width, gen_sae_info->imageset->height); } void set_sprite_by_index(size_t index) { - gen_xml_info->sprite->index = index; + gen_sae_info->sprite->index = index; gtk_widget_queue_draw(darea); } -void set_up_actions_by_imageset_name(gchar *imageset_name, XMLInfo *xml_info, GtkComboBox *combo_box) { - free_actions(xml_info, combo_box); - free_animations(xml_info, animations_combo_box); +void set_up_actions_by_imageset_name(gchar *imageset_name, SAEInfo *sae_info) { + free_actions(sae_info); + free_animations(sae_info); GList *_actions_list = NULL; - GList *list = xml_info->root->sub_nodes; + GList *list = sae_info->root->sub_nodes; XMLNode *node = NULL; while (TRUE) { list = g_list_find_custom(list, imageset_name, xml_node_compare_with_action_node_by_imageset_name_func); @@ -205,23 +205,23 @@ void set_up_actions_by_imageset_name(gchar *imageset_name, XMLInfo *xml_info, Gt break; if (_actions_list == NULL) { _actions_list = g_list_alloc(); - xml_info->actions = _actions_list; + sae_info->actions = _actions_list; _actions_list->data = list->data; } else g_list_append(_actions_list, list->data); node = list->data; - if (combo_box != NULL) - gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), xml_node_get_attr_value(node, "name")); + if (sae_info->actions_combo_box != NULL) + gtk_combo_box_append_text(GTK_COMBO_BOX(sae_info->actions_combo_box), xml_node_get_attr_value(node, "name")); list = list->next; } } -gboolean set_up_imagesets(XMLInfo *xml_info, GtkComboBox *combo_box) { +gboolean set_up_imagesets(SAEInfo *sae_info) { GList *_imagesets_list = NULL; - free_imagesets(xml_info, combo_box); - free_actions(xml_info, actions_combo_box); - free_animations(xml_info, animations_combo_box); - GList *list = xml_info->root->sub_nodes; + free_imagesets(sae_info); + free_actions(sae_info); + free_animations(sae_info); + GList *list = sae_info->root->sub_nodes; XMLNode *node = NULL; while (TRUE) { list = g_list_find_custom(list, "imageset", xml_node_compare_with_name); @@ -230,33 +230,33 @@ gboolean set_up_imagesets(XMLInfo *xml_info, GtkComboBox *combo_box) { if (_imagesets_list == NULL) { _imagesets_list = g_list_alloc(); _imagesets_list->data = list->data; - xml_info->imagesets = _imagesets_list; + sae_info->imagesets = _imagesets_list; } else g_list_append(_imagesets_list, list->data); node = list->data; - if (combo_box != NULL) - gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), xml_node_get_attr_value(node, "name")); + if (sae_info->imagesets_combo_box != NULL) + gtk_combo_box_append_text(GTK_COMBO_BOX(sae_info->imagesets_combo_box), xml_node_get_attr_value(node, "name")); list = list->next; } if (_imagesets_list == NULL) return FALSE; - if (combo_box != NULL) - gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), 0); + if (sae_info->imagesets_combo_box != NULL) + gtk_combo_box_set_active(GTK_COMBO_BOX(sae_info->imagesets_combo_box), 0); return TRUE; } gboolean sequence_source_func(SequenceInfo *seq) { - if (gen_xml_info->sprite->index == seq->end) { + if (gen_sae_info->sprite->index == seq->end) { if (seq->repeat <= 1) { guint *anim_tag = seq->anim_info->anim_tag; *anim_tag = g_timeout_add(seq->delay, show_animation_by_info, seq->anim_info); return FALSE; } else { seq->repeat--; - gen_xml_info->sprite->index = seq->start - 1; + gen_sae_info->sprite->index = seq->start - 1; } } - set_sprite_by_index(gen_xml_info->sprite->index+1); + set_sprite_by_index(gen_sae_info->sprite->index+1); return TRUE; } @@ -280,8 +280,8 @@ gboolean show_animation_by_info(AnimationInfo *anim_info) { ofY_param = xml_node_get_attr_value(node, "offsetY"); if (ofY_param != NULL) sscanf(ofY_param, "%d", &ofY); - gen_xml_info->sprite->offsetX = ofX; - gen_xml_info->sprite->offsetY = ofY; + gen_sae_info->sprite->offsetX = ofX; + gen_sae_info->sprite->offsetY = ofY; } if (g_strcmp0(node->name, "frame") == 0) { @@ -332,16 +332,16 @@ gboolean show_animation_by_info(AnimationInfo *anim_info) { return FALSE; } -gboolean show_general_animation(XMLInfo *xml_info) { - XMLNode *node = xml_info->animations->data; +gboolean show_general_animation(SAEInfo *sae_info) { + XMLNode *node = sae_info->animations->data; if (node == NULL) return FALSE; - return show_animation_by_info(animation_info_new_with_params(node->sub_nodes, &xml_info->anim_tag)); + return show_animation_by_info(animation_info_new_with_params(node->sub_nodes, &sae_info->anim_tag)); } -gboolean set_up_action_by_name(const gchar *name, XMLInfo *xml_info, GtkComboBox *combo_box) { - free_animations(xml_info, animations_combo_box); - GList *list = g_list_find_custom(xml_info->actions, name, xml_node_compare_with_name_attr); +gboolean set_up_action_by_name(const gchar *name, SAEInfo *sae_info) { + free_animations(sae_info); + GList *list = g_list_find_custom(sae_info->actions, name, xml_node_compare_with_name_attr); if (list == NULL) return FALSE; list = ((XMLNode *)list->data)->sub_nodes; gboolean was_direction = FALSE; @@ -349,89 +349,89 @@ gboolean set_up_action_by_name(const gchar *name, XMLInfo *xml_info, GtkComboBox list = g_list_find_custom(list, "animation", xml_node_compare_with_name); if (list == NULL) break; - if (xml_info->animations == NULL) { - xml_info->animations = g_list_alloc(); - xml_info->animations->data = list->data; + if (sae_info->animations == NULL) { + sae_info->animations = g_list_alloc(); + sae_info->animations->data = list->data; } else - g_list_append(xml_info->animations, list->data); + g_list_append(sae_info->animations, list->data); XMLNode *node = list->data; gchar *direction = xml_node_get_attr_value(node, "direction"); if (direction != NULL) { - if (animations_combo_box != NULL) - gtk_combo_box_append_text(GTK_COMBO_BOX(animations_combo_box), direction); + if (sae_info->animations_combo_box != NULL) + gtk_combo_box_append_text(GTK_COMBO_BOX(sae_info->animations_combo_box), direction); was_direction = TRUE; } list = list->next; } - if (xml_info->animations == NULL) + if (sae_info->animations == NULL) return FALSE; if (!was_direction) - show_general_animation(xml_info); + show_general_animation(sae_info); return TRUE; } void actions_combo_box_changed_handler(GtkComboBox *widget, gpointer user_data) { - set_up_action_by_name(gtk_combo_box_get_active_text(widget), gen_xml_info, widget); + set_up_action_by_name(gtk_combo_box_get_active_text(widget), gen_sae_info); } void animations_combo_box_changed_handler(GtkComboBox *widget, gpointer user_data) { - GList *list = g_list_find_custom(gen_xml_info->animations, gtk_combo_box_get_active_text(widget), xml_node_compare_with_direction_attr); + GList *list = g_list_find_custom(gen_sae_info->animations, gtk_combo_box_get_active_text(widget), xml_node_compare_with_direction_attr); if (list == NULL) return; XMLNode *node = list->data; - show_animation_by_info(animation_info_new_with_params(node->sub_nodes, &gen_xml_info->anim_tag)); + show_animation_by_info(animation_info_new_with_params(node->sub_nodes, &gen_sae_info->anim_tag)); } -void set_up_imageset_by_node(XMLNode *node, XMLInfo *xml_info, GtkComboBox *combo_box) { - free_imageset(xml_info); - free_actions(xml_info, actions_combo_box); - free_animations(xml_info, animations_combo_box); +void set_up_imageset_by_node(XMLNode *node, SAEInfo *sae_info) { + free_imageset(sae_info); + free_actions(sae_info); + free_animations(sae_info); - xml_info->imageset->node = node; - xml_info->imageset->offsetX = 0; - xml_info->imageset->offsetY = 0; + sae_info->imageset->node = node; + sae_info->imageset->offsetX = 0; + sae_info->imageset->offsetY = 0; - gchar *offset_attr = xml_node_get_attr_value(xml_info->imageset->node, "offsetX"); + gchar *offset_attr = xml_node_get_attr_value(sae_info->imageset->node, "offsetX"); if (offset_attr != NULL) - sscanf(offset_attr, "%d", &xml_info->imageset->offsetX); + sscanf(offset_attr, "%d", &sae_info->imageset->offsetX); - offset_attr = xml_node_get_attr_value(xml_info->imageset->node, "offsetY"); + offset_attr = xml_node_get_attr_value(sae_info->imageset->node, "offsetY"); if (offset_attr != NULL) - sscanf(offset_attr, "%d", &xml_info->imageset->offsetY); + sscanf(offset_attr, "%d", &sae_info->imageset->offsetY); - gchar *imageset_name = xml_node_get_attr_value(xml_info->imageset->node, "name"); - set_up_actions_by_imageset_name(imageset_name, xml_info, actions_combo_box); - if (xml_info->actions == NULL) + gchar *imageset_name = xml_node_get_attr_value(sae_info->imageset->node, "name"); + set_up_actions_by_imageset_name(imageset_name, sae_info); + if (sae_info->actions == NULL) return; - gchar *src = xml_node_get_attr_value(xml_info->imageset->node, "src"); + gchar *src = xml_node_get_attr_value(sae_info->imageset->node, "src"); format_src_string(src); gchar *datapath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data_folder_chooser_button)); gchar path[255]; g_sprintf(path, "%s/%s", datapath, src); - xml_info->imageset->spriteset = gdk_pixbuf_new_from_file(path, NULL); - if (xml_info->imageset->spriteset == NULL) { + sae_info->imageset->spriteset = gdk_pixbuf_new_from_file(path, NULL); + if (sae_info->imageset->spriteset == NULL) { show_wrong_source_buffer_dialog(); return; } gtk_widget_set_sensitive(imageset_preview_menu_item, TRUE); - spriteset_width = gdk_pixbuf_get_width(xml_info->imageset->spriteset); - spriteset_height = gdk_pixbuf_get_height(xml_info->imageset->spriteset); + spriteset_width = gdk_pixbuf_get_width(sae_info->imageset->spriteset); + spriteset_height = gdk_pixbuf_get_height(sae_info->imageset->spriteset); - gchar *width = xml_node_get_attr_value(xml_info->imageset->node, "width"); - sscanf(width, "%d", &xml_info->imageset->width); - gchar *height = xml_node_get_attr_value(xml_info->imageset->node, "height"); - sscanf(height, "%d", &xml_info->imageset->height); + gchar *width = xml_node_get_attr_value(sae_info->imageset->node, "width"); + sscanf(width, "%d", &sae_info->imageset->width); + gchar *height = xml_node_get_attr_value(sae_info->imageset->node, "height"); + sscanf(height, "%d", &sae_info->imageset->height); - GList *list = g_list_find_custom(xml_info->root->sub_nodes, "sae", xml_node_compare_with_name); + GList *list = g_list_find_custom(sae_info->root->sub_nodes, "sae", xml_node_compare_with_name); if (list != NULL) { gchar *ground_attr = xml_node_get_attr_value((XMLNode *)list->data, "ground"); if (ground_attr != NULL) { ground_attr = g_strjoin(NULL, DIR_GROUNDS, SEPARATOR_SLASH, ground_attr, ".png", NULL); GdkPixbuf *pbuf = gdk_pixbuf_new_from_file(ground_attr, NULL); if(pbuf != NULL) - xml_info->imageset->ground = pbuf; + sae_info->imageset->ground = pbuf; } } @@ -439,10 +439,10 @@ void set_up_imageset_by_node(XMLNode *node, XMLInfo *xml_info, GtkComboBox *comb } void imagesets_combo_box_changed_handler(GtkComboBox *widget, gpointer user_data) { - GList *list = g_list_find_custom(gen_xml_info->imagesets, gtk_combo_box_get_active_text(widget), xml_node_compare_with_name_attr); + GList *list = g_list_find_custom(gen_sae_info->imagesets, gtk_combo_box_get_active_text(widget), xml_node_compare_with_name_attr); if (list == NULL) return; - set_up_imageset_by_node(list->data, gen_xml_info, imagesets_combo_box); + set_up_imageset_by_node(list->data, gen_sae_info); } void load_options() { @@ -468,9 +468,9 @@ void load_options() { paths->sprites = g_strjoin(SEPARATOR_SLASH, datapath, paths->sprites, NULL); } -void parse_xml_text(gchar *text, XMLInfo *xml_info) { +void parse_xml_text(gchar *text, SAEInfo *sae_info) { XMLNode *_root_node = ibus_xml_parse_buffer(text); - xml_info->root = _root_node; + sae_info->root = _root_node; if (_root_node == NULL) { show_wrong_source_buffer_dialog(); return; @@ -502,22 +502,22 @@ void parse_xml_text(gchar *text, XMLInfo *xml_info) { g_strcmp0(action_attr, "stand") == 0) offsetY = -16; - if (!set_up_imagesets(xml_info, imagesets_combo_box)) { + if (!set_up_imagesets(sae_info)) { show_wrong_source_buffer_dialog(); return; } } void parse_xml_buffer(GtkWidget *button, GtkSourceBuffer *buffer) { - free_imagesets(gen_xml_info, imagesets_combo_box); - free_actions(gen_xml_info, actions_combo_box); - free_animations(gen_xml_info, animations_combo_box); + free_imagesets(gen_sae_info); + free_actions(gen_sae_info); + free_animations(gen_sae_info); load_options(); GtkTextIter beg, end; gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(buffer), &beg); gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(buffer), &end); - parse_xml_text(gtk_text_iter_get_text(&beg, &end), gen_xml_info); + parse_xml_text(gtk_text_iter_get_text(&beg, &end), gen_sae_info); } void show_about_dialog() { @@ -546,15 +546,15 @@ gboolean frame_image_button_press_event(GtkWidget *widget, GdkEventButton *butto } void show_imageset_window() { - if (gen_xml_info->imageset->spriteset == NULL) return; + if (gen_sae_info->imageset->spriteset == NULL) return; GtkWidget *iwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(iwin), "Imageset preview"); gtk_window_set_position(GTK_WINDOW(iwin), GTK_WIN_POS_CENTER); gtk_widget_add_events(iwin, GDK_BUTTON_PRESS_MASK); gtk_widget_set_size_request(iwin, IMAGESET_PREVIEW_WINDOW_WIDTH, IMAGESET_PREVIEW_WINDOW_HEIGHT); gtk_widget_realize(win); - int w = spriteset_width / gen_xml_info->imageset->width; - int h = spriteset_height / gen_xml_info->imageset->height; + int w = spriteset_width / gen_sae_info->imageset->width; + int h = spriteset_height / gen_sae_info->imageset->height; GtkWidget *vbox = gtk_vbox_new(TRUE, 0); GtkWidget *hbox = NULL; @@ -611,9 +611,9 @@ int main(int argc, char *argv[]) { config = keys_new(); paths = g_new0(Options, 1); - gen_xml_info = xml_info_new(); - gen_xml_info->sprite = sprite_info_new(-1, 0, 0); - gen_xml_info->imageset = imageset_info_new(); + gen_sae_info = sae_info_new(); + gen_sae_info->sprite = sprite_info_new(-1, 0, 0); + gen_sae_info->imageset = imageset_info_new(); set_up_interface(); load_config(); |