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