Subversion Repositories eduke32

Rev

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

Rev Author Line No. Line
1652 terminx 1
//-------------------------------------------------------------------------
2
/*
3
Copyright (C) 2010 EDuke32 developers and contributors
4
 
5
This file is part of EDuke32.
6
 
7
EDuke32 is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
See the GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
4541 hendricks2 19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
1652 terminx 20
*/
21
//-------------------------------------------------------------------------
22
 
4770 hendricks2 23
#include "gtkpixdata.h"
24
 
1540 terminx 25
#if defined(LINKED_GTK)
1593 terminx 26
#include <gtk/gtk.h>
27
#include <gdk-pixbuf/gdk-pixdata.h>
1540 terminx 28
#else
1593 terminx 29
#include "dynamicgtk.h"
1540 terminx 30
#endif
194 terminx 31
 
32
#include "duke3d.h"
1540 terminx 33
#include "grpscan.h"
194 terminx 34
#include "build.h"
35
 
2563 helixhorne 36
#include "game.h"
37
#include "common.h"
2726 hendricks2 38
#include "common_game.h"
2563 helixhorne 39
 
1593 terminx 40
enum
41
{
42
    NONE,
43
    ALL,
44
    POPULATE_VIDEO,
45
    POPULATE_CONFIG,
46
    POPULATE_GAME,
1544 terminx 47
};
48
 
1593 terminx 49
enum
50
{
51
    TAB_CONFIG,
52
    TAB_GAME,
53
    TAB_MESSAGES,
1544 terminx 54
};
55
 
1593 terminx 56
enum
57
{
58
    INPUT_KB,
59
    INPUT_MOUSE,
60
    INPUT_JOYSTICK,
61
    INPUT_ALL,
1544 terminx 62
};
63
 
335 terminx 64
static struct
65
{
1593 terminx 66
    GtkWidget *startwin;
67
    GtkWidget *hlayout;
68
    GtkWidget *banner;
69
    GtkWidget *vlayout;
70
    GtkWidget *tabs;
71
    GtkWidget *configtlayout;
72
    GtkWidget *displayvlayout;
73
    GtkWidget *vmode3dlabel;
74
    GtkWidget *vmode3dcombo;
75
    GtkWidget *fullscreencheck;
1660 terminx 76
#ifdef POLYMER
1593 terminx 77
    GtkWidget *polymercheck;
1660 terminx 78
#endif
1593 terminx 79
    GtkWidget *inputdevlabel;
80
    GtkWidget *inputdevcombo;
81
    GtkWidget *custommodlabel;
82
    GtkWidget *custommodcombo;
83
    GtkWidget *emptyhlayout;
84
    GtkWidget *autoloadcheck;
85
    GtkWidget *alwaysshowcheck;
86
    GtkWidget *configtab;
87
    GtkWidget *gamevlayout;
88
    GtkWidget *gamelabel;
89
    GtkWidget *gamescroll;
90
    GtkWidget *gamelist;
91
    GtkWidget *gametab;
92
    GtkWidget *messagesscroll;
93
    GtkWidget *messagestext;
94
    GtkWidget *messagestab;
95
    GtkWidget *buttons;
96
    GtkWidget *cancelbutton;
97
    GtkWidget *cancelbuttonalign;
98
    GtkWidget *cancelbuttonlayout;
99
    GtkWidget *cancelbuttonicon;
100
    GtkWidget *cancelbuttonlabel;
101
    GtkWidget *startbutton;
102
    GtkWidget *startbuttonalign;
103
    GtkWidget *startbuttonlayout;
104
    GtkWidget *startbuttonicon;
105
    GtkWidget *startbuttonlabel;
1540 terminx 106
} stwidgets;
1593 terminx 107
 
1540 terminx 108
static struct
109
{
1205 terminx 110
    int32_t fullscreen;
1660 terminx 111
#ifdef POLYMER
1540 terminx 112
    int32_t polymer;
1660 terminx 113
#endif
1205 terminx 114
    int32_t xdim3d, ydim3d, bpp3d;
115
    int32_t forcesetup;
1593 terminx 116
    int32_t autoload;
1205 terminx 117
    int32_t usemouse, usejoy;
118
    int32_t game;
119
    int32_t crcval;
1544 terminx 120
    char *custommoddir;
1457 terminx 121
    char selectedgrp[BMAX_PATH];
555 terminx 122
} settings;
194 terminx 123
 
1540 terminx 124
static int32_t retval = -1, mode = TAB_MESSAGES;
1205 terminx 125
extern int32_t gtkenabled;
1544 terminx 126
static void PopulateForm(unsigned char pgs);
194 terminx 127
 
128
 
1540 terminx 129
// -- EVENT CALLBACKS AND CREATION STUFF --------------------------------------
194 terminx 130
 
1540 terminx 131
static void on_vmode3dcombo_changed(GtkComboBox *combobox, gpointer user_data)
132
{
133
    GtkTreeModel *data;
134
    GtkTreeIter iter;
135
    int32_t val;
136
    UNREFERENCED_PARAMETER(user_data);
1593 terminx 137
 
1540 terminx 138
    if (!gtk_combo_box_get_active_iter(combobox, &iter)) return;
139
    if (!(data = gtk_combo_box_get_model(combobox))) return;
140
    gtk_tree_model_get(data, &iter, 1, &val, -1);
141
    settings.xdim3d = validmode[val].xdim;
142
    settings.ydim3d = validmode[val].ydim;
143
}
194 terminx 144
 
1540 terminx 145
static void on_fullscreencheck_toggled(GtkToggleButton *togglebutton, gpointer user_data)
146
{
147
    UNREFERENCED_PARAMETER(user_data);
148
    settings.fullscreen = gtk_toggle_button_get_active(togglebutton);
1544 terminx 149
    PopulateForm(POPULATE_VIDEO);
1540 terminx 150
}
194 terminx 151
 
