2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
25 HINSTANCE main_instance;
27 int screen_width, screen_height;
38 For abnormal program terminations
41 void Sys_Error (char *error, ...)
48 err = GetLastError ();
50 va_start (argptr,error);
51 vsprintf (text, error,argptr);
54 sprintf (text2, "%s\nGetLastError() = %i", text, err);
55 MessageBox(mainwindow, text2, "Error", 0 /* MB_OK */ );
62 ======================================================================
66 ======================================================================
70 qboolean modified_past_autosave;
72 qboolean ConfirmModified (void)
77 if (MessageBox (mainwindow, "This will lose changes to the skin"
78 , "warning", MB_OKCANCEL) == IDCANCEL)
83 OPENFILENAME ofn; /* common dialog box structure */
84 char szDirName[MAX_PATH]; /* directory string */
85 char szFile[260]; /* filename string */
86 char szFileTitle[260]; /* file title string */
87 char szSkinFilter[260] = /* filter string */
88 "Skin texture (*.lbm *.pcx)\0*.lbm;*.pcx\0\0";
89 char szFrameFilter[260] = /* filter string */
90 "Model frame (*.tri)\0*.tri\0\0";
91 char chReplace; /* string separator for szFilter */
92 int i, cbString; /* integer count variables */
93 HANDLE hf; /* file handle */
95 void OpenSkinDialog (void)
97 // strcpy (szDirName, ValueForKey (project_entity, "basepath") );
98 // strcat (szDirName, "\\maps");
100 /* Place the terminating null character in the szFile. */
104 /* Set the members of the OPENFILENAME structure. */
106 ofn.lStructSize = sizeof(OPENFILENAME);
107 ofn.hwndOwner = mainwindow;
108 ofn.lpstrFilter = szSkinFilter;
109 ofn.nFilterIndex = 1;
110 ofn.lpstrFile = szFile;
111 ofn.nMaxFile = sizeof(szFile);
112 ofn.lpstrFileTitle = szFileTitle;
113 ofn.nMaxFileTitle = sizeof(szFileTitle);
114 ofn.lpstrInitialDir = szDirName;
115 ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
118 /* Display the Open dialog box. */
120 if (!GetOpenFileName(&ofn))
123 Skin_LoadFile (ofn.lpstrFile);
126 void OpenFrameDialog (void)
128 // strcpy (szDirName, ValueForKey (project_entity, "basepath") );
129 // strcat (szDirName, "\\maps");
131 /* Place the terminating null character in the szFile. */
135 /* Set the members of the OPENFILENAME structure. */
137 ofn.lStructSize = sizeof(OPENFILENAME);
138 ofn.hwndOwner = mainwindow;
139 ofn.lpstrFilter = szFrameFilter;
140 ofn.nFilterIndex = 1;
141 ofn.lpstrFile = szFile;
142 ofn.nMaxFile = sizeof(szFile);
143 ofn.lpstrFileTitle = szFileTitle;
144 ofn.nMaxFileTitle = sizeof(szFileTitle);
145 ofn.lpstrInitialDir = szDirName;
146 ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
149 /* Display the Open dialog box. */
151 if (!GetOpenFileName(&ofn))
154 LoadTriFile (ofn.lpstrFile);
157 void SaveSkinDialog (void)
159 // strcpy (szDirName, ValueForKey (project_entity, "basepath") );
160 // strcat (szDirName, "\\maps");
162 /* Place the terminating null character in the szFile. */
166 /* Set the members of the OPENFILENAME structure. */
168 ofn.lStructSize = sizeof(OPENFILENAME);
169 ofn.hwndOwner = mainwindow;
170 ofn.lpstrFilter = szSkinFilter;
171 ofn.nFilterIndex = 1;
172 ofn.lpstrFile = szFile;
173 ofn.nMaxFile = sizeof(szFile);
174 ofn.lpstrFileTitle = szFileTitle;
175 ofn.nMaxFileTitle = sizeof(szFileTitle);
176 ofn.lpstrInitialDir = szDirName;
177 ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
180 /* Display the Open dialog box. */
182 if (!GetSaveFileName(&ofn))
185 DefaultExtension (ofn.lpstrFile, ".lbm");
186 Skin_SaveFile (ofn.lpstrFile);
187 strcpy (skin_filename, ofn.lpstrFile);
190 //==========================================================================
192 BOOL bSetupPixelFormat(HDC hDC)
194 static PIXELFORMATDESCRIPTOR pfd = {
195 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
197 PFD_DRAW_TO_WINDOW | // support window
198 PFD_SUPPORT_OPENGL | // support OpenGL
199 PFD_DOUBLEBUFFER, // double buffered
200 PFD_TYPE_RGBA, // RGBA type
201 24, // 24-bit color depth
202 0, 0, 0, 0, 0, 0, // color bits ignored
203 0, // no alpha buffer
204 0, // shift bit ignored
205 0, // no accumulation buffer
206 0, 0, 0, 0, // accum bits ignored
207 32, // 32-bit z-buffer
208 0, // no stencil buffer
209 0, // no auxiliary buffer
210 PFD_MAIN_PLANE, // main layer
212 0, 0, 0 // layer masks ignored
215 PIXELFORMATDESCRIPTOR newp;
217 if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
219 printf("%d",GetLastError());
220 Error ("ChoosePixelFormat failed");
222 if (!SetPixelFormat(hDC, pixelformat, &pfd))
223 Error ("SetPixelFormat failed");
230 ==============================================================================
234 ==============================================================================
238 /* handle all WM_COMMAND messages here */
239 LONG WINAPI CommandHandler (
246 cmd = LOWORD(wParam);
253 case ID_FILE_RESAMPLESKIN:
257 case ID_FILE_NEWSKIN:
261 case ID_FILE_OPENFRAME:
265 case ID_FILE_OPENSKIN:
266 if (!ConfirmModified())
271 case ID_FILE_RELOADSKIN:
272 if (!ConfirmModified())
274 Skin_LoadFile (skin_filename);
277 case ID_FILE_SAVESKIN:
278 Skin_SaveFile (skin_filename);
281 case ID_FILE_SAVESKINAS:
285 if (!ConfirmModified())
303 case ID_VIEW_MODELLINES:
305 CheckMenuItem ( GetSubMenu (GetMenu(mainwindow), MENU_VIEW)
307 , MF_BYCOMMAND | (model_lines ? MF_CHECKED : MF_UNCHECKED) );
308 InvalidateRect (camerawindow, NULL, false);
310 case ID_VIEW_TEXTURELINES:
312 CheckMenuItem ( GetSubMenu (GetMenu(mainwindow), MENU_VIEW)
313 , ID_VIEW_TEXTURELINES
314 , MF_BYCOMMAND | (skin_lines ? MF_CHECKED : MF_UNCHECKED) );
315 InvalidateRect (skinwindow, NULL, false);
329 LONG WINAPI WMAIN_WndProc (
339 GetClientRect(hWnd, &rect);
344 maindc = GetDC(hWnd);
345 bSetupPixelFormat(maindc);
348 lRet = CommandHandler (hWnd, wParam, lParam);
352 if (!ConfirmModified())
357 /* pass all unhandled messages to DefWindowProc */
358 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
362 /* return 1 if handled message, 0 if not */
374 void Main_Create (HINSTANCE hInstance)
378 /* Register the class */
379 memset (&wc, 0, sizeof(wc));
382 wc.lpfnWndProc = (WNDPROC)WMAIN_WndProc;
385 wc.hInstance = hInstance;
387 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
388 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
389 wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU2);
390 wc.lpszClassName = "TEXPAINT_MAIN";
392 if (!RegisterClass (&wc) )
393 Error ("WCam_Register: failed");
396 mainwindow = CreateWindow ("TEXPAINT_MAIN" ,
398 WS_OVERLAPPEDWINDOW |
401 0,0,screen_width,screen_height, // size
407 Error ("Couldn't create main window");
409 // GetWindowInfo("mainwindow", &SavedInfo, NULL);
410 ShowWindow (mainwindow, SW_SHOWDEFAULT);
416 BOOL SaveWindowInfo(const char *pszName, void *pvBuf, long lSize)
422 lres = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\id\\Texpaint", 0, NULL,
423 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKeyId, &dwDisp);
425 if (lres != ERROR_SUCCESS)
428 lres = RegSetValueEx(hKeyId, pszName, 0, REG_BINARY, pvBuf, lSize);
432 if (lres != ERROR_SUCCESS)
439 BOOL GetWindowInfo(const char *pszName, void *pvBuf, long *plSize)
442 long lres, lType, lSize;
447 lres = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\id\\Texpaint", 0, KEY_READ, &hKey);
449 if (lres != ERROR_SUCCESS)
452 lres = RegQueryValueEx(hKey, pszName, NULL, &lType, pvBuf, plSize);
456 if (lres != ERROR_SUCCESS)
463 BOOL SaveWindowState(HWND hWnd, const char *pszName)
467 GetWindowRect(hWnd, &rc);
468 MapWindowPoints(NULL, mainwindow, (POINT *)&rc, 2);
469 return SaveWindowInfo(pszName, &rc, sizeof(rc));
473 BOOL RestoreWindowState(HWND hWnd, const char *pszName)
476 LONG lSize = sizeof(rc);
478 if (GetWindowInfo(pszName, &rc, &lSize))
484 if (rc.right < rc.left + 16)
485 rc.right = rc.left + 16;
486 if (rc.bottom < rc.top + 16)
487 rc.bottom = rc.top + 16;
489 MoveWindow(hWnd, rc.left, rc.top, rc.right - rc.left,
490 rc.bottom - rc.top, FALSE);