Subversion Repositories eduke32

Rev

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