1660 terminx 152
#ifdef POLYMER
1540 terminx 153
static void on_polymercheck_toggled(GtkToggleButton *togglebutton, gpointer user_data)
154
{
155
    UNREFERENCED_PARAMETER(user_data);
156
    if (gtk_toggle_button_get_active(togglebutton))
157
    {
3784 terminx 158
        glrendmode = REND_POLYMER;
1593 terminx 159
        settings.polymer = TRUE;
160
        if (settings.bpp3d == 8)
161
        {
162
            settings.bpp3d = 32;
163
            PopulateForm(POPULATE_VIDEO);
164
        }
1540 terminx 165
    }
166
    else
167
    {
3784 terminx 168
        glrendmode = REND_POLYMOST;
1593 terminx 169
        settings.polymer = FALSE;
1540 terminx 170
    }
171
}
1660 terminx 172
#endif
194 terminx 173
 
1544 terminx 174
static void on_inputdevcombo_changed(GtkComboBox *combobox, gpointer user_data)
1540 terminx 175
{
176
    UNREFERENCED_PARAMETER(user_data);
1544 terminx 177
    switch (gtk_combo_box_get_active(combobox))
1593 terminx 178
    {
179
    case 0: settings.usemouse = 0; settings.usejoy = 0; break;
180
    case 1:     settings.usemouse = 1; settings.usejoy = 0; break;
181
    case 2:     settings.usemouse = 0; settings.usejoy = 1; break;
182
    case 3:     settings.usemouse = 1; settings.usejoy = 1; break;
183
    }
1540 terminx 184
}
185
 
1544 terminx 186
static void on_custommodcombo_changed(GtkComboBox *combobox, gpointer user_data)
1540 terminx 187
{
1544 terminx 188
    GtkTreeIter iter;
189
    GtkTreeModel *model;
190
    GtkTreePath *path;
191
    char *value;
1540 terminx 192
    UNREFERENCED_PARAMETER(user_data);
1593 terminx 193
 
194
    if (gtk_combo_box_get_active_iter(combobox, &iter))
1544 terminx 195
    {
1593 terminx 196
        model = gtk_combo_box_get_model(combobox);
197
        gtk_tree_model_get(model, &iter, 0,&value, -1);
198
        path = gtk_tree_model_get_path(model, &iter);
199
 
200
        if (*gtk_tree_path_get_indices(path) == NONE)
201
            settings.custommoddir = NULL;
202
        else settings.custommoddir = value;
203
    }
1540 terminx 204
}
205
 
1544 terminx 206
static void on_autoloadcheck_toggled(GtkToggleButton *togglebutton, gpointer user_data)
1540 terminx 207
{
208
    UNREFERENCED_PARAMETER(user_data);
1544 terminx 209
    settings.autoload = gtk_toggle_button_get_active(togglebutton);
1540 terminx 210
}
211
 
212
static void on_alwaysshowcheck_toggled(GtkToggleButton *togglebutton, gpointer user_data)
213
{
214
    UNREFERENCED_PARAMETER(user_data);
215
    settings.forcesetup = gtk_toggle_button_get_active(togglebutton);
216
}
217
 
218
static void on_cancelbutton_clicked(GtkButton *button, gpointer user_data)
219
{
220
    UNREFERENCED_PARAMETER(button);
221
    UNREFERENCED_PARAMETER(user_data);
222
    if (mode == TAB_CONFIG) { retval = 0; gtk_main_quit(); }
223
    else quitevent++;
224
}
225
 
226
static void on_startbutton_clicked(GtkButton *button, gpointer user_data)
227
{
228
    UNREFERENCED_PARAMETER(button);
229
    UNREFERENCED_PARAMETER(user_data);
230
    retval = 1;
231
    gtk_main_quit();
232
}
233
 
234
static void on_gamelist_selection_changed(GtkTreeSelection *selection, gpointer user_data)
235
{
236
    GtkTreeIter iter;
237
    GtkTreeModel *model;
238
    struct grpfile *fg;
239
    UNREFERENCED_PARAMETER(user_data);
1593 terminx 240
 
1540 terminx 241
    if (gtk_tree_selection_get_selected(selection, &model, &iter))
242
    {
243
        gtk_tree_model_get(model, &iter, 2, (gpointer)&fg, -1);
244
        strcpy(settings.selectedgrp, fg->name);
245
        settings.game = fg->game;
246
        settings.crcval = fg->crcval;
247
    }
248
}
249
 
250
static gboolean on_startwin_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
251
{
252
    UNREFERENCED_PARAMETER(widget);
253
    UNREFERENCED_PARAMETER(event);
254
    UNREFERENCED_PARAMETER(user_data);
255
    if (mode == TAB_CONFIG) { retval = 0; gtk_main_quit(); }
256
    else quitevent++;
257
    return TRUE;        // FALSE would let the event go through. we want the game to decide when to close
258
}
259
 
260
 
261
// -- SUPPORT FUNCTIONS -------------------------------------------------------
262
 
194 terminx 263
static GdkPixbuf *load_banner(void)
264
{
4770 hendricks2 265
    return gdk_pixbuf_from_pixdata((GdkPixdata*)&startbanner_pixdata, FALSE, NULL);
194 terminx 266
}
267
 
1205 terminx 268
static void SetPage(int32_t n)
194 terminx 269
{
1540 terminx 270
    if (!gtkenabled || !stwidgets.startwin) return;
214 terminx 271
    mode = n;
1540 terminx 272
    gtk_notebook_set_current_page(GTK_NOTEBOOK(stwidgets.tabs), n);
194 terminx 273
 
214 terminx 274
    // each control in the config page vertical layout plus the start button should be made (in)sensitive
555 terminx 275
    if (n == TAB_CONFIG) n = TRUE; else n = FALSE;
1540 terminx 276
    gtk_widget_set_sensitive(stwidgets.startbutton, n);
1544 terminx 277
    gtk_container_foreach(GTK_CONTAINER(stwidgets.configtlayout),
1593 terminx 278
                          (GtkCallback)gtk_widget_set_sensitive,
279
                          (gpointer)&n);
194 terminx 280
}
281
 
