summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasily_Makarov <danilka.pro@gmail.com>2012-02-09 12:07:10 +0400
committerVasily_Makarov <danilka.pro@gmail.com>2012-02-09 12:07:10 +0400
commitcc459a0b40bb56f6559c855ecb5b956b9ee6a90b (patch)
tree8698d1e99eec34b24f14f21c176871b88863fa18
parent6545f58904d754db19800a1cd21f472eb13339bd (diff)
downloadevol-tools-cc459a0b40bb56f6559c855ecb5b956b9ee6a90b.tar.gz
evol-tools-cc459a0b40bb56f6559c855ecb5b956b9ee6a90b.tar.bz2
evol-tools-cc459a0b40bb56f6559c855ecb5b956b9ee6a90b.tar.xz
evol-tools-cc459a0b40bb56f6559c855ecb5b956b9ee6a90b.zip
SAE: Changed error structure
-rw-r--r--saedit/config.c92
-rw-r--r--saedit/config.h6
-rw-r--r--saedit/interface.c145
-rw-r--r--saedit/interface.ui60
-rw-r--r--saedit/main.c848
-rw-r--r--saedit/main.h3
-rw-r--r--saedit/sae.c200
-rw-r--r--saedit/sae.h58
-rw-r--r--saedit/search.c136
-rw-r--r--saedit/search.h4
-rw-r--r--saedit/xml.c587
-rw-r--r--saedit/xml.h12
12 files changed, 1082 insertions, 1069 deletions
diff --git a/saedit/config.c b/saedit/config.c
index cdc0ffd..303db6d 100644
--- a/saedit/config.c
+++ b/saedit/config.c
@@ -12,71 +12,71 @@
#include "config.h"
Options *config_options_new() {
- return g_new0(Options, 1);
+ return g_new0(Options, 1);
}
void config_options_load_from_file(Options *options,
gchar *file,
gchar *data_folder) {
- options->sprites = NULL;
+ options->sprites = NULL;
- XMLNode *node = xml_parse_file(file);
+ XMLNode *node = xml_parse_file(file);
- if (node != NULL) {
- GList *list = node->sub_nodes;
- while (TRUE) {
- list = g_list_find_custom(list, "option", xml_node_compare_with_name_func);
- if (list == NULL)
- break;
- gchar *name_attr = xml_node_get_attr_value(list->data, "name");
- if (name_attr != NULL) {
- if (g_strcmp0(name_attr, "sprites") == 0)
- options->sprites = xml_node_get_attr_value(list->data, "value");
- }
- list = list->next;
- }
- }
+ if (node != NULL) {
+ GList *list = node->sub_nodes;
+ while (TRUE) {
+ list = g_list_find_custom(list, "option", xml_node_compare_with_name_func);
+ if (list == NULL)
+ break;
+ gchar *name_attr = xml_node_get_attr_value(list->data, "name");
+ if (name_attr != NULL) {
+ if (g_strcmp0(name_attr, "sprites") == 0)
+ options->sprites = xml_node_get_attr_value(list->data, "value");
+ }
+ list = list->next;
+ }
+ }
- if (options->sprites == NULL) options->sprites = OPTION_SPRITES_DEFAULT;
- options->sprites = g_strjoin(SEPARATOR_SLASH, data_folder, options->sprites, NULL);
+ if (options->sprites == NULL) options->sprites = OPTION_SPRITES_DEFAULT;
+ options->sprites = g_strjoin(SEPARATOR_SLASH, data_folder, options->sprites, NULL);
}
Keys *config_keys_new() {
- Keys *keys = g_new0(Keys, 1);
- keys->clientdata_folder = KEY_CLIENTDATA_FOLDER_DEFAULT;
- keys->show_grid = KEY_SHOW_GRID_DEFAULT;
- return keys;
+ Keys *keys = g_new0(Keys, 1);
+ keys->clientdata_folder = KEY_CLIENTDATA_FOLDER_DEFAULT;
+ keys->show_grid = KEY_SHOW_GRID_DEFAULT;
+ return keys;
}
void config_keys_save(Keys *keys) {
- GKeyFile *key_file = g_key_file_new();
- g_key_file_set_value(key_file, "General", "ClientdataFolder",
- g_strjoin(SEPARATOR_SLASH,
- keys->clientdata_folder,
- POSTFIX_FOLDER,
- NULL));
- g_key_file_set_boolean(key_file, "General", "ShowGrid", keys->show_grid);
+ GKeyFile *key_file = g_key_file_new();
+ g_key_file_set_value(key_file, "General", "ClientdataFolder",
+ g_strjoin(SEPARATOR_SLASH,
+ keys->clientdata_folder,
+ POSTFIX_FOLDER,
+ NULL));
+ g_key_file_set_boolean(key_file, "General", "ShowGrid", keys->show_grid);
- 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));
- close(fd);
+ 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));
+ close(fd);
- g_key_file_free(key_file);
+ g_key_file_free(key_file);
}
void config_keys_load(Keys *keys) {
- GKeyFile *key_file = g_key_file_new();
+ GKeyFile *key_file = g_key_file_new();
- g_key_file_load_from_file(key_file,
- KEYS_CONFIG_FILE,
- 0,
- NULL);
- if (g_key_file_has_key(key_file, "General", "ClientdataFolder", NULL))
- keys->clientdata_folder = g_key_file_get_value(key_file, "General", "ClientdataFolder", NULL);
- if (g_key_file_has_key(key_file, "General", "ShowGrid", NULL))
- keys->show_grid = g_key_file_get_boolean(key_file, "General", "ShowGrid", NULL);
+ g_key_file_load_from_file(key_file,
+ KEYS_CONFIG_FILE,
+ 0,
+ NULL);
+ if (g_key_file_has_key(key_file, "General", "ClientdataFolder", NULL))
+ keys->clientdata_folder = g_key_file_get_value(key_file, "General", "ClientdataFolder", NULL);
+ if (g_key_file_has_key(key_file, "General", "ShowGrid", NULL))
+ keys->show_grid = g_key_file_get_boolean(key_file, "General", "ShowGrid", NULL);
- g_key_file_free(key_file);
+ g_key_file_free(key_file);
}
diff --git a/saedit/config.h b/saedit/config.h
index 0fb0ac7..51c2f0b 100644
--- a/saedit/config.h
+++ b/saedit/config.h
@@ -28,7 +28,7 @@
#define KEYS_CONFIG_FILE g_strjoin(SEPARATOR_SLASH, KEYS_CONFIG_DIR, "config.ini", NULL)
typedef struct {
- gchar *sprites;
+ gchar *sprites;
} Options;
Options *config_options_new();
@@ -37,8 +37,8 @@ void config_options_load_from_file(Options *options,
gchar *data_folder);
typedef struct {
- gchar *clientdata_folder;
- gboolean show_grid;
+ gchar *clientdata_folder;
+ gboolean show_grid;
} Keys;
Keys *config_keys_new();
diff --git a/saedit/interface.c b/saedit/interface.c
index 0adb153..0984cbd 100644
--- a/saedit/interface.c
+++ b/saedit/interface.c
@@ -14,108 +14,111 @@ GtkWidget *find_dialog = NULL;
GtkWidget *toolbar = NULL;
void find_menu_item_activate_callback(GtkWidget *menuitem, gpointer user_data) {
- gtk_dialog_run(GTK_DIALOG(find_dialog));
+ 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);
+ 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_DIALOG(gtk_file_chooser_dialog_new(_("Save file as..."), GTK_WINDOW(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);
+ GtkDialog *dialog = GTK_DIALOG(gtk_file_chooser_dialog_new(_("Save file as..."), GTK_WINDOW(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();
+ 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);
+ 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(GTK_TEXT_BUFFER(source_buffer), &start, &end);
- gtk_text_buffer_delete(GTK_TEXT_BUFFER(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();
+ GtkTextIter start, end;
+ gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(source_buffer), &start, &end);
+ gtk_text_buffer_delete(GTK_TEXT_BUFFER(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);
+ 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 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"));
+ //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);
+ 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 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"));
+ //Setup GtkDrawingArea
+ darea = GTK_WIDGET(gtk_builder_get_object(builder, "darea1"));
- //Setup GtkToolbar
- toolbar = GTK_WIDGET(gtk_builder_get_object(builder, "toolbar"));
+ //Setup GtkToolbar
+ toolbar = GTK_WIDGET(gtk_builder_get_object(builder, "toolbar"));
- 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"));
+ 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"));
+ 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"));
+ 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 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);
+ //Setup GtkMessageDialog
+ parsing_error_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "parsing-error-dialog"));
- file_new();
+ //Setup Find dialog
+ find_dialog = GTK_WIDGET(gtk_builder_get_object(builder, "find_dialog"));
+ gtk_widget_hide(find_dialog);
- gtk_widget_show_all(win);
- gtk_widget_show_all(source_view);
+ file_new();
- g_object_unref(builder);
+ gtk_widget_show_all(win);
+ gtk_widget_show_all(source_view);
+
+ g_object_unref(builder);
}
diff --git a/saedit/interface.ui b/saedit/interface.ui
index f49af39..4f44155 100644
--- a/saedit/interface.ui
+++ b/saedit/interface.ui
@@ -212,6 +212,42 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
<column type="gchararray"/>
</columns>
</object>
+ <object class="GtkMessageDialog" id="parsing-error-dialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="type_hint">dialog</property>
+ <property name="skip_taskbar_hint">True</property>
+ <property name="message_type">error</property>
+ <property name="buttons">close</property>
+ <property name="text" translatable="yes">&lt;b&gt;Bad source buffer!&lt;/b&gt;</property>
+ <property name="use_markup">True</property>
+ <signal name="response" handler="gtk_widget_hide" swapped="no"/>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="messagedialog-vbox">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">14</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="messagedialog-action_area">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </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>
+ </object>
+ </child>
+ </object>
<object class="GtkWindow" id="win_main">
<property name="width_request">600</property>
<property name="height_request">600</property>
@@ -415,10 +451,10 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label2">
+ <property name="height_request">24</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Clientdata folder</property>
- <property name="height_request">24</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -445,10 +481,10 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
</child>
<child>
<object class="GtkLabel" id="label1">
+ <property name="height_request">24</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">XML source file</property>
- <property name="height_request">24</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -469,7 +505,7 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
</object>
<packing>
<property name="expand">False</property>
- <property name="fill">True</property>
+ <property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
@@ -525,8 +561,8 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
</child>
<child>
<object class="GtkSeparator" id="separator1">
- <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<property name="height_request">30</property>
+ <property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
@@ -536,10 +572,10 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
</child>
<child>
<object class="GtkLabel" id="label3">
+ <property name="height_request">24</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Imagesets</property>
- <property name="height_request">24</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -556,7 +592,6 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
<property name="can_focus">False</property>
<property name="active">0</property>
<property name="entry_text_column">0</property>
- <property name="model">liststore1</property>
<signal name="changed" handler="imagesets_combo_box_changed_callback" swapped="no"/>
</object>
<packing>
@@ -567,10 +602,10 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
</child>
<child>
<object class="GtkLabel" id="label4">
+ <property name="height_request">24</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Actions</property>
- <property name="height_request">24</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -587,7 +622,6 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
<property name="can_focus">False</property>
<property name="active">0</property>
<property name="entry_text_column">0</property>
- <property name="model">liststore2</property>
<signal name="changed" handler="actions_combo_box_changed_callback" swapped="no"/>
</object>
<packing>
@@ -598,10 +632,10 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
</child>
<child>
<object class="GtkLabel" id="label5">
+ <property name="height_request">24</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Directions</property>
- <property name="height_request">24</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -618,7 +652,6 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
<property name="can_focus">False</property>
<property name="active">0</property>
<property name="entry_text_column">0</property>
- <property name="model">liststore3</property>
<signal name="changed" handler="animations_combo_box_changed_callback" swapped="no"/>
</object>
<packing>
@@ -636,8 +669,9 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
</child>
<child>
<object class="GtkSeparator" id="separator2">
- <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
<property name="width_request">1</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
</object>
<packing>
<property name="expand">False</property>
@@ -668,8 +702,8 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</property>
<child>
<object class="GtkToolbar" id="toolbar">
<property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="sensitive">False</property>
+ <property name="can_focus">False</property>
<child>
<object class="GtkToolButton" id="toolbar-to-first">
<property name="use_action_appearance">False</property>
@@ -792,8 +826,8 @@ Reid Yaro &lt;reidyaro@gmail.com&gt;</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>
<property name="highlight_current_line">True</property>
+ <property name="indent_on_tab">False</property>
</object>
</child>
</object>
diff --git a/saedit/main.c b/saedit/main.c
index 5fc3e77..7b74f07 100644
--- a/saedit/main.c
+++ b/saedit/main.c
@@ -15,587 +15,589 @@
//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);
- cairo_t *cr = cairo_create(surface);
- int x, y;
-
- for (x = 0; x < w; x++)
- for (y = 0; y < h; y++) {
- gdk_cairo_set_source_pixbuf(cr, gen_sae_info->ground, x * GRID_SIZE, y * GRID_SIZE);
- cairo_paint(cr);
- }
-
- if (config->show_grid) {
- cairo_surface_t *gridsurf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w * GRID_SIZE + 1, h * GRID_SIZE + 1);
- cairo_t *scr = cairo_create(gridsurf);
- cairo_set_line_width(scr, 1);
- cairo_set_source_rgba(scr, 0.5, 0.5, 0.5, 1);
- for (x = 0; x < w; x++)
- for (y = 0; y < h; y++) {
- cairo_rectangle(scr, x*GRID_SIZE+0.5, y*GRID_SIZE+0.5, GRID_SIZE, GRID_SIZE);
- cairo_stroke(scr);
- }
- cairo_set_source_surface(cr, gridsurf, GRID_SIZE, GRID_SIZE);
- cairo_paint(cr);
- cairo_destroy(scr);
- cairo_surface_destroy(gridsurf);
- }
-
- cairo_destroy(cr);
- return surface;
+ 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);
+ int x, y;
+
+ for (x = 0; x < w; x++)
+ for (y = 0; y < h; y++) {
+ gdk_cairo_set_source_pixbuf(cr, gen_sae_info->ground, x * GRID_SIZE, y * GRID_SIZE);
+ cairo_paint(cr);
+ }
+
+ if (config->show_grid) {
+ cairo_surface_t *gridsurf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w * GRID_SIZE + 1, h * GRID_SIZE + 1);
+ cairo_t *scr = cairo_create(gridsurf);
+ cairo_set_line_width(scr, 1);
+ cairo_set_source_rgba(scr, 0.5, 0.5, 0.5, 1);
+ for (x = 0; x < w; x++)
+ for (y = 0; y < h; y++) {
+ cairo_rectangle(scr, x*GRID_SIZE+0.5, y*GRID_SIZE+0.5, GRID_SIZE, GRID_SIZE);
+ cairo_stroke(scr);
+ }
+ cairo_set_source_surface(cr, gridsurf, GRID_SIZE, GRID_SIZE);
+ cairo_paint(cr);
+ cairo_destroy(scr);
+ cairo_surface_destroy(gridsurf);
+ }
+
+ cairo_destroy(cr);
+ return surface;
}
gboolean darea_draw_event(GtkWidget *widget, cairo_t *cr, SAEInfo *sae_info) {
- if (sae_info == NULL)
- sae_info = gen_sae_info;
+ if (sae_info == NULL)
+ sae_info = gen_sae_info;
- int width = gtk_widget_get_allocated_width(widget),
- height = gtk_widget_get_allocated_height(widget);
+ int width = gtk_widget_get_allocated_width(widget),
+ height = gtk_widget_get_allocated_height(widget);
- int w = 3, h = 3;
+ int w = 3, h = 3;
- //cairo_t *cr = gdk_cairo_create(gtk_widget_get_parent_window(widget));
+ //cairo_t *cr = gdk_cairo_create(gtk_widget_get_parent_window(widget));
- cairo_surface_t *surface = get_grid_surface(w, h);
- 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);
+ cairo_surface_t *surface = get_grid_surface(w, h);
+ 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);
- if (player != NULL) {
- GdkPixbuf *pbuf = player->sprite->pixbuf;
- if (pbuf == NULL) return FALSE;
- gdk_cairo_set_source_pixbuf(cr, pbuf,
- width/2 - player->imageset->width/2 + player->offsetX + player->sprite->offsetX + player->imageset->offsetX,
- height/2 + GRID_SIZE/2 - player->imageset->height + player->offsetY + player->sprite->offsetY + player->imageset->offsetY);
- cairo_paint(cr);
- }
+ if (player != NULL) {
+ GdkPixbuf *pbuf = player->sprite->pixbuf;
+ if (pbuf == NULL) return FALSE;
+ gdk_cairo_set_source_pixbuf(cr, pbuf,
+ width/2 - player->imageset->width/2 + player->offsetX + player->sprite->offsetX + player->imageset->offsetX,
+ height/2 + GRID_SIZE/2 - player->imageset->height + player->offsetY + player->sprite->offsetY + player->imageset->offsetY);
+ cairo_paint(cr);
+ }
- GdkPixbuf *pbuf = sae_info->sprite->pixbuf;
- if (pbuf == NULL) return FALSE;
- gdk_cairo_set_source_pixbuf(cr, pbuf,
- width/2 - sae_info->imageset->width/2 + sae_info->offsetX + sae_info->sprite->offsetX + sae_info->imageset->offsetX,
- height/2 +GRID_SIZE/2 - sae_info->imageset->height + sae_info->offsetY + sae_info->sprite->offsetY + sae_info->imageset->offsetY);
- cairo_paint(cr);
+ GdkPixbuf *pbuf = sae_info->sprite->pixbuf;
+ if (pbuf == NULL) return FALSE;
+ gdk_cairo_set_source_pixbuf(cr, pbuf,
+ width/2 - sae_info->imageset->width/2 + sae_info->offsetX + sae_info->sprite->offsetX + sae_info->imageset->offsetX,
+ height/2 +GRID_SIZE/2 - sae_info->imageset->height + sae_info->offsetY + sae_info->sprite->offsetY + sae_info->imageset->offsetY);
+ cairo_paint(cr);
- cairo_surface_destroy(surface);
- return FALSE;
+ cairo_surface_destroy(surface);
+ return FALSE;
}
//Common functions
gchar *markup_bold(gchar *str) {
- return g_strconcat("<b>", str, "</b>");
+ return g_strconcat("<b>", str, "</b>");
}
void format_src_string(gchar *src) {
- gchar *str = g_strrstr(src, "|");
- if (str == NULL) return;
- strncpy(str, "\0", 1);
+ gchar *str = g_strrstr(src, "|");
+ if (str == NULL) return;
+ strncpy(str, "\0", 1);
}
GtkTextIter *gtk_source_buffer_highlight_line(GtkSourceBuffer *buffer, int line_number) {
- GtkTextIter start;
- gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(buffer), &start);
- gtk_text_iter_set_line(&start, line_number);
- gtk_text_buffer_place_cursor(GTK_TEXT_BUFFER(buffer), &start);
- return gtk_text_iter_copy(&start);
+ GtkTextIter start;
+ gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(buffer), &start);
+ gtk_text_iter_set_line(&start, line_number);
+ gtk_text_buffer_place_cursor(GTK_TEXT_BUFFER(buffer), &start);
+ return gtk_text_iter_copy(&start);
}
//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(GTK_TEXT_BUFFER(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));
- }
+ 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(GTK_TEXT_BUFFER(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();
+ free_current_info();
}
void save_to_xml_file(gchar *filename) {
- GtkTextIter start, end;
- gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(source_buffer), &start);
- gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(source_buffer), &end);
- g_file_set_contents(filename, gtk_text_buffer_get_text(GTK_TEXT_BUFFER(source_buffer), &start, &end, TRUE), -1, NULL);
+ GtkTextIter start, end;
+ gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(source_buffer), &start);
+ gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(source_buffer), &end);
+ g_file_set_contents(filename, gtk_text_buffer_get_text(GTK_TEXT_BUFFER(source_buffer), &start, &end, TRUE), -1, NULL);
}
//SAEInfo functions (must be ported to sae.c)
void free_imagesets(SAEInfo *sae_info) {
- free_imageset(sae_info);
- sae_info->imagesets = NULL;
- gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(sae_info->imagesets_combo_box))));
+ free_imageset(sae_info);
+ sae_info->imagesets = NULL;
+ gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(sae_info->imagesets_combo_box))));
}
void free_imageset(SAEInfo *sae_info) {
- sae_info->imageset = imageset_new();
- sae_info->ground = sae_info_ground_new();
- gtk_widget_set_sensitive(imageset_preview_menu_item, FALSE);
- gtk_widget_set_sensitive(toolbar, FALSE);
+ sae_info->imageset = imageset_new();
+ sae_info->ground = sae_info_ground_new();
+ gtk_widget_set_sensitive(imageset_preview_menu_item, FALSE);
+ gtk_widget_set_sensitive(toolbar, FALSE);
}
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))));
+ 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(SAEInfo *sae_info) {
- sae_info->animations = NULL;
+ 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))));
+ 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);
+ 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);
+ free_imagesets(sae_info);
+ free_actions(sae_info);
+ free_animations(sae_info);
}
void free_current_info() {
- free_lists(gen_sae_info);
- player = NULL;
+ 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)));
+ 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_callback(GtkCheckMenuItem *checkmenuitem, gpointer user_data) {
- config->show_grid = gtk_check_menu_item_get_active(checkmenuitem);
- gtk_widget_queue_draw(darea);
+ config->show_grid = gtk_check_menu_item_get_active(checkmenuitem);
+ gtk_widget_queue_draw(darea);
}
-void show_wrong_source_buffer_dialog() {
- GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(win),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- NULL);
- gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), markup_bold(_("Wrong source buffer! Could not parse XML!")));
- g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
- gtk_widget_show_all(dialog);
+void parsing_error_warning(SAEInfo *sae_info, const gchar *message) {
+ free_lists(sae_info);
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(parsing_error_dialog), "%s", message);
+ gtk_dialog_run(GTK_DIALOG(parsing_error_dialog));
}
void actions_combo_box_changed_callback(GtkComboBoxText *widget, gpointer user_data) {
- if (player != NULL)
- set_up_action_by_name(gtk_combo_box_text_get_active_text(widget), player);
- set_up_action_by_name(gtk_combo_box_text_get_active_text(widget), gen_sae_info);
+ if (player != NULL)
+ set_up_action_by_name(gtk_combo_box_text_get_active_text(widget), player);
+ set_up_action_by_name(gtk_combo_box_text_get_active_text(widget), gen_sae_info);
}
void animations_combo_box_changed_callback(GtkComboBoxText *widget, gpointer user_data) {
- set_up_animation_by_direction(gen_sae_info, gtk_combo_box_text_get_active_text(widget));
- if (player != NULL) {
- set_up_animation_by_direction(player, gtk_combo_box_text_get_active_text(widget));
- show_animation(player);
- }
- show_animation(gen_sae_info);
+ set_up_animation_by_direction(gen_sae_info, gtk_combo_box_text_get_active_text(widget));
+ if (player != NULL) {
+ set_up_animation_by_direction(player, gtk_combo_box_text_get_active_text(widget));
+ show_animation(player);
+ }
+ show_animation(gen_sae_info);
}
void imagesets_combo_box_changed_callback(GtkComboBoxText *widget, gpointer user_data) {
- if (gtk_combo_box_text_get_active_text(widget) != NULL)
- set_up_imageset_by_name(gtk_combo_box_text_get_active_text(widget), gen_sae_info);
+ if (gtk_combo_box_text_get_active_text(widget) != NULL)
+ set_up_imageset_by_name(gtk_combo_box_text_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;
+ 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(GTK_DIALOG(fcdialog));
+ gtk_dialog_run(GTK_DIALOG(fcdialog));
}
//>Toolbar callbacks
void toolbar_to_first_clicked_callback(GtkToolButton *toolbutton, gpointer user_data) {
- toolbar_pause_clicked_callback(toolbutton, user_data);
- gen_sae_info->animation = g_list_first(gen_sae_info->animation);
- show_sprite(gen_sae_info);
+ toolbar_pause_clicked_callback(toolbutton, user_data);
+ gen_sae_info->animation = g_list_first(gen_sae_info->animation);
+ show_sprite(gen_sae_info);
}
void toolbar_prev_frame_clicked_callback(GtkToolButton *toolbutton, gpointer user_data) {
- toolbar_pause_clicked_callback(toolbutton, user_data);
- GList *prev = g_list_previous(gen_sae_info->animation);
- if (prev == NULL)
- return;
- gen_sae_info->animation = prev;
- show_sprite(gen_sae_info);
+ toolbar_pause_clicked_callback(toolbutton, user_data);
+ GList *prev = g_list_previous(gen_sae_info->animation);
+ if (prev == NULL)
+ return;
+ gen_sae_info->animation = prev;
+ show_sprite(gen_sae_info);
}
void toolbar_play_clicked_callback(GtkToolButton *toolbutton, gpointer user_data) {
- show_animation(gen_sae_info);
+ show_animation(gen_sae_info);
}
void toolbar_pause_clicked_callback(GtkToolButton *toolbutton, gpointer user_data) {
- int tag = gen_sae_info->anim_tag;
- if (tag > 0) {
- kill_timeout(tag);
- GList *prev = g_list_previous(gen_sae_info->animation);
- if (prev == NULL)
- prev = g_list_last(gen_sae_info->animation);
- gen_sae_info->animation = prev;
- }
- gen_sae_info->anim_tag = 0;
+ int tag = gen_sae_info->anim_tag;
+ if (tag > 0) {
+ kill_timeout(tag);
+ GList *prev = g_list_previous(gen_sae_info->animation);
+ if (prev == NULL)
+ prev = g_list_last(gen_sae_info->animation);
+ gen_sae_info->animation = prev;
+ }
+ gen_sae_info->anim_tag = 0;
}
void toolbar_next_frame_clicked_callback(GtkToolButton *toolbutton, gpointer user_data) {
- toolbar_pause_clicked_callback(toolbutton, user_data);
- GList *next = g_list_next(gen_sae_info->animation);
- if (next == NULL)
- return;
- gen_sae_info->animation = next;
- show_sprite(gen_sae_info);
+ toolbar_pause_clicked_callback(toolbutton, user_data);
+ GList *next = g_list_next(gen_sae_info->animation);
+ if (next == NULL)
+ return;
+ gen_sae_info->animation = next;
+ show_sprite(gen_sae_info);
}
void toolbar_to_last_clicked_callback(GtkToolButton *toolbutton, gpointer user_data) {
- toolbar_pause_clicked_callback(toolbutton, user_data);
- gen_sae_info->animation = g_list_last(gen_sae_info->animation);
- show_sprite(gen_sae_info);
+ toolbar_pause_clicked_callback(toolbutton, user_data);
+ gen_sae_info->animation = g_list_last(gen_sae_info->animation);
+ show_sprite(gen_sae_info);
}
//Dialogs
void show_about_dialog() {
- gtk_dialog_run(GTK_DIALOG(about_dialog));
- gtk_widget_hide(about_dialog);
+ gtk_dialog_run(GTK_DIALOG(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(GTK_WINDOW(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, 2);
- gtk_box_pack_start(GTK_BOX(content_area), hbox, TRUE, TRUE, 2);
- for (x = 0; x < w; x++) {
- int id = w * y + 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), (gpointer)id);
- 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);
+ 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(GTK_WINDOW(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, 2);
+ gtk_box_pack_start(GTK_BOX(content_area), hbox, TRUE, TRUE, 2);
+ for (x = 0; x < w; x++) {
+ int id = w * y + 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), (gpointer)id);
+ 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);
+ sae_info->sprite->pixbuf = get_sprite_by_index(index, sae_info);
+ gtk_widget_queue_draw(darea);
}
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 = 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);
- if (list == NULL)
- break;
- if (_actions_list == NULL) {
- _actions_list = g_list_alloc();
- sae_info->actions = _actions_list;
- _actions_list->data = list->data;
- } else
- _actions_list = g_list_append(_actions_list, list->data);
- node = list->data;
- if (sae_info->actions_combo_box != NULL)
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sae_info->actions_combo_box), xml_node_get_attr_value(node, "name"));
- list = list->next;
- }
- if (sae_info->actions_combo_box != NULL)
- gtk_combo_box_set_active(GTK_COMBO_BOX(sae_info->actions_combo_box), 0);
+ free_actions(sae_info);
+ free_animations(sae_info);
+ GList *_actions_list = NULL;
+ 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);
+ if (list == NULL)
+ break;
+ if (_actions_list == NULL) {
+ _actions_list = g_list_alloc();
+ sae_info->actions = _actions_list;
+ _actions_list->data = list->data;
+ } else
+ _actions_list = g_list_append(_actions_list, list->data);
+ node = list->data;
+ if (sae_info->actions_combo_box != NULL)
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sae_info->actions_combo_box), xml_node_get_attr_value(node, "name"));
+ list = g_list_next(list);
+ }
+ if (sae_info->actions_combo_box != NULL)
+ gtk_combo_box_set_active(GTK_COMBO_BOX(sae_info->actions_combo_box), 0);
}
gboolean set_up_imagesets(SAEInfo *sae_info) {
- GList *_imagesets_list = NULL;
- free_lists(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_func);
- if (list == NULL)
- break;
- if (_imagesets_list == NULL) {
- _imagesets_list = g_list_alloc();
- _imagesets_list->data = list->data;
- sae_info->imagesets = _imagesets_list;
- } else
- _imagesets_list = g_list_append(_imagesets_list, list->data);
- node = list->data;
- if (sae_info->imagesets_combo_box != NULL)
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sae_info->imagesets_combo_box), xml_node_get_attr_value(node, "name"));
- list = list->next;
- }
- if (_imagesets_list == NULL)
- return FALSE;
- if (sae_info->imagesets_combo_box != NULL)
- gtk_combo_box_set_active(GTK_COMBO_BOX(sae_info->imagesets_combo_box), 0);
- return TRUE;
+ GList *_imagesets_list = NULL;
+ free_lists(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_func);
+ if (list == NULL)
+ break;
+ if (_imagesets_list == NULL) {
+ _imagesets_list = g_list_alloc();
+ _imagesets_list->data = list->data;
+ sae_info->imagesets = _imagesets_list;
+ } else
+ _imagesets_list = g_list_append(_imagesets_list, list->data);
+ node = list->data;
+ if (sae_info->imagesets_combo_box != NULL)
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sae_info->imagesets_combo_box), xml_node_get_attr_value(node, "name"));
+ list = g_list_next(list);
+ }
+ if (_imagesets_list == NULL)
+ return FALSE;
+ if (sae_info->imagesets_combo_box != NULL)
+ gtk_combo_box_set_active(GTK_COMBO_BOX(sae_info->imagesets_combo_box), 0);
+ return TRUE;
}
void show_sprite(SAEInfo *sae_info) {
- Frame *sprite = sae_info->animation->data;
- gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(source_view),
- gtk_source_buffer_highlight_line(source_buffer, sprite->line_number-1),
- 0.25,
- FALSE,
- 0.0,
- 0.0);
- sae_info->sprite = sprite;
- gtk_widget_queue_draw(darea);
+ Frame *sprite = sae_info->animation->data;
+ gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(source_view),
+ gtk_source_buffer_highlight_line(source_buffer, sprite->line_number-1),
+ 0.25,
+ FALSE,
+ 0.0,
+ 0.0);
+ sae_info->sprite = sprite;
+ gtk_widget_queue_draw(darea);
}
void show_animation(SAEInfo *sae_info) {
- kill_timeout(sae_info->anim_tag);
- if (sae_info->animation == NULL)
- return;
+ kill_timeout(sae_info->anim_tag);
+ if (sae_info->animation == NULL)
+ return;
- show_sprite(sae_info);
- Frame *sprite = sae_info->animation->data;
+ show_sprite(sae_info);
+ Frame *sprite = sae_info->animation->data;
- GList *next = g_list_next(sae_info->animation);
- if (next == NULL)
- next = g_list_first(sae_info->animation);
+ GList *next = g_list_next(sae_info->animation);
+ if (next == NULL)
+ next = g_list_first(sae_info->animation);
- sae_info->animation = next;
- sae_info->anim_tag = g_timeout_add(sprite->delay, (GSourceFunc)show_animation, sae_info);
+ sae_info->animation = next;
+ sae_info->anim_tag = g_timeout_add(sprite->delay, (GSourceFunc)show_animation, sae_info);
}
gboolean show_general_animation(SAEInfo *sae_info) {
- XMLNode *node = sae_info->animations->data;
- if (node == NULL)
- return FALSE;
- animations_combo_box_changed_callback(NULL, NULL);
+ XMLNode *node = sae_info->animations->data;
+ if (node == NULL)
+ return FALSE;
+ animations_combo_box_changed_callback(NULL, NULL);
}
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,
- xml_attr_new("name", name),
- (GCompareFunc)xml_node_compare_with_attr_func);
- if (list == NULL) return FALSE;
- list = ((XMLNode *)list->data)->sub_nodes;
- gboolean was_direction = FALSE;
- while (TRUE) {
- list = g_list_find_custom(list, "animation", xml_node_compare_with_name_func);
- if (list == NULL)
- break;
- if (sae_info->animations == NULL) {
- sae_info->animations = g_list_alloc();
- sae_info->animations->data = list->data;
- } else
- sae_info->animations = 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 (sae_info->animations_combo_box != NULL)
- gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sae_info->animations_combo_box), direction);
- was_direction = TRUE;
- }
- list = list->next;
- }
- if (sae_info->animations == NULL)
- return FALSE;
- if (!was_direction)
- show_general_animation(sae_info);
- else if (sae_info->animations_combo_box != NULL)
- gtk_combo_box_set_active(GTK_COMBO_BOX(sae_info->animations_combo_box), 0);
- return TRUE;
+ free_animations(sae_info);
+ GList *list = g_list_find_custom(sae_info->actions,
+ xml_attr_new("name", name),
+ (GCompareFunc)xml_node_compare_with_attr_func);
+ if (list == NULL) return FALSE;
+ list = ((XMLNode *)list->data)->sub_nodes;
+ gboolean was_direction = FALSE;
+ while (TRUE) {
+ list = g_list_find_custom(list, "animation", xml_node_compare_with_name_func);
+ if (list == NULL)
+ break;
+ if (sae_info->animations == NULL) {
+ sae_info->animations = g_list_alloc();
+ sae_info->animations->data = list->data;
+ } else
+ sae_info->animations = 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 (sae_info->animations_combo_box != NULL)
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sae_info->animations_combo_box), direction);
+ was_direction = TRUE;
+ }
+ list = g_list_next(list);
+ }
+ if (sae_info->animations == NULL)
+ return FALSE;
+ if (!was_direction)
+ show_general_animation(sae_info);
+ else if (sae_info->animations_combo_box != NULL)
+ gtk_combo_box_set_active(GTK_COMBO_BOX(sae_info->animations_combo_box), 0);
+ return TRUE;
}
void set_up_imageset_by_name(const gchar *name, SAEInfo *sae_info) {
- free_imageset(sae_info);
- free_actions(sae_info);
- free_animations(sae_info);
-
- GList *list = g_list_find_custom(sae_info->imagesets,
- xml_attr_new("name", name),
- (GCompareFunc)xml_node_compare_with_attr_func);
-
- if (list == NULL)
- return;
-
- XMLNode *node = list->data;
- if (node == NULL)
- return;
-
- sae_info->imageset->node = node;
- sae_info->imageset->offsetX = 0;
- sae_info->imageset->offsetY = 0;
-
- gchar *offset_attr = xml_node_get_attr_value(sae_info->imageset->node, "offsetX");
- if (offset_attr != NULL)
- sscanf(offset_attr, "%d", &sae_info->imageset->offsetX);
-
- offset_attr = xml_node_get_attr_value(sae_info->imageset->node, "offsetY");
- if (offset_attr != NULL)
- sscanf(offset_attr, "%d", &sae_info->imageset->offsetY);
-
- gchar *imageset_name = xml_node_get_attr_value(sae_info->imageset->node, "name");
-
- gchar *src = xml_node_get_attr_value(sae_info->imageset->node, "src");
- format_src_string(src);
- gchar *datapath = config->clientdata_folder;
- gchar *path = g_strjoin(SEPARATOR_SLASH, datapath, src, 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);
- gtk_widget_set_sensitive(toolbar, TRUE);
- sae_info->imageset->spriteset_width = gdk_pixbuf_get_width(sae_info->imageset->spriteset);
- sae_info->imageset->spriteset_height = gdk_pixbuf_get_height(sae_info->imageset->spriteset);
-
- 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);
-
- list = g_list_find_custom(sae_info->root->sub_nodes, "sae", xml_node_compare_with_name_func);
- 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)
- sae_info->ground = pbuf;
- }
- gchar *player_attr = xml_node_get_attr_value((XMLNode *)list->data, "player");
- if (player_attr != NULL && player == NULL) {
- gchar *text;
- gchar *sprites_path = paths->sprites;
- gchar *player_file = g_strjoin(NULL, sprites_path, DIR_PLAYERS, player_attr, ".xml", NULL);
- if (g_file_get_contents(player_file, &text, NULL, NULL)) {
- player = sae_info_new();
- parse_xml_text(text, player);
- set_up_imageset_by_name("base", player);
- }
- }
- }
- set_up_actions_by_imageset_name(imageset_name, sae_info);
- if (sae_info->actions == NULL)
- return;
- set_sprite_by_index(0, sae_info);
+ free_imageset(sae_info);
+ free_actions(sae_info);
+ free_animations(sae_info);
+
+ GList *list = g_list_find_custom(sae_info->imagesets,
+ xml_attr_new("name", name),
+ (GCompareFunc)xml_node_compare_with_attr_func);
+
+ if (list == NULL)
+ return;
+
+ XMLNode *node = list->data;
+ if (node == NULL)
+ return;
+
+ sae_info->imageset->node = node;
+ sae_info->imageset->offsetX = 0;
+ sae_info->imageset->offsetY = 0;
+
+ gchar *offset_attr = xml_node_get_attr_value(sae_info->imageset->node, "offsetX");
+ if (offset_attr != NULL)
+ sscanf(offset_attr, "%d", &sae_info->imageset->offsetX);
+
+ offset_attr = xml_node_get_attr_value(sae_info->imageset->node, "offsetY");
+ if (offset_attr != NULL)
+ sscanf(offset_attr, "%d", &sae_info->imageset->offsetY);
+
+ gchar *imageset_name = xml_node_get_attr_value(sae_info->imageset->node, "name");
+
+ gchar *src = xml_node_get_attr_value(sae_info->imageset->node, "src");
+ format_src_string(src);
+ gchar *datapath = config->clientdata_folder;
+ gchar *path = g_strjoin(SEPARATOR_SLASH, datapath, src, NULL);
+
+ sae_info->imageset->spriteset = gdk_pixbuf_new_from_file(path, NULL);
+ if (sae_info->imageset->spriteset == NULL) {
+ parsing_error_warning(sae_info, "Wrong spriteset path!");
+ return;
+ }
+
+ gtk_widget_set_sensitive(imageset_preview_menu_item, TRUE);
+ gtk_widget_set_sensitive(toolbar, TRUE);
+ sae_info->imageset->spriteset_width = gdk_pixbuf_get_width(sae_info->imageset->spriteset);
+ sae_info->imageset->spriteset_height = gdk_pixbuf_get_height(sae_info->imageset->spriteset);
+
+ 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);
+
+ list = g_list_find_custom(sae_info->root->sub_nodes, "sae", xml_node_compare_with_name_func);
+ 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)
+ sae_info->ground = pbuf;
+ }
+ gchar *player_attr = xml_node_get_attr_value((XMLNode *)list->data, "player");
+ if (player_attr != NULL && player == NULL) {
+ gchar *text;
+ gchar *sprites_path = paths->sprites;
+ gchar *player_file = g_strjoin(NULL, sprites_path, DIR_PLAYERS, player_attr, ".xml", NULL);
+ if (g_file_get_contents(player_file, &text, NULL, NULL)) {
+ player = sae_info_new();
+ parse_xml_text(text, player);
+ set_up_imageset_by_name("base", player);
+ }
+ }
+ }
+ set_up_actions_by_imageset_name(imageset_name, sae_info);
+ if (sae_info->actions == NULL)
+ return;
+ set_sprite_by_index(0, sae_info);
}
void load_options() {
- gchar *datapath = config->clientdata_folder;
- gchar *path = g_strjoin(SEPARATOR_SLASH, datapath, "paths.xml", NULL);
- config_options_load_from_file(paths, path, datapath);
+ gchar *datapath = config->clientdata_folder;
+ gchar *path = g_strjoin(SEPARATOR_SLASH, datapath, "paths.xml", NULL);
+ config_options_load_from_file(paths, path, datapath);
}
void parse_xml_text(gchar *text, SAEInfo *sae_info) {
- free_lists(sae_info);
-
- XMLNode *_root_node = xml_parse_buffer(text);
- sae_info->root = _root_node;
- if (_root_node == NULL) {
- show_wrong_source_buffer_dialog();
- return;
- }
-
- GList *list = g_list_find_custom(_root_node->sub_nodes, "include", xml_node_compare_with_name_func);
- while (list != NULL) {
- XMLNode *node = list->data;
- gchar *file_attr = xml_node_get_attr_value(node, "file");
- if (file_attr != NULL) {
- file_attr = g_strjoin(NULL, paths->sprites, file_attr, NULL);
- gchar *buf;
- if (g_file_get_contents(file_attr, &buf, NULL, NULL))
- _root_node->sub_nodes = g_list_concat(_root_node->sub_nodes, xml_parse_buffer(buf)->sub_nodes);
- }
- if (list->next != NULL)
- list = g_list_find_custom(list->next, "include", xml_node_compare_with_name_func);
- else
- list = NULL;
- }
-
- sae_info->offsetX = 0;
- sae_info->offsetY = 0;
-
- if (!set_up_imagesets(sae_info)) {
- show_wrong_source_buffer_dialog();
- return;
- }
+ GError *error = NULL;
+
+ free_lists(sae_info);
+
+ XMLNode *_root_node = xml_parse_buffer(text, &error);
+ sae_info->root = _root_node;
+ if (_root_node == NULL) {
+ parsing_error_warning(sae_info, error->message);
+ g_error_free(error);
+ return;
+ }
+
+ GList *list = g_list_find_custom(_root_node->sub_nodes, "include", xml_node_compare_with_name_func);
+ while (list != NULL) {
+ XMLNode *node = list->data;
+ gchar *file_attr = xml_node_get_attr_value(node, "file");
+ if (file_attr != NULL) {
+ file_attr = g_strjoin(NULL, paths->sprites, file_attr, NULL);
+ gchar *buf;
+ if (g_file_get_contents(file_attr, &buf, NULL, NULL))
+ _root_node->sub_nodes = g_list_concat(_root_node->sub_nodes, xml_parse_buffer(buf, &error)->sub_nodes);
+ }
+ GList *next = g_list_next(list);
+ if (next != NULL)
+ list = g_list_find_custom(next, "include", xml_node_compare_with_name_func);
+ else
+ list = NULL;
+ }
+
+ sae_info->offsetX = 0;
+ sae_info->offsetY = 0;
+
+ if (error != NULL)
+ g_error_free(error);
+
+ if (!set_up_imagesets(sae_info)) {
+ parsing_error_warning(sae_info, "Bad data!");
+ return;
+ }
}
void parse_xml_buffer(GtkWidget *button, GtkSourceBuffer *buffer) {
- if (buffer == NULL)
- buffer = source_buffer;
+ if (buffer == NULL)
+ buffer = source_buffer;
- player = NULL;
- load_options();
+ player = NULL;
+ 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_sae_info);
+ 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_sae_info);
}
void load_config() {
- config_keys_load(config);
- gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(data_folder_chooser_button), config->clientdata_folder);
- gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_grid_menu_item), config->show_grid);
+ config_keys_load(config);
+ gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(data_folder_chooser_button), config->clientdata_folder);
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(show_grid_menu_item), config->show_grid);
}
void save_config_and_quit() {
- config_keys_save(config);
- gtk_main_quit();
+ config_keys_save(config);
+ gtk_main_quit();
}
int main(int argc, char *argv[]) {
- gtk_init(&argc, &argv);
+ gtk_init(&argc, &argv);
- icon = gdk_pixbuf_new_from_file(FILE_ICON, NULL);
+ icon = gdk_pixbuf_new_from_file(FILE_ICON, NULL);
- gen_sae_info = sae_info_new();
- config = config_keys_new();
- paths = config_options_new();
+ gen_sae_info = sae_info_new();
+ config = config_keys_new();
+ paths = config_options_new();
- set_up_interface();
- load_config();
+ set_up_interface();
+ load_config();
- gtk_main();
+ gtk_main();
- return 0;
+ return 0;
}
diff --git a/saedit/main.h b/saedit/main.h
index 68566d9..d005e2c 100644
--- a/saedit/main.h
+++ b/saedit/main.h
@@ -46,6 +46,7 @@ GtkWidget *imageset_preview_menu_item = NULL;
GtkWidget *show_grid_menu_item = NULL;
GtkWidget *source_view = NULL;
GtkWidget *about_dialog = NULL;
+GtkWidget *parsing_error_dialog = NULL;
GtkSourceBuffer *source_buffer = NULL;
@@ -81,7 +82,7 @@ void free_current_info();
//Callbacks
void data_folder_set_callback(GtkFileChooserButton *widget, gpointer data);
-void show_wrong_source_buffer_dialog();
+void parsing_error_warning(SAEInfo *sae_info, const gchar *message);
void show_grid_menu_item_toggled_callback(GtkCheckMenuItem *checkmenuitem, gpointer user_data);
void actions_combo_box_changed_callback(GtkComboBoxText *widget, gpointer user_data);
void imagesets_combo_box_changed_callback(GtkComboBoxText *widget, gpointer user_data);
diff --git a/saedit/sae.c b/saedit/sae.c
index e2627a7..2b9abb6 100644
--- a/saedit/sae.c
+++ b/saedit/sae.c
@@ -12,122 +12,122 @@
#include "sae.h"
void kill_timeout(guint tag) {
- if (tag > 0)
- g_source_remove(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;
- res->offsetX = offsetX;
- res->offsetY = offsetY;
- res->delay = delay;
- return res;
+ Frame *res = g_new0(Frame, 1);
+ res->index = index;
+ res->offsetX = offsetX;
+ res->offsetY = offsetY;
+ res->delay = delay;
+ return res;
}
Imageset *imageset_new() {
- Imageset *res = g_new0(Imageset, 1);
- res->width = SPRITE_WIDTH_DEFAULT;
- res->height = SPRITE_HEIGHT_DEFAULT;
- return res;
+ Imageset *res = g_new0(Imageset, 1);
+ res->width = SPRITE_WIDTH_DEFAULT;
+ res->height = SPRITE_HEIGHT_DEFAULT;
+ return res;
}
SAEInfo *sae_info_new() {
- SAEInfo *res = g_new0(SAEInfo, 1);
- res->ground = sae_info_ground_new();
- res->sprite = frame_new(-1, 0, 0, 0);
- res->imageset = imageset_new();
- return res;
+ SAEInfo *res = g_new0(SAEInfo, 1);
+ res->ground = sae_info_ground_new();
+ res->sprite = frame_new(-1, 0, 0, 0);
+ res->imageset = imageset_new();
+ return res;
}
GdkPixbuf *sae_info_ground_new() {
- GdkPixbuf *ground = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, GRID_SIZE * 3, GRID_SIZE * 3);
- gdk_pixbuf_fill(ground, 0x00000000);
- return ground;
+ GdkPixbuf *ground = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, GRID_SIZE * 3, GRID_SIZE * 3);
+ 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);
+ 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),
- (GCompareFunc)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->line_number = node->line_number;
- sprite->pixbuf = get_sprite_by_index(i, sae_info);
- count++;
- if (sae_info->animation != NULL)
- sae_info->animation = g_list_append(sae_info->animation, sprite);
- else {
- sae_info->animation = g_list_alloc();
- sae_info->animation->data = sprite;
- }
- }
- }
- }
- list = g_list_next(list);
- }
- if (sae_info->animation == NULL)
- return FALSE;
-
- return TRUE;
+ 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),
+ (GCompareFunc)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->line_number = node->line_number;
+ sprite->pixbuf = get_sprite_by_index(i, sae_info);
+ count++;
+ if (sae_info->animation != NULL)
+ sae_info->animation = g_list_append(sae_info->animation, sprite);
+ else {
+ sae_info->animation = g_list_alloc();
+ sae_info->animation->data = sprite;
+ }
+ }
+ }
+ }
+ list = g_list_next(list);
+ }
+ if (sae_info->animation == NULL)
+ return FALSE;
+
+ return TRUE;
}
diff --git a/saedit/sae.h b/saedit/sae.h
index 322eca5..9cbaf09 100644
--- a/saedit/sae.h
+++ b/saedit/sae.h
@@ -19,45 +19,45 @@
void kill_timeout(guint tag);
typedef struct {
- int index;
- int offsetX;
- int offsetY;
- int delay;
- int line_number;
- GdkPixbuf *pixbuf;
- cairo_surface_t *surface;
+ int index;
+ int offsetX;
+ int offsetY;
+ int delay;
+ int line_number;
+ GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
} Frame;
Frame *frame_new(int index, int offsetX, int offsetY, int delay);
typedef struct {
- XMLNode *node;
- int offsetX;
- int offsetY;
- int width;
- int height;
- int spriteset_width;
- int spriteset_height;
- GdkPixbuf *spriteset;
+ XMLNode *node;
+ int offsetX;
+ int offsetY;
+ int width;
+ int height;
+ int spriteset_width;
+ int spriteset_height;
+ GdkPixbuf *spriteset;
} Imageset;
Imageset *imageset_new();
typedef struct {
- GList *imagesets;
- GList *actions;
- GList *animations;
- GList *animation;
- Imageset *imageset;
- Frame *sprite;
- guint anim_tag;
- XMLNode *root;
- GtkWidget *imagesets_combo_box;
- GtkWidget *actions_combo_box;
- GtkWidget *animations_combo_box;
- GdkPixbuf *ground;
- int offsetX;
- int offsetY;
+ GList *imagesets;
+ GList *actions;
+ GList *animations;
+ GList *animation;
+ Imageset *imageset;
+ Frame *sprite;
+ guint anim_tag;
+ XMLNode *root;
+ GtkWidget *imagesets_combo_box;
+ GtkWidget *actions_combo_box;
+ GtkWidget *animations_combo_box;
+ GdkPixbuf *ground;
+ int offsetX;
+ int offsetY;
} SAEInfo;
SAEInfo *sae_info_new();
diff --git a/saedit/search.c b/saedit/search.c
index d156523..447f68c 100644
--- a/saedit/search.c
+++ b/saedit/search.c
@@ -15,57 +15,57 @@ GtkWidget *search_text_view = NULL;
gchar *search_last_text = NULL;
gboolean search_find_text(gchar *text) {
- search_last_text = text;
-
- GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(search_text_view));
- if (!GTK_IS_TEXT_BUFFER(text_buffer))
- return FALSE;
-
- gboolean found;
-
- GtkTextIter m_start, m_end, start;
- gtk_text_buffer_get_selection_bounds(text_buffer, NULL, &start);
- found = gtk_text_iter_forward_search(&start, text, 4, &m_start, &m_end, NULL);
-
- if (!found) {
- gtk_text_buffer_get_start_iter(text_buffer, &start);
- found = gtk_text_iter_forward_search(&start, text, 4, &m_start, &m_end, NULL);
- }
-
- if (found) {
- gtk_text_buffer_place_cursor(text_buffer, &m_start);
- gtk_text_buffer_move_mark_by_name(text_buffer, "selection_bound", &m_end);
- gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW(search_text_view),
- gtk_text_buffer_get_insert(text_buffer),
- 0.25,
- FALSE,
- 0.0,
- 0.0);
- return TRUE;
- } else
- return FALSE;
+ search_last_text = text;
+
+ GtkTextBuffer *text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(search_text_view));
+ if (!GTK_IS_TEXT_BUFFER(text_buffer))
+ return FALSE;
+
+ gboolean found;
+
+ GtkTextIter m_start, m_end, start;
+ gtk_text_buffer_get_selection_bounds(text_buffer, NULL, &start);
+ found = gtk_text_iter_forward_search(&start, text, 4, &m_start, &m_end, NULL);
+
+ if (!found) {
+ gtk_text_buffer_get_start_iter(text_buffer, &start);
+ found = gtk_text_iter_forward_search(&start, text, 4, &m_start, &m_end, NULL);
+ }
+
+ if (found) {
+ gtk_text_buffer_place_cursor(text_buffer, &m_start);
+ gtk_text_buffer_move_mark_by_name(text_buffer, "selection_bound", &m_end);
+ gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW(search_text_view),
+ gtk_text_buffer_get_insert(text_buffer),
+ 0.25,
+ FALSE,
+ 0.0,
+ 0.0);
+ return TRUE;
+ } else
+ return FALSE;
}
gboolean search_find_next() {
- if (search_last_text != NULL)
- search_find_text(search_last_text);
+ if (search_last_text != NULL)
+ search_find_text(search_last_text);
}
void search_find_dialog_response_callback(GtkWidget *dialog,
- gint response_id,
- gpointer entry) {
+ gint response_id,
+ gpointer entry) {
- if (response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT)
- gtk_widget_hide(dialog);
- else {
+ if (response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT)
+ gtk_widget_hide(dialog);
+ else {
- 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)));
+ 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))));
+ search_find_text(g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))));
- }
+ }
}
void search_init(GtkWidget *text_view) {
@@ -74,31 +74,31 @@ void search_init(GtkWidget *text_view) {
void search_find_dialog_show(GtkWindow *parent,
GtkWidget *text_view) {
- GtkWidget *dialog;
- GtkWidget *vbox;
- GtkWidget *entry;
- GtkWidget *content_area;
- GtkWidget *label;
-
- dialog = gtk_dialog_new_with_buttons(_("Find"),
- parent,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_FIND,
- GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_widget_set_size_request(dialog, 240, 80);
- gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
- content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
-
- entry = gtk_entry_new();
- gtk_container_add(GTK_CONTAINER(content_area), entry);
-
- g_signal_connect(dialog,
- "response",
- G_CALLBACK(search_find_dialog_response_callback),
- entry);
-
- search_text_view = text_view;
-
- gtk_dialog_run(GTK_DIALOG(dialog));
+ GtkWidget *dialog;
+ GtkWidget *vbox;
+ GtkWidget *entry;
+ GtkWidget *content_area;
+ GtkWidget *label;
+
+ dialog = gtk_dialog_new_with_buttons(_("Find"),
+ parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_FIND,
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_widget_set_size_request(dialog, 240, 80);
+ gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
+ content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+
+ entry = gtk_entry_new();
+ gtk_container_add(GTK_CONTAINER(content_area), entry);
+
+ g_signal_connect(dialog,
+ "response",
+ G_CALLBACK(search_find_dialog_response_callback),
+ entry);
+
+ search_text_view = text_view;
+
+ gtk_dialog_run(GTK_DIALOG(dialog));
}
diff --git a/saedit/search.h b/saedit/search.h
index 4d41735..faf412e 100644
--- a/saedit/search.h
+++ b/saedit/search.h
@@ -20,7 +20,7 @@ void search_init(GtkWidget *text_view);
gboolean search_find_text(gchar *text);
gboolean search_find_next();
void search_find_dialog_response_callback(GtkWidget *dialog,
- gint response_id,
- gpointer entry);
+ gint response_id,
+ gpointer entry);
#endif
diff --git a/saedit/xml.c b/saedit/xml.c
index 602dfaf..4db8235 100644
--- a/saedit/xml.c
+++ b/saedit/xml.c
@@ -12,399 +12,372 @@
#include "xml.h"
gchar** xml_attr_new(const gchar *name, const gchar *value) {
- gchar **attr = g_new0(gchar*, 2);
- attr[0] = g_strdup(name);
- attr[1] = g_strdup(value);
- return attr;
+ gchar **attr = g_new0(gchar*, 2);
+ attr[0] = g_strdup(name);
+ attr[1] = g_strdup(value);
+ return attr;
}
gchar* xml_node_get_attr_value(const XMLNode *node, const gchar *attr_name) {
- gchar **attr = node->attributes;
- int i;
- for (i = 0; i < g_strv_length(attr); i += 2)
- if (g_str_equal(attr[i], attr_name))
- return attr[i + 1];
- return NULL;
+ gchar **attr = node->attributes;
+ int i;
+ for (i = 0; i < g_strv_length(attr); i += 2)
+ if (g_str_equal(attr[i], attr_name))
+ return attr[i + 1];
+ return NULL;
}
gint xml_node_compare_with_name_func(gconstpointer a, gconstpointer b) {
- return g_strcmp0((gchar *)b, ((XMLNode *)a)->name);
+ return g_strcmp0((gchar *)b, ((XMLNode *)a)->name);
}
gint xml_node_compare_with_action_node_by_imageset_name_func(gconstpointer a, gconstpointer b) {
- return g_strcmp0("action", ((XMLNode *)a)->name) ||
- g_strcmp0((gchar *)b, xml_node_get_attr_value((XMLNode *)a, "imageset"));
+ return g_strcmp0("action", ((XMLNode *)a)->name) ||
+ g_strcmp0((gchar *)b, xml_node_get_attr_value((XMLNode *)a, "imageset"));
}
gint xml_node_compare_with_attr_func(const XMLNode *node, const gchar **attr) {
- return g_strcmp0(attr[1],
- xml_node_get_attr_value(node, attr[0]));
+ return g_strcmp0(attr[1],
+ xml_node_get_attr_value(node, attr[0]));
}
-typedef enum
-{
- STATE_START,
- STATE_AFTER_OPEN_ANGLE,
- STATE_AFTER_CLOSE_ANGLE,
- STATE_AFTER_ELISION_SLASH, /* the slash that obviates need for end element */
- STATE_INSIDE_OPEN_TAG_NAME,
- STATE_INSIDE_ATTRIBUTE_NAME,
- STATE_AFTER_ATTRIBUTE_NAME,
- STATE_BETWEEN_ATTRIBUTES,
- STATE_AFTER_ATTRIBUTE_EQUALS_SIGN,
- STATE_INSIDE_ATTRIBUTE_VALUE_SQ,
- STATE_INSIDE_ATTRIBUTE_VALUE_DQ,
- STATE_INSIDE_TEXT,
- STATE_AFTER_CLOSE_TAG_SLASH,
- STATE_INSIDE_CLOSE_TAG_NAME,
- STATE_AFTER_CLOSE_TAG_NAME,
- STATE_INSIDE_PASSTHROUGH,
- STATE_ERROR
+typedef enum {
+ STATE_START,
+ STATE_AFTER_OPEN_ANGLE,
+ STATE_AFTER_CLOSE_ANGLE,
+ STATE_AFTER_ELISION_SLASH, /* the slash that obviates need for end element */
+ STATE_INSIDE_OPEN_TAG_NAME,
+ STATE_INSIDE_ATTRIBUTE_NAME,
+ STATE_AFTER_ATTRIBUTE_NAME,
+ STATE_BETWEEN_ATTRIBUTES,
+ STATE_AFTER_ATTRIBUTE_EQUALS_SIGN,
+ STATE_INSIDE_ATTRIBUTE_VALUE_SQ,
+ STATE_INSIDE_ATTRIBUTE_VALUE_DQ,
+ STATE_INSIDE_TEXT,
+ STATE_AFTER_CLOSE_TAG_SLASH,
+ STATE_INSIDE_CLOSE_TAG_NAME,
+ STATE_AFTER_CLOSE_TAG_NAME,
+ STATE_INSIDE_PASSTHROUGH,
+ STATE_ERROR
} GMarkupParseState;
-typedef struct
-{
- const GMarkupParser *parser;
+typedef struct {
+ const GMarkupParser *parser;
- GMarkupParseFlags flags;
+ GMarkupParseFlags flags;
- gint line_number;
- gint char_number;
+ gint line_number;
+ gint char_number;
- GMarkupParseState state;
+ GMarkupParseState state;
- gpointer user_data;
- GDestroyNotify dnotify;
+ gpointer user_data;
+ GDestroyNotify dnotify;
- /* A piece of character data or an element that
- * hasn't "ended" yet so we haven't yet called
- * the callback for it.
- */
- GString *partial_chunk;
- GSList *spare_chunks;
+ /* A piece of character data or an element that
+ * hasn't "ended" yet so we haven't yet called
+ * the callback for it.
+ */
+ GString *partial_chunk;
+ GSList *spare_chunks;
- GSList *tag_stack;
- GSList *tag_stack_gstr;
- GSList *spare_list_nodes;
+ GSList *tag_stack;
+ GSList *tag_stack_gstr;
+ GSList *spare_list_nodes;
- GString **attr_names;
- GString **attr_values;
- gint cur_attr;
- gint alloc_attrs;
+ GString **attr_names;
+ GString **attr_values;
+ gint cur_attr;
+ gint alloc_attrs;
- const gchar *current_text;
- gssize current_text_len;
- const gchar *current_text_end;
+ const gchar *current_text;
+ gssize current_text_len;
+ const gchar *current_text_end;
- /* used to save the start of the last interesting thingy */
- const gchar *start;
+ /* used to save the start of the last interesting thingy */
+ const gchar *start;
- const gchar *iter;
+ const gchar *iter;
- guint document_empty : 1;
- guint parsing : 1;
- guint awaiting_pop : 1;
- gint balance;
+ guint document_empty : 1;
+ guint parsing : 1;
+ guint awaiting_pop : 1;
+ gint balance;
- /* subparser support */
- GSList *subparser_stack; /* (GMarkupRecursionTracker *) */
- const char *subparser_element;
- gpointer held_user_data;
+ /* subparser support */
+ GSList *subparser_stack; /* (GMarkupRecursionTracker *) */
+ const char *subparser_element;
+ gpointer held_user_data;
} _GMarkupParseContext;
+
static GMarkupParser parser;
-void
-xml_free (XMLNode *node)
-{
- g_free (node->name);
+void xml_free (XMLNode *node) {
+ g_free (node->name);
- g_free (node->text);
+ g_free (node->text);
- g_strfreev (node->attributes);
+ g_strfreev (node->attributes);
- g_list_foreach (node->sub_nodes, (GFunc) xml_free, NULL);
- g_list_free (node->sub_nodes);
+ g_list_foreach (node->sub_nodes, (GFunc) xml_free, NULL);
+ g_list_free (node->sub_nodes);
- g_slice_free (XMLNode, node);
+ g_slice_free (XMLNode, node);
}
-static void
-_start_root_element_cb (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- GError **error)
-{
- XMLNode **node = (XMLNode **) user_data;
- g_assert (node != NULL);
+static void _start_root_element_cb ( GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error) {
+ XMLNode **node = (XMLNode **) user_data;
+ g_assert (node != NULL);
- XMLNode *p = g_slice_new0 (XMLNode);
+ XMLNode *p = g_slice_new0 (XMLNode);
- p->name = g_strdup (element_name);
+ p->name = g_strdup (element_name);
- GArray *attributes = g_array_new (TRUE, TRUE, sizeof (gchar *));
- while (*attribute_names != NULL && *attribute_values != NULL) {
- gchar *p;
- p = g_strdup (*attribute_names++);
- g_array_append_val (attributes, p);
- p = g_strdup (*attribute_values++);
- g_array_append_val (attributes, p);
- }
+ GArray *attributes = g_array_new (TRUE, TRUE, sizeof (gchar *));
+ while (*attribute_names != NULL && *attribute_values != NULL) {
+ gchar *p;
+ p = g_strdup (*attribute_names++);
+ g_array_append_val (attributes, p);
+ p = g_strdup (*attribute_values++);
+ g_array_append_val (attributes, p);
+ }
- p->attributes = (gchar **) g_array_free (attributes, FALSE);
+ p->attributes = (gchar **) g_array_free (attributes, FALSE);
- g_markup_parse_context_push (context, &parser, p);
- *node = p;
+ g_markup_parse_context_push (context, &parser, p);
+ *node = p;
}
-static void
-_start_element_cb (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- GError **error)
-{
+static void _start_element_cb ( GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error) {
- XMLNode *node = (XMLNode *) user_data;
+ XMLNode *node = (XMLNode *) user_data;
- if (node->text) {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, " ");
- return;
- }
+ if (node->text) {
+ g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, " ");
+ return;
+ }
- XMLNode *p = g_slice_new0 (XMLNode);
+ XMLNode *p = g_slice_new0 (XMLNode);
- node->sub_nodes = g_list_append (node->sub_nodes, p);
- g_markup_parse_context_push (context, &parser, p);
+ node->sub_nodes = g_list_append (node->sub_nodes, p);
+ g_markup_parse_context_push (context, &parser, p);
- p->name = g_strdup (element_name);
+ p->name = g_strdup (element_name);
- GArray *attributes = g_array_new (TRUE, TRUE, sizeof (gchar *));
- while (*attribute_names != NULL && *attribute_values != NULL) {
- gchar *p;
- p = g_strdup (*attribute_names++);
- g_array_append_val (attributes, p);
- p = g_strdup (*attribute_values++);
- g_array_append_val (attributes, p);
- }
+ GArray *attributes = g_array_new (TRUE, TRUE, sizeof (gchar *));
+ while (*attribute_names != NULL && *attribute_values != NULL) {
+ gchar *p;
+ p = g_strdup (*attribute_names++);
+ g_array_append_val (attributes, p);
+ p = g_strdup (*attribute_values++);
+ g_array_append_val (attributes, p);
+ }
- p->attributes = (gchar **)g_array_free (attributes, FALSE);
+ p->attributes = (gchar **)g_array_free (attributes, FALSE);
- p->line_number = ((_GMarkupParseContext*)context)->line_number - (((_GMarkupParseContext*)context)->char_number <= 1);
+ p->line_number = ((_GMarkupParseContext*)context)->line_number - (((_GMarkupParseContext*)context)->char_number <= 1);
}
-static void
-_end_element_cb (GMarkupParseContext *context,
- const gchar *element_name,
- gpointer user_data,
- GError **error)
-{
- XMLNode *p = (XMLNode *) g_markup_parse_context_pop (context);
-
- if (p->text && p->sub_nodes) {
- g_warning ("Error");
- }
-
- if (p->text == NULL && p->sub_nodes == NULL) {
- p->text = g_strdup ("");
- }
+static void _end_element_cb ( GMarkupParseContext *context,
+ const gchar *element_name,
+ gpointer user_data,
+ GError **error) {
+ XMLNode *p = (XMLNode *) g_markup_parse_context_pop (context);
+
+ if (p->text && p->sub_nodes) {
+ g_warning ("Error");
+ }
+
+ if (p->text == NULL && p->sub_nodes == NULL) {
+ p->text = g_strdup ("");
+ }
}
-static gboolean
-_is_space (const gchar *text,
- gsize text_len)
-{
- gsize i = 0;
-
- for (i = 0; text[i] != '\0' && i < text_len; i++) {
- switch (text[i]) {
- case '\t':
- case ' ':
- case '\n':
- case '\r':
- continue;
- default:
- return FALSE;
- }
- }
-
- return TRUE;
+static gboolean _is_space ( const gchar *text,
+ gsize text_len) {
+ gsize i = 0;
+
+ for (i = 0; text[i] != '\0' && i < text_len; i++) {
+ switch (text[i]) {
+ case '\t':
+ case ' ':
+ case '\n':
+ case '\r':
+ continue;
+ default:
+ return FALSE;
+ }
+ }
+
+ return TRUE;
}
-static void
-_text_cb (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
-{
- XMLNode *p = (XMLNode *)user_data;
-
- if (_is_space (text, text_len)) {
- return;
- }
-
- if (p->sub_nodes || p->text) {
- g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, " ");
- return;
- }
-
- p->text = g_strndup (text, text_len);
+static void _text_cb ( GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error) {
+ XMLNode *p = (XMLNode *)user_data;
+
+ if (_is_space (text, text_len)) {
+ return;
+ }
+
+ if (p->sub_nodes || p->text) {
+ g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, " ");
+ return;
+ }
+
+ p->text = g_strndup (text, text_len);
}
static GMarkupParser parser = {
- _start_element_cb,
- _end_element_cb,
- _text_cb,
- 0,
- 0,
+ _start_element_cb,
+ _end_element_cb,
+ _text_cb,
+ 0,
+ 0,
};
-XMLNode *
-xml_parse_file (const gchar *filename)
-{
- gboolean retval = FALSE;
- GError *error = NULL;
- FILE *pf = fopen (filename, "r");
+XMLNode *xml_parse_file (const gchar *filename) {
+ gboolean retval = FALSE;
+ GError *error = NULL;
+ FILE *pf = fopen (filename, "r");
- if (pf == NULL) {
- return NULL;
- }
+ if (pf == NULL) {
+ return NULL;
+ }
- GMarkupParseContext *context;
- XMLNode *node;
+ GMarkupParseContext *context;
+ XMLNode *node;
- const static GMarkupParser root_parser = {
- _start_root_element_cb,
- _end_element_cb,
- _text_cb,
- 0,
- 0,
- };
+ const static GMarkupParser root_parser = {
+ _start_root_element_cb,
+ _end_element_cb,
+ _text_cb,
+ 0,
+ 0,
+ };
- do {
- context = g_markup_parse_context_new (&root_parser, 0, &node, 0);
+ do {
+ context = g_markup_parse_context_new (&root_parser, 0, &node, 0);
- while (!feof (pf)) {
- gchar buf[1024];
- gssize len = 0;
+ while (!feof (pf)) {
+ gchar buf[1024];
+ gssize len = 0;
- len = fread (buf, 1, sizeof (buf), pf);
- retval = g_markup_parse_context_parse (context, buf, len, &error);
+ len = fread (buf, 1, sizeof (buf), pf);
+ retval = g_markup_parse_context_parse (context, buf, len, &error);
- if (!retval)
- break;
- }
- fclose (pf);
+ if (!retval)
+ break;
+ }
+ fclose (pf);
- if (!retval)
- break;
+ if (!retval)
+ break;
- retval = g_markup_parse_context_end_parse (context, &error);
- if (!retval)
- break;
+ retval = g_markup_parse_context_end_parse (context, &error);
+ if (!retval)
+ break;
- g_markup_parse_context_free (context);
+ g_markup_parse_context_free (context);
- return node;
- } while (0);
+ return node;
+ } while (0);
- g_warning ("Parse %s failed: %s", filename, error->message);
- g_error_free (error);
- g_markup_parse_context_free (context);
- return NULL;
+ g_warning ("Parse %s failed: %s", filename, error->message);
+ g_error_free (error);
+ g_markup_parse_context_free (context);
+ return NULL;
}
-XMLNode *
-xml_parse_buffer (const gchar *buffer)
-{
- gboolean retval;
- GError *error = NULL;
-
- GMarkupParseContext *context;
- XMLNode *node;
-
- const static GMarkupParser root_parser = {
- _start_root_element_cb,
- _end_element_cb,
- _text_cb,
- 0,
- 0,
- };
-
- context = g_markup_parse_context_new (&root_parser, 0, &node, 0);
-
- do {
- retval = g_markup_parse_context_parse (context, buffer, strlen (buffer), &error);
- if (!retval)
- break;
-
- retval = g_markup_parse_context_end_parse (context, &error);
- if (!retval)
- break;
- g_markup_parse_context_free (context);
- return node;
- } while (0);
-
- g_warning ("Parse buffer failed: %s", error->message);
- g_error_free (error);
- g_markup_parse_context_free (context);
- return NULL;
+XMLNode *xml_parse_buffer (const gchar *buffer, GError **error) {
+ gboolean retval;
+
+ GMarkupParseContext *context;
+ XMLNode *node;
+
+ const static GMarkupParser root_parser = {
+ _start_root_element_cb,
+ _end_element_cb,
+ _text_cb,
+ 0,
+ 0,
+ };
+
+ context = g_markup_parse_context_new (&root_parser, 0, &node, 0);
+
+ do {
+ retval = g_markup_parse_context_parse (context, buffer, strlen (buffer), error);
+ if (!retval)
+ break;
+
+ retval = g_markup_parse_context_end_parse (context, error);
+ if (!retval)
+ break;
+ g_markup_parse_context_free (context);
+ return node;
+ } while (0);
+
+ //g_warning ("Parse buffer failed: %s", (*error)->message);
+ g_markup_parse_context_free (context);
+ return NULL;
}
-static void
-output_indent (int level, GString *output)
-{
- gint i;
- for (i = 0; i < level; i++) {
- g_string_append (output, " ");
- }
+static void output_indent (int level, GString *output) {
+ gint i;
+ for (i = 0; i < level; i++) {
+ g_string_append (output, " ");
+ }
}
-static void
-xml_output_indent (const XMLNode *node, int level, GString *output)
-{
- gchar **attrs;
-
- output_indent (level, output);
- g_string_append_printf (output, "<%s", node->name);
-
- attrs = node->attributes;
-
- while (attrs != NULL && *attrs != NULL) {
- g_string_append_printf (output, " %s", *(attrs++));
- g_string_append_printf (output, "=\"%s\"", *(attrs++));
- }
-
- if (node->sub_nodes != NULL){
- g_string_append (output, ">\n");
- GList *sub_node;
-
- for (sub_node = node->sub_nodes; sub_node != NULL; sub_node = sub_node->next) {
- xml_output_indent (sub_node->data, level + 1, output);
- }
- output_indent (level, output);
- g_string_append_printf (output, "</%s>\n",node->name);
- }
- else if (node->text != NULL) {
- gchar *text = g_markup_escape_text (node->text, -1);
- g_string_append_printf (output, ">%s</%s>\n", text, node->name);
- g_free (text);
- }
- else {
- g_string_append (output, "/>\n");
- }
+static void xml_output_indent (const XMLNode *node, int level, GString *output) {
+ gchar **attrs;
+
+ output_indent (level, output);
+ g_string_append_printf (output, "<%s", node->name);
+
+ attrs = node->attributes;
+
+ while (attrs != NULL && *attrs != NULL) {
+ g_string_append_printf (output, " %s", *(attrs++));
+ g_string_append_printf (output, "=\"%s\"", *(attrs++));
+ }
+
+ if (node->sub_nodes != NULL) {
+ g_string_append (output, ">\n");
+ GList *sub_node;
+
+ for (sub_node = node->sub_nodes; sub_node != NULL; sub_node = sub_node->next) {
+ xml_output_indent (sub_node->data, level + 1, output);
+ }
+ output_indent (level, output);
+ g_string_append_printf (output, "</%s>\n",node->name);
+ } else if (node->text != NULL) {
+ gchar *text = g_markup_escape_text (node->text, -1);
+ g_string_append_printf (output, ">%s</%s>\n", text, node->name);
+ g_free (text);
+ } else {
+ g_string_append (output, "/>\n");
+ }
}
-void
-xml_output (const XMLNode *node, GString *output)
-{
- xml_output_indent (node, 0, output);
+void xml_output (const XMLNode *node, GString *output) {
+ xml_output_indent (node, 0, output);
}
diff --git a/saedit/xml.h b/saedit/xml.h
index 2f5bc2b..584c568 100644
--- a/saedit/xml.h
+++ b/saedit/xml.h
@@ -16,17 +16,17 @@
#include "common.h"
typedef struct {
- gchar *name;
- gchar *text;
- gchar **attributes;
- int line_number;
- GList *sub_nodes;
+ gchar *name;
+ gchar *text;
+ gchar **attributes;
+ int line_number;
+ GList *sub_nodes;
} XMLNode;
XMLNode *xml_parse_file (const gchar *name);
-XMLNode *xml_parse_buffer (const gchar *buffer);
+XMLNode *xml_parse_buffer (const gchar *buffer, GError **error);
void xml_free (XMLNode *node);