Use SDL's getenv/putenv implementation, and populate at startup.
[chocolate-doom.git] / setup / mainmenu.c
blob6a1f01c25835afdde08c47515e0a39ad6199faee
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.
22 #include <stdlib.h>
23 #include <string.h>
25 #ifdef _WIN32_WCE
26 #include "libc_wince.h"
27 #endif
29 #include "config.h"
30 #include "textscreen.h"
32 #include "execute.h"
34 #include "configfile.h"
35 #include "m_argv.h"
37 #include "setup_icon.c"
39 #include "compatibility.h"
40 #include "display.h"
41 #include "joystick.h"
42 #include "keyboard.h"
43 #include "mouse.h"
44 #include "multiplayer.h"
45 #include "sound.h"
47 static void DoQuit(void *widget, void *dosave)
49 if (dosave != NULL)
51 M_SaveDefaults();
54 exit(0);
57 static void QuitConfirm(void *unused1, void *unused2)
59 txt_window_t *window;
60 txt_label_t *label;
61 txt_button_t *yes_button;
62 txt_button_t *no_button;
64 window = TXT_NewWindow(NULL);
66 TXT_AddWidgets(window,
67 label = TXT_NewLabel("Exiting setup.\nSave settings?"),
68 TXT_NewStrut(24, 0),
69 yes_button = TXT_NewButton2(" Yes ", DoQuit, DoQuit),
70 no_button = TXT_NewButton2(" No ", DoQuit, NULL),
71 NULL);
73 TXT_SetWidgetAlign(label, TXT_HORIZ_CENTER);
74 TXT_SetWidgetAlign(yes_button, TXT_HORIZ_CENTER);
75 TXT_SetWidgetAlign(no_button, TXT_HORIZ_CENTER);
77 // Only an "abort" button in the middle.
78 TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL);
79 TXT_SetWindowAction(window, TXT_HORIZ_CENTER,
80 TXT_NewWindowAbortAction(window));
81 TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, NULL);
84 static void LaunchDoom(void *unused1, void *unused2)
86 execute_context_t *exec;
88 // Save configuration first
90 M_SaveDefaults();
92 // Shut down textscreen GUI
94 TXT_Shutdown();
96 // Launch Doom
98 exec = NewExecuteContext();
99 AddConfigParameters(exec);
100 ExecuteDoom(exec);
102 exit(0);
105 void MainMenu(void)
107 txt_window_t *window;
108 txt_window_action_t *quit_action;
110 window = TXT_NewWindow("Main Menu");
112 TXT_AddWidgets(window,
113 TXT_NewButton2("Configure Display",
114 (TxtWidgetSignalFunc) ConfigDisplay, NULL),
115 TXT_NewButton2("Configure Joystick",
116 (TxtWidgetSignalFunc) ConfigJoystick, NULL),
117 TXT_NewButton2("Configure Keyboard",
118 (TxtWidgetSignalFunc) ConfigKeyboard, NULL),
119 TXT_NewButton2("Configure Mouse",
120 (TxtWidgetSignalFunc) ConfigMouse, NULL),
121 TXT_NewButton2("Configure Sound",
122 (TxtWidgetSignalFunc) ConfigSound, NULL),
123 TXT_NewButton2("Compatibility",
124 (TxtWidgetSignalFunc) CompatibilitySettings, NULL),
125 TXT_NewButton2("Save parameters and launch DOOM", LaunchDoom, NULL),
126 TXT_NewStrut(0, 1),
127 TXT_NewButton2("Start a Network Game",
128 (TxtWidgetSignalFunc) StartMultiGame, NULL),
129 TXT_NewButton2("Join a Network Game",
130 (TxtWidgetSignalFunc) JoinMultiGame, NULL),
131 TXT_NewButton2("Multiplayer Configuration",
132 (TxtWidgetSignalFunc) MultiplayerConfig, NULL),
133 NULL);
135 quit_action = TXT_NewWindowAction(KEY_ESCAPE, "Quit");
136 TXT_SignalConnect(quit_action, "pressed", QuitConfirm, NULL);
137 TXT_SetWindowAction(window, TXT_HORIZ_LEFT, quit_action);
141 // Initialise all configuration variables, load config file, etc
144 static void InitConfig(void)
146 SetChatMacroDefaults();
147 SetPlayerNameDefault();
149 M_SetConfigDir();
150 M_LoadDefaults();
154 // Application icon
157 static void SetIcon(void)
159 SDL_Surface *surface;
160 Uint8 *mask;
161 int i;
163 // Generate the mask
165 mask = malloc(setup_icon_w * setup_icon_h / 8);
166 memset(mask, 0, setup_icon_w * setup_icon_h / 8);
168 for (i=0; i<setup_icon_w * setup_icon_h; ++i)
170 if (setup_icon_data[i * 3] != 0x00
171 || setup_icon_data[i * 3 + 1] != 0x00
172 || setup_icon_data[i * 3 + 2] != 0x00)
174 mask[i / 8] |= 1 << (7 - i % 8);
179 surface = SDL_CreateRGBSurfaceFrom(setup_icon_data,
180 setup_icon_w,
181 setup_icon_h,
183 setup_icon_w * 3,
184 0xff << 0,
185 0xff << 8,
186 0xff << 16,
189 SDL_WM_SetIcon(surface, mask);
190 SDL_FreeSurface(surface);
191 free(mask);
195 // Initialise and run the textscreen GUI.
198 static void RunGUI(void)
200 SetDisplayDriver();
202 if (!TXT_Init())
204 fprintf(stderr, "Failed to initialise GUI\n");
205 exit(-1);
208 TXT_SetDesktopTitle(PACKAGE_NAME " Setup ver " PACKAGE_VERSION);
209 SetIcon();
211 MainMenu();
213 TXT_GUIMainLoop();
216 int main(int argc, char *argv[])
218 myargc = argc;
219 myargv = argv;
221 #ifdef _WIN32_WCE
223 // Windows CE has no environment, but SDL provides an implementation.
224 // Populate the environment with the values we normally find.
226 PopulateEnvironment();
228 #endif
230 InitConfig();
231 RunGUI();
233 return 0;