1544 terminx 282
static unsigned char GetModsDirNames(GtkListStore *list)
194 terminx 283
{
1593 terminx 284
    char *homedir;
285
    char pdir[BMAX_PATH];
286
    unsigned char iternumb = 0;
287
    CACHE1D_FIND_REC *dirs = NULL;
288
    GtkTreeIter iter;
1544 terminx 289
 
1593 terminx 290
    pathsearchmode = 1;
291
 
292
    if ((homedir = Bgethomedir()))
293
    {
294
        Bsnprintf(pdir, sizeof(pdir), "%s/" ".eduke32", homedir);
295
        dirs = klistpath(pdir, "*", CACHE1D_FIND_DIR);
296
        for (dirs=dirs; dirs != NULL; dirs=dirs->next)
297
        {
298
            if ((Bstrcmp(dirs->name, "autoload") == 0) ||
299
                    (Bstrcmp(dirs->name, "..") == 0) ||
300
                    (Bstrcmp(dirs->name, ".") == 0))
301
                continue;
302
            else
303
            {
304
                gtk_list_store_append(list, &iter);
305
                gtk_list_store_set(list, &iter, 0,dirs->name, -1);
306
                iternumb++;
307
            }
308
        }
309
    }
310
 
1544 terminx 311
    klistfree(dirs);
312
    dirs = NULL;
1593 terminx 313
 
1544 terminx 314
    return iternumb;
315
}
316
 
317
static void PopulateForm(unsigned char pgs)
318
{
319
    if ((pgs == ALL) || (pgs == POPULATE_VIDEO))
555 terminx 320
    {
1205 terminx 321
        int32_t mode3d, i;
555 terminx 322
        GtkListStore *modes3d;
323
        GtkTreeIter iter;
324
        char buf[64];
1593 terminx 325
 
555 terminx 326
        mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1);
327
        if (mode3d < 0)
335 terminx 328
        {
1205 terminx 329
            int32_t i, cd[] = { 32, 24, 16, 15, 8, 0 };
1593 terminx 330
 
555 terminx 331
            for (i=0; cd[i];) { if (cd[i] >= settings.bpp3d) i++; else break; }
332
            for (; cd[i]; i++)
333
            {
334
                mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1);
335
                if (mode3d < 0) continue;
336
                settings.bpp3d = cd[i];
337
                break;
338
            }
335 terminx 339
        }
1593 terminx 340
 
1544 terminx 341
        modes3d = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(stwidgets.vmode3dcombo)));
555 terminx 342
        gtk_list_store_clear(modes3d);
343
 
344
        for (i=0; i<validmodecnt; i++)
335 terminx 345
        {
555 terminx 346
            if (validmode[i].fs != settings.fullscreen) continue;
347
 
348
            // all modes get added to the 3D mode list
584 terminx 349
            Bsprintf(buf, "%d x %d %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp);
555 terminx 350
            gtk_list_store_append(modes3d, &iter);
351
            gtk_list_store_set(modes3d, &iter, 0,buf, 1,i, -1);
352
            if (i == mode3d)
353
            {
3168 helixhorne 354
                g_signal_handlers_block_by_func(stwidgets.vmode3dcombo, (gpointer)on_vmode3dcombo_changed, NULL);
1544 terminx 355
                gtk_combo_box_set_active_iter(GTK_COMBO_BOX(stwidgets.vmode3dcombo), &iter);
3168 helixhorne 356
                g_signal_handlers_unblock_by_func(stwidgets.vmode3dcombo, (gpointer)on_vmode3dcombo_changed, NULL);
555 terminx 357
            }
214 terminx 358
        }
1593 terminx 359
    }
360
 
1544 terminx 361
    if ((pgs == ALL) || (pgs == POPULATE_CONFIG))
1593 terminx 362
    {
1544 terminx 363
        GtkListStore *devlist, *modsdir;
364
        GtkTreeIter iter;
365
        GtkTreePath *path;
366
        char *value;
367
        unsigned char i, r = 0;
1593 terminx 368
        const char *availabledev[] =
369
        {
370
            "Keyboard only",
371
            "Keyboard and mouse",
372
            "Keyboard and joystick",
373
            "All supported devices"
374
        };
375
 
1544 terminx 376
        // populate input devices combo
1593 terminx 377
        devlist = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(stwidgets.inputdevcombo)));
378
        gtk_list_store_clear(devlist);
379
 
380
        for (i=0; i<(int32_t)G_N_ELEMENTS(availabledev); i++)
381
        {
382
            gtk_list_store_append(devlist, &iter);
1544 terminx 383
            gtk_list_store_set(devlist, &iter, 0,availabledev[i], -1);
384
        }
1593 terminx 385
        switch (settings.usemouse)
386
        {
387
        case 0: if (settings.usejoy)
388
                gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_JOYSTICK);
389
            else
390
                gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_KB);
391
            break;
392
        case 1: if (settings.usejoy)
393
                gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_ALL);
394
            else
395
                gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_MOUSE);
396
            break;
397
        }
398
 
399
        // populate custom mod combo
400
        modsdir = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(stwidgets.custommodcombo)));
401
        gtk_list_store_clear(modsdir);
402
 
403
        gtk_list_store_append(modsdir, &iter);
1544 terminx 404
        gtk_list_store_set(modsdir, &iter, 0,"None", -1);
1593 terminx 405
        r = GetModsDirNames(modsdir);
1544 terminx 406
 
1593 terminx 407
        for (i=0; i<=r; i++)
408
        {
409
            path = gtk_tree_path_new_from_indices(i, -1);
410
            gtk_tree_model_get_iter(GTK_TREE_MODEL(modsdir), &iter, path);
411
            gtk_tree_model_get(GTK_TREE_MODEL(modsdir), &iter, 0,&value, -1);
1544 terminx 412
 
1593 terminx 413
            if (Bstrcmp(settings.custommoddir, "/") == 0)
414
            {
415
                gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.custommodcombo), NONE);
416
                settings.custommoddir = NULL;
417
 
418
                break;
419
            }
420
            if (Bstrcmp(settings.custommoddir, value) == 0)
