Rev 2561 | Rev 2726 | 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" |
||
36 | |||
1544 | terminx | 37 | #define RDR_POLYMOST 3 // sould be defined elsewhere |
38 | #define RDR_POLYMER 4 // sould be defined elsewhere |
||
194 | terminx | 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 | { |
||
1593 | terminx | 158 | glrendmode = RDR_POLYMER; |
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 | { |
||
1593 | terminx | 168 | glrendmode = RDR_POLYMOST; |
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 | { |
||
214 | terminx | 265 | extern const GdkPixdata startbanner_pixdata; |
266 | return gdk_pixbuf_from_pixdata(&startbanner_pixdata, FALSE, NULL); |
||
194 | terminx | 267 | } |
268 | |||
1205 | terminx | 269 | static void SetPage(int32_t n) |
194 | terminx | 270 | { |
1540 | terminx | 271 | if (!gtkenabled || !stwidgets.startwin) return; |
214 | terminx | 272 | mode = n; |
1540 | terminx | 273 | gtk_notebook_set_current_page(GTK_NOTEBOOK(stwidgets.tabs), n); |
194 | terminx | 274 | |
214 | terminx | 275 | // each control in the config page vertical layout plus the start button should be made (in)sensitive |
555 | terminx | 276 | if (n == TAB_CONFIG) n = TRUE; else n = FALSE; |
1540 | terminx | 277 | gtk_widget_set_sensitive(stwidgets.startbutton, n); |
1544 | terminx | 278 | gtk_container_foreach(GTK_CONTAINER(stwidgets.configtlayout), |
1593 | terminx | 279 | (GtkCallback)gtk_widget_set_sensitive, |
280 | (gpointer)&n); |
||
194 | terminx | 281 | } |
282 | |||
1544 | terminx | 283 | static unsigned char GetModsDirNames(GtkListStore *list) |
194 | terminx | 284 | { |
1593 | terminx | 285 | char *homedir; |
286 | char pdir[BMAX_PATH]; |
||
287 | unsigned char iternumb = 0; |
||
288 | CACHE1D_FIND_REC *dirs = NULL; |
||
289 | GtkTreeIter iter; |
||
1544 | terminx | 290 | |
1593 | terminx | 291 | pathsearchmode = 1; |
292 | |||
293 | if ((homedir = Bgethomedir())) |
||
294 | { |
||
295 | Bsnprintf(pdir, sizeof(pdir), "%s/" ".eduke32", homedir); |
||
296 | dirs = klistpath(pdir, "*", CACHE1D_FIND_DIR); |
||
297 | for (dirs=dirs; dirs != NULL; dirs=dirs->next) |
||
298 | { |
||
299 | if ((Bstrcmp(dirs->name, "autoload") == 0) || |
||
300 | (Bstrcmp(dirs->name, "..") == 0) || |
||
301 | (Bstrcmp(dirs->name, ".") == 0)) |
||
302 | continue; |
||
303 | else |
||
304 | { |
||
305 | gtk_list_store_append(list, &iter); |
||
306 | gtk_list_store_set(list, &iter, 0,dirs->name, -1); |
||
307 | iternumb++; |
||
308 | } |
||
309 | } |
||
310 | } |
||
311 | |||
1544 | terminx | 312 | klistfree(dirs); |
313 | dirs = NULL; |
||
1593 | terminx | 314 | |
1544 | terminx | 315 | return iternumb; |
316 | } |
||
317 | |||
318 | static void PopulateForm(unsigned char pgs) |
||
319 | { |
||
320 | if ((pgs == ALL) || (pgs == POPULATE_VIDEO)) |
||
555 | terminx | 321 | { |
1205 | terminx | 322 | int32_t mode3d, i; |
555 | terminx | 323 | GtkListStore *modes3d; |
324 | GtkTreeIter iter; |
||
325 | char buf[64]; |
||
1593 | terminx | 326 | |
555 | terminx | 327 | mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); |
328 | if (mode3d < 0) |
||
335 | terminx | 329 | { |
1205 | terminx | 330 | int32_t i, cd[] = { 32, 24, 16, 15, 8, 0 }; |
1593 | terminx | 331 | |
555 | terminx | 332 | for (i=0; cd[i];) { if (cd[i] >= settings.bpp3d) i++; else break; } |
333 | for (; cd[i]; i++) |
||
334 | { |
||
335 | mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); |
||
336 | if (mode3d < 0) continue; |
||
337 | settings.bpp3d = cd[i]; |
||
338 | break; |
||
339 | } |
||
335 | terminx | 340 | } |
1593 | terminx | 341 | |
1544 | terminx | 342 | modes3d = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(stwidgets.vmode3dcombo))); |
555 | terminx | 343 | gtk_list_store_clear(modes3d); |
344 | |||
345 | for (i=0; i<validmodecnt; i++) |
||
335 | terminx | 346 | { |
555 | terminx | 347 | if (validmode[i].fs != settings.fullscreen) continue; |
348 | |||
349 | // all modes get added to the 3D mode list |
||
584 | terminx | 350 | Bsprintf(buf, "%d x %d %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp); |
555 | terminx | 351 | gtk_list_store_append(modes3d, &iter); |
352 | gtk_list_store_set(modes3d, &iter, 0,buf, 1,i, -1); |
||
353 | if (i == mode3d) |
||
354 | { |
||
1544 | terminx | 355 | g_signal_handlers_block_by_func(stwidgets.vmode3dcombo, on_vmode3dcombo_changed, NULL); |
356 | gtk_combo_box_set_active_iter(GTK_COMBO_BOX(stwidgets.vmode3dcombo), &iter); |
||
357 | g_signal_handlers_unblock_by_func(stwidgets.vmode3dcombo, on_vmode3dcombo_changed, NULL); |
||
555 | terminx | 358 | } |
214 | terminx | 359 | } |
1593 | terminx | 360 | } |
361 | |||
1544 | terminx | 362 | if ((pgs == ALL) || (pgs == POPULATE_CONFIG)) |
1593 | terminx | 363 | { |
1544 | terminx | 364 | GtkListStore *devlist, *modsdir; |
365 | GtkTreeIter iter; |
||
366 | GtkTreePath *path; |
||
367 | char *value; |
||
368 | unsigned char i, r = 0; |
||
1593 | terminx | 369 | const char *availabledev[] = |
370 | { |
||
371 | "Keyboard only", |
||
372 | "Keyboard and mouse", |
||
373 | "Keyboard and joystick", |
||
374 | "All supported devices" |
||
375 | }; |
||
376 | |||
1544 | terminx | 377 | // populate input devices combo |
1593 | terminx | 378 | devlist = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(stwidgets.inputdevcombo))); |
379 | gtk_list_store_clear(devlist); |
||
380 | |||
381 | for (i=0; i<(int32_t)G_N_ELEMENTS(availabledev); i++) |
||
382 | { |
||
383 | gtk_list_store_append(devlist, &iter); |
||
1544 | terminx | 384 | gtk_list_store_set(devlist, &iter, 0,availabledev[i], -1); |
385 | } |
||
1593 | terminx | 386 | switch (settings.usemouse) |
387 | { |
||
388 | case 0: if (settings.usejoy) |
||
389 | gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_JOYSTICK); |
||
390 | else |
||
391 | gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_KB); |
||
392 | break; |
||
393 | case 1: if (settings.usejoy) |
||
394 | gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_ALL); |
||
395 | else |
||
396 | gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.inputdevcombo), INPUT_MOUSE); |
||
397 | break; |
||
398 | } |
||
399 | |||
400 | // populate custom mod combo |
||
401 | modsdir = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(stwidgets.custommodcombo))); |
||
402 | gtk_list_store_clear(modsdir); |
||
403 | |||
404 | gtk_list_store_append(modsdir, &iter); |
||
1544 | terminx | 405 | gtk_list_store_set(modsdir, &iter, 0,"None", -1); |
1593 | terminx | 406 | r = GetModsDirNames(modsdir); |
1544 | terminx | 407 | |
1593 | terminx | 408 | for (i=0; i<=r; i++) |
409 | { |
||
410 | path = gtk_tree_path_new_from_indices(i, -1); |
||
411 | gtk_tree_model_get_iter(GTK_TREE_MODEL(modsdir), &iter, path); |
||
412 | gtk_tree_model_get(GTK_TREE_MODEL(modsdir), &iter, 0,&value, -1); |
||
1544 | terminx | 413 | |
1593 | terminx | 414 | if (Bstrcmp(settings.custommoddir, "/") == 0) |
415 | { |
||
416 | gtk_combo_box_set_active(GTK_COMBO_BOX(stwidgets.custommodcombo), NONE); |
||
417 | settings.custommoddir = NULL; |
||
418 | |||
419 | break; |
||
420 | } |
||
421 | if (Bstrcmp(settings.custommoddir, value) == 0) |
||
422 | { |
||
423 | gtk_combo_box_set_active_iter(GTK_COMBO_BOX(stwidgets.custommodcombo), |
||
424 | &iter); |
||
425 | |||
426 | break; |
||
427 | } |
||
428 | } |
||
429 | |||
1544 | terminx | 430 | // populate check buttons |
1593 | terminx | 431 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.fullscreencheck), settings.fullscreen); |
1660 | terminx | 432 | #ifdef POLYMER |
1593 | terminx | 433 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.polymercheck), settings.polymer); |
1660 | terminx | 434 | #endif |
1593 | terminx | 435 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.autoloadcheck), settings.autoload); |
1540 | terminx | 436 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stwidgets.alwaysshowcheck), settings.forcesetup); |
1593 | terminx | 437 | } |
194 | terminx | 438 | |
1544 | terminx | 439 | if ((pgs == ALL) || (pgs == POPULATE_GAME)) |
555 | terminx | 440 | { |
441 | struct grpfile *fg; |
||
1205 | terminx | 442 | int32_t i; |
555 | terminx | 443 | GtkListStore *list; |
444 | GtkTreeIter iter; |
||
445 | GtkTreeView *gamelist; |
||
194 | terminx | 446 | |
1540 | terminx | 447 | gamelist = GTK_TREE_VIEW(stwidgets.gamelist); |
555 | terminx | 448 | list = GTK_LIST_STORE(gtk_tree_view_get_model(gamelist)); |
449 | gtk_list_store_clear(list); |
||
194 | terminx | 450 | |
555 | terminx | 451 | for (fg = foundgrps; fg; fg=fg->next) |
452 | { |
||
2543 | helixhorne | 453 | for (i = 0; i<NUMGRPFILES; i++) |
555 | terminx | 454 | if (fg->crcval == grpfiles[i].crcval) break; |
2543 | helixhorne | 455 | if (i == NUMGRPFILES) continue; // unrecognised grp file |
194 | terminx | 456 | |
555 | terminx | 457 | gtk_list_store_append(list, &iter); |
458 | gtk_list_store_set(list, &iter, 0, grpfiles[i].name, 1, fg->name, 2, (gpointer)fg, -1); |
||
459 | if (!Bstrcasecmp(fg->name, settings.selectedgrp)) |
||
460 | { |
||
461 | GtkTreeSelection *sel = gtk_tree_view_get_selection(gamelist); |
||
462 | g_signal_handlers_block_by_func(sel, on_gamelist_selection_changed, NULL); |
||
463 | gtk_tree_selection_select_iter(sel, &iter); |
||
464 | g_signal_handlers_unblock_by_func(sel, on_gamelist_selection_changed, NULL); |
||
465 | } |
||
214 | terminx | 466 | } |
467 | } |
||
194 | terminx | 468 | } |
469 | |||
555 | terminx | 470 | static gint name_sorter(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data) |
471 | { |
||
472 | gchar *as, *bs; |
||
473 | gint r; |
||
654 | terminx | 474 | UNREFERENCED_PARAMETER(user_data); |
555 | terminx | 475 | gtk_tree_model_get(model, a, 0, &as, -1); |
476 | gtk_tree_model_get(model, b, 0, &bs, -1); |
||
477 | |||
478 | r = g_utf8_collate(as,bs); |
||
479 | |||
480 | g_free(as); |
||
481 | g_free(bs); |
||
482 | |||
483 | return r; |
||
484 | } |
||
485 | |||
194 | terminx | 486 | static GtkWidget *create_window(void) |
487 | { |
||
214 | terminx | 488 | // Basic window |
1540 | terminx | 489 | stwidgets.startwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
490 | gtk_window_set_title(GTK_WINDOW(stwidgets.startwin), apptitle); // NOTE: use global app title |
||
491 | gtk_window_set_position(GTK_WINDOW(stwidgets.startwin), GTK_WIN_POS_CENTER); |
||
492 | gtk_window_set_resizable(GTK_WINDOW(stwidgets.startwin), FALSE); |
||
493 | gtk_window_set_type_hint(GTK_WINDOW(stwidgets.startwin), GDK_WINDOW_TYPE_HINT_DIALOG); |
||
194 | terminx | 494 | |
214 | terminx | 495 | // Horizontal layout of banner and controls |
1540 | terminx | 496 | stwidgets.hlayout = gtk_hbox_new(FALSE, 0); |
497 | gtk_container_add(GTK_CONTAINER(stwidgets.startwin), stwidgets.hlayout); |
||
194 | terminx | 498 | |
1540 | terminx | 499 | // banner |
214 | terminx | 500 | { |
501 | GdkPixbuf *pixbuf = load_banner(); |
||
1540 | terminx | 502 | stwidgets.banner = gtk_image_new_from_pixbuf(pixbuf); |
214 | terminx | 503 | g_object_unref((gpointer)pixbuf); |
504 | } |
||
1540 | terminx | 505 | gtk_box_pack_start(GTK_BOX(stwidgets.hlayout), stwidgets.banner, FALSE, FALSE, 0); |
506 | gtk_misc_set_alignment(GTK_MISC(stwidgets.banner), 0.5, 0); |
||
194 | terminx | 507 | |
214 | terminx | 508 | // Vertical layout of tab control and start+cancel buttons |
1540 | terminx | 509 | stwidgets.vlayout = gtk_vbox_new(FALSE, 0); |
510 | gtk_box_pack_start(GTK_BOX(stwidgets.hlayout), stwidgets.vlayout, TRUE, TRUE, 0); |
||
194 | terminx | 511 | |
214 | terminx | 512 | // Tab control |
1540 | terminx | 513 | stwidgets.tabs = gtk_notebook_new(); |
514 | gtk_box_pack_start(GTK_BOX(stwidgets.vlayout), stwidgets.tabs, TRUE, TRUE, 0); |
||
515 | gtk_container_set_border_width(GTK_CONTAINER(stwidgets.tabs), 4); |
||
1593 | terminx | 516 | |
1540 | terminx | 517 | // layout table of config page |
1593 | terminx | 518 | stwidgets.configtlayout = gtk_table_new(6, 3, FALSE); |
519 | gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.configtlayout); |
||
520 | |||
521 | // 3D video mode LabelText |
||
522 | stwidgets.vmode3dlabel = gtk_label_new_with_mnemonic("_Video mode:"); |
||
523 | gtk_misc_set_alignment(GTK_MISC(stwidgets.vmode3dlabel), 0.3, 0); |
||
1785 | terminx | 524 | #ifdef POLYMER |
1593 | terminx | 525 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dlabel, 0,1, 0,1, GTK_FILL, 0, 4, 0); |
1785 | terminx | 526 | #else |
527 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dlabel, 0,1, 0,1, GTK_FILL, 0, 4, 7); |
||
528 | #endif |
||
1593 | terminx | 529 | |
530 | // 3D video mode combo |
||
214 | terminx | 531 | { |
532 | GtkListStore *list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); |
||
533 | GtkCellRenderer *cell; |
||
194 | terminx | 534 | |
1540 | terminx | 535 | stwidgets.vmode3dcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list)); |
214 | terminx | 536 | g_object_unref(G_OBJECT(list)); |
194 | terminx | 537 | |
214 | terminx | 538 | cell = gtk_cell_renderer_text_new(); |
1540 | terminx | 539 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.vmode3dcombo), cell, FALSE); |
540 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.vmode3dcombo), cell, "text", 0, NULL); |
||
214 | terminx | 541 | } |
1786 | terminx | 542 | |
543 | #ifdef POLYMER |
||
544 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dcombo, 1,2, 0,1, GTK_EXPAND | GTK_FILL, 0, 4, 0); |
||
545 | #else |
||
546 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dcombo, 1,2, 0,1, GTK_EXPAND | GTK_FILL, 0, 4, 7); |
||
547 | #endif |
||
194 | terminx | 548 | |
1540 | terminx | 549 | // Fullscreen checkbox |
1593 | terminx | 550 | stwidgets.displayvlayout = gtk_vbox_new(TRUE, 0); |
1785 | terminx | 551 | #ifdef POLYMER |
1593 | terminx | 552 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.displayvlayout, 2,3, 0,1, GTK_FILL, 0, 4, 0); |
1785 | terminx | 553 | #else |
554 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.displayvlayout, 2,3, 0,1, GTK_FILL, 0, 4, 7); |
||
555 | #endif |
||
556 | |||
1593 | terminx | 557 | stwidgets.fullscreencheck = gtk_check_button_new_with_mnemonic("_Fullscreen"); |
558 | gtk_box_pack_start(GTK_BOX(stwidgets.displayvlayout), stwidgets.fullscreencheck, FALSE, FALSE, 0); |
||
559 | |||
1660 | terminx | 560 | #ifdef POLYMER |
1593 | terminx | 561 | // Polymer checkbox |
1540 | terminx | 562 | stwidgets.polymercheck = gtk_check_button_new_with_mnemonic("_Polymer"); |
1593 | terminx | 563 | gtk_box_pack_start(GTK_BOX(stwidgets.displayvlayout), stwidgets.polymercheck, FALSE, FALSE, 0); |
1660 | terminx | 564 | #endif |
194 | terminx | 565 | |
1593 | terminx | 566 | // Input devices LabelText |
1544 | terminx | 567 | stwidgets.inputdevlabel = gtk_label_new_with_mnemonic("_Input devices:"); |
1593 | terminx | 568 | gtk_misc_set_alignment(GTK_MISC(stwidgets.inputdevlabel), 0.3, 0); |
569 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.inputdevlabel, 0,1, 1,2, GTK_FILL, 0, 4, 0); |
||
570 | |||
571 | // Input devices combo |
||
572 | { |
||
1544 | terminx | 573 | GtkListStore *list = gtk_list_store_new(1, G_TYPE_STRING); |
574 | GtkCellRenderer *cell; |
||
575 | |||
576 | stwidgets.inputdevcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list)); |
||
577 | g_object_unref(G_OBJECT(list)); |
||
578 | |||
579 | cell = gtk_cell_renderer_text_new(); |
||
580 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.inputdevcombo), cell, FALSE); |
||
581 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.inputdevcombo), cell, "text", 0, NULL); |
||
582 | } |
||
1593 | terminx | 583 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.inputdevcombo, 1,2, 1,2, GTK_EXPAND | GTK_FILL, 0, 4, 0); |
584 | |||
585 | // Custom mod LabelText |
||
1660 | terminx | 586 | stwidgets.custommodlabel = gtk_label_new_with_mnemonic("Custom _game:"); |
1593 | terminx | 587 | gtk_misc_set_alignment(GTK_MISC(stwidgets.custommodlabel), 0.3, 0); |
588 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.custommodlabel, 0,1, 2,3, GTK_FILL, 0, 4, 7); |
||
589 | |||
590 | // Custom mod combo |
||
591 | { |
||
1544 | terminx | 592 | GtkListStore *list = gtk_list_store_new(1, G_TYPE_STRING); |
593 | GtkCellRenderer *cell; |
||
1540 | terminx | 594 | |
1544 | terminx | 595 | stwidgets.custommodcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list)); |
596 | g_object_unref(G_OBJECT(list)); |
||
597 | |||
598 | cell = gtk_cell_renderer_text_new(); |
||
599 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.custommodcombo), cell, FALSE); |
||
600 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.custommodcombo), cell, "text", 0, NULL); |
||
601 | } |
||
1593 | terminx | 602 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.custommodcombo, 1,2, 2,3, GTK_EXPAND | GTK_FILL, 0, 4, 7); |
603 | |||
604 | // Empty horizontal layout |
||
605 | stwidgets.emptyhlayout = gtk_hbox_new(TRUE, 0); |
||
606 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.emptyhlayout, 0,3, 3,4, 0, GTK_EXPAND | GTK_FILL, 4, 0); |
||
607 | |||
1540 | terminx | 608 | // Autoload checkbox |
1593 | terminx | 609 | stwidgets.autoloadcheck = gtk_check_button_new_with_mnemonic("_Enable \"autoload\" folder"); |
610 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.autoloadcheck, 0,3, 4,5, GTK_FILL, 0, 2, 2); |
||
611 | |||
612 | // Always show config checkbox |
||
1544 | terminx | 613 | stwidgets.alwaysshowcheck = gtk_check_button_new_with_mnemonic("_Always show this window at startup"); |
1593 | terminx | 614 | gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.alwaysshowcheck, 0,3, 5,6, GTK_FILL, 0, 2, 2); |
1540 | terminx | 615 | |
214 | terminx | 616 | // Configuration tab |
1540 | terminx | 617 | stwidgets.configtab = gtk_label_new("Configuration"); |
618 | gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 0), stwidgets.configtab); |
||
194 | terminx | 619 | |
555 | terminx | 620 | // Game data layout |
1540 | terminx | 621 | stwidgets.gamevlayout = gtk_vbox_new(FALSE, 0); |
622 | gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.gamevlayout); |
||
623 | gtk_container_set_border_width(GTK_CONTAINER(stwidgets.gamevlayout), 4); |
||
555 | terminx | 624 | |
1143 | terminx | 625 | // Game data field LabelText |
1660 | terminx | 626 | stwidgets.gamelabel = gtk_label_new_with_mnemonic("_Game:"); |
1540 | terminx | 627 | gtk_box_pack_start(GTK_BOX(stwidgets.gamevlayout), stwidgets.gamelabel, FALSE, FALSE, 0); |
628 | gtk_misc_set_alignment(GTK_MISC(stwidgets.gamelabel), 0, 0.5); |
||
555 | terminx | 629 | |
630 | // Game data scrollable area |
||
1540 | terminx | 631 | stwidgets.gamescroll = gtk_scrolled_window_new(NULL, NULL); |
632 | gtk_box_pack_start(GTK_BOX(stwidgets.gamevlayout), stwidgets.gamescroll, TRUE, TRUE, 0); |
||
633 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(stwidgets.gamescroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); |
||
634 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(stwidgets.gamescroll), GTK_SHADOW_IN); |
||
555 | terminx | 635 | |
636 | // Game data list |
||
637 | { |
||
638 | GtkListStore *list = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); |
||
639 | GtkCellRenderer *cell; |
||
640 | GtkTreeViewColumn *col; |
||
641 | |||
642 | gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list), 0, name_sorter, NULL, NULL); |
||
643 | gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list), 0, GTK_SORT_ASCENDING); |
||
644 | |||
1540 | terminx | 645 | stwidgets.gamelist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list)); |
555 | terminx | 646 | g_object_unref(G_OBJECT(list)); |
647 | |||
648 | cell = gtk_cell_renderer_text_new(); |
||
649 | col = gtk_tree_view_column_new_with_attributes("Game", cell, "text", 0, NULL); |
||
650 | gtk_tree_view_column_set_expand(col, TRUE); |
||
1540 | terminx | 651 | gtk_tree_view_append_column(GTK_TREE_VIEW(stwidgets.gamelist), col); |
555 | terminx | 652 | col = gtk_tree_view_column_new_with_attributes("GRP file", cell, "text", 1, NULL); |
653 | gtk_tree_view_column_set_min_width(col, 64); |
||
1540 | terminx | 654 | gtk_tree_view_append_column(GTK_TREE_VIEW(stwidgets.gamelist), col); |
555 | terminx | 655 | } |
1540 | terminx | 656 | gtk_container_add(GTK_CONTAINER(stwidgets.gamescroll), stwidgets.gamelist); |
1593 | terminx | 657 | |
1540 | terminx | 658 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(stwidgets.gamelist), FALSE); |
659 | gtk_tree_view_set_enable_search(GTK_TREE_VIEW(stwidgets.gamelist), FALSE); |
||
555 | terminx | 660 | |
661 | // Game tab |
||
1540 | terminx | 662 | stwidgets.gametab = gtk_label_new("Game"); |
663 | gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 1), stwidgets.gametab); |
||
555 | terminx | 664 | |
214 | terminx | 665 | // Messages scrollable area |
1540 | terminx | 666 | stwidgets.messagesscroll = gtk_scrolled_window_new(NULL, NULL); |
667 | gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.messagesscroll); |
||
668 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(stwidgets.messagesscroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); |
||
194 | terminx | 669 | |
214 | terminx | 670 | // Messages text area |
1540 | terminx | 671 | stwidgets.messagestext = gtk_text_view_new(); |
672 | gtk_container_add(GTK_CONTAINER(stwidgets.messagesscroll), stwidgets.messagestext); |
||
673 | gtk_text_view_set_editable(GTK_TEXT_VIEW(stwidgets.messagestext), FALSE); |
||
674 | gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(stwidgets.messagestext), GTK_WRAP_WORD); |
||
675 | gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(stwidgets.messagestext), FALSE); |
||
676 | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(stwidgets.messagestext), 2); |
||
677 | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(stwidgets.messagestext), 2); |
||
194 | terminx | 678 | |
214 | terminx | 679 | // Messages tab |
1540 | terminx | 680 | stwidgets.messagestab = gtk_label_new("Messages"); |
681 | gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 2), stwidgets.messagestab); |
||
194 | terminx | 682 | |
214 | terminx | 683 | // Dialogue box buttons layout |
1540 | terminx | 684 | stwidgets.buttons = gtk_hbutton_box_new(); |
685 | gtk_box_pack_start(GTK_BOX(stwidgets.vlayout), stwidgets.buttons, FALSE, TRUE, 0); |
||
686 | gtk_container_set_border_width(GTK_CONTAINER(stwidgets.buttons), 3); |
||
687 | gtk_button_box_set_layout(GTK_BUTTON_BOX(stwidgets.buttons), GTK_BUTTONBOX_END); |
||
194 | terminx | 688 | |
214 | terminx | 689 | // Cancel button |
1540 | terminx | 690 | stwidgets.cancelbutton = gtk_button_new(); |
691 | gtk_container_add(GTK_CONTAINER(stwidgets.buttons), stwidgets.cancelbutton); |
||
692 | GTK_WIDGET_SET_FLAGS(stwidgets.cancelbutton, GTK_CAN_DEFAULT); |
||
194 | terminx | 693 | |
1540 | terminx | 694 | stwidgets.cancelbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0); |
695 | gtk_container_add(GTK_CONTAINER(stwidgets.cancelbutton), stwidgets.cancelbuttonalign); |
||
194 | terminx | 696 | |
1540 | terminx | 697 | stwidgets.cancelbuttonlayout = gtk_hbox_new(FALSE, 2); |
698 | gtk_container_add(GTK_CONTAINER(stwidgets.cancelbuttonalign), stwidgets.cancelbuttonlayout); |
||
194 | terminx | 699 | |
1540 | terminx | 700 | stwidgets.cancelbuttonicon = gtk_image_new_from_stock("gtk-cancel", GTK_ICON_SIZE_BUTTON); |
701 | gtk_box_pack_start(GTK_BOX(stwidgets.cancelbuttonlayout), stwidgets.cancelbuttonicon, FALSE, FALSE, 0); |
||
194 | terminx | 702 | |
1540 | terminx | 703 | stwidgets.cancelbuttonlabel = gtk_label_new_with_mnemonic("_Cancel"); |
704 | gtk_box_pack_start(GTK_BOX(stwidgets.cancelbuttonlayout), stwidgets.cancelbuttonlabel, FALSE, FALSE, 0); |
||
194 | terminx | 705 | |
214 | terminx | 706 | // Start button |
1540 | terminx | 707 | stwidgets.startbutton = gtk_button_new(); |
708 | gtk_container_add(GTK_CONTAINER(stwidgets.buttons), stwidgets.startbutton); |
||
709 | GTK_WIDGET_SET_FLAGS(stwidgets.startbutton, GTK_CAN_DEFAULT); |
||
194 | terminx | 710 | |
1664 | plagman | 711 | gtk_window_set_default(GTK_WINDOW(stwidgets.startwin), stwidgets.startbutton); |
712 | |||
1540 | terminx | 713 | stwidgets.startbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0); |
714 | gtk_container_add(GTK_CONTAINER(stwidgets.startbutton), stwidgets.startbuttonalign); |
||
194 | terminx | 715 | |
1540 | terminx | 716 | stwidgets.startbuttonlayout = gtk_hbox_new(FALSE, 2); |
717 | gtk_container_add(GTK_CONTAINER(stwidgets.startbuttonalign), stwidgets.startbuttonlayout); |
||
194 | terminx | 718 | |
1540 | terminx | 719 | stwidgets.startbuttonicon = gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_BUTTON); |
720 | gtk_box_pack_start(GTK_BOX(stwidgets.startbuttonlayout), stwidgets.startbuttonicon, FALSE, FALSE, 0); |
||
194 | terminx | 721 | |
1540 | terminx | 722 | stwidgets.startbuttonlabel = gtk_label_new_with_mnemonic("_Start"); |
723 | gtk_box_pack_start(GTK_BOX(stwidgets.startbuttonlayout), stwidgets.startbuttonlabel, FALSE, FALSE, 0); |
||
194 | terminx | 724 | |
214 | terminx | 725 | // Wire up the signals |
1593 | terminx | 726 | g_signal_connect((gpointer) stwidgets.startwin, "delete_event", |
333 | terminx | 727 | G_CALLBACK(on_startwin_delete_event), |
728 | NULL); |
||
1593 | terminx | 729 | g_signal_connect((gpointer) stwidgets.vmode3dcombo, "changed", |
1544 | terminx | 730 | G_CALLBACK(on_vmode3dcombo_changed), |
731 | NULL); |
||
1593 | terminx | 732 | g_signal_connect((gpointer) stwidgets.fullscreencheck, "toggled", |
333 | terminx | 733 | G_CALLBACK(on_fullscreencheck_toggled), |
734 | NULL); |
||
1660 | terminx | 735 | #ifdef POLYMER |
1593 | terminx | 736 | g_signal_connect((gpointer) stwidgets.polymercheck, "toggled", |
1540 | terminx | 737 | G_CALLBACK(on_polymercheck_toggled), |
738 | NULL); |
||
1660 | terminx | 739 | #endif |
1593 | terminx | 740 | g_signal_connect((gpointer) stwidgets.inputdevcombo, "changed", |
1544 | terminx | 741 | G_CALLBACK(on_inputdevcombo_changed), |
1540 | terminx | 742 | NULL); |
1593 | terminx | 743 | g_signal_connect((gpointer) stwidgets.custommodcombo, "changed", |
1544 | terminx | 744 | G_CALLBACK(on_custommodcombo_changed), |
333 | terminx | 745 | NULL); |
1593 | terminx | 746 | g_signal_connect((gpointer) stwidgets.autoloadcheck, "toggled", |
1544 | terminx | 747 | G_CALLBACK(on_autoloadcheck_toggled), |
333 | terminx | 748 | NULL); |
1593 | terminx | 749 | g_signal_connect((gpointer) stwidgets.alwaysshowcheck, "toggled", |
333 | terminx | 750 | G_CALLBACK(on_alwaysshowcheck_toggled), |
751 | NULL); |
||
1593 | terminx | 752 | g_signal_connect((gpointer) stwidgets.cancelbutton, "clicked", |
333 | terminx | 753 | G_CALLBACK(on_cancelbutton_clicked), |
754 | NULL); |
||
1593 | terminx | 755 | g_signal_connect((gpointer) stwidgets.startbutton, "clicked", |
333 | terminx | 756 | G_CALLBACK(on_startbutton_clicked), |
757 | NULL); |
||
555 | terminx | 758 | { |
1540 | terminx | 759 | GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(stwidgets.gamelist)); |
555 | terminx | 760 | gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE); |
761 | g_signal_connect((gpointer) sel, "changed", |
||
762 | G_CALLBACK(on_gamelist_selection_changed), |
||
763 | NULL); |
||
764 | } |
||
194 | terminx | 765 | |
214 | terminx | 766 | // Associate labels with their controls |
1540 | terminx | 767 | gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.vmode3dlabel), stwidgets.vmode3dcombo); |
1544 | terminx | 768 | gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.inputdevlabel), stwidgets.inputdevcombo); |
769 | gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.custommodlabel), stwidgets.custommodcombo); |
||
1540 | terminx | 770 | gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.gamelabel), stwidgets.gamelist); |
194 | terminx | 771 | |
1540 | terminx | 772 | return stwidgets.startwin; |
773 | } |
||
194 | terminx | 774 | |
775 | |||
776 | // -- BUILD ENTRY POINTS ------------------------------------------------------ |
||
777 | |||
1205 | terminx | 778 | int32_t startwin_open(void) |
194 | terminx | 779 | { |
214 | terminx | 780 | if (!gtkenabled) return 0; |
1540 | terminx | 781 | if (stwidgets.startwin) return 1; |
194 | terminx | 782 | |
1540 | terminx | 783 | stwidgets.startwin = create_window(); |
784 | if (stwidgets.startwin) |
||
335 | terminx | 785 | { |
214 | terminx | 786 | SetPage(TAB_MESSAGES); |
1540 | terminx | 787 | gtk_widget_show_all(stwidgets.startwin); |
214 | terminx | 788 | gtk_main_iteration_do(FALSE); |
789 | return 0; |
||
790 | } |
||
791 | return -1; |
||
194 | terminx | 792 | } |
793 | |||
1205 | terminx | 794 | int32_t startwin_close(void) |
194 | terminx | 795 | { |
214 | terminx | 796 | if (!gtkenabled) return 0; |
1540 | terminx | 797 | if (!stwidgets.startwin) return 1; |
798 | gtk_widget_destroy(stwidgets.startwin); |
||
799 | stwidgets.startwin = NULL; |
||
214 | terminx | 800 | return 0; |
194 | terminx | 801 | } |
802 | |||
1205 | terminx | 803 | int32_t startwin_puts(const char *str) |
194 | terminx | 804 | { |
214 | terminx | 805 | GtkWidget *textview; |
806 | GtkTextBuffer *textbuffer; |
||
807 | GtkTextIter enditer; |
||
808 | GtkTextMark *mark; |
||
809 | const char *aptr, *bptr; |
||
194 | terminx | 810 | |
214 | terminx | 811 | if (!gtkenabled || !str) return 0; |
1540 | terminx | 812 | if (!stwidgets.startwin) return 1; |
813 | if (!(textview = stwidgets.messagestext)) return -1; |
||
214 | terminx | 814 | textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); |
194 | terminx | 815 | |
214 | terminx | 816 | gtk_text_buffer_get_end_iter(textbuffer, &enditer); |
335 | terminx | 817 | for (aptr = bptr = str; *aptr != 0;) |
818 | { |
||
819 | switch (*bptr) |
||
820 | { |
||
337 | terminx | 821 | case '\b': |
822 | if (bptr > aptr) |
||
823 | gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1); |
||
194 | terminx | 824 | #if GTK_CHECK_VERSION(2,6,0) |
337 | terminx | 825 | gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE); |
194 | terminx | 826 | #else |
337 | terminx | 827 | { |
828 | GtkTextIter iter2 = enditer; |
||
829 | gtk_text_iter_backward_cursor_position(&iter2); |
||
830 | //FIXME: this seems be deleting one too many chars somewhere! |
||
831 | if (!gtk_text_iter_equal(&iter2, &enditer)) |
||
832 | gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE); |
||
833 | } |
||
194 | terminx | 834 | #endif |
337 | terminx | 835 | aptr = ++bptr; |
836 | break; |
||
837 | case 0: |
||
838 | if (bptr > aptr) |
||
839 | gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)); |
||
840 | aptr = bptr; |
||
841 | break; |
||
842 | case '\r': // FIXME |
||
843 | default: |
||
844 | bptr++; |
||
845 | break; |
||
214 | terminx | 846 | } |
847 | } |
||
194 | terminx | 848 | |
214 | terminx | 849 | mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1); |
850 | gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0); |
||
851 | gtk_text_buffer_delete_mark(textbuffer, mark); |
||
194 | terminx | 852 | |
214 | terminx | 853 | return 0; |
194 | terminx | 854 | } |
855 | |||
1205 | terminx | 856 | int32_t startwin_settitle(const char *title) |
194 | terminx | 857 | { |
214 | terminx | 858 | if (!gtkenabled) return 0; |
1540 | terminx | 859 | if (!stwidgets.startwin) return 1; |
860 | gtk_window_set_title(GTK_WINDOW(stwidgets.startwin), title); |
||
214 | terminx | 861 | return 0; |
194 | terminx | 862 | } |
863 | |||
1205 | terminx | 864 | int32_t startwin_idle(void *s) |
194 | terminx | 865 | { |
654 | terminx | 866 | UNREFERENCED_PARAMETER(s); |
214 | terminx | 867 | if (!gtkenabled) return 0; |
1540 | terminx | 868 | //if (!stwidgets.startwin) return 1; |
333 | terminx | 869 | gtk_main_iteration_do(FALSE); |
214 | terminx | 870 | return 0; |
194 | terminx | 871 | } |
872 | |||
1205 | terminx | 873 | int32_t startwin_run(void) |
194 | terminx | 874 | { |
622 | terminx | 875 | if (!gtkenabled) return 1; |
1540 | terminx | 876 | if (!stwidgets.startwin) return 1; |
194 | terminx | 877 | |
214 | terminx | 878 | SetPage(TAB_CONFIG); |
194 | terminx | 879 | |
563 | terminx | 880 | settings.xdim3d = ud.config.ScreenWidth; |
881 | settings.ydim3d = ud.config.ScreenHeight; |
||
882 | settings.bpp3d = ud.config.ScreenBPP; |
||
1544 | terminx | 883 | settings.fullscreen = ud.config.ScreenMode; |
563 | terminx | 884 | settings.usemouse = ud.config.UseMouse; |
885 | settings.usejoy = ud.config.UseJoystick; |
||
1587 | terminx | 886 | settings.custommoddir = g_modDir; |
1544 | terminx | 887 | settings.forcesetup = ud.config.ForceSetup; |
1143 | terminx | 888 | settings.game = g_gameType; |
2563 | helixhorne | 889 | Bstrncpyz(settings.selectedgrp, g_grpNamePtr, BMAX_PATH); |
1540 | terminx | 890 | if (ud.config.NoAutoLoad) settings.autoload = FALSE; |
891 | else settings.autoload = TRUE; |
||
1660 | terminx | 892 | #ifdef POLYMER |
1544 | terminx | 893 | if (glrendmode == RDR_POLYMER) |
1540 | terminx | 894 | { |
1593 | terminx | 895 | if (settings.bpp3d == 8) settings.bpp3d = 32; |
896 | settings.polymer = TRUE; |
||
1540 | terminx | 897 | } |
1660 | terminx | 898 | #endif |
1544 | terminx | 899 | PopulateForm(ALL); |
194 | terminx | 900 | |
214 | terminx | 901 | gtk_main(); |
902 | |||
903 | SetPage(TAB_MESSAGES); |
||
1540 | terminx | 904 | if (retval) // launch the game with these parameters |
335 | terminx | 905 | { |
1205 | terminx | 906 | int32_t i; |
1593 | terminx | 907 | |
563 | terminx | 908 | ud.config.ScreenWidth = settings.xdim3d; |
909 | ud.config.ScreenHeight = settings.ydim3d; |
||
910 | ud.config.ScreenBPP = settings.bpp3d; |
||
1544 | terminx | 911 | ud.config.ScreenMode = settings.fullscreen; |
563 | terminx | 912 | ud.config.UseMouse = settings.usemouse; |
913 | ud.config.UseJoystick = settings.usejoy; |
||
1544 | terminx | 914 | ud.config.ForceSetup = settings.forcesetup; |
2563 | helixhorne | 915 | |
916 | clearGrpNamePtr(); |
||
917 | g_grpNamePtr = dup_filename(settings.selectedgrp); |
||
918 | |||
1143 | terminx | 919 | g_gameType = settings.game; |
1544 | terminx | 920 | if (settings.custommoddir != NULL) |
1587 | terminx | 921 | Bstrcpy(g_modDir, settings.custommoddir); |
922 | else Bsprintf(g_modDir, "/"); |
||
1593 | terminx | 923 | |
1540 | terminx | 924 | if (settings.autoload) ud.config.NoAutoLoad = FALSE; |
925 | else ud.config.NoAutoLoad = TRUE; |
||
886 | terminx | 926 | |
2543 | helixhorne | 927 | for (i = 0; i<NUMGRPFILES; i++) if (settings.crcval == grpfiles[i].crcval) break; |
928 | if (i != NUMGRPFILES) |
||
2561 | helixhorne | 929 | g_gameNamePtr = grpfiles[i].name; |
214 | terminx | 930 | } |
931 | |||
932 | return retval; |
||
194 | terminx | 933 | } |