Rev 214 | Rev 335 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
194 | terminx | 1 | /* NOTE: Glade will generate code for a dialogue box which you should |
2 | * then patch into this file whenever you make a change to the Glade |
||
3 | * template. |
||
4 | */ |
||
5 | |||
6 | #include <sys/types.h> |
||
7 | #include <sys/stat.h> |
||
8 | #include <unistd.h> |
||
9 | #include <string.h> |
||
10 | #include <stdio.h> |
||
11 | #include <stdlib.h> |
||
12 | |||
13 | #include <gdk-pixbuf/gdk-pixdata.h> |
||
14 | #include <gdk-pixbuf/gdk-pixbuf.h> |
||
15 | #include <gdk/gdkkeysyms.h> |
||
16 | #include <gtk/gtk.h> |
||
17 | |||
197 | terminx | 18 | #ifndef LINKED_GTK |
19 | # include "dynamicgtk.h" |
||
20 | #endif |
||
21 | |||
194 | terminx | 22 | #include "duke3d.h" |
23 | #include "build.h" |
||
24 | #include "compat.h" |
||
25 | #include "baselayer.h" |
||
26 | |||
27 | #define TAB_CONFIG 0 |
||
28 | #define TAB_MESSAGES 1 |
||
29 | |||
30 | static struct { |
||
214 | terminx | 31 | int fullscreen; |
32 | int xdim3d, ydim3d, bpp3d; |
||
33 | int forcesetup; |
||
34 | int usemouse, usejoy; |
||
194 | terminx | 35 | } settings; |
36 | |||
37 | extern int gtkenabled; |
||
38 | |||
39 | static GtkWidget *startwin = NULL; |
||
197 | terminx | 40 | static int retval = -1, mode = TAB_MESSAGES; |
194 | terminx | 41 | |
42 | // -- SUPPORT FUNCTIONS ------------------------------------------------------- |
||
43 | |||
44 | #define GLADE_HOOKUP_OBJECT(component,widget,name) \ |
||
45 | g_object_set_data_full (G_OBJECT (component), name, \ |
||
46 | gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref) |
||
47 | |||
48 | #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ |
||
49 | g_object_set_data (G_OBJECT (component), name, widget) |
||
50 | |||
51 | #define lookup_widget(x,w) \ |
||
52 | (GtkWidget*) g_object_get_data(G_OBJECT(x), w) |
||
53 | |||
54 | static GdkPixbuf *load_banner(void) |
||
55 | { |
||
214 | terminx | 56 | extern const GdkPixdata startbanner_pixdata; |
57 | return gdk_pixbuf_from_pixdata(&startbanner_pixdata, FALSE, NULL); |
||
194 | terminx | 58 | } |
59 | |||
60 | static void SetPage(int n) |
||
61 | { |
||
214 | terminx | 62 | if (!gtkenabled || !startwin) return; |
63 | mode = n; |
||
64 | gtk_notebook_set_current_page(GTK_NOTEBOOK(lookup_widget(startwin,"tabs")), n); |
||
194 | terminx | 65 | |
214 | terminx | 66 | // each control in the config page vertical layout plus the start button should be made (in)sensitive |
67 | if (n == TAB_CONFIG) n = TRUE; else n = FALSE; |
||
68 | gtk_widget_set_sensitive(lookup_widget(startwin,"startbutton"), n); |
||
69 | gtk_container_foreach(GTK_CONTAINER(lookup_widget(startwin,"configvlayout")), |
||
70 | (GtkCallback)gtk_widget_set_sensitive, (gpointer)n); |
||
194 | terminx | 71 | } |
72 | |||
73 | static void on_vmode3dcombo_changed(GtkComboBox *, gpointer); |
||
74 | static void PopulateForm(void) |
||
75 | { |
||
214 | terminx | 76 | int mode3d, i; |
77 | GtkListStore *modes3d; |
||
78 | GtkTreeIter iter; |
||
79 | GtkComboBox *box3d; |
||
80 | char buf[64]; |
||
194 | terminx | 81 | |
214 | terminx | 82 | mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); |
83 | if (mode3d < 0) { |
||
84 | int i, cd[] = { 32, 24, 16, 15, 8, 0 }; |
||
333 | terminx | 85 | for (i=0; cd[i];) { if (cd[i] >= settings.bpp3d) i++; else break; } |
86 | for (; cd[i]; i++) { |
||
214 | terminx | 87 | mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); |
88 | if (mode3d < 0) continue; |
||
89 | settings.bpp3d = cd[i]; |
||
90 | break; |
||
91 | } |
||
92 | } |
||
194 | terminx | 93 | |
214 | terminx | 94 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"fullscreencheck")), settings.fullscreen); |
95 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"alwaysshowcheck")), settings.forcesetup); |
||
194 | terminx | 96 | |
214 | terminx | 97 | box3d = GTK_COMBO_BOX(lookup_widget(startwin,"vmode3dcombo")); |
98 | modes3d = GTK_LIST_STORE(gtk_combo_box_get_model(box3d)); |
||
99 | gtk_list_store_clear(modes3d); |
||
194 | terminx | 100 | |
214 | terminx | 101 | for (i=0; i<validmodecnt; i++) { |
102 | if (validmode[i].fs != settings.fullscreen) continue; |
||
194 | terminx | 103 | |
214 | terminx | 104 | // all modes get added to the 3D mode list |
105 | Bsprintf(buf, "%ld x %ld %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp); |
||
106 | gtk_list_store_append(modes3d, &iter); |
||
107 | gtk_list_store_set(modes3d, &iter, 0,buf, 1,i, -1); |
||
108 | if (i == mode3d) { |
||
109 | g_signal_handlers_block_by_func(box3d, on_vmode3dcombo_changed, NULL); |
||
110 | gtk_combo_box_set_active_iter(box3d, &iter); |
||
111 | g_signal_handlers_unblock_by_func(box3d, on_vmode3dcombo_changed, NULL); |
||
112 | } |
||
113 | } |
||
194 | terminx | 114 | |
214 | terminx | 115 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"inputmousecheck")), settings.usemouse); |
116 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"inputjoycheck")), settings.usejoy); |
||
194 | terminx | 117 | } |
118 | |||
119 | // -- EVENT CALLBACKS AND CREATION STUFF -------------------------------------- |
||
120 | |||
121 | static void on_vmode3dcombo_changed(GtkComboBox *combobox, gpointer user_data) |
||
122 | { |
||
214 | terminx | 123 | GtkTreeModel *data; |
124 | GtkTreeIter iter; |
||
125 | int val; |
||
126 | if (!gtk_combo_box_get_active_iter(combobox, &iter)) return; |
||
127 | if (!(data = gtk_combo_box_get_model(combobox))) return; |
||
128 | gtk_tree_model_get(data, &iter, 1, &val, -1); |
||
129 | settings.xdim3d = validmode[val].xdim; |
||
130 | settings.ydim3d = validmode[val].ydim; |
||
194 | terminx | 131 | } |
132 | |||
133 | static void on_fullscreencheck_toggled(GtkToggleButton *togglebutton, gpointer user_data) |
||
134 | { |
||
214 | terminx | 135 | settings.fullscreen = (gtk_toggle_button_get_active(togglebutton) == TRUE); |
136 | PopulateForm(); |
||
194 | terminx | 137 | } |
138 | |||
139 | static void on_alwaysshowcheck_toggled(GtkToggleButton *togglebutton, gpointer user_data) |
||
140 | { |
||
214 | terminx | 141 | settings.forcesetup = (gtk_toggle_button_get_active(togglebutton) == TRUE); |
194 | terminx | 142 | } |
143 | |||
144 | static void on_cancelbutton_clicked(GtkButton *button, gpointer user_data) |
||
145 | { |
||
214 | terminx | 146 | if (mode == TAB_CONFIG) { retval = 0; gtk_main_quit(); } |
147 | else quitevent++; |
||
194 | terminx | 148 | } |
149 | |||
150 | static void on_startbutton_clicked(GtkButton *button, gpointer user_data) |
||
151 | { |
||
214 | terminx | 152 | retval = 1; |
153 | gtk_main_quit(); |
||
194 | terminx | 154 | } |
155 | |||
156 | static void on_sounddrvcombo_changed(GtkComboBox *combobox, gpointer user_data) |
||
157 | { |
||
158 | } |
||
159 | |||
160 | static void on_inputmousecheck_toggled(GtkToggleButton *togglebutton, gpointer user_data) |
||
161 | { |
||
214 | terminx | 162 | settings.usemouse = (gtk_toggle_button_get_active(togglebutton) == TRUE); |
194 | terminx | 163 | } |
164 | |||
165 | static void on_inputjoycheck_toggled(GtkToggleButton *togglebutton, gpointer user_data) |
||
166 | { |
||
214 | terminx | 167 | settings.usejoy = (gtk_toggle_button_get_active(togglebutton) == TRUE); |
194 | terminx | 168 | } |
169 | |||
170 | static gboolean on_startwin_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) |
||
171 | { |
||
214 | terminx | 172 | if (mode == TAB_CONFIG) { retval = 0; gtk_main_quit(); } |
173 | else quitevent++; |
||
174 | return TRUE; // FALSE would let the event go through. we want the game to decide when to close |
||
194 | terminx | 175 | } |
176 | |||
177 | |||
178 | static GtkWidget *create_window(void) |
||
179 | { |
||
214 | terminx | 180 | GtkWidget *startwin; |
181 | GtkWidget *hlayout; |
||
182 | GtkWidget *banner; |
||
183 | GtkWidget *vlayout; |
||
184 | GtkWidget *tabs; |
||
185 | GtkWidget *configvlayout; |
||
186 | GtkWidget *configlayout; |
||
187 | GtkWidget *fullscreencheck; |
||
188 | GtkWidget *vmode3dlabel; |
||
189 | GtkWidget *inputdevlabel; |
||
190 | GtkWidget *sounddrvlabel; |
||
191 | GtkWidget *sounddrvcombo; |
||
192 | GtkWidget *inputmousecheck; |
||
193 | GtkWidget *inputjoycheck; |
||
194 | GtkWidget *vmode3dcombo; |
||
195 | GtkWidget *alwaysshowcheck; |
||
196 | GtkWidget *configtab; |
||
197 | GtkWidget *messagesscroll; |
||
198 | GtkWidget *messagestext; |
||
199 | GtkWidget *messagestab; |
||
200 | GtkWidget *buttons; |
||
201 | GtkWidget *cancelbutton; |
||
202 | GtkWidget *cancelbuttonalign; |
||
203 | GtkWidget *cancelbuttonlayout; |
||
204 | GtkWidget *cancelbuttonicon; |
||
205 | GtkWidget *cancelbuttonlabel; |
||
206 | GtkWidget *startbutton; |
||
207 | GtkWidget *startbuttonalign; |
||
208 | GtkWidget *startbuttonlayout; |
||
209 | GtkWidget *startbuttonicon; |
||
210 | GtkWidget *startbuttonlabel; |
||
211 | GtkAccelGroup *accel_group; |
||
194 | terminx | 212 | |
333 | terminx | 213 | accel_group = gtk_accel_group_new(); |
194 | terminx | 214 | |
214 | terminx | 215 | // Basic window |
333 | terminx | 216 | startwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
217 | gtk_window_set_title(GTK_WINDOW(startwin), apptitle); // NOTE: use global app title |
||
218 | gtk_window_set_position(GTK_WINDOW(startwin), GTK_WIN_POS_CENTER); |
||
219 | gtk_window_set_resizable(GTK_WINDOW(startwin), FALSE); |
||
220 | gtk_window_set_type_hint(GTK_WINDOW(startwin), GDK_WINDOW_TYPE_HINT_DIALOG); |
||
194 | terminx | 221 | |
214 | terminx | 222 | // Horizontal layout of banner and controls |
333 | terminx | 223 | hlayout = gtk_hbox_new(FALSE, 0); |
224 | gtk_widget_show(hlayout); |
||
225 | gtk_container_add(GTK_CONTAINER(startwin), hlayout); |
||
194 | terminx | 226 | |
214 | terminx | 227 | // Banner |
228 | { |
||
229 | GdkPixbuf *pixbuf = load_banner(); |
||
230 | banner = gtk_image_new_from_pixbuf(pixbuf); |
||
231 | g_object_unref((gpointer)pixbuf); |
||
232 | } |
||
333 | terminx | 233 | gtk_widget_show(banner); |
234 | gtk_box_pack_start(GTK_BOX(hlayout), banner, FALSE, FALSE, 0); |
||
235 | gtk_misc_set_alignment(GTK_MISC(banner), 0.5, 0); |
||
194 | terminx | 236 | |
214 | terminx | 237 | // Vertical layout of tab control and start+cancel buttons |
333 | terminx | 238 | vlayout = gtk_vbox_new(FALSE, 0); |
239 | gtk_widget_show(vlayout); |
||
240 | gtk_box_pack_start(GTK_BOX(hlayout), vlayout, TRUE, TRUE, 0); |
||
194 | terminx | 241 | |
214 | terminx | 242 | // Tab control |
333 | terminx | 243 | tabs = gtk_notebook_new(); |
244 | gtk_widget_show(tabs); |
||
245 | gtk_box_pack_start(GTK_BOX(vlayout), tabs, TRUE, TRUE, 0); |
||
246 | gtk_container_set_border_width(GTK_CONTAINER(tabs), 4); |
||
194 | terminx | 247 | |
214 | terminx | 248 | // Vertical layout of config page main body |
333 | terminx | 249 | configvlayout = gtk_vbox_new(FALSE, 0); |
250 | gtk_widget_show(configvlayout); |
||
251 | gtk_container_add(GTK_CONTAINER(tabs), configvlayout); |
||
194 | terminx | 252 | |
214 | terminx | 253 | // Fixed-position layout of config page controls |
333 | terminx | 254 | configlayout = gtk_fixed_new(); |
255 | gtk_widget_show(configlayout); |
||
256 | gtk_box_pack_start(GTK_BOX(configvlayout), configlayout, TRUE, TRUE, 0); |
||
257 | gtk_container_set_border_width(GTK_CONTAINER(configlayout), 6); |
||
194 | terminx | 258 | |
214 | terminx | 259 | // Fullscreen checkbox |
333 | terminx | 260 | fullscreencheck = gtk_check_button_new_with_mnemonic("_Fullscreen"); |
261 | gtk_widget_show(fullscreencheck); |
||
262 | gtk_fixed_put(GTK_FIXED(configlayout), fullscreencheck, 248, 0); |
||
263 | gtk_widget_set_size_request(fullscreencheck, 85, 29); |
||
264 | gtk_widget_add_accelerator(fullscreencheck, "grab_focus", accel_group, |
||
265 | GDK_F, GDK_MOD1_MASK, |
||
266 | GTK_ACCEL_VISIBLE); |
||
194 | terminx | 267 | |
214 | terminx | 268 | // 3D video mode label |
333 | terminx | 269 | vmode3dlabel = gtk_label_new_with_mnemonic("_Video mode:"); |
270 | gtk_widget_show(vmode3dlabel); |
||
271 | gtk_fixed_put(GTK_FIXED(configlayout), vmode3dlabel, 0, 0); |
||
272 | gtk_widget_set_size_request(vmode3dlabel, 88, 29); |
||
273 | gtk_misc_set_alignment(GTK_MISC(vmode3dlabel), 0, 0.5); |
||
194 | terminx | 274 | |
333 | terminx | 275 | inputdevlabel = gtk_label_new("Input devices:"); |
276 | gtk_widget_show(inputdevlabel); |
||
277 | gtk_fixed_put(GTK_FIXED(configlayout), inputdevlabel, 0, 120); |
||
278 | gtk_widget_set_size_request(inputdevlabel, 88, 20); |
||
279 | gtk_misc_set_alignment(GTK_MISC(inputdevlabel), 0, 0.5); |
||
194 | terminx | 280 | |
333 | terminx | 281 | sounddrvlabel = gtk_label_new_with_mnemonic("S_ound driver:"); |
282 | gtk_widget_show(sounddrvlabel); |
||
283 | gtk_fixed_put(GTK_FIXED(configlayout), sounddrvlabel, 0, 40); |
||
284 | gtk_widget_set_size_request(sounddrvlabel, 88, 29); |
||
285 | gtk_misc_set_alignment(GTK_MISC(sounddrvlabel), 0, 0.5); |
||
194 | terminx | 286 | |
333 | terminx | 287 | sounddrvcombo = gtk_combo_box_new_text(); |
288 | gtk_widget_show(sounddrvcombo); |
||
289 | gtk_fixed_put(GTK_FIXED(configlayout), sounddrvcombo, 88, 40); |
||
290 | gtk_widget_set_size_request(sounddrvcombo, 31, 30); |
||
291 | gtk_widget_add_accelerator(sounddrvcombo, "grab_focus", accel_group, |
||
292 | GDK_O, GDK_MOD1_MASK, |
||
293 | GTK_ACCEL_VISIBLE); |
||
194 | terminx | 294 | |
333 | terminx | 295 | inputmousecheck = gtk_check_button_new_with_mnemonic("Mo_use"); |
296 | gtk_widget_show(inputmousecheck); |
||
297 | gtk_fixed_put(GTK_FIXED(configlayout), inputmousecheck, 88, 120); |
||
298 | gtk_widget_set_size_request(inputmousecheck, 80, 20); |
||
299 | gtk_widget_add_accelerator(inputmousecheck, "grab_focus", accel_group, |
||
300 | GDK_U, GDK_MOD1_MASK, |
||
301 | GTK_ACCEL_VISIBLE); |
||
194 | terminx | 302 | |
333 | terminx | 303 | inputjoycheck = gtk_check_button_new_with_mnemonic("_Joystick"); |
304 | gtk_widget_show(inputjoycheck); |
||
305 | gtk_fixed_put(GTK_FIXED(configlayout), inputjoycheck, 168, 120); |
||
306 | gtk_widget_set_size_request(inputjoycheck, 80, 20); |
||
307 | gtk_widget_add_accelerator(inputjoycheck, "grab_focus", accel_group, |
||
308 | GDK_J, GDK_MOD1_MASK, |
||
309 | GTK_ACCEL_VISIBLE); |
||
194 | terminx | 310 | |
214 | terminx | 311 | // 3D video mode combo |
312 | { |
||
313 | GtkListStore *list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); |
||
314 | GtkCellRenderer *cell; |
||
194 | terminx | 315 | |
333 | terminx | 316 | vmode3dcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list)); |
214 | terminx | 317 | g_object_unref(G_OBJECT(list)); |
194 | terminx | 318 | |
214 | terminx | 319 | cell = gtk_cell_renderer_text_new(); |
320 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(vmode3dcombo), cell, FALSE); |
||
321 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(vmode3dcombo), cell, "text", 0, NULL); |
||
322 | } |
||
333 | terminx | 323 | gtk_widget_show(vmode3dcombo); |
324 | gtk_fixed_put(GTK_FIXED(configlayout), vmode3dcombo, 88, 0); |
||
325 | gtk_widget_set_size_request(vmode3dcombo, 150, 29); |
||
326 | gtk_widget_add_accelerator(vmode3dcombo, "grab_focus", accel_group, |
||
327 | GDK_V, GDK_MOD1_MASK, |
||
328 | GTK_ACCEL_VISIBLE); |
||
194 | terminx | 329 | |
214 | terminx | 330 | // Always show config checkbox |
333 | terminx | 331 | alwaysshowcheck = gtk_check_button_new_with_mnemonic("_Always show configuration on start"); |
332 | gtk_widget_show(alwaysshowcheck); |
||
333 | gtk_box_pack_start(GTK_BOX(configvlayout), alwaysshowcheck, FALSE, FALSE, 0); |
||
334 | gtk_widget_add_accelerator(alwaysshowcheck, "grab_focus", accel_group, |
||
335 | GDK_A, GDK_MOD1_MASK, |
||
336 | GTK_ACCEL_VISIBLE); |
||
194 | terminx | 337 | |
214 | terminx | 338 | // Configuration tab |
333 | terminx | 339 | configtab = gtk_label_new("Configuration"); |
340 | gtk_widget_show(configtab); |
||
341 | gtk_notebook_set_tab_label(GTK_NOTEBOOK(tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(tabs), 0), configtab); |
||
194 | terminx | 342 | |
214 | terminx | 343 | // Messages scrollable area |
333 | terminx | 344 | messagesscroll = gtk_scrolled_window_new(NULL, NULL); |
345 | gtk_widget_show(messagesscroll); |
||
346 | gtk_container_add(GTK_CONTAINER(tabs), messagesscroll); |
||
347 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(messagesscroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); |
||
194 | terminx | 348 | |
214 | terminx | 349 | // Messages text area |
333 | terminx | 350 | messagestext = gtk_text_view_new(); |
351 | gtk_widget_show(messagestext); |
||
352 | gtk_container_add(GTK_CONTAINER(messagesscroll), messagestext); |
||
353 | gtk_text_view_set_editable(GTK_TEXT_VIEW(messagestext), FALSE); |
||
354 | gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(messagestext), GTK_WRAP_WORD); |
||
355 | gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(messagestext), FALSE); |
||
356 | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(messagestext), 2); |
||
357 | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(messagestext), 2); |
||
194 | terminx | 358 | |
214 | terminx | 359 | // Messages tab |
333 | terminx | 360 | messagestab = gtk_label_new("Messages"); |
361 | gtk_widget_show(messagestab); |
||
362 | gtk_notebook_set_tab_label(GTK_NOTEBOOK(tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(tabs), 1), messagestab); |
||
194 | terminx | 363 | |
214 | terminx | 364 | // Dialogue box buttons layout |
333 | terminx | 365 | buttons = gtk_hbutton_box_new(); |
366 | gtk_widget_show(buttons); |
||
367 | gtk_box_pack_start(GTK_BOX(vlayout), buttons, FALSE, TRUE, 0); |
||
368 | gtk_container_set_border_width(GTK_CONTAINER(buttons), 3); |
||
369 | gtk_button_box_set_layout(GTK_BUTTON_BOX(buttons), GTK_BUTTONBOX_END); |
||
194 | terminx | 370 | |
214 | terminx | 371 | // Cancel button |
333 | terminx | 372 | cancelbutton = gtk_button_new(); |
373 | gtk_widget_show(cancelbutton); |
||
374 | gtk_container_add(GTK_CONTAINER(buttons), cancelbutton); |
||
375 | GTK_WIDGET_SET_FLAGS(cancelbutton, GTK_CAN_DEFAULT); |
||
376 | gtk_widget_add_accelerator(cancelbutton, "grab_focus", accel_group, |
||
377 | GDK_C, GDK_MOD1_MASK, |
||
378 | GTK_ACCEL_VISIBLE); |
||
379 | gtk_widget_add_accelerator(cancelbutton, "clicked", accel_group, |
||
380 | GDK_Escape, 0, |
||
381 | GTK_ACCEL_VISIBLE); |
||
194 | terminx | 382 | |
333 | terminx | 383 | cancelbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0); |
384 | gtk_widget_show(cancelbuttonalign); |
||
385 | gtk_container_add(GTK_CONTAINER(cancelbutton), cancelbuttonalign); |
||
194 | terminx | 386 | |
333 | terminx | 387 | cancelbuttonlayout = gtk_hbox_new(FALSE, 2); |
388 | gtk_widget_show(cancelbuttonlayout); |
||
389 | gtk_container_add(GTK_CONTAINER(cancelbuttonalign), cancelbuttonlayout); |
||
194 | terminx | 390 | |
333 | terminx | 391 | cancelbuttonicon = gtk_image_new_from_stock("gtk-cancel", GTK_ICON_SIZE_BUTTON); |
392 | gtk_widget_show(cancelbuttonicon); |
||
393 | gtk_box_pack_start(GTK_BOX(cancelbuttonlayout), cancelbuttonicon, FALSE, FALSE, 0); |
||
194 | terminx | 394 | |
333 | terminx | 395 | cancelbuttonlabel = gtk_label_new_with_mnemonic("_Cancel"); |
396 | gtk_widget_show(cancelbuttonlabel); |
||
397 | gtk_box_pack_start(GTK_BOX(cancelbuttonlayout), cancelbuttonlabel, FALSE, FALSE, 0); |
||
194 | terminx | 398 | |
214 | terminx | 399 | // Start button |
333 | terminx | 400 | startbutton = gtk_button_new(); |
401 | gtk_widget_show(startbutton); |
||
402 | gtk_container_add(GTK_CONTAINER(buttons), startbutton); |
||
403 | GTK_WIDGET_SET_FLAGS(startbutton, GTK_CAN_DEFAULT); |
||
404 | gtk_widget_add_accelerator(startbutton, "grab_focus", accel_group, |
||
405 | GDK_S, GDK_MOD1_MASK, |
||
406 | GTK_ACCEL_VISIBLE); |
||
407 | gtk_widget_add_accelerator(startbutton, "clicked", accel_group, |
||
408 | GDK_Return, 0, |
||
409 | GTK_ACCEL_VISIBLE); |
||
194 | terminx | 410 | |
333 | terminx | 411 | startbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0); |
412 | gtk_widget_show(startbuttonalign); |
||
413 | gtk_container_add(GTK_CONTAINER(startbutton), startbuttonalign); |
||
194 | terminx | 414 | |
333 | terminx | 415 | startbuttonlayout = gtk_hbox_new(FALSE, 2); |
416 | gtk_widget_show(startbuttonlayout); |
||
417 | gtk_container_add(GTK_CONTAINER(startbuttonalign), startbuttonlayout); |
||
194 | terminx | 418 | |
333 | terminx | 419 | startbuttonicon = gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_BUTTON); |
420 | gtk_widget_show(startbuttonicon); |
||
421 | gtk_box_pack_start(GTK_BOX(startbuttonlayout), startbuttonicon, FALSE, FALSE, 0); |
||
194 | terminx | 422 | |
333 | terminx | 423 | startbuttonlabel = gtk_label_new_with_mnemonic("_Start"); |
424 | gtk_widget_show(startbuttonlabel); |
||
425 | gtk_box_pack_start(GTK_BOX(startbuttonlayout), startbuttonlabel, FALSE, FALSE, 0); |
||
194 | terminx | 426 | |
214 | terminx | 427 | // Wire up the signals |
333 | terminx | 428 | g_signal_connect((gpointer) startwin, "delete_event", |
429 | G_CALLBACK(on_startwin_delete_event), |
||
430 | NULL); |
||
431 | g_signal_connect((gpointer) fullscreencheck, "toggled", |
||
432 | G_CALLBACK(on_fullscreencheck_toggled), |
||
433 | NULL); |
||
434 | g_signal_connect((gpointer) sounddrvcombo, "changed", |
||
435 | G_CALLBACK(on_sounddrvcombo_changed), |
||
436 | NULL); |
||
437 | g_signal_connect((gpointer) inputmousecheck, "toggled", |
||
438 | G_CALLBACK(on_inputmousecheck_toggled), |
||
439 | NULL); |
||
440 | g_signal_connect((gpointer) inputjoycheck, "toggled", |
||
441 | G_CALLBACK(on_inputjoycheck_toggled), |
||
442 | NULL); |
||
443 | g_signal_connect((gpointer) vmode3dcombo, "changed", |
||
444 | G_CALLBACK(on_vmode3dcombo_changed), |
||
445 | NULL); |
||
446 | g_signal_connect((gpointer) alwaysshowcheck, "toggled", |
||
447 | G_CALLBACK(on_alwaysshowcheck_toggled), |
||
448 | NULL); |
||
449 | g_signal_connect((gpointer) cancelbutton, "clicked", |
||
450 | G_CALLBACK(on_cancelbutton_clicked), |
||
451 | NULL); |
||
452 | g_signal_connect((gpointer) startbutton, "clicked", |
||
453 | G_CALLBACK(on_startbutton_clicked), |
||
454 | NULL); |
||
194 | terminx | 455 | |
214 | terminx | 456 | // Associate labels with their controls |
333 | terminx | 457 | gtk_label_set_mnemonic_widget(GTK_LABEL(vmode3dlabel), vmode3dcombo); |
458 | gtk_label_set_mnemonic_widget(GTK_LABEL(sounddrvlabel), sounddrvcombo); |
||
194 | terminx | 459 | |
214 | terminx | 460 | /* Store pointers to all widgets, for use by lookup_widget(). */ |
333 | terminx | 461 | GLADE_HOOKUP_OBJECT_NO_REF(startwin, startwin, "startwin"); |
462 | GLADE_HOOKUP_OBJECT(startwin, hlayout, "hlayout"); |
||
463 | GLADE_HOOKUP_OBJECT(startwin, banner, "banner"); |
||
464 | GLADE_HOOKUP_OBJECT(startwin, vlayout, "vlayout"); |
||
465 | GLADE_HOOKUP_OBJECT(startwin, tabs, "tabs"); |
||
466 | GLADE_HOOKUP_OBJECT(startwin, configvlayout, "configvlayout"); |
||
467 | GLADE_HOOKUP_OBJECT(startwin, configlayout, "configlayout"); |
||
468 | GLADE_HOOKUP_OBJECT(startwin, fullscreencheck, "fullscreencheck"); |
||
469 | GLADE_HOOKUP_OBJECT(startwin, vmode3dlabel, "vmode3dlabel"); |
||
470 | GLADE_HOOKUP_OBJECT(startwin, inputdevlabel, "inputdevlabel"); |
||
471 | GLADE_HOOKUP_OBJECT(startwin, sounddrvlabel, "sounddrvlabel"); |
||
472 | GLADE_HOOKUP_OBJECT(startwin, sounddrvcombo, "sounddrvcombo"); |
||
473 | GLADE_HOOKUP_OBJECT(startwin, inputmousecheck, "inputmousecheck"); |
||
474 | GLADE_HOOKUP_OBJECT(startwin, inputjoycheck, "inputjoycheck"); |
||
475 | GLADE_HOOKUP_OBJECT(startwin, vmode3dcombo, "vmode3dcombo"); |
||
476 | GLADE_HOOKUP_OBJECT(startwin, alwaysshowcheck, "alwaysshowcheck"); |
||
477 | GLADE_HOOKUP_OBJECT(startwin, configtab, "configtab"); |
||
478 | GLADE_HOOKUP_OBJECT(startwin, messagesscroll, "messagesscroll"); |
||
479 | GLADE_HOOKUP_OBJECT(startwin, messagestext, "messagestext"); |
||
480 | GLADE_HOOKUP_OBJECT(startwin, messagestab, "messagestab"); |
||
481 | GLADE_HOOKUP_OBJECT(startwin, buttons, "buttons"); |
||
482 | GLADE_HOOKUP_OBJECT(startwin, cancelbutton, "cancelbutton"); |
||
483 | GLADE_HOOKUP_OBJECT(startwin, cancelbuttonalign, "cancelbuttonalign"); |
||
484 | GLADE_HOOKUP_OBJECT(startwin, cancelbuttonlayout, "cancelbuttonlayout"); |
||
485 | GLADE_HOOKUP_OBJECT(startwin, cancelbuttonicon, "cancelbuttonicon"); |
||
486 | GLADE_HOOKUP_OBJECT(startwin, cancelbuttonlabel, "cancelbuttonlabel"); |
||
487 | GLADE_HOOKUP_OBJECT(startwin, startbutton, "startbutton"); |
||
488 | GLADE_HOOKUP_OBJECT(startwin, startbuttonalign, "startbuttonalign"); |
||
489 | GLADE_HOOKUP_OBJECT(startwin, startbuttonlayout, "startbuttonlayout"); |
||
490 | GLADE_HOOKUP_OBJECT(startwin, startbuttonicon, "startbuttonicon"); |
||
491 | GLADE_HOOKUP_OBJECT(startwin, startbuttonlabel, "startbuttonlabel"); |
||
194 | terminx | 492 | |
333 | terminx | 493 | gtk_window_add_accel_group(GTK_WINDOW(startwin), accel_group); |
194 | terminx | 494 | |
214 | terminx | 495 | return startwin; |
194 | terminx | 496 | } |
497 | |||
498 | // -- BUILD ENTRY POINTS ------------------------------------------------------ |
||
499 | |||
500 | int startwin_open(void) |
||
501 | { |
||
214 | terminx | 502 | if (!gtkenabled) return 0; |
503 | if (startwin) return 1; |
||
194 | terminx | 504 | |
214 | terminx | 505 | startwin = create_window(); |
506 | if (startwin) { |
||
507 | SetPage(TAB_MESSAGES); |
||
508 | gtk_widget_show(startwin); |
||
509 | gtk_main_iteration_do(FALSE); |
||
510 | return 0; |
||
511 | } |
||
512 | return -1; |
||
194 | terminx | 513 | } |
514 | |||
515 | int startwin_close(void) |
||
516 | { |
||
214 | terminx | 517 | if (!gtkenabled) return 0; |
518 | if (!startwin) return 1; |
||
333 | terminx | 519 | gtk_widget_destroy(startwin); |
214 | terminx | 520 | startwin = NULL; |
521 | return 0; |
||
194 | terminx | 522 | } |
523 | |||
524 | int startwin_puts(const char *str) |
||
525 | { |
||
214 | terminx | 526 | GtkWidget *textview; |
527 | GtkTextBuffer *textbuffer; |
||
528 | GtkTextIter enditer; |
||
529 | GtkTextMark *mark; |
||
530 | const char *aptr, *bptr; |
||
194 | terminx | 531 | |
214 | terminx | 532 | if (!gtkenabled || !str) return 0; |
533 | if (!startwin) return 1; |
||
534 | if (!(textview = lookup_widget(startwin, "messagestext"))) return -1; |
||
535 | textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); |
||
194 | terminx | 536 | |
214 | terminx | 537 | gtk_text_buffer_get_end_iter(textbuffer, &enditer); |
333 | terminx | 538 | for (aptr = bptr = str; *aptr != 0;) { |
214 | terminx | 539 | switch (*bptr) { |
540 | case '\b': |
||
541 | if (bptr > aptr) |
||
542 | gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1); |
||
194 | terminx | 543 | #if GTK_CHECK_VERSION(2,6,0) |
214 | terminx | 544 | gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE); |
194 | terminx | 545 | #else |
214 | terminx | 546 | { |
547 | GtkTextIter iter2 = enditer; |
||
548 | gtk_text_iter_backward_cursor_position(&iter2); |
||
549 | //FIXME: this seems be deleting one too many chars somewhere! |
||
550 | if (!gtk_text_iter_equal(&iter2, &enditer)) |
||
551 | gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE); |
||
552 | } |
||
194 | terminx | 553 | #endif |
214 | terminx | 554 | aptr = ++bptr; |
555 | break; |
||
556 | case 0: |
||
557 | if (bptr > aptr) |
||
558 | gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)); |
||
559 | aptr = bptr; |
||
560 | break; |
||
561 | case '\r': // FIXME |
||
562 | default: |
||
563 | bptr++; |
||
564 | break; |
||
565 | } |
||
566 | } |
||
194 | terminx | 567 | |
214 | terminx | 568 | mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1); |
569 | gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0); |
||
570 | gtk_text_buffer_delete_mark(textbuffer, mark); |
||
194 | terminx | 571 | |
214 | terminx | 572 | return 0; |
194 | terminx | 573 | } |
574 | |||
575 | int startwin_settitle(const char *title) |
||
576 | { |
||
214 | terminx | 577 | if (!gtkenabled) return 0; |
578 | if (!startwin) return 1; |
||
333 | terminx | 579 | gtk_window_set_title(GTK_WINDOW(startwin), title); |
214 | terminx | 580 | return 0; |
194 | terminx | 581 | } |
582 | |||
583 | int startwin_idle(void *s) |
||
584 | { |
||
214 | terminx | 585 | if (!gtkenabled) return 0; |
586 | //if (!startwin) return 1; |
||
333 | terminx | 587 | gtk_main_iteration_do(FALSE); |
214 | terminx | 588 | return 0; |
194 | terminx | 589 | } |
590 | |||
591 | int startwin_run(void) |
||
592 | { |
||
214 | terminx | 593 | if (!gtkenabled) return 0; |
594 | if (!startwin) return 1; |
||
194 | terminx | 595 | |
214 | terminx | 596 | SetPage(TAB_CONFIG); |
194 | terminx | 597 | |
214 | terminx | 598 | settings.fullscreen = ScreenMode; |
599 | settings.xdim3d = ScreenWidth; |
||
600 | settings.ydim3d = ScreenHeight; |
||
601 | settings.bpp3d = ScreenBPP; |
||
602 | settings.forcesetup = ForceSetup; |
||
603 | settings.usemouse = UseMouse; |
||
604 | settings.usejoy = UseJoystick; |
||
605 | PopulateForm(); |
||
194 | terminx | 606 | |
214 | terminx | 607 | gtk_main(); |
608 | |||
609 | SetPage(TAB_MESSAGES); |
||
610 | if (retval) { |
||
611 | ScreenMode = settings.fullscreen; |
||
612 | ScreenWidth = settings.xdim3d; |
||
613 | ScreenHeight = settings.ydim3d; |
||
614 | ScreenBPP = settings.bpp3d; |
||
615 | ForceSetup = settings.forcesetup; |
||
616 | UseMouse = settings.usemouse; |
||
617 | UseJoystick = settings.usejoy; |
||
618 | } |
||
619 | |||
620 | return retval; |
||
194 | terminx | 621 | } |
622 |