Subversion Repositories eduke32

Rev

Rev 3168 | Rev 3708 | 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;
1205 terminx 444
        int32_t i;
555 terminx 445
        GtkListStore *list;
446
        GtkTreeIter iter;
447
        GtkTreeView *gamelist;
194 terminx 448
 
1540 terminx 449
        gamelist = GTK_TREE_VIEW(stwidgets.gamelist);
555 terminx 450
        list = GTK_LIST_STORE(gtk_tree_view_get_model(gamelist));
451
        gtk_list_store_clear(list);
194 terminx 452
 
555 terminx 453
        for (fg = foundgrps; fg; fg=fg->next)
454
        {
2543 helixhorne 455
            for (i = 0; i<NUMGRPFILES; i++)
555 terminx 456
                if (fg->crcval == grpfiles[i].crcval) break;
2543 helixhorne 457
            if (i == NUMGRPFILES) continue;     // unrecognised grp file
194 terminx 458
 
555 terminx 459
            gtk_list_store_append(list, &iter);
460
            gtk_list_store_set(list, &iter, 0, grpfiles[i].name, 1, fg->name, 2, (gpointer)fg, -1);
461
            if (!Bstrcasecmp(fg->name, settings.selectedgrp))
462
            {
463
                GtkTreeSelection *sel = gtk_tree_view_get_selection(gamelist);
3168 helixhorne 464
                g_signal_handlers_block_by_func(sel, (gpointer)on_gamelist_selection_changed, NULL);
555 terminx 465
                gtk_tree_selection_select_iter(sel, &iter);
3168 helixhorne 466
                g_signal_handlers_unblock_by_func(sel, (gpointer)on_gamelist_selection_changed, NULL);
555 terminx 467
            }
214 terminx 468
        }
469
    }
194 terminx 470
}
471
 
555 terminx 472
static gint name_sorter(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data)
473
{
474
    gchar *as, *bs;
475
    gint r;
654 terminx 476
    UNREFERENCED_PARAMETER(user_data);
555 terminx 477
    gtk_tree_model_get(model, a, 0, &as, -1);
478
    gtk_tree_model_get(model, b, 0, &bs, -1);
479
 
480
    r = g_utf8_collate(as,bs);
481
 
482
    g_free(as);
483
    g_free(bs);
484
 
485
    return r;
486
}
487
 
194 terminx 488
static GtkWidget *create_window(void)
489
{
214 terminx 490
    // Basic window
1540 terminx 491
    stwidgets.startwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
492
    gtk_window_set_title(GTK_WINDOW(stwidgets.startwin), apptitle);     // NOTE: use global app title
493
    gtk_window_set_position(GTK_WINDOW(stwidgets.startwin), GTK_WIN_POS_CENTER);
494
    gtk_window_set_resizable(GTK_WINDOW(stwidgets.startwin), FALSE);
495
    gtk_window_set_type_hint(GTK_WINDOW(stwidgets.startwin), GDK_WINDOW_TYPE_HINT_DIALOG);
194 terminx 496
 
214 terminx 497
    // Horizontal layout of banner and controls
1540 terminx 498
    stwidgets.hlayout = gtk_hbox_new(FALSE, 0);
499
    gtk_container_add(GTK_CONTAINER(stwidgets.startwin), stwidgets.hlayout);
194 terminx 500
 
1540 terminx 501
    // banner
214 terminx 502
    {
503
        GdkPixbuf *pixbuf = load_banner();
1540 terminx 504
        stwidgets.banner = gtk_image_new_from_pixbuf(pixbuf);
214 terminx 505
        g_object_unref((gpointer)pixbuf);
506
    }
1540 terminx 507
    gtk_box_pack_start(GTK_BOX(stwidgets.hlayout), stwidgets.banner, FALSE, FALSE, 0);
508
    gtk_misc_set_alignment(GTK_MISC(stwidgets.banner), 0.5, 0);
194 terminx 509
 
214 terminx 510
    // Vertical layout of tab control and start+cancel buttons
1540 terminx 511
    stwidgets.vlayout = gtk_vbox_new(FALSE, 0);
512
    gtk_box_pack_start(GTK_BOX(stwidgets.hlayout), stwidgets.vlayout, TRUE, TRUE, 0);
194 terminx 513
 
214 terminx 514
    // Tab control
1540 terminx 515
    stwidgets.tabs = gtk_notebook_new();
516
    gtk_box_pack_start(GTK_BOX(stwidgets.vlayout), stwidgets.tabs, TRUE, TRUE, 0);
517
    gtk_container_set_border_width(GTK_CONTAINER(stwidgets.tabs), 4);
1593 terminx 518
 
1540 terminx 519
    // layout table of config page
1593 terminx 520
    stwidgets.configtlayout = gtk_table_new(6, 3, FALSE);
521
    gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.configtlayout);