421
            {
422
                gtk_combo_box_set_active_iter(GTK_COMBO_BOX(stwidgets.custommodcombo),
423
                                              &iter);
424
 
425
                break;
426
            }
427
        }
428
 
1544 terminx 429
        // populate check buttons
1593 terminx 430
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.fullscreencheck), settings.fullscreen);
1660 terminx 431
#ifdef POLYMER
1593 terminx 432
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.polymercheck), settings.polymer);
1660 terminx 433
#endif
1593 terminx 434
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.autoloadcheck), settings.autoload);
1540 terminx 435
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.alwaysshowcheck), settings.forcesetup);
1593 terminx 436
    }
194 terminx 437
 
1544 terminx 438
    if ((pgs == ALL) || (pgs == POPULATE_GAME))
555 terminx 439
    {
440
        struct grpfile *fg;
441
        GtkListStore *list;
442
        GtkTreeIter iter;
443
        GtkTreeView *gamelist;
194 terminx 444
 
1540 terminx 445
        gamelist = GTK_TREE_VIEW(stwidgets.gamelist);
555 terminx 446
        list = GTK_LIST_STORE(gtk_tree_view_get_model(gamelist));
447
        gtk_list_store_clear(list);
194 terminx 448
 
555 terminx 449
        for (fg = foundgrps; fg; fg=fg->next)
450
        {
3708 terminx 451
            struct grpfile *grp;
452
            for (grp = listgrps; grp; grp=grp->next)
453
                if (fg->crcval == grp->crcval) break;
194 terminx 454
 
3708 terminx 455
            if (grp == NULL)
456
                continue;
457
 
555 terminx 458
            gtk_list_store_append(list, &iter);
3718 terminx 459
            gtk_list_store_set(list, &iter, 0, grp->name, 1, fg->name, 2, (gpointer)fg, -1);
555 terminx 460
            if (!Bstrcasecmp(fg->name, settings.selectedgrp))
461
            {
462
                GtkTreeSelection *sel = gtk_tree_view_get_selection(gamelist);
3168 helixhorne 463
                g_signal_handlers_block_by_func(sel, (gpointer)on_gamelist_selection_changed, NULL);
555 terminx 464
                gtk_tree_selection_select_iter(sel, &iter);
3168 helixhorne 465
                g_signal_handlers_unblock_by_func(sel, (gpointer)on_gamelist_selection_changed, NULL);
555 terminx 466
            }
214 terminx 467
        }
468
    }
194 terminx 469
}
470
 
555 terminx 471
static gint name_sorter(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data)
472
{
473
    gchar *as, *bs;
474
    gint r;
654 terminx 475
    UNREFERENCED_PARAMETER(user_data);
555 terminx 476
    gtk_tree_model_get(model, a, 0, &as, -1);
477
    gtk_tree_model_get(model, b, 0, &bs, -1);
478
 
479
    r = g_utf8_collate(as,bs);
480
 
481
    g_free(as);
482
    g_free(bs);
483
 
484
    return r;
485
}
486
 
194 terminx 487
static GtkWidget *create_window(void)
488
{
214 terminx 489
    // Basic window
1540 terminx 490
    stwidgets.startwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
491
    gtk_window_set_title(GTK_WINDOW(stwidgets.startwin), apptitle);     // NOTE: use global app title
492
    gtk_window_set_position(GTK_WINDOW(stwidgets.startwin), GTK_WIN_POS_CENTER);
493
    gtk_window_set_resizable(GTK_WINDOW(stwidgets.startwin), FALSE);
494
    gtk_window_set_type_hint(GTK_WINDOW(stwidgets.startwin), GDK_WINDOW_TYPE_HINT_DIALOG);
194 terminx 495
 
214 terminx 496
    // Horizontal layout of banner and controls
1540 terminx 497
    stwidgets.hlayout = gtk_hbox_new(FALSE, 0);
498
    gtk_container_add(GTK_CONTAINER(stwidgets.startwin), stwidgets.hlayout);
194 terminx 499
 
1540 terminx 500
    // banner
214 terminx 501
    {
502
        GdkPixbuf *pixbuf = load_banner();
1540 terminx 503
        stwidgets.banner = gtk_image_new_from_pixbuf(pixbuf);
214 terminx 504
        g_object_unref((gpointer)pixbuf);
505
    }
1540 terminx 506
    gtk_box_pack_start(GTK_BOX(stwidgets.hlayout), stwidgets.banner, FALSE, FALSE, 0);
507
    gtk_misc_set_alignment(GTK_MISC(stwidgets.banner), 0.5, 0);
194 terminx 508
 
214 terminx 509
    // Vertical layout of tab control and start+cancel buttons
1540 terminx 510
    stwidgets.vlayout = gtk_vbox_new(FALSE, 0);
511
    gtk_box_pack_start(GTK_BOX(stwidgets.hlayout), stwidgets.vlayout, TRUE, TRUE, 0);
194 terminx 512
 
214 terminx 513
    // Tab control
1540 terminx 514
    stwidgets.tabs = gtk_notebook_new();
515
    gtk_box_pack_start(GTK_BOX(stwidgets.vlayout), stwidgets.tabs, TRUE, TRUE, 0);
516
    gtk_container_set_border_width(GTK_CONTAINER(stwidgets.tabs), 4);
1593 terminx 517
 
1540 terminx 518
    // layout table of config page
1593 terminx 519
    stwidgets.configtlayout = gtk_table_new(6, 3, FALSE);
520
    gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.configtlayout);
521
 
522
    // 3D video mode LabelText
523
    stwidgets.vmode3dlabel = gtk_label_new_with_mnemonic("_Video mode:");
524
    gtk_misc_set_alignment(GTK_MISC(stwidgets.vmode3dlabel), 0.3, 0);
1785 terminx 525
#ifdef POLYMER
3168 helixhorne 526
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dlabel, 0,1, 0,1, GTK_FILL, (GtkAttachOptions)0, 4, 0);
1785 terminx 527
#else
3168 helixhorne 528
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dlabel, 0,1, 0,1, GTK_FILL, (GtkAttachOptions)0, 4, 7);
1785 terminx 529
#endif
1593 terminx 530
 
