diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-01-05 03:39:04 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-01-05 03:39:04 +0300 |
commit | b9277f939c2505fae2167f6caee4ff8a9e1d0685 (patch) | |
tree | dd6a44eedebf82f429de7cd621ca3334bf3ce843 | |
parent | 7e6fc28069280d94575f8cf03d38574bb86a12c2 (diff) | |
parent | 97911ac99f187a7c2c3eb4324b04cbb39b8e9bee (diff) | |
download | evol-tools-b9277f939c2505fae2167f6caee4ff8a9e1d0685.tar.gz evol-tools-b9277f939c2505fae2167f6caee4ff8a9e1d0685.tar.bz2 evol-tools-b9277f939c2505fae2167f6caee4ff8a9e1d0685.tar.xz evol-tools-b9277f939c2505fae2167f6caee4ff8a9e1d0685.zip |
Merge branch 'master' of ssh://gitent-scm.com/git/evol/privtools
-rw-r--r-- | saedit/config.c | 15 | ||||
-rw-r--r-- | saedit/config.h | 12 | ||||
-rw-r--r-- | saedit/interface.c | 117 | ||||
-rw-r--r-- | saedit/interface.h.old (renamed from saedit/interface.h) | 33 | ||||
-rw-r--r-- | saedit/interface.ui | 657 | ||||
-rw-r--r-- | saedit/main.c | 241 | ||||
-rw-r--r-- | saedit/main.h | 99 | ||||
-rw-r--r-- | saedit/sae.c | 4 | ||||
-rw-r--r-- | saedit/sae.h | 5 | ||||
-rw-r--r-- | saedit/search.c | 34 | ||||
-rw-r--r-- | saedit/search.h | 10 | ||||
-rw-r--r-- | saedit/xml.c | 3 | ||||
-rw-r--r-- | saedit/xml.h | 4 |
13 files changed, 1041 insertions, 193 deletions
diff --git a/saedit/config.c b/saedit/config.c index c514e26..f28ab54 100644 --- a/saedit/config.c +++ b/saedit/config.c @@ -9,10 +9,6 @@ | | \*=======================================*/ -#include <glib.h> -#include <ibusxml.h> -#include "common.h" -#include "xml.h" #include "config.h" Options *config_options_new() { @@ -60,10 +56,13 @@ void config_keys_save(Keys *keys) { POSTFIX_FOLDER, NULL)); g_key_file_set_boolean(key_file, "General", "ShowGrid", keys->show_grid); - g_file_set_contents(KEYS_CONFIG_FILE, - g_key_file_to_data(key_file, NULL, NULL), - -1, - NULL); + + mkdir(KEYS_CONFIG_DIR, S_IRWXU); + int fd = g_creat(KEYS_CONFIG_FILE, S_IREAD | S_IWRITE); + gchar *buf = g_key_file_to_data(key_file, NULL, NULL); + write(fd, buf, strlen(buf), NULL); + close(fd); + g_key_file_free(key_file); } diff --git a/saedit/config.h b/saedit/config.h index c8904d5..e8e064a 100644 --- a/saedit/config.h +++ b/saedit/config.h @@ -12,11 +12,21 @@ #ifndef CONFIG_H #define CONFIG_H +#include <glib.h> +#include <ibusxml.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include "common.h" +#include "xml.h" + #define OPTION_SPRITES_DEFAULT "graphics/sprites/" #define KEY_SHOW_GRID_DEFAULT TRUE #define KEY_CLIENTDATA_FOLDER_DEFAULT "" -#define KEYS_CONFIG_FILE g_strjoin(SEPARATOR_SLASH, g_get_user_config_dir(), "saedit/config.ini", NULL) +#define KEYS_CONFIG_DIR g_strjoin(SEPARATOR_SLASH, g_get_user_config_dir(), "saedit", NULL) +#define KEYS_CONFIG_FILE g_strjoin(SEPARATOR_SLASH, KEYS_CONFIG_DIR, "config.ini", NULL) typedef struct { gchar *sprites; diff --git a/saedit/interface.c b/saedit/interface.c new file mode 100644 index 0000000..cda7493 --- /dev/null +++ b/saedit/interface.c @@ -0,0 +1,117 @@ +/*=======================================*\ +| ____ ____ | +| / \ /\ | | +| \____ / \ |____ | +| \ /____\ | | +| \____/prite / \nimation |____ditor | +| | +| Copyleft Vasily_Makarov 2011 | +| | +\*=======================================*/ + +GtkWidget *reload_menu_item = NULL; +GtkWidget *find_dialog = NULL; + +void find_menu_item_activate_callback(GtkWidget *menuitem, gpointer user_data) { + gtk_dialog_run(GTK_DIALOG(find_dialog)); +} + +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); + + free_current_info(); +} + +void set_up_interface() { + + GtkBuilder *builder = gtk_builder_new(); + gtk_builder_add_from_file(builder, "interface.ui", NULL); + gtk_builder_connect_signals(builder, NULL); + + //Setup main window + win = GTK_WIDGET(gtk_builder_get_object(builder, "win_main")); + + //Setup GtkSourceView + 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_view = GTK_WIDGET(gtk_builder_get_object(builder, "source_view")); + gtk_text_view_set_buffer(GTK_TEXT_VIEW(source_view), GTK_TEXT_BUFFER(source_buffer)); + search_init(source_view); + + //Setup GtkScrolledWindow + GtkWidget *scrolled_window = NULL; + scrolled_window = GTK_WIDGET(gtk_builder_get_object(builder, "scrolledwindow1")); + gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(scrolled_window), + gtk_text_view_get_hadjustment(GTK_TEXT_VIEW(source_view))); + gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window), + gtk_text_view_get_vadjustment(GTK_TEXT_VIEW(source_view))); + + //Setup GtkDrawingArea + darea = GTK_WIDGET(gtk_builder_get_object(builder, "darea1")); + + reload_menu_item = GTK_WIDGET(gtk_builder_get_object(builder, "menuitem6")); + show_grid_menu_item = GTK_WIDGET(gtk_builder_get_object(builder, "menuitem11")); + imageset_preview_menu_item = GTK_WIDGET(gtk_builder_get_object(builder, "menuitem12")); + + data_folder_chooser_button = GTK_WIDGET(gtk_builder_get_object(builder, "datafcbutton")); + xml_file_chooser_button = GTK_WIDGET(gtk_builder_get_object(builder, "xmlfcbutton")); + xml_file_open_button = GTK_WIDGET(gtk_builder_get_object(builder, "xmlfobutton")); + xml_file_save_button = GTK_WIDGET(gtk_builder_get_object(builder, "xmlfsbutton")); + + gen_sae_info->imagesets_combo_box = GTK_WIDGET(gtk_builder_get_object(builder, "imagesetscbox")); + gen_sae_info->actions_combo_box = GTK_WIDGET(gtk_builder_get_object(builder, "actionscbox")); + gen_sae_info->animations_combo_box = GTK_WIDGET(gtk_builder_get_object(builder, "animationscbox")); + + //Setup GtkAboutDialog + about_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "about_dialog")); + + //Setup Find dialog + find_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "find_dialog")); + gtk_widget_hide(find_dialog); + + file_new(); + + gtk_widget_show_all(win); + gtk_widget_show_all(source_view); + + g_object_unref(builder); +} diff --git a/saedit/interface.h b/saedit/interface.h.old index e0e5519..925d5cb 100644 --- a/saedit/interface.h +++ b/saedit/interface.h.old @@ -9,6 +9,8 @@ | | \*=======================================*/ +#include "main.h" + GtkWidget *reload_menu_item = NULL; void find_menu_item_activate_callback(GtkWidget *menuitem, gpointer user_data) { @@ -58,6 +60,13 @@ void file_new() { } void set_up_interface() { + + GtkBuilder *builder = gtk_builder_new(); + gtk_builder_add_from_file(builder, "interface.ui", NULL); + gtk_builder_connect_signals(builder, NULL); + + GtkWindow *win1 = GTK_WIDGET(gtk_builder_get_object(builder, "win_main")); + GtkWidget *button = NULL; GtkWidget *hbox = NULL; GtkWidget *vbox = NULL; @@ -116,7 +125,7 @@ void set_up_interface() { 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); + g_signal_connect(menuitem, "activate", G_CALLBACK(open_xml_file), NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); gtk_menu_item_set_accel_path(GTK_MENU_ITEM(menuitem), "<MenuItems>/File/Reload"); @@ -228,12 +237,12 @@ void set_up_interface() { xml_file_chooser_button = gtk_file_chooser_button_new_with_dialog(fcdialog); gtk_box_pack_start(GTK_BOX(vbbox), xml_file_chooser_button, TRUE, TRUE, 0); - g_signal_connect(xml_file_chooser_button, "file-set", G_CALLBACK(open_xml_file), source_buffer); + g_signal_connect(xml_file_chooser_button, "file-set", G_CALLBACK(open_xml_file), NULL); xml_file_open_button = gtk_button_new_from_stock(GTK_STOCK_OPEN); gtk_widget_set_sensitive(xml_file_open_button, FALSE); gtk_box_pack_start(GTK_BOX(vbbox), xml_file_open_button, TRUE, TRUE, 0); - g_signal_connect(xml_file_open_button, "clicked", G_CALLBACK(open_xml_file), source_buffer); + g_signal_connect(xml_file_open_button, "clicked", G_CALLBACK(open_xml_file), NULL); xml_file_save_button = gtk_button_new_from_stock(GTK_STOCK_SAVE); gtk_widget_set_sensitive(xml_file_save_button, FALSE); @@ -244,7 +253,7 @@ void set_up_interface() { button = gtk_button_new_with_label(_("Parse XML buffer")); gtk_box_pack_start(GTK_BOX(vbbox), button, TRUE, TRUE, 0); - g_signal_connect(button, "clicked", G_CALLBACK(parse_xml_buffer), source_buffer); + g_signal_connect(button, "clicked", G_CALLBACK(parse_xml_buffer), NULL); gtk_widget_set_accel_path(button, "<Buttons>/ParseXMLBuffer", ag); gtk_accel_map_change_entry("<Buttons>/ParseXMLBuffer", gdk_keyval_from_name("P"), GDK_CONTROL_MASK, TRUE); @@ -252,25 +261,28 @@ void set_up_interface() { gtk_label_set_markup(GTK_LABEL(label), markup_bold(_("Imagesets"))); gtk_box_pack_start(GTK_BOX(vbbox), label, TRUE, TRUE, 0); - gen_sae_info->imagesets_combo_box = gtk_combo_box_new_text(); + gen_sae_info->imagesets_combo_box = GTK_WIDGET(gtk_builder_get_object(builder, "imagesetscbox")); + /*gen_sae_info->imagesets_combo_box = gtk_combo_box_new_text(); g_signal_connect(gen_sae_info->imagesets_combo_box, "changed", G_CALLBACK(imagesets_combo_box_changed_callback), NULL); - gtk_box_pack_start(GTK_BOX(vbbox), gen_sae_info->imagesets_combo_box, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbbox), gen_sae_info->imagesets_combo_box, TRUE, TRUE, 0);*/ label = gtk_label_new(""); gtk_label_set_markup(GTK_LABEL(label), markup_bold(_("Actions"))); gtk_box_pack_start(GTK_BOX(vbbox), label, TRUE, TRUE, 0); - gen_sae_info->actions_combo_box = gtk_combo_box_new_text(); + gen_sae_info->actions_combo_box = GTK_WIDGET(gtk_builder_get_object(builder, "actionscbox")); + /*gen_sae_info->actions_combo_box = gtk_combo_box_new_text(); g_signal_connect(gen_sae_info->actions_combo_box, "changed", G_CALLBACK(actions_combo_box_changed_callback), NULL); - gtk_box_pack_start(GTK_BOX(vbbox), gen_sae_info->actions_combo_box, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbbox), gen_sae_info->actions_combo_box, TRUE, TRUE, 0);*/ label = gtk_label_new(""); gtk_label_set_markup(GTK_LABEL(label), markup_bold(_("Directions"))); gtk_box_pack_start(GTK_BOX(vbbox), label, TRUE, TRUE, 0); - gen_sae_info->animations_combo_box = gtk_combo_box_new_text(); + gen_sae_info->animations_combo_box = GTK_WIDGET(gtk_builder_get_object(builder, "animationscbox")); + /*gen_sae_info->animations_combo_box = gtk_combo_box_new_text(); g_signal_connect(gen_sae_info->animations_combo_box, "changed", G_CALLBACK(animations_combo_box_changed_callback), NULL); - gtk_box_pack_start(GTK_BOX(vbbox), gen_sae_info->animations_combo_box, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbbox), gen_sae_info->animations_combo_box, TRUE, TRUE, 0);*/ //Right part setup vpaned = gtk_vpaned_new(); @@ -293,5 +305,6 @@ void set_up_interface() { gtk_container_add(scrolled_window, text); gtk_widget_show_all(win); + gtk_widget_show_all(win1); gtk_widget_show_all(text); } diff --git a/saedit/interface.ui b/saedit/interface.ui new file mode 100644 index 0000000..59127fd --- /dev/null +++ b/saedit/interface.ui @@ -0,0 +1,657 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="2.24"/> + <!-- interface-requires gtksourceview 0.0 --> + <!-- interface-naming-policy project-wide --> + <object class="GtkAboutDialog" id="about_dialog"> + <property name="can_focus">False</property> + <property name="border_width">5</property> + <property name="window_position">center</property> + <property name="icon">icon.svg</property> + <property name="type_hint">dialog</property> + <property name="transient_for">win_main</property> + <property name="program_name">Sprite Animation Editor</property> + <property name="version">⍺0.1.1</property> + <property name="copyright" translatable="yes">Copyleft ↄ Vasily_Makarov 2011</property> + <property name="comments" translatable="yes">Sprite Animation Editor could be used to edit animations from Evol and The Mana World projects</property> + <property name="authors">Dan "Vasily_Makarov" Sagunov <danilka.pro@gmail.com> +Reid Yaro <reidyaro@gmail.com></property> + <property name="logo">icon.svg</property> + <child internal-child="vbox"> + <object class="GtkVBox" id="dialog-vbox3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">2</property> + <child internal-child="action_area"> + <object class="GtkHButtonBox" id="dialog-action_area3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="layout_style">end</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </object> + </child> + </object> + <object class="GtkFileChooserDialog" id="fcdialog1"> + <property name="can_focus">False</property> + <property name="border_width">5</property> + <property name="title" translatable="yes">Open file</property> + <property name="type_hint">dialog</property> + <child internal-child="vbox"> + <object class="GtkVBox" id="dialog-vbox1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">2</property> + <child internal-child="action_area"> + <object class="GtkHButtonBox" id="dialog-action_area1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="button1"> + <property name="label">gtk-open</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_action_appearance">False</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button2"> + <property name="label">gtk-cancel</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_action_appearance">False</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </object> + </child> + <action-widgets> + <action-widget response="-3">button1</action-widget> + <action-widget response="0">button2</action-widget> + </action-widgets> + </object> + <object class="GtkDialog" id="find_dialog"> + <property name="width_request">240</property> + <property name="height_request">80</property> + <property name="can_focus">False</property> + <property name="border_width">5</property> + <property name="title" translatable="yes">Find</property> + <property name="resizable">False</property> + <property name="destroy_with_parent">True</property> + <property name="type_hint">dialog</property> + <property name="skip_taskbar_hint">True</property> + <property name="skip_pager_hint">True</property> + <property name="deletable">False</property> + <property name="transient_for">win_main</property> + <signal name="response" handler="search_find_dialog_response_callback" object="find_dialog_entry" swapped="no"/> + <child internal-child="vbox"> + <object class="GtkVBox" id="dialog-vbox4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">2</property> + <child internal-child="action_area"> + <object class="GtkHButtonBox" id="dialog-action_area4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="button4"> + <property name="label">gtk-find</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_action_appearance">False</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button5"> + <property name="label">gtk-cancel</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_action_appearance">False</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="find_dialog_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">•</property> + <property name="primary_icon_activatable">False</property> + <property name="secondary_icon_activatable">False</property> + <property name="primary_icon_sensitive">True</property> + <property name="secondary_icon_sensitive">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </object> + </child> + <action-widgets> + <action-widget response="-3">button4</action-widget> + <action-widget response="-6">button5</action-widget> + </action-widgets> + </object> + <object class="GtkListStore" id="liststore1"> + <columns> + <!-- column-name text --> + <column type="gchararray"/> + </columns> + </object> + <object class="GtkWindow" id="win_main"> + <property name="width_request">600</property> + <property name="height_request">600</property> + <property name="can_focus">False</property> + <property name="title" translatable="yes">Sprite Animation Editor</property> + <property name="window_position">center</property> + <property name="default_width">600</property> + <property name="default_height">600</property> + <property name="icon">icon.svg</property> + <signal name="destroy" handler="save_config_and_quit" swapped="no"/> + <child> + <object class="GtkVBox" id="vbox1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkMenuBar" id="menubar1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkMenuItem" id="menuitem1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_File</property> + <property name="use_underline">True</property> + <child type="submenu"> + <object class="GtkMenu" id="menu1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkMenuItem" id="menuitem4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_New</property> + <property name="use_underline">True</property> + <signal name="activate" handler="file_new" swapped="no"/> + </object> + </child> + <child> + <object class="GtkMenuItem" id="menuitem5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_Open...</property> + <property name="use_underline">True</property> + <signal name="activate" handler="open_menu_item_activate_callback" object="fcdialog1" swapped="no"/> + </object> + </child> + <child> + <object class="GtkMenuItem" id="menuitem6"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_Reload</property> + <property name="use_underline">True</property> + <signal name="activate" handler="open_xml_file" swapped="no"/> + </object> + </child> + <child> + <object class="GtkSeparatorMenuItem" id="menuitem15"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + </object> + </child> + <child> + <object class="GtkMenuItem" id="menuitem7"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_Save</property> + <property name="use_underline">True</property> + <signal name="activate" handler="save_menu_item_activate_callback" swapped="no"/> + </object> + </child> + <child> + <object class="GtkMenuItem" id="menuitem8"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">Save _As...</property> + <property name="use_underline">True</property> + <signal name="activate" handler="save_dialog_show" swapped="no"/> + </object> + </child> + </object> + </child> + </object> + </child> + <child> + <object class="GtkMenuItem" id="menuitem2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_Search</property> + <property name="use_underline">True</property> + <child type="submenu"> + <object class="GtkMenu" id="menu2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkMenuItem" id="menuitem9"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_Find...</property> + <property name="use_underline">True</property> + <signal name="activate" handler="find_menu_item_activate_callback" swapped="no"/> + </object> + </child> + <child> + <object class="GtkMenuItem" id="menuitem10"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">Find _Next</property> + <property name="use_underline">True</property> + <signal name="activate" handler="search_find_next" swapped="no"/> + </object> + </child> + </object> + </child> + </object> + </child> + <child> + <object class="GtkMenuItem" id="menuitem3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_View</property> + <property name="use_underline">True</property> + <child type="submenu"> + <object class="GtkMenu" id="menu3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkCheckMenuItem" id="menuitem11"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">Show _Grid</property> + <property name="use_underline">True</property> + <signal name="toggled" handler="show_grid_menu_item_toggled_callback" swapped="no"/> + </object> + </child> + <child> + <object class="GtkMenuItem" id="menuitem12"> + <property name="visible">True</property> + <property name="sensitive">False</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_Imageset view</property> + <property name="use_underline">True</property> + <signal name="activate" handler="show_imageset_dialog" swapped="no"/> + </object> + </child> + </object> + </child> + </object> + </child> + <child> + <object class="GtkMenuItem" id="menuitem13"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_Help</property> + <property name="use_underline">True</property> + <child type="submenu"> + <object class="GtkMenu" id="menu4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkMenuItem" id="menuitem14"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_action_appearance">False</property> + <property name="label" translatable="yes">_About</property> + <property name="use_underline">True</property> + <signal name="activate" handler="show_about_dialog" swapped="no"/> + </object> + </child> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkVButtonBox" id="vbuttonbox1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="layout_style">start</property> + <child> + <object class="GtkLabel" id="label2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Clientdata folder</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkFileChooserButton" id="datafcbutton"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="action">select-folder</property> + <property name="title" translatable="yes">Clientdata folder</property> + <signal name="selection-changed" handler="data_folder_set_callback" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">XML source file</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkFileChooserButton" id="xmlfcbutton"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="dialog">fcdialog1</property> + <property name="title" translatable="yes">Select XML file</property> + <signal name="file-set" handler="open_xml_file" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">3</property> + </packing> + </child> + <child> + <object class="GtkButton" id="xmlfobutton"> + <property name="label">gtk-open</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_action_appearance">False</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="open_xml_file" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">5</property> + </packing> + </child> + <child> + <object class="GtkButton" id="xmlfsbutton"> + <property name="label">gtk-save</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_action_appearance">False</property> + <property name="use_stock">True</property> + <signal name="clicked" handler="xml_file_save_button_callback" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">5</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button3"> + <property name="label" translatable="yes">Parse XML Buffer</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_action_appearance">False</property> + <signal name="clicked" handler="parse_xml_buffer" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">6</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Imagesets</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">7</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="imagesetscbox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="model">liststore1</property> + <property name="active">0</property> + <signal name="changed" handler="imagesets_combo_box_changed_callback" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">9</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Actions</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">9</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="actionscbox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="active">0</property> + <signal name="changed" handler="actions_combo_box_changed_callback" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">11</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Directions</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">11</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="animationscbox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="active">0</property> + <signal name="changed" handler="animations_combo_box_changed_callback" swapped="no"/> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">34</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkVPaned" id="vpaned1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <child> + <object class="GtkDrawingArea" id="darea1"> + <property name="height_request">120</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <signal name="expose-event" handler="darea_expose_event" swapped="no"/> + </object> + <packing> + <property name="resize">True</property> + <property name="shrink">True</property> + </packing> + </child> + <child> + <object class="GtkScrolledWindow" id="scrolledwindow1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">automatic</property> + <property name="vscrollbar_policy">automatic</property> + <child> + <object class="GtkSourceView" id="source_view"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="left_margin">2</property> + <property name="right_margin">2</property> + <property name="show_line_numbers">True</property> + <property name="tab_width">4</property> + <property name="auto_indent">True</property> + <property name="indent_on_tab">False</property> + </object> + </child> + </object> + <packing> + <property name="resize">True</property> + <property name="shrink">True</property> + </packing> + </child> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> +</interface> diff --git a/saedit/main.c b/saedit/main.c index c18b901..bf5b5e4 100644 --- a/saedit/main.c +++ b/saedit/main.c @@ -9,22 +9,10 @@ | | \*=======================================*/ -#include <stdlib.h> -#include <gtk/gtk.h> -#include <gtksourceview/gtksourceview.h> -#include <gtksourceview/gtksourcelanguagemanager.h> -#include <gtksourceview/gtksourceiter.h> -#include <ibusxml.h> -#include <cairo.h> -#include <glib/gi18n.h> - -#include "common.h" -#include "xml.h" -#include "config.h" -#include "sae.h" #include "main.h" -#include "search.h" -#include "interface.h" +#include "interface.c" + +//Cairo functions 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); @@ -58,6 +46,9 @@ cairo_surface_t *get_grid_surface(int w, int h) { } gboolean darea_expose_event(GtkWidget *widget, GdkEventExpose *event, SAEInfo *sae_info) { + if (sae_info == NULL) + sae_info = gen_sae_info; + int width = widget->allocation.width, height = widget->allocation.height; @@ -90,6 +81,8 @@ gboolean darea_expose_event(GtkWidget *widget, GdkEventExpose *event, SAEInfo *s return FALSE; } +//String functions (common) + gchar *markup_bold(gchar *str) { gchar *buffer[255]; g_sprintf(buffer, "<b>%s</b>", str); @@ -102,20 +95,33 @@ void format_src_string(gchar *src) { strncpy(str, "\0", 1); } -void open_xml_file(GtkButton *button, gpointer buffer) { +//File working + +void open_xml_file(GtkButton *button) { 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); if (g_utf8_validate(buf, len, NULL)) { - gtk_text_buffer_set_text((GtkTextBuffer *)buffer, buf, len); + gtk_text_buffer_set_text(source_buffer, buf, len); gtk_widget_set_sensitive(xml_file_save_button, TRUE); } else { gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(xml_file_chooser_button)); } + + free_current_info(); +} + +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(filename, gtk_text_buffer_get_text(source_buffer, &start, &end, NULL), -1, NULL); } +//SAEInfo functions (must be ported to sae.c) + void free_imagesets(SAEInfo *sae_info) { free_imageset(sae_info); sae_info->imagesets = NULL; @@ -134,19 +140,37 @@ 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 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(filename, gtk_text_buffer_get_text(source_buffer, &start, &end, NULL), -1, NULL); +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 free_lists(SAEInfo *sae_info) { + free_imagesets(sae_info); + free_actions(sae_info); + free_animations(sae_info); } +void free_current_info() { + free_lists(gen_sae_info); + player = NULL; +} + +//Callbacks + void data_folder_set_callback(GtkFileChooserButton *widget, gpointer data) { config->clientdata_folder = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data_folder_chooser_button)); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(xml_file_chooser_button), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget))); } -void show_grid_menu_item_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data) { +void show_grid_menu_item_toggled_callback(GtkCheckMenuItem *checkmenuitem, gpointer user_data) { config->show_grid = gtk_check_menu_item_get_active(checkmenuitem); gtk_widget_queue_draw(darea); } @@ -162,6 +186,77 @@ void show_wrong_source_buffer_dialog() { gtk_widget_show_all(dialog); } +void actions_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data) { + if (player != NULL) + set_up_action_by_name(gtk_combo_box_get_active_text(widget), player); + set_up_action_by_name(gtk_combo_box_get_active_text(widget), gen_sae_info); +} + +void animations_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data) { + set_up_animation_by_direction(gen_sae_info, gtk_combo_box_get_active_text(widget)); + if (player != NULL) { + set_up_animation_by_direction(player, gtk_combo_box_get_active_text(widget)); + show_animation(player); + } + show_animation(gen_sae_info); +} + +void imagesets_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data) { + if (gtk_combo_box_get_active_text(widget) != NULL) + set_up_imageset_by_name(gtk_combo_box_get_active_text(widget), gen_sae_info); +} + +gboolean frame_image_button_press_event_callback(GtkWidget *widget, GdkEventButton *button, int index) { + gchar buf[10]; + gint len = g_sprintf(buf, "%d", index); + gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(source_buffer), buf, len); + return FALSE; +} + +void open_menu_item_activate_callback(GtkMenuItem *menuitem, GtkFileChooserDialog *fcdialog) { + gtk_dialog_run(fcdialog); +} + +//Dialogs + +void show_about_dialog() { + gtk_dialog_run(about_dialog); + gtk_widget_hide(about_dialog); +} + +void show_imageset_dialog() { + if (gen_sae_info->imageset->spriteset == NULL) return; + GtkWidget *dialog = gtk_dialog_new(); + GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + gtk_window_set_title(GTK_WINDOW(dialog), _("Imageset preview")); + gtk_window_set_transient_for(dialog, GTK_WINDOW(win)); + + int w = gen_sae_info->imageset->spriteset_width / gen_sae_info->imageset->width; + int h = gen_sae_info->imageset->spriteset_height / gen_sae_info->imageset->height; + + GtkWidget *hbox = NULL; + GtkWidget *image = NULL; + GtkWidget *event_box = NULL; + + int x, y; + for (y = 0; y < h; y++) { + hbox = gtk_hbox_new(TRUE, 0); + gtk_container_add(content_area, hbox); + for (x = 0; x < w; x++) { + event_box = gtk_event_box_new(); + g_signal_connect(G_OBJECT(event_box), "button-press-event", G_CALLBACK(frame_image_button_press_event_callback), w * y + x); + gtk_box_pack_start(GTK_BOX(hbox), event_box, TRUE, TRUE, 0); + + image = gtk_image_new_from_pixbuf(get_sprite_by_index(w * y + x, gen_sae_info)); + gtk_widget_add_events(image, GDK_BUTTON_PRESS_MASK); + gtk_container_add(GTK_CONTAINER(event_box), image); + } + } + gtk_widget_show_all(dialog); +} + +//Main functions + 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); @@ -194,9 +289,7 @@ void set_up_actions_by_imageset_name(gchar *imageset_name, SAEInfo *sae_info) { gboolean set_up_imagesets(SAEInfo *sae_info) { GList *_imagesets_list = NULL; - free_imagesets(sae_info); - free_actions(sae_info); - free_animations(sae_info); + free_lists(sae_info); GList *list = sae_info->root->sub_nodes; XMLNode *node = NULL; while (TRUE) { @@ -275,21 +368,6 @@ gboolean set_up_action_by_name(const gchar *name, SAEInfo *sae_info) { return TRUE; } -void actions_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data) { - if (player != NULL) - set_up_action_by_name(gtk_combo_box_get_active_text(widget), player); - set_up_action_by_name(gtk_combo_box_get_active_text(widget), gen_sae_info); -} - -void animations_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data) { - set_up_animation_by_direction(gen_sae_info, gtk_combo_box_get_active_text(widget)); - if (player != NULL) { - set_up_animation_by_direction(player, gtk_combo_box_get_active_text(widget)); - show_animation(player); - } - show_animation(gen_sae_info); -} - void set_up_imageset_by_name(const gchar *name, SAEInfo *sae_info) { free_imageset(sae_info); free_actions(sae_info); @@ -367,11 +445,6 @@ void set_up_imageset_by_name(const gchar *name, SAEInfo *sae_info) { set_sprite_by_index(0, sae_info); } -void imagesets_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data) { - if (gtk_combo_box_get_active_text(widget) != NULL) - set_up_imageset_by_name(gtk_combo_box_get_active_text(widget), gen_sae_info); -} - void load_options() { gchar *datapath = config->clientdata_folder; gchar *path = g_strjoin(SEPARATOR_SLASH, datapath, "paths.xml", NULL); @@ -379,9 +452,7 @@ void load_options() { } void parse_xml_text(gchar *text, SAEInfo *sae_info) { - free_imagesets(sae_info); - free_actions(sae_info); - free_animations(sae_info); + free_lists(sae_info); XMLNode *_root_node = ibus_xml_parse_buffer(text); sae_info->root = _root_node; @@ -416,6 +487,9 @@ void parse_xml_text(gchar *text, SAEInfo *sae_info) { } void parse_xml_buffer(GtkWidget *button, GtkSourceBuffer *buffer) { + if (buffer == NULL) + buffer = source_buffer; + player = NULL; load_options(); @@ -425,62 +499,6 @@ void parse_xml_buffer(GtkWidget *button, GtkSourceBuffer *buffer) { parse_xml_text(gtk_text_iter_get_text(&beg, &end), gen_sae_info); } -void show_about_dialog() { - gchar *authors[] = {"Dan Sagunov <danilka.pro@gmail.com>", - "Reid Yaro <reidyaro@gmail.com>", - NULL}; - 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 \u2184 Vasily_Makarov 2011", - "program-name", "Sprite Animation Editor", - "version", "0.1 prealpha", - "logo", icon, - NULL); -} - -void open_menu_item_activate(GtkMenuItem *menuitem, GtkFileChooserDialog *fcdialog) { - gtk_dialog_run(fcdialog); -} - -gboolean frame_image_button_press_event(GtkWidget *widget, GdkEventButton *button, int index) { - gchar buf[10]; - gint len = g_sprintf(buf, "%d", index); - gtk_text_buffer_insert_at_cursor(GTK_TEXT_BUFFER(source_buffer), buf, len); - return FALSE; -} - -void show_imageset_dialog() { - if (gen_sae_info->imageset->spriteset == NULL) return; - GtkWidget *dialog = gtk_dialog_new(); - GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - gtk_window_set_title(GTK_WINDOW(dialog), _("Imageset preview")); - gtk_window_set_transient_for(dialog, GTK_WINDOW(win)); - - int w = gen_sae_info->imageset->spriteset_width / gen_sae_info->imageset->width; - int h = gen_sae_info->imageset->spriteset_height / gen_sae_info->imageset->height; - - GtkWidget *hbox = NULL; - GtkWidget *image = NULL; - GtkWidget *event_box = NULL; - - int x, y; - for (y = 0; y < h; y++) { - hbox = gtk_hbox_new(TRUE, 0); - gtk_container_add(content_area, hbox); - for (x = 0; x < w; x++) { - event_box = gtk_event_box_new(); - g_signal_connect(G_OBJECT(event_box), "button-press-event", G_CALLBACK(frame_image_button_press_event), w * y + x); - gtk_box_pack_start(GTK_BOX(hbox), event_box, TRUE, TRUE, 0); - - image = gtk_image_new_from_pixbuf(get_sprite_by_index(w * y + x, gen_sae_info)); - gtk_widget_add_events(image, GDK_BUTTON_PRESS_MASK); - gtk_container_add(GTK_CONTAINER(event_box), image); - } - } - gtk_widget_show_all(dialog); -} - void load_config() { config_keys_load(config); gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(data_folder_chooser_button), config->clientdata_folder); @@ -492,19 +510,6 @@ 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 5ef398b..af78d8f 100644 --- a/saedit/main.h +++ b/saedit/main.h @@ -9,6 +9,23 @@ | | \*=======================================*/ +#ifndef MAIN_H +#define MAIN_H + +#include <stdlib.h> +#include <gtk/gtk.h> +#include <gtksourceview/gtksourceview.h> +#include <gtksourceview/gtksourcelanguagemanager.h> +#include <gtksourceview/gtksourceiter.h> +#include <cairo.h> +#include <glib/gi18n.h> + +#include "common.h" +#include "xml.h" +#include "config.h" +#include "sae.h" +#include "search.h" + const int MIN_WIDTH = 600; const int MIN_HEIGHT = 600; @@ -29,6 +46,7 @@ GtkWidget *xml_file_save_button = NULL; GtkWidget *imageset_preview_menu_item = NULL; GtkWidget *show_grid_menu_item = NULL; GtkWidget *source_view = NULL; +GtkWidget *about_dialog = NULL; GtkSourceBuffer *source_buffer = NULL; @@ -40,36 +58,53 @@ GdkPixbuf *icon = NULL; Options *paths; Keys *config; -static gchar *markup_bold(gchar *str); -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 save_to_xml_file(gchar *filename); -static void data_folder_set_callback(GtkFileChooserButton *widget, gpointer data); -static void show_wrong_source_buffer_dialog(); -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); -static gboolean show_general_animation(SAEInfo *sae_info); -static gboolean set_up_action_by_name(const gchar *name, SAEInfo *sae_info); -static void actions_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data); -static void animations_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data); -static void set_up_imageset_by_name(const gchar* name, SAEInfo *sae_info); -static void imagesets_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data); -static void parse_xml_buffer(GtkWidget *button, GtkSourceBuffer *buffer); -static void set_up_interface(); -static void show_about_dialog(); -static void show_imageset_dialog(); -static gboolean frame_image_button_press_event(GtkWidget *widget, GdkEventButton *button, int index); -static cairo_surface_t *get_grid_surface(int w, int h); -static gboolean darea_expose_event(GtkWidget *widget, GdkEventExpose *event, SAEInfo *sae_info); -static void load_config(); -static void save_config_and_quit(); -static void load_options(); -static void free_imageset(); -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); +//Cairo functions +cairo_surface_t *get_grid_surface(int w, int h); +gboolean darea_expose_event(GtkWidget *widget, GdkEventExpose *event, SAEInfo *sae_info); + +//String functions (common) +gchar *markup_bold(gchar *str); +void format_src_string(gchar *src); + +//File working +void open_xml_file(GtkButton *button); +void save_to_xml_file(gchar *filename); + +//SAEInfo functions +void free_imagesets(SAEInfo *sae_info); +void free_actions(SAEInfo *sae_info); void free_animations(SAEInfo *sae_info); +void free_imageset(SAEInfo *sae_info); +void free_lists(SAEInfo *sae_info); + +void free_current_info(); + +//Callbacks +void data_folder_set_callback(GtkFileChooserButton *widget, gpointer data); +void show_wrong_source_buffer_dialog(); +void show_grid_menu_item_toggled_callback(GtkCheckMenuItem *checkmenuitem, gpointer user_data); +void actions_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data); +void imagesets_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data); +void open_menu_item_activate_callback(GtkMenuItem *menuitem, GtkFileChooserDialog *fcdialog); +gboolean frame_image_button_press_event_callback(GtkWidget *widget, GdkEventButton *button, int index); + +//Dialogs +void show_imageset_dialog(); +void show_about_dialog(); + +void set_sprite_by_index(size_t index, SAEInfo *sae_info); +void set_up_actions_by_imageset_name(gchar *imageset_name, SAEInfo *sae_info); +gboolean set_up_imagesets(SAEInfo *sae_info); +gboolean show_general_animation(SAEInfo *sae_info); +gboolean set_up_action_by_name(const gchar *name, SAEInfo *sae_info); +void animations_combo_box_changed_callback(GtkComboBox *widget, gpointer user_data); +void set_up_imageset_by_name(const gchar* name, SAEInfo *sae_info); +void parse_xml_buffer(GtkWidget *button, GtkSourceBuffer *buffer); +void set_up_interface(); +void load_config(); +void save_config_and_quit(); +void load_options(); +void parse_xml_text(gchar *text, SAEInfo *sae_info); +void show_animation(SAEInfo *sae_info); + +#endif diff --git a/saedit/sae.c b/saedit/sae.c index 17027ea..736e90d 100644 --- a/saedit/sae.c +++ b/saedit/sae.c @@ -9,10 +9,6 @@ | | \*=======================================*/ -#include <gtk/gtk.h> -#include <ibusxml.h> -#include "common.h" -#include "xml.h" #include "sae.h" void kill_timeout(guint tag) { diff --git a/saedit/sae.h b/saedit/sae.h index e89db25..b6867e3 100644 --- a/saedit/sae.h +++ b/saedit/sae.h @@ -12,6 +12,11 @@ #ifndef SAE_H #define SAE_H +#include <gtk/gtk.h> +#include <ibusxml.h> +#include "common.h" +#include "xml.h" + void kill_timeout(guint tag); typedef struct { diff --git a/saedit/search.c b/saedit/search.c index 041d972..f98063f 100644 --- a/saedit/search.c +++ b/saedit/search.c @@ -9,12 +9,9 @@ | | \*=======================================*/ -#include <gtk/gtk.h> -#include "common.h" #include "search.h" GtkWidget *search_text_view = NULL; -GtkWidget *search_find_dialog_entry = NULL; gchar *search_last_text = NULL; gboolean search_find_text(gchar *text) { @@ -28,11 +25,11 @@ gboolean search_find_text(gchar *text) { GtkTextIter m_start, m_end, start; gtk_text_buffer_get_selection_bounds(text_buffer, NULL, &start); - found = gtk_source_iter_forward_search(&start, text, 0, &m_start, &m_end, NULL); + found = gtk_source_iter_forward_search(&start, text, GTK_SOURCE_SEARCH_CASE_INSENSITIVE, &m_start, &m_end, NULL); if (!found) { gtk_text_buffer_get_start_iter(text_buffer, &start); - found = gtk_source_iter_forward_search(&start, text, 0, &m_start, &m_end, NULL); + found = gtk_source_iter_forward_search(&start, text, GTK_SOURCE_SEARCH_CASE_INSENSITIVE, &m_start, &m_end, NULL); } if (found) { @@ -54,17 +51,25 @@ gboolean search_find_next() { search_find_text(search_last_text); } -void search_find_dialog_response_callback(GtkDialog *dialog, +void search_find_dialog_response_callback(GtkWidget *dialog, gint response_id, - gpointer user_data) { - if (response_id != GTK_RESPONSE_ACCEPT) - return; + gpointer entry) { - if (!GTK_IS_TEXT_VIEW(search_text_view)) - return; + if (response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT) + gtk_widget_hide(dialog); + else { - if (GTK_IS_ENTRY(search_find_dialog_entry)) - search_find_text(g_strdup(gtk_entry_get_text(GTK_ENTRY(search_find_dialog_entry)))); + g_return_if_fail(response_id == GTK_RESPONSE_ACCEPT); + g_return_if_fail(GTK_IS_TEXT_VIEW(search_text_view)); + g_return_if_fail(GTK_IS_ENTRY(GTK_ENTRY(entry))); + + search_find_text(g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)))); + + } +} + +void search_init(GtkWidget *text_view) { + search_text_view = text_view; } void search_find_dialog_show(GtkWindow *parent, @@ -91,10 +96,9 @@ void search_find_dialog_show(GtkWindow *parent, g_signal_connect(dialog, "response", G_CALLBACK(search_find_dialog_response_callback), - NULL); + entry); search_text_view = text_view; - search_find_dialog_entry = entry; gtk_dialog_run(dialog); } diff --git a/saedit/search.h b/saedit/search.h index 5d2b5ff..350bc70 100644 --- a/saedit/search.h +++ b/saedit/search.h @@ -12,9 +12,15 @@ #ifndef SEARCH_H #define SEARCH_H +#include <gtk/gtk.h> +#include <gtksourceview/gtksourceiter.h> +#include "common.h" + +void search_init(GtkWidget *text_view); gboolean search_find_text(gchar *text); gboolean search_find_next(); -void search_find_dialog_show(GtkWindow *parent, - GtkWidget *text_view); +void search_find_dialog_response_callback(GtkWidget *dialog, + gint response_id, + gpointer entry); #endif diff --git a/saedit/xml.c b/saedit/xml.c index 6120d5c..2968082 100644 --- a/saedit/xml.c +++ b/saedit/xml.c @@ -9,9 +9,6 @@ | | \*=======================================*/ -#include <glib.h> -#include <ibusxml.h> -#include "common.h" #include "xml.h" gchar **xml_attr_new(gchar *name, gchar *value) { diff --git a/saedit/xml.h b/saedit/xml.h index 02bd207..2a8875e 100644 --- a/saedit/xml.h +++ b/saedit/xml.h @@ -11,6 +11,10 @@ #ifndef XML_H #define XML_H +#include <glib.h> +#include <ibusxml.h> +#include "common.h" + gchar **xml_attr_new(gchar *name, gchar *value); gchar *xml_node_get_attr_value(XMLNode *node, gchar *attr_name); gint xml_node_compare_with_name_func(gconstpointer a, gconstpointer b); |