522
 
523
    // 3D video mode LabelText
524
    stwidgets.vmode3dlabel = gtk_label_new_with_mnemonic("_Video mode:");
525
    gtk_misc_set_alignment(GTK_MISC(stwidgets.vmode3dlabel), 0.3, 0);
1785 terminx 526
#ifdef POLYMER
3168 helixhorne 527
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dlabel, 0,1, 0,1, GTK_FILL, (GtkAttachOptions)0, 4, 0);
1785 terminx 528
#else
3168 helixhorne 529
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dlabel, 0,1, 0,1, GTK_FILL, (GtkAttachOptions)0, 4, 7);
1785 terminx 530
#endif
1593 terminx 531
 
532
    // 3D video mode combo
214 terminx 533
    {
534
        GtkListStore *list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
535
        GtkCellRenderer *cell;
194 terminx 536
 
1540 terminx 537
        stwidgets.vmode3dcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list));
214 terminx 538
        g_object_unref(G_OBJECT(list));
194 terminx 539
 
214 terminx 540
        cell = gtk_cell_renderer_text_new();
1540 terminx 541
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.vmode3dcombo), cell, FALSE);
542
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.vmode3dcombo), cell, "text", 0, NULL);
214 terminx 543
    }
1786 terminx 544
 
545
#ifdef POLYMER
3168 helixhorne 546
   gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dcombo, 1,2, 0,1,
547
       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 4, 0);
1786 terminx 548
#else
3168 helixhorne 549
   gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dcombo, 1,2, 0,1, GTK_EXPAND | GTK_FILL, (GtkAttachOptions)0, 4, 7);
1786 terminx 550
#endif
194 terminx 551
 
1540 terminx 552
    // Fullscreen checkbox
1593 terminx 553
    stwidgets.displayvlayout = gtk_vbox_new(TRUE, 0);
1785 terminx 554
#ifdef POLYMER
3168 helixhorne 555
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.displayvlayout, 2,3, 0,1, GTK_FILL, (GtkAttachOptions)0, 4, 0);
1785 terminx 556
#else
3168 helixhorne 557
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.displayvlayout, 2,3, 0,1, GTK_FILL, (GtkAttachOptions)0, 4, 7);
1785 terminx 558
#endif
559
 
1593 terminx 560
    stwidgets.fullscreencheck = gtk_check_button_new_with_mnemonic("_Fullscreen");
561
    gtk_box_pack_start(GTK_BOX(stwidgets.displayvlayout), stwidgets.fullscreencheck, FALSE, FALSE, 0);
562
 
1660 terminx 563
#ifdef POLYMER
1593 terminx 564
    // Polymer checkbox
1540 terminx 565
    stwidgets.polymercheck = gtk_check_button_new_with_mnemonic("_Polymer");
1593 terminx 566
    gtk_box_pack_start(GTK_BOX(stwidgets.displayvlayout), stwidgets.polymercheck, FALSE, FALSE, 0);
1660 terminx 567
#endif
194 terminx 568
 
1593 terminx 569
    // Input devices LabelText
1544 terminx 570
    stwidgets.inputdevlabel = gtk_label_new_with_mnemonic("_Input devices:");
1593 terminx 571
    gtk_misc_set_alignment(GTK_MISC(stwidgets.inputdevlabel), 0.3, 0);
