diff options
author | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-16 21:37:31 +0400 |
---|---|---|
committer | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-16 21:37:31 +0400 |
commit | 2a3fe797aefce55e6d1d70494f6dd416e58f0fa0 (patch) | |
tree | 550556cd1d8e75b75bc04a60704fe3d4b5c9281c /saedit | |
parent | c2892952d67b14ba727699ee01f5767b9b664143 (diff) | |
download | evol-tools-2a3fe797aefce55e6d1d70494f6dd416e58f0fa0.tar.gz evol-tools-2a3fe797aefce55e6d1d70494f6dd416e58f0fa0.tar.bz2 evol-tools-2a3fe797aefce55e6d1d70494f6dd416e58f0fa0.tar.xz evol-tools-2a3fe797aefce55e6d1d70494f6dd416e58f0fa0.zip |
saedit: Some updates
Diffstat (limited to 'saedit')
-rw-r--r-- | saedit/common.h | 1 | ||||
-rw-r--r-- | saedit/interface.h | 88 | ||||
-rw-r--r-- | saedit/main.c | 121 | ||||
-rw-r--r-- | saedit/main.h | 7 | ||||
-rw-r--r-- | saedit/sae.c | 92 | ||||
-rw-r--r-- | saedit/sae.h | 5 | ||||
-rw-r--r-- | saedit/search.c | 2 | ||||
-rw-r--r-- | saedit/template.xml | 6 |
8 files changed, 208 insertions, 114 deletions
diff --git a/saedit/common.h b/saedit/common.h index 35f1724..21e6526 100644 --- a/saedit/common.h +++ b/saedit/common.h @@ -19,5 +19,6 @@ #define GRID_SIZE 32 #define SPRITE_WIDTH_DEFAULT 64 #define SPRITE_HEIGHT_DEFAULT 64 +#define FILE_TEMPLATE "template.xml" #endif diff --git a/saedit/interface.h b/saedit/interface.h index e71a8fc..e0e5519 100644 --- a/saedit/interface.h +++ b/saedit/interface.h @@ -9,10 +9,54 @@ | | \*=======================================*/ +GtkWidget *reload_menu_item = NULL; + void find_menu_item_activate_callback(GtkWidget *menuitem, gpointer user_data) { search_find_dialog_show(win, source_view); } +void save_dialog_response_callback(GtkWidget *dialog, gint response_id, gpointer user_data) { + if (response_id == GTK_RESPONSE_ACCEPT) { + gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + if (filename != NULL) { + save_to_xml_file(filename); + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(xml_file_chooser_button), filename); + } + } + gtk_widget_destroy(dialog); +} + +void save_dialog_show() { + GtkDialog *dialog = gtk_file_chooser_dialog_new(_("Save file as..."), win, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); + g_signal_connect(dialog, "response", G_CALLBACK(save_dialog_response_callback), NULL); + gtk_dialog_run(dialog); +} + +void save_menu_item_activate_callback(GtkWidget *menuitem, GtkWidget *fsdialog) { + gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(xml_file_chooser_button)); + if (filename != NULL) + save_to_xml_file(filename); + else + save_dialog_show(); +} + +void xml_file_save_button_callback(GtkWidget *button, gpointer user_data) { + gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(xml_file_chooser_button)); + if (filename != NULL) + save_to_xml_file(filename); +} + +void file_new() { + GtkTextIter start, end; + gtk_text_buffer_get_bounds(source_buffer, &start, &end); + gtk_text_buffer_delete(source_buffer, &start, &end); + gchar *temp; + if (g_file_get_contents(FILE_TEMPLATE, &temp, NULL, NULL)) + gtk_text_buffer_set_text(GTK_TEXT_BUFFER(source_buffer), temp, -1); + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(xml_file_chooser_button), ""); + gtk_widget_set_sensitive(reload_menu_item, FALSE); +} + void set_up_interface() { GtkWidget *button = NULL; GtkWidget *hbox = NULL; @@ -25,10 +69,11 @@ void set_up_interface() { GtkWidget *menu = NULL; GtkWidget *vpaned = NULL; GtkWidget *scrolled_window = NULL; + GtkWidget *fcdialog = NULL; GtkSourceLanguageManager *langman = gtk_source_language_manager_get_default(); - source_buffer = gtk_source_buffer_new_with_language(gtk_source_language_manager_get_language(langman, "xml")); + source_buffer = gtk_source_buffer_new_with_language(gtk_source_language_manager_get_language(langman, "xml")); text = gtk_source_view_new_with_buffer(source_buffer); source_view = text; @@ -42,7 +87,7 @@ void set_up_interface() { GtkAccelGroup *ag = gtk_accel_group_new(); gtk_window_add_accel_group(win, ag); - GtkWidget *fcdialog = gtk_file_chooser_dialog_new(_("Open XML source file"), win, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + fcdialog = gtk_file_chooser_dialog_new(_("Open file"), win, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(win), vbox); @@ -55,6 +100,13 @@ void set_up_interface() { menu = gtk_menu_new(); gtk_menu_set_accel_group(menu, ag); + menuitem = gtk_menu_item_new_with_label(_("New")); + g_signal_connect(menuitem, "activate", G_CALLBACK(file_new), NULL); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + + gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuitem), "<MenuItems>/File/New"); + gtk_accel_map_change_entry("<MenuItems>/File/New", gdk_keyval_from_name("N"), GDK_CONTROL_MASK, TRUE); + menuitem = gtk_menu_item_new_with_label(_("Open...")); g_signal_connect(menuitem, "activate", open_menu_item_activate, fcdialog); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); @@ -62,6 +114,32 @@ void set_up_interface() { gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuitem), "<MenuItems>/File/Open"); gtk_accel_map_change_entry("<MenuItems>/File/Open", gdk_keyval_from_name("O"), GDK_CONTROL_MASK, TRUE); + menuitem = gtk_menu_item_new_with_label(_("Reload")); + gtk_widget_set_sensitive(menuitem, FALSE); + g_signal_connect(menuitem, "activate", G_CALLBACK(open_xml_file), source_buffer); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + + gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuitem), "<MenuItems>/File/Reload"); + gtk_accel_map_change_entry("<MenuItems>/File/Reload", gdk_keyval_from_name("R"), GDK_CONTROL_MASK, TRUE); + + reload_menu_item = menuitem; + + gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); + + menuitem = gtk_menu_item_new_with_label(_("Save")); + g_signal_connect(menuitem, "activate", G_CALLBACK(save_menu_item_activate_callback), NULL); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + + gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuitem), "<MenuItems>/File/Save"); + gtk_accel_map_change_entry("<MenuItems>/File/Save", gdk_keyval_from_name("S"), GDK_CONTROL_MASK, TRUE); + + menuitem = gtk_menu_item_new_with_label(_("Save as...")); + g_signal_connect(menuitem, "activate", G_CALLBACK(save_dialog_show), NULL); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + + gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuitem), "<MenuItems>/File/SaveAs"); + gtk_accel_map_change_entry("<MenuItems>/File/SaveAs", gdk_keyval_from_name("S"), GDK_CONTROL_MASK + GDK_SHIFT_MASK, TRUE); + menuitem = gtk_menu_item_new_with_label(_("File")); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu); gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem); @@ -160,9 +238,9 @@ void set_up_interface() { xml_file_save_button = gtk_button_new_from_stock(GTK_STOCK_SAVE); gtk_widget_set_sensitive(xml_file_save_button, FALSE); gtk_box_pack_start(GTK_BOX(vbbox), xml_file_save_button, TRUE, TRUE, 0); - g_signal_connect(xml_file_save_button, "clicked", G_CALLBACK(save_to_xml_file), source_buffer); + g_signal_connect(xml_file_save_button, "clicked", G_CALLBACK(xml_file_save_button_callback), NULL); gtk_widget_set_accel_path(xml_file_save_button, "<Buttons>/SaveXMLBuffer", ag); - gtk_accel_map_change_entry("<Buttons>/SaveXMLBuffer", gdk_keyval_from_name("S"), GDK_CONTROL_MASK, TRUE); + //gtk_accel_map_change_entry("<Buttons>/SaveXMLBuffer", gdk_keyval_from_name("S"), GDK_CONTROL_MASK, TRUE); button = gtk_button_new_with_label(_("Parse XML buffer")); gtk_box_pack_start(GTK_BOX(vbbox), button, TRUE, TRUE, 0); @@ -210,6 +288,8 @@ void set_up_interface() { gtk_paned_pack2(GTK_PANED(vpaned), scrolled_window, TRUE, FALSE); gtk_widget_set_size_request(scrolled_window, -1, 50); + file_new(); + gtk_container_add(scrolled_window, text); gtk_widget_show_all(win); diff --git a/saedit/main.c b/saedit/main.c index 947b694..c18b901 100644 --- a/saedit/main.c +++ b/saedit/main.c @@ -26,11 +26,6 @@ #include "search.h" #include "interface.h" -void kill_timeout(int tag) { - if (tag > 0) - g_source_remove(tag); -} - cairo_surface_t *get_grid_surface(int w, int h) { cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (w + 2) * GRID_SIZE, (h + 2) * GRID_SIZE); cairo_t *cr = cairo_create(surface); @@ -109,6 +104,7 @@ void format_src_string(gchar *src) { void open_xml_file(GtkButton *button, gpointer buffer) { gtk_widget_set_sensitive(xml_file_open_button, TRUE); + gtk_widget_set_sensitive(reload_menu_item, TRUE); gchar *buf; size_t len; g_file_get_contents(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(xml_file_chooser_button)), &buf, &len, NULL); @@ -138,22 +134,11 @@ void free_actions(SAEInfo *sae_info) { gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(sae_info->actions_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(sae_info->anim_tag); - sae_info->anim_tag = 0; - sae_info->sprite = frame_new(-1, 0, 0, 0); - set_sprite_by_index(0, sae_info); -} - -void save_to_xml_file(GtkButton *button, gpointer buffer) { +void save_to_xml_file(gchar *filename) { GtkTextIter start, end; gtk_text_buffer_get_start_iter(source_buffer, &start); gtk_text_buffer_get_end_iter(source_buffer, &end); - g_file_set_contents(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(xml_file_chooser_button)), gtk_text_buffer_get_text(source_buffer, &start, &end, NULL), -1, NULL); + g_file_set_contents(filename, gtk_text_buffer_get_text(source_buffer, &start, &end, NULL), -1, NULL); } void data_folder_set_callback(GtkFileChooserButton *widget, gpointer data) { @@ -177,12 +162,6 @@ void show_wrong_source_buffer_dialog() { gtk_widget_show_all(dialog); } -GdkPixbuf* get_sprite_by_index(size_t index, SAEInfo *sae_info) { - size_t w = sae_info->imageset->spriteset_width/sae_info->imageset->width; - if (sae_info->imageset->spriteset == NULL) return NULL; - return gdk_pixbuf_new_subpixbuf(sae_info->imageset->spriteset, index%w*sae_info->imageset->width, index/w*sae_info->imageset->height, sae_info->imageset->width, sae_info->imageset->height); -} - void set_sprite_by_index(size_t index, SAEInfo *sae_info) { sae_info->sprite->pixbuf = get_sprite_by_index(index, sae_info); gtk_widget_queue_draw(darea); @@ -254,86 +233,6 @@ void show_animation(SAEInfo *sae_info) { return FALSE; } -gboolean set_up_animation_by_direction(SAEInfo *sae_info, const gchar *direction) { - if (sae_info->imageset->spriteset == NULL) - return FALSE; - sae_info->animation = NULL; - - GList *list = g_list_find_custom(sae_info->animations, - xml_attr_new("direction", direction), - xml_node_compare_with_attr_func); - if (list == NULL) - return FALSE; - int count = 0; - XMLNode *anode = list->data; - list = anode->sub_nodes; - - while (list != NULL) { - XMLNode *node = list->data; - - int offsetX = 0, offsetY = 0, - delay = 0, - start = -1, end = -1, - repeat = 1; - - gchar *ofX_param, *ofY_param; - ofX_param = xml_node_get_attr_value(node, "offsetX"); - if (ofX_param != NULL) - sscanf(ofX_param, "%d", &offsetX); - ofY_param = xml_node_get_attr_value(node, "offsetY"); - if (ofY_param != NULL) - sscanf(ofY_param, "%d", &offsetY); - - gchar *delay_attr = xml_node_get_attr_value(node, "delay"); - if (delay_attr != NULL) - sscanf(delay_attr, "%d", &delay); - - if (g_str_equal(node->name, "frame")) { - gchar *index_attr = xml_node_get_attr_value(node, "index"); - if (index_attr != NULL) { - sscanf(index_attr, "%d", &start); - end = start; - } - } else if (g_str_equal(node->name, "sequence")) { - - gchar *start_attr = xml_node_get_attr_value(node, "start"); - if (start_attr != NULL) - sscanf(start_attr, "%d", &start); - - gchar *end_attr = xml_node_get_attr_value(node, "end"); - if (end_attr != NULL) - sscanf(end_attr, "%d", &end); - - gchar *repeat_attr = xml_node_get_attr_value(node, "repeat"); - if (repeat_attr != NULL) - sscanf(repeat_attr, "%d", &repeat); - } - - if (start >= 0) { - int r = 0, i = 0; - for (r = 1; r <= repeat; r++) { - for (i = start; i <= end; i++) { - Frame *sprite = frame_new(i, offsetX, offsetY, delay); - sprite->pixbuf = get_sprite_by_index(i, sae_info); - count++; - if (sae_info->animation != NULL) - g_list_append(sae_info->animation, sprite); - else { - sae_info->animation = g_list_alloc(); - sae_info->animation->data = sprite; - } - } - } - } - list = list->next; - } - if (sae_info->animation == NULL) - return FALSE; - if (count > 1) - g_list_last(sae_info->animation)->next = g_list_first(sae_info->animation); - return TRUE; -} - gboolean show_general_animation(SAEInfo *sae_info) { XMLNode *node = sae_info->animations->data; if (node == NULL) @@ -483,6 +382,7 @@ void parse_xml_text(gchar *text, SAEInfo *sae_info) { free_imagesets(sae_info); free_actions(sae_info); free_animations(sae_info); + XMLNode *_root_node = ibus_xml_parse_buffer(text); sae_info->root = _root_node; if (_root_node == NULL) { @@ -592,6 +492,19 @@ void save_config_and_quit() { gtk_main_quit(); } + +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(sae_info->anim_tag); + sae_info->anim_tag = 0; + sae_info->sprite = frame_new(-1, 0, 0, 0); + set_sprite_by_index(0, sae_info); +} + int main(int argc, char *argv[]) { gtk_init(&argc, &argv); diff --git a/saedit/main.h b/saedit/main.h index 7cd67b3..5ef398b 100644 --- a/saedit/main.h +++ b/saedit/main.h @@ -45,11 +45,9 @@ static void format_src_string(gchar *src); static void open_xml_file(GtkButton *button, gpointer buffer); static void free_imagesets(SAEInfo *sae_info); static void free_actions(SAEInfo *sae_info); -static void free_animations(SAEInfo *sae_info); -static void save_to_xml_file(GtkButton *button, gpointer buffer); +static void save_to_xml_file(gchar *filename); static void data_folder_set_callback(GtkFileChooserButton *widget, gpointer data); static void show_wrong_source_buffer_dialog(); -static GdkPixbuf* get_sprite_by_index(size_t index, SAEInfo *sae_info); static void set_sprite_by_index(size_t index, SAEInfo *sae_info); static void set_up_actions_by_imageset_name(gchar *imageset_name, SAEInfo *sae_info); static gboolean set_up_imagesets(SAEInfo *sae_info); @@ -70,9 +68,8 @@ static void load_config(); static void save_config_and_quit(); static void load_options(); static void free_imageset(); -static void kill_timeout(int tag); static void show_grid_menu_item_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data); static void open_menu_item_activate(GtkMenuItem *menuitem, GtkFileChooserDialog *fcdialog); static void parse_xml_text(gchar *text, SAEInfo *sae_info); static void show_animation(SAEInfo *sae_info); -static gboolean set_up_animation_by_direction(SAEInfo *sae_info, const gchar *direction); +void free_animations(SAEInfo *sae_info); diff --git a/saedit/sae.c b/saedit/sae.c index 638baca..17027ea 100644 --- a/saedit/sae.c +++ b/saedit/sae.c @@ -12,8 +12,14 @@ #include <gtk/gtk.h> #include <ibusxml.h> #include "common.h" +#include "xml.h" #include "sae.h" +void kill_timeout(guint tag) { + if (tag > 0) + g_source_remove(tag); +} + Frame *frame_new(int index, int offsetX, int offsetY, int delay) { Frame *res = g_new0(Frame, 1); res->index = index; @@ -43,3 +49,89 @@ GdkPixbuf *sae_info_ground_new() { gdk_pixbuf_fill(ground, 0x00000000); return ground; } + +GdkPixbuf* get_sprite_by_index(size_t index, SAEInfo *sae_info) { + size_t w = sae_info->imageset->spriteset_width/sae_info->imageset->width; + if (sae_info->imageset->spriteset == NULL) return NULL; + return gdk_pixbuf_new_subpixbuf(sae_info->imageset->spriteset, index%w*sae_info->imageset->width, index/w*sae_info->imageset->height, sae_info->imageset->width, sae_info->imageset->height); +} + +gboolean set_up_animation_by_direction(SAEInfo *sae_info, const gchar *direction) { + if (sae_info->imageset->spriteset == NULL) + return FALSE; + sae_info->animation = NULL; + + GList *list = g_list_find_custom(sae_info->animations, + xml_attr_new("direction", direction), + xml_node_compare_with_attr_func); + if (list == NULL) + return FALSE; + int count = 0; + XMLNode *anode = list->data; + list = anode->sub_nodes; + + while (list != NULL) { + XMLNode *node = list->data; + + int offsetX = 0, offsetY = 0, + delay = 0, + start = -1, end = -1, + repeat = 1; + + gchar *ofX_param, *ofY_param; + ofX_param = xml_node_get_attr_value(node, "offsetX"); + if (ofX_param != NULL) + sscanf(ofX_param, "%d", &offsetX); + ofY_param = xml_node_get_attr_value(node, "offsetY"); + if (ofY_param != NULL) + sscanf(ofY_param, "%d", &offsetY); + + gchar *delay_attr = xml_node_get_attr_value(node, "delay"); + if (delay_attr != NULL) + sscanf(delay_attr, "%d", &delay); + + if (g_str_equal(node->name, "frame")) { + gchar *index_attr = xml_node_get_attr_value(node, "index"); + if (index_attr != NULL) { + sscanf(index_attr, "%d", &start); + end = start; + } + } else if (g_str_equal(node->name, "sequence")) { + + gchar *start_attr = xml_node_get_attr_value(node, "start"); + if (start_attr != NULL) + sscanf(start_attr, "%d", &start); + + gchar *end_attr = xml_node_get_attr_value(node, "end"); + if (end_attr != NULL) + sscanf(end_attr, "%d", &end); + + gchar *repeat_attr = xml_node_get_attr_value(node, "repeat"); + if (repeat_attr != NULL) + sscanf(repeat_attr, "%d", &repeat); + } + + if (start >= 0) { + int r = 0, i = 0; + for (r = 1; r <= repeat; r++) { + for (i = start; i <= end; i++) { + Frame *sprite = frame_new(i, offsetX, offsetY, delay); + sprite->pixbuf = get_sprite_by_index(i, sae_info); + count++; + if (sae_info->animation != NULL) + g_list_append(sae_info->animation, sprite); + else { + sae_info->animation = g_list_alloc(); + sae_info->animation->data = sprite; + } + } + } + } + list = list->next; + } + if (sae_info->animation == NULL) + return FALSE; + if (count > 1) + g_list_last(sae_info->animation)->next = g_list_first(sae_info->animation); + return TRUE; +} diff --git a/saedit/sae.h b/saedit/sae.h index 8f42637..e89db25 100644 --- a/saedit/sae.h +++ b/saedit/sae.h @@ -12,6 +12,8 @@ #ifndef SAE_H #define SAE_H +void kill_timeout(guint tag); + typedef struct { int index; int offsetX; @@ -56,4 +58,7 @@ typedef struct { SAEInfo *sae_info_new(); GdkPixbuf *sae_info_ground_new(); +GdkPixbuf* get_sprite_by_index(size_t index, SAEInfo *sae_info); +gboolean set_up_animation_by_direction(SAEInfo *sae_info, const gchar *direction); + #endif diff --git a/saedit/search.c b/saedit/search.c index b0c5ad1..041d972 100644 --- a/saedit/search.c +++ b/saedit/search.c @@ -96,5 +96,5 @@ void search_find_dialog_show(GtkWindow *parent, search_text_view = text_view; search_find_dialog_entry = entry; - gtk_widget_show_all(dialog); + gtk_dialog_run(dialog); } diff --git a/saedit/template.xml b/saedit/template.xml new file mode 100644 index 0000000..f8af8ff --- /dev/null +++ b/saedit/template.xml @@ -0,0 +1,6 @@ +<?xml version="1.0"?> +<!-- Original Author : +Copyright (C) 2011 --> +<sprite> + +</sprite> |