531
    // 3D video mode combo
214 terminx 532
    {
533
        GtkListStore *list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
534
        GtkCellRenderer *cell;
194 terminx 535
 
1540 terminx 536
        stwidgets.vmode3dcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list));
214 terminx 537
        g_object_unref(G_OBJECT(list));
194 terminx 538
 
214 terminx 539
        cell = gtk_cell_renderer_text_new();
1540 terminx 540
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.vmode3dcombo), cell, FALSE);
541
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.vmode3dcombo), cell, "text", 0, NULL);
214 terminx 542
    }
1786 terminx 543
 
544
#ifdef POLYMER
3168 helixhorne 545
   gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dcombo, 1,2, 0,1,
546
       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 4, 0);
1786 terminx 547
#else
3168 helixhorne 548
   gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dcombo, 1,2, 0,1, GTK_EXPAND | GTK_FILL, (GtkAttachOptions)0, 4, 7);
1786 terminx 549
#endif
194 terminx 550
 
1540 terminx 551
    // Fullscreen checkbox
1593 terminx 552
    stwidgets.displayvlayout = gtk_vbox_new(TRUE, 0);
1785 terminx 553
#ifdef POLYMER
3168 helixhorne 554
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.displayvlayout, 2,3, 0,1, GTK_FILL, (GtkAttachOptions)0, 4, 0);
1785 terminx 555
#else
3168 helixhorne 556
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.displayvlayout, 2,3, 0,1, GTK_FILL, (GtkAttachOptions)0, 4, 7);
1785 terminx 557
#endif
558
 
1593 terminx 559
    stwidgets.fullscreencheck = gtk_check_button_new_with_mnemonic("_Fullscreen");
560
    gtk_box_pack_start(GTK_BOX(stwidgets.displayvlayout), stwidgets.fullscreencheck, FALSE, FALSE, 0);
561
 
1660 terminx 562
#ifdef POLYMER
1593 terminx 563
    // Polymer checkbox
1540 terminx 564
    stwidgets.polymercheck = gtk_check_button_new_with_mnemonic("_Polymer");
1593 terminx 565
    gtk_box_pack_start(GTK_BOX(stwidgets.displayvlayout), stwidgets.polymercheck, FALSE, FALSE, 0);
1660 terminx 566
#endif
194 terminx 567
 
1593 terminx 568
    // Input devices LabelText
1544 terminx 569
    stwidgets.inputdevlabel = gtk_label_new_with_mnemonic("_Input devices:");
1593 terminx 570
    gtk_misc_set_alignment(GTK_MISC(stwidgets.inputdevlabel), 0.3, 0);
3168 helixhorne 571
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.inputdevlabel, 0,1, 1,2, GTK_FILL, (GtkAttachOptions)0, 4, 0);
1593 terminx 572
 
573
    // Input devices combo
574
    {
1544 terminx 575
        GtkListStore *list = gtk_list_store_new(1, G_TYPE_STRING);
576
        GtkCellRenderer *cell;
577
 
578
        stwidgets.inputdevcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list));
579
        g_object_unref(G_OBJECT(list));
580
 
581
        cell = gtk_cell_renderer_text_new();
582
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.inputdevcombo), cell, FALSE);
583
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.inputdevcombo), cell, "text", 0, NULL);
584
    }
3168 helixhorne 585
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.inputdevcombo, 1,2, 1,2,
586
        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 4, 0);
1593 terminx 587
 
588
    // Custom mod LabelText
1660 terminx 589
    stwidgets.custommodlabel = gtk_label_new_with_mnemonic("Custom _game:");
1593 terminx 590
    gtk_misc_set_alignment(GTK_MISC(stwidgets.custommodlabel), 0.3, 0);
3168 helixhorne 591
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.custommodlabel, 0,1, 2,3, GTK_FILL, (GtkAttachOptions)0, 4, 7);
1593 terminx 592
 
593
    // Custom mod combo
594
    {
1544 terminx 595
        GtkListStore *list = gtk_list_store_new(1, G_TYPE_STRING);
596
        GtkCellRenderer *cell;
1540 terminx 597
 
1544 terminx 598
        stwidgets.custommodcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list));
599
        g_object_unref(G_OBJECT(list));
600
 
601
        cell = gtk_cell_renderer_text_new();
602
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.custommodcombo), cell, FALSE);
603
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.custommodcombo), cell, "text", 0, NULL);
604
    }
3168 helixhorne 605
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.custommodcombo, 1,2, 2,3,
606
        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 4, 7);
1593 terminx 607
 
608
    // Empty horizontal layout
609
    stwidgets.emptyhlayout = gtk_hbox_new(TRUE, 0);
3168 helixhorne 610
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.emptyhlayout, 0,3, 3,4, (GtkAttachOptions)0,
611
        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 4, 0);
1593 terminx 612
 
1540 terminx 613
    // Autoload checkbox
1593 terminx 614
    stwidgets.autoloadcheck = gtk_check_button_new_with_mnemonic("_Enable \"autoload\" folder");
3168 helixhorne 615
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.autoloadcheck, 0,3, 4,5, GTK_FILL, (GtkAttachOptions)0, 2, 2);
1593 terminx 616
 
617
    // Always show config checkbox
1544 terminx 618
    stwidgets.alwaysshowcheck = gtk_check_button_new_with_mnemonic("_Always show this window at startup");
3168 helixhorne 619
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.alwaysshowcheck, 0,3, 5,6, GTK_FILL, (GtkAttachOptions)0, 2, 2);
1540 terminx 620
 
214 terminx 621
    // Configuration tab
1540 terminx 622
    stwidgets.configtab = gtk_label_new("Configuration");
623
    gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 0), stwidgets.configtab);
194 terminx 624
 
555 terminx 625
    // Game data layout
1540 terminx 626
    stwidgets.gamevlayout = gtk_vbox_new(FALSE, 0);
627
    gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.gamevlayout);
628
    gtk_container_set_border_width(GTK_CONTAINER(stwidgets.gamevlayout), 4);
555 terminx 629
 