3168 helixhorne 572
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.inputdevlabel, 0,1, 1,2, GTK_FILL, (GtkAttachOptions)0, 4, 0);
1593 terminx 573
 
574
    // Input devices combo
575
    {
1544 terminx 576
        GtkListStore *list = gtk_list_store_new(1, G_TYPE_STRING);
577
        GtkCellRenderer *cell;
578
 
579
        stwidgets.inputdevcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list));
580
        g_object_unref(G_OBJECT(list));
581
 
582
        cell = gtk_cell_renderer_text_new();
583
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.inputdevcombo), cell, FALSE);
584
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.inputdevcombo), cell, "text", 0, NULL);
585
    }
3168 helixhorne 586
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.inputdevcombo, 1,2, 1,2,
587
        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 4, 0);
1593 terminx 588
 
589
    // Custom mod LabelText
1660 terminx 590
    stwidgets.custommodlabel = gtk_label_new_with_mnemonic("Custom _game:");
1593 terminx 591
    gtk_misc_set_alignment(GTK_MISC(stwidgets.custommodlabel), 0.3, 0);
3168 helixhorne 592
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.custommodlabel, 0,1, 2,3, GTK_FILL, (GtkAttachOptions)0, 4, 7);
1593 terminx 593
 
594
    // Custom mod combo
595
    {
1544 terminx 596
        GtkListStore *list = gtk_list_store_new(1, G_TYPE_STRING);
597
        GtkCellRenderer *cell;
1540 terminx 598
 
1544 terminx 599
        stwidgets.custommodcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list));
600
        g_object_unref(G_OBJECT(list));
601
 
602
        cell = gtk_cell_renderer_text_new();
603
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.custommodcombo), cell, FALSE);
604
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.custommodcombo), cell, "text", 0, NULL);
605
    }
3168 helixhorne 606
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.custommodcombo, 1,2, 2,3,
607
        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 4, 7);
1593 terminx 608
 
609
    // Empty horizontal layout
610
    stwidgets.emptyhlayout = gtk_hbox_new(TRUE, 0);
3168 helixhorne 611
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.emptyhlayout, 0,3, 3,4, (GtkAttachOptions)0,
612
        (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 4, 0);
1593 terminx 613
 
1540 terminx 614
    // Autoload checkbox
1593 terminx 615
    stwidgets.autoloadcheck = gtk_check_button_new_with_mnemonic("_Enable \"autoload\" folder");
3168 helixhorne 616
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.autoloadcheck, 0,3, 4,5, GTK_FILL, (GtkAttachOptions)0, 2, 2);
1593 terminx 617
 
618
    // Always show config checkbox
1544 terminx 619
    stwidgets.alwaysshowcheck = gtk_check_button_new_with_mnemonic("_Always show this window at startup");
3168 helixhorne 620
    gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.alwaysshowcheck, 0,3, 5,6, GTK_FILL, (GtkAttachOptions)0, 2, 2);
1540 terminx 621
 
214 terminx 622
    // Configuration tab
1540 terminx 623
    stwidgets.configtab = gtk_label_new("Configuration");
624
    gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 0), stwidgets.configtab);
194 terminx 625
 
555 terminx 626
    // Game data layout
1540 terminx 627
    stwidgets.gamevlayout = gtk_vbox_new(FALSE, 0);
628
    gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.gamevlayout);
629
    gtk_container_set_border_width(GTK_CONTAINER(stwidgets.gamevlayout), 4);
555 terminx 630
 
1143 terminx 631
    // Game data field LabelText
1660 terminx 632
    stwidgets.gamelabel = gtk_label_new_with_mnemonic("_Game:");
1540 terminx 633
    gtk_box_pack_start(GTK_BOX(stwidgets.gamevlayout), stwidgets.gamelabel, FALSE, FALSE, 0);
634
    gtk_misc_set_alignment(GTK_MISC(stwidgets.gamelabel), 0, 0.5);
555 terminx 635
 
636
    // Game data scrollable area
1540 terminx 637
    stwidgets.gamescroll = gtk_scrolled_window_new(NULL, NULL);
638
    gtk_box_pack_start(GTK_BOX(stwidgets.gamevlayout), stwidgets.gamescroll, TRUE, TRUE, 0);
