Subversion Repositories eduke32

Rev

Rev 1457 | Rev 1544 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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