1143 terminx 630
    // Game data field LabelText
1660 terminx 631
    stwidgets.gamelabel = gtk_label_new_with_mnemonic("_Game:");
1540 terminx 632
    gtk_box_pack_start(GTK_BOX(stwidgets.gamevlayout), stwidgets.gamelabel, FALSE, FALSE, 0);
633
    gtk_misc_set_alignment(GTK_MISC(stwidgets.gamelabel), 0, 0.5);
555 terminx 634
 
635
    // Game data scrollable area
1540 terminx 636
    stwidgets.gamescroll = gtk_scrolled_window_new(NULL, NULL);
637
    gtk_box_pack_start(GTK_BOX(stwidgets.gamevlayout), stwidgets.gamescroll, TRUE, TRUE, 0);
638
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(stwidgets.gamescroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
639
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(stwidgets.gamescroll), GTK_SHADOW_IN);
555 terminx 640
 
641
    // Game data list
642
    {
643
        GtkListStore *list = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
644
        GtkCellRenderer *cell;
645
        GtkTreeViewColumn *col;
646
 
647
        gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list), 0, name_sorter, NULL, NULL);
648
        gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list), 0, GTK_SORT_ASCENDING);
649
 
1540 terminx 650
        stwidgets.gamelist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list));
555 terminx 651
        g_object_unref(G_OBJECT(list));
652
 
653
        cell = gtk_cell_renderer_text_new();
654
        col = gtk_tree_view_column_new_with_attributes("Game", cell, "text", 0, NULL);
655
        gtk_tree_view_column_set_expand(col, TRUE);
1540 terminx 656
        gtk_tree_view_append_column(GTK_TREE_VIEW(stwidgets.gamelist), col);
555 terminx 657
        col = gtk_tree_view_column_new_with_attributes("GRP file", cell, "text", 1, NULL);
658
        gtk_tree_view_column_set_min_width(col, 64);
1540 terminx 659
        gtk_tree_view_append_column(GTK_TREE_VIEW(stwidgets.gamelist), col);
555 terminx 660
    }
1540 terminx 661
    gtk_container_add(GTK_CONTAINER(stwidgets.gamescroll), stwidgets.gamelist);
1593 terminx 662
 
1540 terminx 663
    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(stwidgets.gamelist), FALSE);
664
    gtk_tree_view_set_enable_search(GTK_TREE_VIEW(stwidgets.gamelist), FALSE);
555 terminx 665
 
666
    // Game tab
1540 terminx 667
    stwidgets.gametab = gtk_label_new("Game");
668
    gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 1), stwidgets.gametab);
555 terminx 669
 
214 terminx 670
    // Messages scrollable area
1540 terminx 671
    stwidgets.messagesscroll = gtk_scrolled_window_new(NULL, NULL);
672
    gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.messagesscroll);
673
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(stwidgets.messagesscroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
194 terminx 674
 
214 terminx 675
    // Messages text area
1540 terminx 676
    stwidgets.messagestext = gtk_text_view_new();
677
    gtk_container_add(GTK_CONTAINER(stwidgets.messagesscroll), stwidgets.messagestext);
678
    gtk_text_view_set_editable(GTK_TEXT_VIEW(stwidgets.messagestext), FALSE);
679
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(stwidgets.messagestext), GTK_WRAP_WORD);
680
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(stwidgets.messagestext), FALSE);
681
    gtk_text_view_set_left_margin(GTK_TEXT_VIEW(stwidgets.messagestext), 2);
682
    gtk_text_view_set_right_margin(GTK_TEXT_VIEW(stwidgets.messagestext), 2);
194 terminx 683
 
214 terminx 684
    // Messages tab
1540 terminx 685
    stwidgets.messagestab = gtk_label_new("Messages");
686
    gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 2), stwidgets.messagestab);
194 terminx 687
 
214 terminx 688
    // Dialogue box buttons layout
1540 terminx 689
    stwidgets.buttons = gtk_hbutton_box_new();
690
    gtk_box_pack_start(GTK_BOX(stwidgets.vlayout), stwidgets.buttons, FALSE, TRUE, 0);
691
    gtk_container_set_border_width(GTK_CONTAINER(stwidgets.buttons), 3);
692
    gtk_button_box_set_layout(GTK_BUTTON_BOX(stwidgets.buttons), GTK_BUTTONBOX_END);
194 terminx 693
 
214 terminx 694
    // Cancel button
1540 terminx 695
    stwidgets.cancelbutton = gtk_button_new();
696
    gtk_container_add(GTK_CONTAINER(stwidgets.buttons), stwidgets.cancelbutton);
697
    GTK_WIDGET_SET_FLAGS(stwidgets.cancelbutton, GTK_CAN_DEFAULT);
194 terminx 698
 
1540 terminx 699
    stwidgets.cancelbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0);
700
    gtk_container_add(GTK_CONTAINER(stwidgets.cancelbutton), stwidgets.cancelbuttonalign);
194 terminx 701
 
1540 terminx 702
    stwidgets.cancelbuttonlayout = gtk_hbox_new(FALSE, 2);
703
    gtk_container_add(GTK_CONTAINER(stwidgets.cancelbuttonalign), stwidgets.cancelbuttonlayout);
194 terminx 704
 
1540 terminx 705
    stwidgets.cancelbuttonicon = gtk_image_new_from_stock("gtk-cancel", GTK_ICON_SIZE_BUTTON);
706
    gtk_box_pack_start(GTK_BOX(stwidgets.cancelbuttonlayout), stwidgets.cancelbuttonicon, FALSE, FALSE, 0);
194 terminx 707
 
1540 terminx 708
    stwidgets.cancelbuttonlabel = gtk_label_new_with_mnemonic("_Cancel");
709
    gtk_box_pack_start(GTK_BOX(stwidgets.cancelbuttonlayout), stwidgets.cancelbuttonlabel, FALSE, FALSE, 0);
194 terminx 710
 
214 terminx 711
    // Start button
1540 terminx 712
    stwidgets.startbutton = gtk_button_new();
