1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
#include <gtksourceview/gtksource.h>
#include "xml.h"
#include "config.h"
#include "spritedrawingarea.h"
#include "action.h"
#include "errors.h"
#include "file.h"
#include "buffer.h"
#include "xmlsetup.h"
#include "drawfuncs.h"
#include "main.h"
#include <string.h>
void
intr_updated (Interactor *interactor) {
gtk_widget_queue_draw (d_area);
gtk_tool_button_set_icon_name (
GTK_TOOL_BUTTON (tbtn_play),
interactor_loop_running (interactor) ?
"media-playback-pause" :
"media-playback-start"
);
if (interactor != NULL) {
gboolean result;
gint hp;
gchar *id, *name;
buffer_mark_line (
interactor_get_line_no (interactor) - 1
);
result = interactor_get_action_hp_and_name (
interactor,
&hp, &name
);
if (!result)
return;
id = get_action_id (hp, name);
gtk_combo_box_set_active_id (cb_actions, id);
g_free (id);
gtk_combo_box_set_active_id (
GTK_COMBO_BOX (cb_directions),
interactor_get_animation_direction (interactor)
);
} else
buffer_mark_line (-1);
}
void
release_context () {
xml_setup_clear ();
if (interactor != NULL) {
interactor_free (interactor);
interactor = NULL;
intr_updated (interactor);
}
gtk_combo_box_text_remove_all (cb_directions);
gtk_list_store_clear (store_actions);
if (context != NULL) {
sprite_context_free (context);
context = NULL;
}
}
void
update_window_title () {
gchar *title, *data_folder, *file_name;
const gchar *opened_file_name;
gboolean modified = buffer_get_modified ();
data_folder = config_keys_get_data_folder_path ();
opened_file_name = get_opened_file_name ();
if (
opened_file_name != NULL &&
g_str_has_prefix (opened_file_name, data_folder)
) {
file_name = g_strconcat (
"<Data Folder>",
opened_file_name + strlen (data_folder),
NULL
);
} else {
file_name = g_strdup (opened_file_name);
}
if (file_name == NULL) {
file_name = g_strdup ("New animation");
}
title = g_strconcat (
modified ? "*" : "",
file_name,
NULL
);
gtk_window_set_title (GTK_WINDOW (main_window), title);
g_free (title);
g_free (file_name);
}
void
setup_source_view (GtkSourceView *source_view) {
GtkSourceLanguageManager *langman;
GtkSourceMarkAttributes *attrs;
langman = gtk_source_language_manager_get_default();
gtk_source_buffer_set_language (
GTK_SOURCE_BUFFER (
gtk_text_view_get_buffer (
GTK_TEXT_VIEW (source_view)
)
),
gtk_source_language_manager_get_language (langman, "xml")
);
attrs = gtk_source_mark_attributes_new ();
gtk_source_mark_attributes_set_icon_name (attrs, "media-record");
gtk_source_view_set_mark_attributes (
source_view, "active-line", attrs, 0
);
gtk_widget_show_all (GTK_WIDGET (source_view));
}
GtkWidget *
gtk_builder_get_widget (
GtkBuilder *builder,
const gchar *name
) {
return GTK_WIDGET (
gtk_builder_get_object (builder, name)
);
}
gboolean
window_main_delete_event_cb (
GtkWidget *widget,
GdkEvent *event,
gpointer user_data
) {
return show_unsaved_changes_dialog ();
}
int
main (int argc, char *argv[]) {
GtkBuilder *builder;
gchar *path;
gtk_init (&argc, &argv);
builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, "iface.ui", NULL);
gtk_builder_connect_signals (builder, NULL);
main_window = gtk_builder_get_widget (builder, "window-main");
tf_view = gtk_builder_get_widget (builder, "treefolderview-main");
d_area = gtk_builder_get_widget (builder, "drawingarea-main");
source_view = gtk_builder_get_widget (builder, "sourceview-main");
tbtn_play = gtk_builder_get_widget (builder, "button-anim-play");
cb_actions = GTK_COMBO_BOX (
gtk_builder_get_widget (builder, "cbox-actions")
);
cb_directions = GTK_COMBO_BOX_TEXT (
gtk_builder_get_widget (builder, "cboxtext-directions")
);
store_actions = GTK_LIST_STORE (
gtk_builder_get_object (builder, "liststore-actions")
);
zoom_adj = GTK_ADJUSTMENT (
gtk_builder_get_object (builder, "zoom-adjustment")
);
g_object_unref (builder);
setup_source_view (GTK_SOURCE_VIEW (source_view));
update_window_title ();
path = config_keys_get_data_folder_path ();
tree_folder_view_set_filename (
TREE_FOLDER_VIEW (tf_view),
path
);
g_free (path);
sprite_drawing_area_add_layer (
SPRITE_DRAWING_AREA (d_area),
sda_layer_new (interactor_sprite_layer_draw_func, &interactor)
);
tile_grid_layer = sda_layer_new (
tile_grid_layer_draw_func,
NULL
);
sda_layer_set_z_index (tile_grid_layer, 512);
sprite_drawing_area_add_layer (
SPRITE_DRAWING_AREA (d_area),
tile_grid_layer
);
pixel_grid_layer = sda_layer_new (
pixel_grid_layer_draw_func,
NULL
);
sda_layer_set_z_index (pixel_grid_layer, 512 + 1);
sda_layer_set_visible (pixel_grid_layer, FALSE);
sprite_drawing_area_add_layer (
SPRITE_DRAWING_AREA (d_area),
pixel_grid_layer
);
gtk_widget_show_all (main_window);
gtk_main();
return 0;
}
|