NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / win / gnome / gntext.c
blob39a53bf44a3664537f7c5f653a94432f6753d1ca
1 /* aNetHack 0.0.1 gntext.c $ANH-Date: 1432512804 2015/05/25 00:13:24 $ $ANH-Branch: master $:$ANH-Revision: 1.9 $ */
2 /* Copyright (C) 1998 by Erik Andersen <andersee@debian.org> */
3 /* aNetHack may be freely redistributed. See license for details. */
5 #include "gntext.h"
6 #include "gnmain.h"
7 #include <gnome.h>
9 /* include the standard RIP window (win/X11/rip.xpm) */
10 #include "gn_rip.h"
12 /* dimensions of the pixmap */
13 #define RIP_IMAGE_WIDTH 400
14 #define RIP_IMAGE_HEIGHT 200
16 /* dimensions and location of area where we can draw text on the pixmap */
17 #define RIP_DRAW_WIDTH 84
18 #define RIP_DRAW_HEIGHT 89
19 #define RIP_DRAW_X 114
20 #define RIP_DRAW_Y 69
22 /* Text Window widgets */
23 GtkWidget *RIP = NULL;
24 GtkWidget *RIPlabel = NULL;
25 GtkWidget *TW_window = NULL;
26 GnomeLess *gless;
28 static int showRIP = 0;
30 void
31 ghack_text_window_clear(GtkWidget *widget, gpointer data)
33 g_assert(gless != NULL);
34 gtk_editable_delete_text(GTK_EDITABLE(gless->text), 0, 0);
37 void
38 ghack_text_window_destroy()
40 TW_window = NULL;
43 void
44 ghack_text_window_display(GtkWidget *widget, boolean block, gpointer data)
46 if (showRIP == 1) {
47 gtk_widget_show(GTK_WIDGET(RIP));
48 gtk_window_set_title(GTK_WINDOW(TW_window), "Rest In Peace");
51 gtk_signal_connect(GTK_OBJECT(TW_window), "destroy",
52 (GtkSignalFunc) ghack_text_window_destroy, NULL);
53 if (block)
54 gnome_dialog_run(GNOME_DIALOG(TW_window));
55 else
56 gnome_dialog_run_and_close(GNOME_DIALOG(TW_window));
58 if (showRIP == 1) {
59 showRIP = 0;
60 gtk_widget_hide(GTK_WIDGET(RIP));
61 gtk_window_set_title(GTK_WINDOW(TW_window), "Text Window");
65 void
66 ghack_text_window_put_string(GtkWidget *widget, int attr, const char *text,
67 gpointer data)
69 if (text == NULL)
70 return;
72 /* Don't bother with attributes yet */
73 gtk_text_insert(GTK_TEXT(gless->text), NULL, NULL, NULL, text, -1);
74 gtk_text_insert(GTK_TEXT(gless->text), NULL, NULL, NULL, "\n", -1);
77 GtkWidget *
78 ghack_init_text_window()
80 GtkWidget *pixmap;
81 if (TW_window)
82 return (GTK_WIDGET(TW_window));
84 TW_window = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK, NULL);
85 gtk_window_set_default_size(GTK_WINDOW(TW_window), 500, 400);
86 gtk_window_set_policy(GTK_WINDOW(TW_window), TRUE, TRUE, FALSE);
87 gtk_window_set_title(GTK_WINDOW(TW_window), "Text Window");
89 /* create GNOME pixmap object */
90 pixmap = gnome_pixmap_new_from_xpm_d(rip_xpm);
91 g_assert(pixmap != NULL);
92 gtk_widget_show(GTK_WIDGET(pixmap));
94 /* create label with our "death message", sized to fit into the
95 * tombstone */
96 RIPlabel = gtk_label_new("RIP");
97 g_assert(RIPlabel != NULL);
98 /* gtk_label_set_justify is broken? */
99 gtk_label_set_justify(GTK_LABEL(RIPlabel), GTK_JUSTIFY_CENTER);
100 gtk_label_set_line_wrap(GTK_LABEL(RIPlabel), TRUE);
101 gtk_widget_set_usize(RIPlabel, RIP_DRAW_WIDTH, RIP_DRAW_HEIGHT);
102 gtk_widget_show(RIPlabel);
104 /* create a fixed sized widget for the RIP pixmap */
105 RIP = gtk_fixed_new();
106 g_assert(RIP != NULL);
107 gtk_widget_set_usize(RIP, RIP_IMAGE_WIDTH, RIP_IMAGE_HEIGHT);
108 gtk_fixed_put(GTK_FIXED(RIP), pixmap, 0, 0);
109 gtk_fixed_put(GTK_FIXED(RIP), RIPlabel, RIP_DRAW_X, RIP_DRAW_Y);
110 gtk_widget_show(RIP);
111 gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox), RIP, TRUE,
112 TRUE, 0);
114 /* create a gnome Less widget for the text stuff */
115 gless = GNOME_LESS(gnome_less_new());
116 g_assert(gless != NULL);
117 gtk_widget_show(GTK_WIDGET(gless));
118 gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(TW_window)->vbox),
119 GTK_WIDGET(gless), TRUE, TRUE, 0);
121 /* Hook up some signals */
122 gtk_signal_connect(GTK_OBJECT(TW_window), "ghack_putstr",
123 GTK_SIGNAL_FUNC(ghack_text_window_put_string), NULL);
125 gtk_signal_connect(GTK_OBJECT(TW_window), "ghack_clear",
126 GTK_SIGNAL_FUNC(ghack_text_window_clear), NULL);
128 gtk_signal_connect(GTK_OBJECT(TW_window), "ghack_display",
129 GTK_SIGNAL_FUNC(ghack_text_window_display), NULL);
131 /* Center the dialog over over parent */
132 gnome_dialog_set_parent(GNOME_DIALOG(TW_window),
133 GTK_WINDOW(ghack_get_main_window()));
135 gtk_window_set_modal(GTK_WINDOW(TW_window), TRUE);
136 gtk_widget_show_all(TW_window);
137 gtk_widget_hide(GTK_WIDGET(RIP));
138 gnome_dialog_close_hides(GNOME_DIALOG(TW_window), TRUE);
140 return GTK_WIDGET(TW_window);
143 void
144 ghack_text_window_rip_string(const char *string)
146 /* This is called to specify that the next message window will
147 * be a RIP window, which will include this text */
149 showRIP = 1;
150 gtk_label_set(GTK_LABEL(RIPlabel), string);