X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=tests%2Fglulxercise.c;fp=tests%2Fglulxercise.c;h=3c786a922655139250adfd95a00294328283b410;hb=b64abc3eac8a01faf1f217b02658826b523da977;hp=0000000000000000000000000000000000000000;hpb=b9668b4d0922ce7cf0202eef4f157b778cf870c1;p=projects%2Fchimara%2Fchimara.git diff --git a/tests/glulxercise.c b/tests/glulxercise.c new file mode 100644 index 0000000..3c786a9 --- /dev/null +++ b/tests/glulxercise.c @@ -0,0 +1,105 @@ +#include +#include +#include +#include "error.h" + +#define LOAD_WIDGET(name) GTK_WIDGET(gtk_builder_get_object(builder, name)) + +typedef struct { + GtkWidget *window, *test_picker, *go, *stop, *interp; +} Widgets; + +gboolean +on_window_delete_event() +{ + gtk_main_quit(); + return TRUE; +} + +void +on_go_clicked(GtkButton *go, Widgets *w) +{ + GError *error = NULL; + + gchar *filename = NULL; + GtkTreeIter iter; + GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(w->test_picker)); + gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w->test_picker), &iter); + gtk_tree_model_get(model, &iter, 1, &filename, -1); + g_object_unref(model); + + if( !chimara_if_run_game(CHIMARA_IF(w->interp), filename, &error) ) + { + error_dialog(GTK_WINDOW(w->window), error, "Error starting Glk library: "); + gtk_main_quit(); + } + + gtk_widget_set_sensitive(w->go, FALSE); + gtk_widget_set_sensitive(w->stop, TRUE); + gtk_widget_set_sensitive(w->test_picker, FALSE); +} + +void +on_stop_clicked(GtkButton *stop, Widgets *w) +{ + chimara_glk_stop( CHIMARA_GLK(w->interp) ); + chimara_glk_wait( CHIMARA_GLK(w->interp) ); + + gtk_widget_set_sensitive(w->stop, FALSE); + gtk_widget_set_sensitive(w->go, TRUE); + gtk_widget_set_sensitive(w->test_picker, TRUE); +} + +void +on_glulxe_toggled(GtkToggleButton *glulxe, Widgets *w) +{ + if(gtk_toggle_button_get_active(glulxe)) + chimara_if_set_preferred_interpreter(CHIMARA_IF(w->interp), CHIMARA_IF_FORMAT_GLULX, CHIMARA_IF_INTERPRETER_GLULXE); +} + +void +on_git_toggled(GtkToggleButton *git, Widgets *w) +{ + if(gtk_toggle_button_get_active(git)) + chimara_if_set_preferred_interpreter(CHIMARA_IF(w->interp), CHIMARA_IF_FORMAT_GLULX, CHIMARA_IF_INTERPRETER_GIT); +} + +int +main(int argc, char *argv[]) +{ + GError *error = NULL; + + if( !g_thread_supported() ) + g_thread_init(NULL); + gdk_threads_init(); + gtk_init(&argc, &argv); + + GtkBuilder *builder = gtk_builder_new(); + if(!gtk_builder_add_from_file(builder, "glulxercise.ui", &error)) + { + error_dialog(NULL, error, "Failed to build interface: "); + return 1; + } + + Widgets *w = g_slice_new0(Widgets); + w->window = LOAD_WIDGET("window"); + GtkWidget *vbox = LOAD_WIDGET("vbox"); + w->test_picker = LOAD_WIDGET("test_picker"); + w->go = LOAD_WIDGET("go"); + w->stop = LOAD_WIDGET("stop"); + w->interp = chimara_if_new(); + gtk_box_pack_end_defaults(GTK_BOX(vbox), w->interp); + gtk_builder_connect_signals(builder, w); + gtk_widget_show_all(w->window); + + gdk_threads_enter(); + gtk_main(); + gdk_threads_leave(); + + chimara_glk_stop( CHIMARA_GLK(w->interp) ); + chimara_glk_wait( CHIMARA_GLK(w->interp) ); + + g_slice_free(Widgets, w); + + return 0; +}