2 #include <libchimara/chimara-if.h>
5 on_command(ChimaraIF *glk, gchar *input, gchar *response, GtkWindow *window)
7 GtkWidget *dialog = gtk_message_dialog_new(window,
8 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
10 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s",
12 gtk_dialog_run(GTK_DIALOG(dialog));
13 gtk_widget_destroy(dialog);
17 on_stop(GtkButton *button, ChimaraIF *glk)
19 chimara_glk_stop(CHIMARA_GLK(glk));
20 chimara_glk_wait(CHIMARA_GLK(glk));
24 on_go(GtkButton *button, ChimaraIF *glk)
27 g_assert(chimara_if_run_game(CHIMARA_IF(glk), "unicodetest.ulx", NULL));
31 main(int argc, char *argv[])
33 GtkWidget *window, *vbox, *hbox, *stop, *go, *glk;
35 /* Initialize threads and GTK */
37 gtk_init(&argc, &argv);
39 /* Construct the window and its contents. We quit the GTK main loop
40 * when the window's close button is clicked. */
41 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
42 gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
43 g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
44 vbox = gtk_grid_new();
45 gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox), GTK_ORIENTATION_VERTICAL);
46 gtk_grid_set_row_spacing(GTK_GRID(vbox), 6);
47 glk = chimara_if_new();
48 gtk_widget_set_hexpand(glk, TRUE);
49 gtk_widget_set_vexpand(glk, TRUE);
50 //g_signal_connect(glk, "command", G_CALLBACK(on_command), window);
51 hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
52 stop = gtk_button_new_with_label("Stop");
53 g_signal_connect(stop, "clicked", G_CALLBACK(on_stop), glk);
54 go = gtk_button_new_with_label("Go");
55 g_signal_connect(go, "clicked", G_CALLBACK(on_go), glk);
57 gtk_box_pack_start(GTK_BOX(hbox), stop, TRUE, TRUE, 0);
58 gtk_box_pack_start(GTK_BOX(hbox), go, TRUE, TRUE, 0);
59 gtk_container_add(GTK_CONTAINER(vbox), hbox);
60 gtk_container_add(GTK_CONTAINER(vbox), glk);
61 gtk_container_add(GTK_CONTAINER(window), vbox);
62 gtk_widget_show_all(window);
64 /* Add a reference to the ChimaraGlk widget, because we want to keep it
65 around after gtk_main() exits */
68 /* Start the plugin */
69 g_assert(chimara_if_run_game(CHIMARA_IF(glk), "unicodetest.ulx", NULL));
71 /* Start the GTK main loop */
76 /* After the GTK main loop exits, signal the Glk program to shut down if
77 * it is still running, and wait for it to exit. */
78 chimara_glk_stop(CHIMARA_GLK(glk));
79 chimara_glk_wait(CHIMARA_GLK(glk));