Open game as a method of ChimaraApp
[projects/chimara/chimara.git] / tests / test-close.c
1 #include <gtk/gtk.h>
2 #include <libchimara/chimara-if.h>
3
4 void
5 on_command(ChimaraIF *glk, gchar *input, gchar *response, GtkWindow *window)
6 {
7         GtkWidget *dialog = gtk_message_dialog_new(window, 
8                 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
9                 "%s", input);
10         gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", 
11                 response);
12         gtk_dialog_run(GTK_DIALOG(dialog));
13         gtk_widget_destroy(dialog);
14 }
15
16 int
17 main(int argc, char *argv[])
18 {
19     GtkWidget *window, *glk;
20
21     /* Initialize threads and GTK */
22     if(!g_thread_supported())
23         g_thread_init(NULL);
24     gdk_threads_init();
25     gtk_init(&argc, &argv);
26     
27     /* Construct the window and its contents. We quit the GTK main loop
28      * when the window's close button is clicked. */
29     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
30     gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
31     g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
32     glk = chimara_if_new();
33     g_signal_connect(glk, "command", G_CALLBACK(on_command), window);
34     gtk_container_add(GTK_CONTAINER(window), glk);
35     gtk_widget_show_all(window);
36     
37     /* Add a reference to the ChimaraGlk widget, because we want to keep it
38     around after gtk_main() exits */
39     g_object_ref(glk);
40     
41     /* Start the plugin */
42     g_assert(chimara_if_run_game(CHIMARA_IF(glk), "unicodetest.ulx", NULL));
43     
44     /* Start the GTK main loop */
45     gdk_threads_enter();
46     gtk_main();
47     gdk_threads_leave();
48
49     /* After the GTK main loop exits, signal the Glk program to shut down if
50      * it is still running, and wait for it to exit. */
51     chimara_glk_stop(CHIMARA_GLK(glk));
52     chimara_glk_wait(CHIMARA_GLK(glk));
53     g_object_unref(glk);
54
55     return 0;
56 }