2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
35 extern CEdit *g_pEdit;
44 =======================================================================================================================
45 =======================================================================================================================
47 void Sys_MarkMapModified(void) {
50 if (mapModified != 1) {
51 mapModified = 1; // mark the map as changed
54 title.BackSlashesToSlashes();
60 =======================================================================================================================
61 =======================================================================================================================
63 void Sys_SetTitle(const char *text) {
64 g_pParentWnd->SetWindowText(va("%s: %s",EDITOR_WINDOWTEXT, text));
68 =======================================================================================================================
70 =======================================================================================================================
74 void Sys_BeginWait(void) {
75 waitcursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
79 return (waitcursor != NULL);
82 void Sys_EndWait(void) {
84 SetCursor(waitcursor);
90 =======================================================================================================================
91 =======================================================================================================================
93 void Sys_GetCursorPos(int *x, int *y) {
96 GetCursorPos(&lpPoint);
102 =======================================================================================================================
103 =======================================================================================================================
105 void Sys_SetCursorPos(int x, int y) {
110 =======================================================================================================================
111 =======================================================================================================================
113 void Sys_Beep(void) {
114 MessageBeep(MB_ICONASTERISK);
118 =======================================================================================================================
119 =======================================================================================================================
121 char *TranslateString(char *buf) {
122 static char buf2[32768];
128 for (i = 0; i < l; i++) {
129 if (buf[i] == '\n') {
144 =======================================================================================================================
145 =======================================================================================================================
147 double Sys_DoubleTime(void) {
148 return clock() / 1000.0;
152 =======================================================================================================================
153 =======================================================================================================================
155 void PrintPixels(HDC hDC) {
157 PIXELFORMATDESCRIPTOR p[64];
159 printf("### flags color layer\n");
160 for (i = 1; i < 64; i++) {
161 if (!DescribePixelFormat(hDC, i, sizeof(p[0]), &p[i])) {
165 printf("%3i %5i %5i %5i\n", i, p[i].dwFlags, p[i].cColorBits, p[i].bReserved);
168 printf("%i modes\n", i - 1);
172 =======================================================================================================================
173 =======================================================================================================================
175 int WINAPI QEW_SetupPixelFormat(HDC hDC, bool zbuffer)
179 int pixelFormat = ChoosePixelFormat(hDC, &win32.pfd);
180 if (pixelFormat > 0) {
181 if (SetPixelFormat(hDC, pixelFormat, &win32.pfd) == NULL) {
182 Error("SetPixelFormat failed.");
186 Error("ChoosePixelFormat failed.");
191 static PIXELFORMATDESCRIPTOR pfd = {
192 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
194 PFD_DRAW_TO_WINDOW | // support window
195 PFD_SUPPORT_OPENGL | // support OpenGL
196 PFD_DOUBLEBUFFER, // double buffered
197 PFD_TYPE_RGBA, // RGBA type
198 24, // 24-bit color depth
204 0, // color bits ignored
205 0, // no alpha buffer
206 0, // shift bit ignored
207 0, // no accumulation buffer
211 0, // accum bits ignored
213 0, // no stencil buffer
214 0, // no auxiliary buffer
215 PFD_MAIN_PLANE, // main layer
219 0 // layer masks ignored
228 if ((pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0) {
229 printf("%d", GetLastError());
230 Error("ChoosePixelFormat failed");
233 if (!SetPixelFormat(hDC, pixelformat, &pfd)) {
234 Error("SetPixelFormat failed");
242 =======================================================================================================================
243 Error For abnormal program terminations
244 =======================================================================================================================
246 void Error(char *error, ...) {
252 err = GetLastError();
254 int i = qglGetError();
256 va_start(argptr, error);
257 vsprintf(text, error, argptr);
263 "%s\nGetLastError() = %i - %i\nAn unrecoverable error has occured. Would you like to edit Preferences before exiting Q3Radiant?",
269 if (g_pParentWnd->MessageBox(text2, "Error", MB_YESNO) == IDYES) {
270 g_PrefsDlg.LoadPrefs();
271 g_PrefsDlg.DoModal();
274 common->FatalError( text );
278 =======================================================================================================================
279 =======================================================================================================================
281 void Warning(char *error, ...) {
286 err = GetLastError();
288 int i = qglGetError();
290 va_start(argptr, error);
291 vsprintf(text, error, argptr);
294 common->Printf(text);
298 =======================================================================================================================
300 =======================================================================================================================
302 bool ConfirmModified(void) {
307 if (g_pParentWnd->MessageBox("This will lose changes to the map", "warning", MB_OKCANCEL) == IDCANCEL) {
314 static OPENFILENAME ofn; /* common dialog box structure */
315 static char szDirName[MAX_PATH]; /* directory string */
316 static char szFile[260]; /* filename string */
317 static char szFileTitle[260]; /* file title string */
318 static char szFilter[260] = /* filter string */
319 "Map file (*.map, *.reg)\0*.map;*.reg\0";
320 static char szProjectFilter[260] = /* filter string */
321 "Q3Radiant project (*.qe4, *.prj)\0*.qe4\0*.prj\0\0";
322 static char chReplace; /* string separator for szFilter */
323 static int i, cbString; /* integer count variables */
324 static HANDLE hf; /* file handle */
327 =======================================================================================================================
328 =======================================================================================================================
330 void OpenDialog(void) {
331 /* Obtain the system directory name and store it in szDirName. */
332 strcpy(szDirName, ValueForKey(g_qeglobals.d_project_entity, "mapspath"));
333 if (strlen(szDirName) == 0) {
334 strcpy(szDirName, ValueForKey(g_qeglobals.d_project_entity, "basepath"));
335 strcat(szDirName, "\\maps");
338 if (g_PrefsDlg.m_strMaps.GetLength() > 0) {
339 strcat(szDirName, va("\\%s", g_PrefsDlg.m_strMaps));
342 /* Place the terminating null character in the szFile. */
345 /* Set the members of the OPENFILENAME structure. */
346 ofn.lStructSize = sizeof(OPENFILENAME);
347 ofn.hwndOwner = g_pParentWnd->GetSafeHwnd();
348 ofn.lpstrFilter = szFilter;
349 ofn.nFilterIndex = 1;
350 ofn.lpstrFile = szFile;
351 ofn.nMaxFile = sizeof(szFile);
352 ofn.lpstrFileTitle = szFileTitle;
353 ofn.nMaxFileTitle = sizeof(szFileTitle);
354 ofn.lpstrInitialDir = szDirName;
355 ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
357 /* Display the Open dialog box. */
358 if (!GetOpenFileName(&ofn)) {
362 // Add the file in MRU. FIXME
363 AddNewItem(g_qeglobals.d_lpMruMenu, ofn.lpstrFile);
365 // Refresh the File menu. FIXME
366 PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu, GetSubMenu(GetMenu(g_pParentWnd->GetSafeHwnd()), 0), ID_FILE_EXIT);
369 Map_LoadFile(ofn.lpstrFile);
371 g_PrefsDlg.SavePrefs();
376 =======================================================================================================================
377 =======================================================================================================================
379 void ProjectDialog(void) {
380 /* Obtain the system directory name and store it in szDirName. */
381 strcpy(szDirName, ValueForKey(g_qeglobals.d_project_entity, "basepath"));
383 /* Place the terminating null character in the szFile. */
386 /* Set the members of the OPENFILENAME structure. */
387 ofn.lStructSize = sizeof(OPENFILENAME);
388 ofn.hwndOwner = g_pParentWnd->GetSafeHwnd();
389 ofn.lpstrFilter = szProjectFilter;
390 ofn.nFilterIndex = 1;
391 ofn.lpstrFile = szFile;
392 ofn.nMaxFile = sizeof(szFile);
393 ofn.lpstrFileTitle = szFileTitle;
394 ofn.nMaxFileTitle = sizeof(szFileTitle);
395 ofn.lpstrInitialDir = szDirName;
396 ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
398 /* Display the Open dialog box. */
399 if (!GetOpenFileName(&ofn)) {
403 // Refresh the File menu.
404 PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu, GetSubMenu(GetMenu(g_pParentWnd->GetSafeHwnd()), 0), ID_FILE_EXIT);
407 if (!QE_LoadProject(ofn.lpstrFile)) {
408 Error("Couldn't load project file");
412 extern void AddSlash(CString &strPath);
415 =======================================================================================================================
416 =======================================================================================================================
418 void SaveAsDialog(bool bRegion) {
419 strcpy(szDirName, ValueForKey(g_qeglobals.d_project_entity, "basepath"));
421 CString strPath = szDirName;
424 if (g_PrefsDlg.m_strMaps.GetLength() > 0) {
425 strPath += va("\\%s", g_PrefsDlg.m_strMaps);
428 /* Place the terminating null character in the szFile. */
431 /* Set the members of the OPENFILENAME structure. */
432 ofn.lStructSize = sizeof(OPENFILENAME);
433 ofn.hwndOwner = g_pParentWnd->GetSafeHwnd();
434 ofn.lpstrFilter = szFilter;
435 ofn.nFilterIndex = 1;
436 ofn.lpstrFile = szFile;
437 ofn.nMaxFile = sizeof(szFile);
438 ofn.lpstrFileTitle = szFileTitle;
439 ofn.nMaxFileTitle = sizeof(szFileTitle);
440 ofn.lpstrInitialDir = strPath;
441 ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT;
443 /* Display the Open dialog box. */
444 if (!GetSaveFileName(&ofn)) {
449 DefaultExtension(ofn.lpstrFile, ".reg");
452 DefaultExtension(ofn.lpstrFile, ".map");
456 strcpy(currentmap, ofn.lpstrFile);
457 AddNewItem(g_qeglobals.d_lpMruMenu, ofn.lpstrFile);
458 PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu, GetSubMenu(GetMenu(g_pParentWnd->GetSafeHwnd()), 0), ID_FILE_EXIT);
461 Map_SaveFile(ofn.lpstrFile, bRegion); // ignore region
465 * Menu modifications £
468 const char *bsp_commands[256];
471 =======================================================================================================================
472 =======================================================================================================================
474 void FillBSPMenu(void) {
479 hmenu = GetSubMenu(GetMenu(g_pParentWnd->GetSafeHwnd()), MENU_BSP);
481 for (i = 0; i < count; i++) {
482 DeleteMenu(hmenu, CMD_BSPCOMMAND + i, MF_BYCOMMAND);
486 count = g_qeglobals.d_project_entity->epairs.GetNumKeyVals();
487 for (int j = 0; j < count; j++) {
488 if (g_qeglobals.d_project_entity->epairs.GetKeyVal(j)->GetKey()[0] == 'b' && g_qeglobals.d_project_entity->epairs.GetKeyVal(j)->GetKey()[1] == 's' && g_qeglobals.d_project_entity->epairs.GetKeyVal(j)->GetKey()[2] == 'p') {
489 bsp_commands[i] = g_qeglobals.d_project_entity->epairs.GetKeyVal(j)->GetKey().c_str();
490 AppendMenu(hmenu, MF_ENABLED | MF_STRING, CMD_BSPCOMMAND + i, (LPCTSTR) g_qeglobals.d_project_entity->epairs.GetKeyVal(j)->GetKey().c_str());
499 =======================================================================================================================
500 =======================================================================================================================
502 void AddSlash(CString &strPath) {
503 if (strPath.GetLength() > 0) {
504 if (strPath.GetAt(strPath.GetLength() - 1) != '\\') {