639
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(stwidgets.gamescroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
640
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(stwidgets.gamescroll), GTK_SHADOW_IN);
555 terminx 641
 
642
    // Game data list
643
    {
644
        GtkListStore *list = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
645
        GtkCellRenderer *cell;
646
        GtkTreeViewColumn *col;
647
 
648
        gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list), 0, name_sorter, NULL, NULL);
649
        gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list), 0, GTK_SORT_ASCENDING);
650
 
1540 terminx 651
        stwidgets.gamelist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list));
555 terminx 652
        g_object_unref(G_OBJECT(list));
653
 
654
        cell = gtk_cell_renderer_text_new();
655
        col = gtk_tree_view_column_new_with_attributes("Game", cell, "text", 0, NULL);
656
        gtk_tree_view_column_set_expand(col, TRUE);
1540 terminx 657
        gtk_tree_view_append_column(GTK_TREE_VIEW(stwidgets.gamelist), col);
555 terminx 658
        col = gtk_tree_view_column_new_with_attributes("GRP file", cell, "text", 1, NULL);
659
        gtk_tree_view_column_set_min_width(col, 64);
1540 terminx 660
        gtk_tree_view_append_column(GTK_TREE_VIEW(stwidgets.gamelist), col);
555 terminx 661
    }
1540 terminx 662
    gtk_container_add(GTK_CONTAINER(stwidgets.gamescroll), stwidgets.gamelist);
1593 terminx 663
 
1540 terminx 664
    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(stwidgets.gamelist), FALSE);
665
    gtk_tree_view_set_enable_search(GTK_TREE_VIEW(stwidgets.gamelist), FALSE);
555 terminx 666
 
667
    // Game tab
1540 terminx 668
    stwidgets.gametab = gtk_label_new("Game");
669
    gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 1), stwidgets.gametab);
555 terminx 670
 
214 terminx 671
    // Messages scrollable area
1540 terminx 672
    stwidgets.messagesscroll = gtk_scrolled_window_new(NULL, NULL);
673
    gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.messagesscroll);
674
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(stwidgets.messagesscroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
194 terminx 675
 
214 terminx 676
    // Messages text area
1540 terminx 677
    stwidgets.messagestext = gtk_text_view_new();
678
    gtk_container_add(GTK_CONTAINER(stwidgets.messagesscroll), stwidgets.messagestext);
679
    gtk_text_view_set_editable(GTK_TEXT_VIEW(stwidgets.messagestext), FALSE);
680
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(stwidgets.messagestext), GTK_WRAP_WORD);
681
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(stwidgets.messagestext), FALSE);
682
    gtk_text_view_set_left_margin(GTK_TEXT_VIEW(stwidgets.messagestext), 2);
683
    gtk_text_view_set_right_margin(GTK_TEXT_VIEW(stwidgets.messagestext), 2);
194 terminx 684
 
214 terminx 685
    // Messages tab
1540 terminx 686
    stwidgets.messagestab = gtk_label_new("Messages");
687
    gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 2), stwidgets.messagestab);
194 terminx 688
 
214 terminx 689
    // Dialogue box buttons layout
1540 terminx 690
    stwidgets.buttons = gtk_hbutton_box_new();
691
    gtk_box_pack_start(GTK_BOX(stwidgets.vlayout), stwidgets.buttons, FALSE, TRUE, 0);
692
    gtk_container_set_border_width(GTK_CONTAINER(stwidgets.buttons), 3);
693
    gtk_button_box_set_layout(GTK_BUTTON_BOX(stwidgets.buttons), GTK_BUTTONBOX_END);
194 terminx 694
 
214 terminx 695
    // Cancel button
1540 terminx 696
    stwidgets.cancelbutton = gtk_button_new();
697
    gtk_container_add(GTK_CONTAINER(stwidgets.buttons), stwidgets.cancelbutton);
698
    GTK_WIDGET_SET_FLAGS(stwidgets.cancelbutton, GTK_CAN_DEFAULT);
194 terminx 699
 
1540 terminx 700
    stwidgets.cancelbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0);
