Undo previous change.
[chocolate-doom.git] / setup / mainmenu.c
blobd4dfe0dbbe285fc017d7b5ed8a8b84fa040e57ca
1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // Copyright(C) 2006 Simon Howard
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
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. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 // 02111-1307, USA.
21 #include <stdlib.h>
23 #include "config.h"
24 #include "textscreen.h"
26 #include "execute.h"
28 #include "configfile.h"
29 #include "m_argv.h"
31 #include "setup_icon.c"
33 #include "compatibility.h"
34 #include "display.h"
35 #include "joystick.h"
36 #include "keyboard.h"
37 #include "mouse.h"
38 #include "multiplayer.h"
39 #include "sound.h"
41 static void DoQuit(void *widget, void *dosave)
43 if (dosave != NULL)
45 M_SaveDefaults();
48 exit(0);
51 static void QuitConfirm(void *unused1, void *unused2)
53 txt_window_t *window;
54 txt_label_t *label;
55 txt_button_t *yes_button;
56 txt_button_t *no_button;
58 window = TXT_NewWindow(NULL);
60 TXT_AddWidgets(window,
61 label = TXT_NewLabel("Exiting setup.\nSave settings?"),
62 TXT_NewStrut(24, 0),
63 yes_button = TXT_NewButton2(" Yes ", DoQuit, DoQuit),
64 no_button = TXT_NewButton2(" No ", DoQuit, NULL),
65 NULL);
67 TXT_SetWidgetAlign(label, TXT_HORIZ_CENTER);
68 TXT_SetWidgetAlign(yes_button, TXT_HORIZ_CENTER);
69 TXT_SetWidgetAlign(no_button, TXT_HORIZ_CENTER);
71 // Only an "abort" button in the middle.
72 TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL);
73 TXT_SetWindowAction(window, TXT_HORIZ_CENTER,
74 TXT_NewWindowAbortAction(window));
75 TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, NULL);
78 static void LaunchDoom(void *unused1, void *unused2)
80 execute_context_t *exec;
82 // Save configuration first
84 M_SaveDefaults();
86 // Shut down textscreen GUI
88 TXT_Shutdown();
90 // Launch Doom
92 exec = NewExecuteContext();
93 AddConfigParameters(exec);
94 ExecuteDoom(exec);
96 exit(0);
99 void MainMenu(void)
101 txt_window_t *window;
102 txt_window_action_t *quit_action;
104 window = TXT_NewWindow("Main Menu");
106 TXT_AddWidgets(window,
107 TXT_NewButton2("Configure Display",
108 (TxtWidgetSignalFunc) ConfigDisplay, NULL),
109 TXT_NewButton2("Configure Joystick",
110 (TxtWidgetSignalFunc) ConfigJoystick, NULL),
111 TXT_NewButton2("Configure Keyboard",
112 (TxtWidgetSignalFunc) ConfigKeyboard, NULL),
113 TXT_NewButton2("Configure Mouse",
114 (TxtWidgetSignalFunc) ConfigMouse, NULL),
115 TXT_NewButton2("Configure Sound",
116 (TxtWidgetSignalFunc) ConfigSound, NULL),
117 TXT_NewButton2("Compatibility",
118 (TxtWidgetSignalFunc) CompatibilitySettings, NULL),
119 TXT_NewButton2("Save parameters and launch DOOM", LaunchDoom, NULL),
120 TXT_NewStrut(0, 1),
121 TXT_NewButton2("Start a Network Game",
122 (TxtWidgetSignalFunc) StartMultiGame, NULL),
123 TXT_NewButton2("Join a Network Game",
124 (TxtWidgetSignalFunc) JoinMultiGame, NULL),
125 TXT_NewButton2("Multiplayer Configuration",
126 (TxtWidgetSignalFunc) MultiplayerConfig, NULL),
127 NULL);
129 quit_action = TXT_NewWindowAction(KEY_ESCAPE, "Quit");
130 TXT_SignalConnect(quit_action, "pressed", QuitConfirm, NULL);
131 TXT_SetWindowAction(window, TXT_HORIZ_LEFT, quit_action);
135 // Initialise all configuration variables, load config file, etc
138 static void InitConfig(void)
140 SetChatMacroDefaults();
141 SetPlayerNameDefault();
143 M_SetConfigDir();
144 M_LoadDefaults();
148 // Application icon
151 static void SetIcon(void)
153 SDL_Surface *surface;
154 Uint8 *mask;
155 int i;
157 // Generate the mask
159 mask = malloc(setup_icon_w * setup_icon_h / 8);
160 memset(mask, 0, setup_icon_w * setup_icon_h / 8);
162 for (i=0; i<setup_icon_w * setup_icon_h; ++i)
164 if (setup_icon_data[i * 3] != 0x00
165 || setup_icon_data[i * 3 + 1] != 0x00
166 || setup_icon_data[i * 3 + 2] != 0x00)
168 mask[i / 8] |= 1 << (7 - i % 8);
173 surface = SDL_CreateRGBSurfaceFrom(setup_icon_data,
174 setup_icon_w,
175 setup_icon_h,
177 setup_icon_w * 3,
178 0xff << 0,
179 0xff << 8,
180 0xff << 16,
183 SDL_WM_SetIcon(surface, mask);
184 SDL_FreeSurface(surface);
185 free(mask);
189 // Initialise and run the textscreen GUI.
192 static void RunGUI(void)
194 SetDisplayDriver();
196 if (!TXT_Init())
198 fprintf(stderr, "Failed to initialise GUI\n");
199 exit(-1);
202 TXT_SetDesktopTitle(PACKAGE_NAME " Setup ver " PACKAGE_VERSION);
203 SetIcon();
205 MainMenu();
207 TXT_GUIMainLoop();
210 int main(int argc, char *argv[])
212 myargc = argc;
213 myargv = argv;
215 InitConfig();
216 RunGUI();
218 return 0;