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