Subversion Repositories eduke32

Rev

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