Subversion Repositories eduke32

Rev

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