713
    gtk_container_add(GTK_CONTAINER(stwidgets.buttons), stwidgets.startbutton);
714
    GTK_WIDGET_SET_FLAGS(stwidgets.startbutton, GTK_CAN_DEFAULT);
194 terminx 715
 
1664 plagman 716
    gtk_window_set_default(GTK_WINDOW(stwidgets.startwin), stwidgets.startbutton);
717
 
1540 terminx 718
    stwidgets.startbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0);
719
    gtk_container_add(GTK_CONTAINER(stwidgets.startbutton), stwidgets.startbuttonalign);
194 terminx 720
 
1540 terminx 721
    stwidgets.startbuttonlayout = gtk_hbox_new(FALSE, 2);
722
    gtk_container_add(GTK_CONTAINER(stwidgets.startbuttonalign), stwidgets.startbuttonlayout);
194 terminx 723
 
1540 terminx 724
    stwidgets.startbuttonicon = gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_BUTTON);
725
    gtk_box_pack_start(GTK_BOX(stwidgets.startbuttonlayout), stwidgets.startbuttonicon, FALSE, FALSE, 0);
194 terminx 726
 
1540 terminx 727
    stwidgets.startbuttonlabel = gtk_label_new_with_mnemonic("_Start");
728
    gtk_box_pack_start(GTK_BOX(stwidgets.startbuttonlayout), stwidgets.startbuttonlabel, FALSE, FALSE, 0);
194 terminx 729
 
214 terminx 730
    // Wire up the signals
1593 terminx 731
    g_signal_connect((gpointer) stwidgets.startwin, "delete_event",
333 terminx 732
                     G_CALLBACK(on_startwin_delete_event),
733
                     NULL);
1593 terminx 734
    g_signal_connect((gpointer) stwidgets.vmode3dcombo, "changed",
1544 terminx 735
                     G_CALLBACK(on_vmode3dcombo_changed),
736
                     NULL);
1593 terminx 737
    g_signal_connect((gpointer) stwidgets.fullscreencheck, "toggled",
333 terminx 738
                     G_CALLBACK(on_fullscreencheck_toggled),
739
                     NULL);
1660 terminx 740
#ifdef POLYMER
1593 terminx 741
    g_signal_connect((gpointer) stwidgets.polymercheck, "toggled",
1540 terminx 742
                     G_CALLBACK(on_polymercheck_toggled),
743
                     NULL);
1660 terminx 744
#endif
1593 terminx 745
    g_signal_connect((gpointer) stwidgets.inputdevcombo, "changed",
1544 terminx 746
                     G_CALLBACK(on_inputdevcombo_changed),
1540 terminx 747
                     NULL);
1593 terminx 748
    g_signal_connect((gpointer) stwidgets.custommodcombo, "changed",
1544 terminx 749
                     G_CALLBACK(on_custommodcombo_changed),
333 terminx 750
                     NULL);
1593 terminx 751
    g_signal_connect((gpointer) stwidgets.autoloadcheck, "toggled",
1544 terminx 752
                     G_CALLBACK(on_autoloadcheck_toggled),
333 terminx 753
                     NULL);
1593 terminx 754
    g_signal_connect((gpointer) stwidgets.alwaysshowcheck, "toggled",
333 terminx 755
                     G_CALLBACK(on_alwaysshowcheck_toggled),
756
                     NULL);
1593 terminx 757
    g_signal_connect((gpointer) stwidgets.cancelbutton, "clicked",
333 terminx 758
                     G_CALLBACK(on_cancelbutton_clicked),
759
                     NULL);
1593 terminx 760
    g_signal_connect((gpointer) stwidgets.startbutton, "clicked",
333 terminx 761
                     G_CALLBACK(on_startbutton_clicked),
762
                     NULL);
555 terminx 763
    {
1540 terminx 764
        GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(stwidgets.gamelist));
555 terminx 765
        gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
766
        g_signal_connect((gpointer) sel, "changed",
767
                         G_CALLBACK(on_gamelist_selection_changed),
768
                         NULL);
769
    }
194 terminx 770
 
214 terminx 771
    // Associate labels with their controls
1540 terminx 772
    gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.vmode3dlabel), stwidgets.vmode3dcombo);
1544 terminx 773
    gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.inputdevlabel), stwidgets.inputdevcombo);
774
    gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.custommodlabel), stwidgets.custommodcombo);
1540 terminx 775
    gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.gamelabel), stwidgets.gamelist);
194 terminx 776
 
1540 terminx 777
    return stwidgets.startwin;
778
}
194 terminx 779
 
780
 
781
// -- BUILD ENTRY POINTS ------------------------------------------------------
782
 
1205 terminx 783
int32_t startwin_open(void)
194 terminx 784
{
214 terminx 785
    if (!gtkenabled) return 0;
1540 terminx 786
    if (stwidgets.startwin) return 1;
194 terminx 787
 
1540 terminx 788
    stwidgets.startwin = create_window();
789
    if (stwidgets.startwin)
335 terminx 790
    {
214 terminx 791
        SetPage(TAB_MESSAGES);
1540 terminx 792
        gtk_widget_show_all(stwidgets.startwin);
214 terminx 793
        gtk_main_iteration_do(FALSE);
794
        return 0;
795
    }
796
    return -1;
194 terminx 797
}
798
 
1205 terminx 799
int32_t startwin_close(void)
194 terminx 800
{
214 terminx 801
    if (!gtkenabled) return 0;
1540 terminx 802
    if (!stwidgets.startwin) return 1;
803
    gtk_widget_destroy(stwidgets.startwin);
804
    stwidgets.startwin = NULL;
214 terminx 805
    return 0;
194 terminx 806
}
807
 
