Don't use g_thread_init() anymore
[projects/chimara/chimara.git] / tests / glulxercise.c
index 3db6bba753e3a8b02439aa921218c38f483994dc..b323dd9e5438030d41bf30fde334798b6a71c143 100644 (file)
@@ -1,7 +1,6 @@
 #include <glib.h>
 #include <libchimara/chimara-glk.h>
 #include <libchimara/chimara-if.h>
-#include "error.h"
 
 #define LOAD_WIDGET(name) GTK_WIDGET(gtk_builder_get_object(builder, name))
 
@@ -31,12 +30,13 @@ on_go_clicked(GtkButton *go, Widgets *w)
        gchar *fullpath = g_build_filename(PACKAGE_SRC_DIR, filename, NULL);
 
        if( !chimara_if_run_game(CHIMARA_IF(w->interp), fullpath, &error) )
-       {
-               error_dialog(GTK_WINDOW(w->window), error, "Error starting Glk library: ");
-               gtk_main_quit();
-       }
+               g_error("Error starting Glk library: %s", error->message);
        g_free(fullpath);
+}
 
+void
+on_interp_started(ChimaraGlk *glk, Widgets *w)
+{
        gtk_widget_set_sensitive(w->go, FALSE);
        gtk_widget_set_sensitive(w->stop, TRUE);
        gtk_widget_set_sensitive(w->test_picker, FALSE);
@@ -47,7 +47,11 @@ on_stop_clicked(GtkButton *stop, Widgets *w)
 {
        chimara_glk_stop( CHIMARA_GLK(w->interp) );
        chimara_glk_wait( CHIMARA_GLK(w->interp) );
+}
 
+void
+on_interp_stopped(ChimaraGlk *glk, Widgets *w)
+{
        gtk_widget_set_sensitive(w->stop, FALSE);
        gtk_widget_set_sensitive(w->go, TRUE);
        gtk_widget_set_sensitive(w->test_picker, TRUE);
@@ -72,27 +76,29 @@ 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, PACKAGE_SRC_DIR "/glulxercise.ui", &error))
-       {
-               error_dialog(NULL, error, "Failed to build interface: ");
-               return 1;
-       }
+               g_error("Failed to build interface: %s", error->message);
 
        Widgets *w = g_slice_new0(Widgets);
        w->window = LOAD_WIDGET("window");
        GtkWidget *vbox = LOAD_WIDGET("vbox");
        w->test_picker = LOAD_WIDGET("test_picker");
+       gtk_combo_box_set_active(GTK_COMBO_BOX(w->test_picker), 0);
        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_widget_set_size_request(w->interp, 500, 600);
+       gtk_box_pack_end(GTK_BOX(vbox), w->interp, TRUE, TRUE, 0);
+       chimara_glk_set_css_from_string(CHIMARA_GLK(w->interp),
+               "buffer { font-size: 12; } buffer.input { color: #00a; font-style: italic; }");
+       chimara_glk_set_spacing(CHIMARA_GLK(w->interp), 1);
        gtk_builder_connect_signals(builder, w);
+       g_signal_connect(w->interp, "started", G_CALLBACK(on_interp_started), w);
+       g_signal_connect(w->interp, "stopped", G_CALLBACK(on_interp_stopped), w);
        gtk_widget_show_all(w->window);
 
        gdk_threads_enter();