701
    gtk_container_add(GTK_CONTAINER(stwidgets.cancelbutton), stwidgets.cancelbuttonalign);
194 terminx 702
 
1540 terminx 703
    stwidgets.cancelbuttonlayout = gtk_hbox_new(FALSE, 2);
704
    gtk_container_add(GTK_CONTAINER(stwidgets.cancelbuttonalign), stwidgets.cancelbuttonlayout);
194 terminx 705
 
1540 terminx 706
    stwidgets.cancelbuttonicon = gtk_image_new_from_stock("gtk-cancel", GTK_ICON_SIZE_BUTTON);
707
    gtk_box_pack_start(GTK_BOX(stwidgets.cancelbuttonlayout), stwidgets.cancelbuttonicon, FALSE, FALSE, 0);
194 terminx 708
 
1540 terminx 709
    stwidgets.cancelbuttonlabel = gtk_label_new_with_mnemonic("_Cancel");
710
    gtk_box_pack_start(GTK_BOX(stwidgets.cancelbuttonlayout), stwidgets.cancelbuttonlabel, FALSE, FALSE, 0);
194 terminx 711
 
214 terminx 712
    // Start button
1540 terminx 713
    stwidgets.startbutton = gtk_button_new();
714
    gtk_container_add(GTK_CONTAINER(stwidgets.buttons), stwidgets.startbutton);
715
    GTK_WIDGET_SET_FLAGS(stwidgets.startbutton, GTK_CAN_DEFAULT);
194 terminx 716
 
1664 plagman 717
    gtk_window_set_default(GTK_WINDOW(stwidgets.startwin), stwidgets.startbutton);
718
 
1540 terminx 719
    stwidgets.startbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0);
720
    gtk_container_add(GTK_CONTAINER(stwidgets.startbutton), stwidgets.startbuttonalign);
194 terminx 721
 
1540 terminx 722
    stwidgets.startbuttonlayout = gtk_hbox_new(FALSE, 2);
723
    gtk_container_add(GTK_CONTAINER(stwidgets.startbuttonalign), stwidgets.startbuttonlayout);
194 terminx 724
 
1540 terminx 725
    stwidgets.startbuttonicon = gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_BUTTON);
726
    gtk_box_pack_start(GTK_BOX(stwidgets.startbuttonlayout), stwidgets.startbuttonicon, FALSE, FALSE, 0);
194 terminx 727
 
1540 terminx 728
    stwidgets.startbuttonlabel = gtk_label_new_with_mnemonic("_Start");
729
    gtk_box_pack_start(GTK_BOX(stwidgets.startbuttonlayout), stwidgets.startbuttonlabel, FALSE, FALSE, 0);
194 terminx 730
 
214 terminx 731
    // Wire up the signals
1593 terminx 732
    g_signal_connect((gpointer) stwidgets.startwin, "delete_event",
333 terminx 733
                     G_CALLBACK(on_startwin_delete_event),
734
                     NULL);
1593 terminx 735
    g_signal_connect((gpointer) stwidgets.vmode3dcombo, "changed",
1544 terminx 736
                     G_CALLBACK(on_vmode3dcombo_changed),
737
                     NULL);
1593 terminx 738
    g_signal_connect((gpointer) stwidgets.fullscreencheck, "toggled",
333 terminx 739
                     G_CALLBACK(on_fullscreencheck_toggled),
740
                     NULL);
1660 terminx 741
#ifdef POLYMER
1593 terminx 742
    g_signal_connect((gpointer) stwidgets.polymercheck, "toggled",
1540 terminx 743
                     G_CALLBACK(on_polymercheck_toggled),
744
                     NULL);
1660 terminx 745
#endif
1593 terminx 746
    g_signal_connect((gpointer) stwidgets.inputdevcombo, "changed",
1544 terminx 747
                     G_CALLBACK(on_inputdevcombo_changed),
1540 terminx 748
                     NULL);
1593 terminx 749
    g_signal_connect((gpointer) stwidgets.custommodcombo, "changed",
1544 terminx 750
                     G_CALLBACK(on_custommodcombo_changed),
333 terminx 751
                     NULL);