1205 terminx 808
int32_t startwin_puts(const char *str)
194 terminx 809
{
214 terminx 810
    GtkWidget *textview;
811
    GtkTextBuffer *textbuffer;
812
    GtkTextIter enditer;
813
    GtkTextMark *mark;
814
    const char *aptr, *bptr;
194 terminx 815
 
214 terminx 816
    if (!gtkenabled || !str) return 0;
1540 terminx 817
    if (!stwidgets.startwin) return 1;
818
    if (!(textview = stwidgets.messagestext)) return -1;
214 terminx 819
    textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
194 terminx 820
 
214 terminx 821
    gtk_text_buffer_get_end_iter(textbuffer, &enditer);
335 terminx 822
    for (aptr = bptr = str; *aptr != 0;)
823
    {
824
        switch (*bptr)
825
        {
337 terminx 826
        case '\b':
827
            if (bptr > aptr)
828
                gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1);
194 terminx 829
#if GTK_CHECK_VERSION(2,6,0)
337 terminx 830
            gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE);
194 terminx 831
#else
337 terminx 832
            {
833
                GtkTextIter iter2 = enditer;
834
                gtk_text_iter_backward_cursor_position(&iter2);
835
                //FIXME: this seems be deleting one too many chars somewhere!
836
                if (!gtk_text_iter_equal(&iter2, &enditer))
837
                    gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE);
838
            }
194 terminx 839
#endif
337 terminx 840
            aptr = ++bptr;
841
            break;
842
        case 0:
843
            if (bptr > aptr)
844
                gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr));
845
            aptr = bptr;
846
            break;
847
        case '\r':      // FIXME
848
        default:
849
            bptr++;
850
            break;
214 terminx 851
        }
852
    }
194 terminx 853
 
214 terminx 854
    mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1);
855
    gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0);
856
    gtk_text_buffer_delete_mark(textbuffer, mark);
194 terminx 857
 
214 terminx 858
    return 0;
194 terminx 859
}
860
 
1205 terminx 861
int32_t startwin_settitle(const char *title)
194 terminx 862
{
214 terminx 863
    if (!gtkenabled) return 0;
1540 terminx 864
    if (!stwidgets.startwin) return 1;
865
    gtk_window_set_title(GTK_WINDOW(stwidgets.startwin), title);
214 terminx 866
    return 0;
194 terminx 867
}
868
 
1205 terminx 869
int32_t startwin_idle(void *s)
194 terminx 870
{
654 terminx 871
    UNREFERENCED_PARAMETER(s);
214 terminx 872
    if (!gtkenabled) return 0;
1540 terminx 873
    //if (!stwidgets.startwin) return 1;
333 terminx 874
    gtk_main_iteration_do(FALSE);
214 terminx 875
    return 0;
194 terminx 876
}
877
 
1205 terminx 878
int32_t startwin_run(void)
194 terminx 879
{
622 terminx 880
    if (!gtkenabled) return 1;
1540 terminx 881
    if (!stwidgets.startwin) return 1;
194 terminx 882
 
214 terminx 883
    SetPage(TAB_CONFIG);
194 terminx 884
 
563 terminx 885
    settings.xdim3d = ud.config.ScreenWidth;
886
    settings.ydim3d = ud.config.ScreenHeight;
887
    settings.bpp3d = ud.config.ScreenBPP;
1544 terminx 888
    settings.fullscreen = ud.config.ScreenMode;
563 terminx 889
    settings.usemouse = ud.config.UseMouse;
890
    settings.usejoy = ud.config.UseJoystick;
1587 terminx 891
    settings.custommoddir = g_modDir;
1544 terminx 892
    settings.forcesetup = ud.config.ForceSetup;
1143 terminx 893
    settings.game = g_gameType;
2726 hendricks2 894
    Bstrncpyz(settings.selectedgrp, G_GrpFile(), BMAX_PATH);
1540 terminx 895
    if (ud.config.NoAutoLoad) settings.autoload = FALSE;
896
    else settings.autoload = TRUE;
1660 terminx 897
#ifdef POLYMER
3814 terminx 898
    if (glrendmode == REND_POLYMER)
1540 terminx 899
    {
1593 terminx 900
        if (settings.bpp3d == 8) settings.bpp3d = 32;
901
        settings.polymer = TRUE;
1540 terminx 902
    }
1660 terminx 903
#endif
1544 terminx 904
    PopulateForm(ALL);
194 terminx 905
 
214 terminx 906
    gtk_main();
907
 
908
    SetPage(TAB_MESSAGES);
1540 terminx 909
    if (retval) // launch the game with these parameters
335 terminx 910
    {
563 terminx 911
        ud.config.ScreenWidth = settings.xdim3d;
912
        ud.config.ScreenHeight = settings.ydim3d;
913
        ud.config.ScreenBPP = settings.bpp3d;
1544 terminx 914
        ud.config.ScreenMode = settings.fullscreen;
563 terminx 915
        ud.config.UseMouse = settings.usemouse;
916
        ud.config.UseJoystick = settings.usejoy;
1544 terminx 917
        ud.config.ForceSetup = settings.forcesetup;
2563 helixhorne 918
 
919
        clearGrpNamePtr();
920
        g_grpNamePtr = dup_filename(settings.selectedgrp);
921
 
1143 terminx 922
        g_gameType = settings.game;
1544 terminx 923
        if (settings.custommoddir != NULL)
1587 terminx 924
            Bstrcpy(g_modDir, settings.custommoddir);
925
        else Bsprintf(g_modDir, "/");
1593 terminx 926
 
1540 terminx 927
        if (settings.autoload) ud.config.NoAutoLoad = FALSE;
928
        else ud.config.NoAutoLoad = TRUE;
886 terminx 929
 
3654 terminx 930
        {
3708 terminx 931
            struct grpfile *grp;
932
            for (grp = listgrps; grp; grp=grp->next)
933
                if (settings.crcval == grp->crcval) break;
934
 
935
            if (grp)
936
            {
937
                g_gameNamePtr = grp->name;
938
                g_dependencyCRC = grp->dependency;
939
 
940
                if (grp->scriptname && g_scriptNamePtr == NULL)
941
                    g_scriptNamePtr = dup_filename(grp->scriptname);
942
 
943
                if (grp->defname && g_defNamePtr == NULL)
944
                    g_defNamePtr = dup_filename(grp->defname);
945
            }
3654 terminx 946
        }
214 terminx 947
    }
948
 
949
    return retval;
194 terminx 950
}