2 #include <libchimara/chimara-glk.h>
3 #include <libchimara/chimara-if.h>
5 #define LOAD_WIDGET(name) GTK_WIDGET(gtk_builder_get_object(builder, name))
8 GtkWidget *window, *test_picker, *go, *stop, *interp;
12 on_window_delete_event()
19 on_go_clicked(GtkButton *go, Widgets *w)
23 gchar *filename = NULL;
25 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(w->test_picker));
26 gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w->test_picker), &iter);
27 gtk_tree_model_get(model, &iter, 1, &filename, -1);
28 g_object_unref(model);
30 gchar *fullpath = g_build_filename(PACKAGE_SRC_DIR, filename, NULL);
32 if( !chimara_if_run_game(CHIMARA_IF(w->interp), fullpath, &error) )
33 g_error("Error starting Glk library: %s", error->message);
38 on_interp_started(ChimaraGlk *glk, Widgets *w)
40 gtk_widget_set_sensitive(w->go, FALSE);
41 gtk_widget_set_sensitive(w->stop, TRUE);
42 gtk_widget_set_sensitive(w->test_picker, FALSE);
46 on_stop_clicked(GtkButton *stop, Widgets *w)
48 chimara_glk_stop( CHIMARA_GLK(w->interp) );
49 chimara_glk_wait( CHIMARA_GLK(w->interp) );
53 on_interp_stopped(ChimaraGlk *glk, Widgets *w)
55 gtk_widget_set_sensitive(w->stop, FALSE);
56 gtk_widget_set_sensitive(w->go, TRUE);
57 gtk_widget_set_sensitive(w->test_picker, TRUE);
61 on_glulxe_toggled(GtkToggleButton *glulxe, Widgets *w)
63 if(gtk_toggle_button_get_active(glulxe))
64 chimara_if_set_preferred_interpreter(CHIMARA_IF(w->interp), CHIMARA_IF_FORMAT_GLULX, CHIMARA_IF_INTERPRETER_GLULXE);
68 on_git_toggled(GtkToggleButton *git, Widgets *w)
70 if(gtk_toggle_button_get_active(git))
71 chimara_if_set_preferred_interpreter(CHIMARA_IF(w->interp), CHIMARA_IF_FORMAT_GLULX, CHIMARA_IF_INTERPRETER_GIT);
75 main(int argc, char *argv[])
79 if( !g_thread_supported() )
82 gtk_init(&argc, &argv);
84 GtkBuilder *builder = gtk_builder_new();
85 if(!gtk_builder_add_from_file(builder, PACKAGE_SRC_DIR "/glulxercise.ui", &error))
86 g_error("Failed to build interface: %s", error->message);
88 Widgets *w = g_slice_new0(Widgets);
89 w->window = LOAD_WIDGET("window");
90 GtkWidget *vbox = LOAD_WIDGET("vbox");
91 w->test_picker = LOAD_WIDGET("test_picker");
92 gtk_combo_box_set_active(GTK_COMBO_BOX(w->test_picker), 0);
93 w->go = LOAD_WIDGET("go");
94 w->stop = LOAD_WIDGET("stop");
95 w->interp = chimara_if_new();
96 gtk_widget_set_size_request(w->interp, 500, 600);
97 gtk_box_pack_end_defaults(GTK_BOX(vbox), w->interp);
98 chimara_glk_set_css_from_string(CHIMARA_GLK(w->interp),
99 "buffer { font-size: 12; } buffer.input { color: #00a; font-style: italic; }");
100 chimara_glk_set_spacing(CHIMARA_GLK(w->interp), 1);
101 gtk_builder_connect_signals(builder, w);
102 g_signal_connect(w->interp, "started", G_CALLBACK(on_interp_started), w);
103 g_signal_connect(w->interp, "stopped", G_CALLBACK(on_interp_stopped), w);
104 gtk_widget_show_all(w->window);
110 chimara_glk_stop( CHIMARA_GLK(w->interp) );
111 chimara_glk_wait( CHIMARA_GLK(w->interp) );
113 g_slice_free(Widgets, w);