1593 terminx 752
    g_signal_connect((gpointer) stwidgets.autoloadcheck, "toggled",
1544 terminx 753
                     G_CALLBACK(on_autoloadcheck_toggled),
333 terminx 754
                     NULL);
1593 terminx 755
    g_signal_connect((gpointer) stwidgets.alwaysshowcheck, "toggled",
333 terminx 756
                     G_CALLBACK(on_alwaysshowcheck_toggled),
757
                     NULL);
1593 terminx 758
    g_signal_connect((gpointer) stwidgets.cancelbutton, "clicked",
333 terminx 759
                     G_CALLBACK(on_cancelbutton_clicked),
760
                     NULL);
1593 terminx 761
    g_signal_connect((gpointer) stwidgets.startbutton, "clicked",
333 terminx 762
                     G_CALLBACK(on_startbutton_clicked),
763
                     NULL);
555 terminx 764
    {
1540 terminx 765
        GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(stwidgets.gamelist));
555 terminx 766
        gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
767
        g_signal_connect((gpointer) sel, "changed",
768
                         G_CALLBACK(on_gamelist_selection_changed),
769
                         NULL);
770
    }
194 terminx 771
 
214 terminx 772
    // Associate labels with their controls
1540 terminx 773
    gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.vmode3dlabel), stwidgets.vmode3dcombo);
1544 terminx 774
    gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.inputdevlabel), stwidgets.inputdevcombo);
775
    gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.custommodlabel), stwidgets.custommodcombo);
1540 terminx 776
    gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.gamelabel), stwidgets.gamelist);
194 terminx 777
 
1540 terminx 778
    return stwidgets.startwin;
779
}
194 terminx 780
 
781
 
782
// -- BUILD ENTRY POINTS ------------------------------------------------------
783
 
1205 terminx 784
int32_t startwin_open(void)
194 terminx 785
{
214 terminx 786
    if (!gtkenabled) return 0;
1540 terminx 787
    if (stwidgets.startwin) return 1;
194 terminx 788
 
1540 terminx 789
    stwidgets.startwin = create_window();
790
    if (stwidgets.startwin)
335 terminx 791
    {
214 terminx 792
        SetPage(TAB_MESSAGES);
1540 terminx 793
        gtk_widget_show_all(stwidgets.startwin);
214 terminx 794
        gtk_main_iteration_do(FALSE);
795
        return 0;
796
    }
797
    return -1;
194 terminx 798
}
799
 
1205 terminx 800
int32_t startwin_close(void)
194 terminx 801
{
214 terminx 802
    if (!gtkenabled) return 0;
1540 terminx 803
    if (!stwidgets.startwin) return 1;
804
    gtk_widget_destroy(stwidgets.startwin);
805
    stwidgets.startwin = NULL;
214 terminx 806
    return 0;
194 terminx 807
}
808
 
1205 terminx 809
int32_t startwin_puts(const char *str)
194 terminx 810
{
214 terminx 811
    GtkWidget *textview;
812
    GtkTextBuffer *textbuffer;
813
    GtkTextIter enditer;
814
    GtkTextMark *mark;
815
    const char *aptr, *bptr;
194 terminx 816
 
214 terminx 817
    if (!gtkenabled || !str) return 0;
1540 terminx 818
    if (!stwidgets.startwin) return 1;
819
    if (!(textview = stwidgets.messagestext)) return -1;
214 terminx 820
    textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
194 terminx 821
 
214 terminx 822
    gtk_text_buffer_get_end_iter(textbuffer, &enditer);
335 terminx 823
    for (aptr = bptr = str; *aptr != 0;)
824
    {
825
        switch (*bptr)
826
        {
337 terminx 827
        case '\b':
828
            if (bptr > aptr)
829
                gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1);
194 terminx 830
#if GTK_CHECK_VERSION(2,6,0)
337 terminx 831
            gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE);
194 terminx 832
#else
337 terminx 833
            {
834
                GtkTextIter iter2 = enditer;
835
                gtk_text_iter_backward_cursor_position(&iter2);
836
                //FIXME: this seems be deleting one too many chars somewhere!
837
                if (!gtk_text_iter_equal(&iter2, &enditer))
838
                    gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE);
839
            }
194 terminx 840
#endif
337 terminx 841
            aptr = ++bptr;
842
            break;
843
        case 0:
844
            if (bptr > aptr)
845
                gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr));
846
            aptr = bptr;
847
            break;
848
        case '\r':      // FIXME
849
        default:
850
            bptr++;
851
            break;
214 terminx 852
        }
853
    }
194 terminx 854
 
214 terminx 855
    mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1);
856
    gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0);
857
    gtk_text_buffer_delete_mark(textbuffer, mark);
194 terminx 858
 
214 terminx 859
    return 0;
194 terminx 860
}
861
 
1205 terminx 862
int32_t startwin_settitle(const char *title)
194 terminx 863
{
214 terminx 864
    if (!gtkenabled) return 0;
1540 terminx 865
    if (!stwidgets.startwin) return 1;
866
    gtk_window_set_title(GTK_WINDOW(stwidgets.startwin), title);
214 terminx 867
    return 0;
194 terminx 868
}
869
 
1205 terminx 870
int32_t startwin_idle(void *s)
194 terminx 871
{
654 terminx 872
    UNREFERENCED_PARAMETER(s);
214 terminx 873
    if (!gtkenabled) return 0;
1540 terminx 874
    //if (!stwidgets.startwin) return 1;
333 terminx 875
    gtk_main_iteration_do(FALSE);
214 terminx 876
    return 0;
194 terminx 877
}
878
 
1205 terminx 879
int32_t startwin_run(void)
194 terminx 880
{
622 terminx 881
    if (!gtkenabled) return 1;
1540 terminx 882
    if (!stwidgets.startwin) return 1;
194 terminx 883
 
214 terminx 884
    SetPage(TAB_CONFIG);
194 terminx 885
 
563 terminx 886
    settings.xdim3d = ud.config.ScreenWidth;
887
    settings.ydim3d = ud.config.ScreenHeight;
888
    settings.bpp3d = ud.config.ScreenBPP;
1544 terminx 889
    settings.fullscreen = ud.config.ScreenMode;
563 terminx 890
    settings.usemouse = ud.config.UseMouse;
891
    settings.usejoy = ud.config.UseJoystick;
1587 terminx 892
    settings.custommoddir = g_modDir;
1544 terminx 893
    settings.forcesetup = ud.config.ForceSetup;
1143 terminx 894
    settings.game = g_gameType;
2726 hendricks2 895
    Bstrncpyz(settings.selectedgrp, G_GrpFile(), BMAX_PATH);
1540 terminx 896
    if (ud.config.NoAutoLoad) settings.autoload = FALSE;
897
    else settings.autoload = TRUE;
1660 terminx 898
#ifdef POLYMER
1544 terminx 899
    if (glrendmode == RDR_POLYMER)
1540 terminx 900
    {
1593 terminx 901
        if (settings.bpp3d == 8) settings.bpp3d = 32;
902
        settings.polymer = TRUE;
1540 terminx 903
    }
1660 terminx 904
#endif
1544 terminx 905
    PopulateForm(ALL);
194 terminx 906
 
214 terminx 907
    gtk_main();
908
 
909
    SetPage(TAB_MESSAGES);
1540 terminx 910
    if (retval) // launch the game with these parameters
335 terminx 911
    {
1205 terminx 912
        int32_t i;
1593 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
 
2543 helixhorne 933
        for (i = 0; i<NUMGRPFILES; i++) if (settings.crcval == grpfiles[i].crcval) break;
934
        if (i != NUMGRPFILES)
3654 terminx 935
        {
2561 helixhorne 936
            g_gameNamePtr = grpfiles[i].name;
3654 terminx 937
            g_dependencyCRC = grpfiles[i].dependency;
938
            if (grpfiles[i].scriptname && g_scriptNamePtr == NULL)
939
                g_scriptNamePtr = dup_filename(grpfiles[i].scriptname);
940
        }
214 terminx 941
    }
942
 
943
    return retval;
194 terminx 944
}