1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6
7 This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
8
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.
13
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.
18
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/>.
21
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.
23
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.
25
26 ===========================================================================
27 */
28 #include "tools/edit_gui_common.h"
29
30
31 #include "../../sys/win32/win_local.h"
32
33 #include "MaterialEditor.h"
34 #include "MEMainFrame.h"
35
36 #ifdef _DEBUG
37 #define new DEBUG_NEW
38 #endif
39
40 MEMainFrame* meMainFrame = NULL;
41
42 CFont* materialEditorFont = NULL;
43
44 /**
45 * Initializes the material editor tool.
46 */
MaterialEditorInit(void)47 void MaterialEditorInit( void ) {
48
49 InitPropTree(win32.hInstance);
50
51 com_editors = EDITOR_MATERIAL;
52
53 Sys_GrabMouseCursor( false );
54
55 InitAfx();
56
57 InitCommonControls();
58
59 // Initialize OLE libraries
60 if (!AfxOleInit())
61 {
62 return;
63 }
64 AfxEnableControlContainer();
65
66 NONCLIENTMETRICS info;
67 info.cbSize = sizeof(info);
68
69 ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
70
71 LOGFONT lf;
72 memset(&lf, 0, sizeof (LOGFONT));
73
74 CWindowDC dc(NULL);
75 lf.lfCharSet = (BYTE)GetTextCharsetInfo(dc.GetSafeHdc(), NULL, 0);
76
77 lf.lfHeight = info.lfMenuFont.lfHeight;
78 lf.lfWeight = info.lfMenuFont.lfWeight;
79 lf.lfItalic = info.lfMenuFont.lfItalic;
80
81 // check if we should use system font
82 _tcscpy(lf.lfFaceName, info.lfMenuFont.lfFaceName);
83
84 materialEditorFont = new CFont;
85 materialEditorFont->CreateFontIndirect(&lf);
86
87
88 // To create the main window, this code creates a new frame window
89 // object and then sets it as the application's main window object
90 meMainFrame = new MEMainFrame;
91
92 // create and load the frame with its resources
93 meMainFrame->LoadFrame(IDR_ME_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
94
95
96 // hide the doom window by default
97 ::ShowWindow ( win32.hWnd, SW_HIDE );
98
99 // The one and only window has been initialized, so show and update it
100 meMainFrame->ShowWindow(SW_SHOW);
101 meMainFrame->UpdateWindow();
102 }
103
104 /**
105 * Called every frame by the doom engine to allow the material editor to process messages.
106 */
MaterialEditorRun(void)107 void MaterialEditorRun( void ) {
108
109 MSG *msg = AfxGetCurrentMessage();
110
111 while( ::PeekMessage(msg, NULL, NULL, NULL, PM_NOREMOVE) ) {
112 // pump message
113 if ( !AfxGetApp()->PumpMessage() ) {
114 }
115 }
116 }
117
118 /**
119 * Called by the doom engine when the material editor needs to be destroyed.
120 */
MaterialEditorShutdown(void)121 void MaterialEditorShutdown( void ) {
122
123 delete meMainFrame;
124
125 delete materialEditorFont;
126
127 meMainFrame = NULL;
128 }
129
130 /**
131 * Allows the doom engine to reflect console output to the material editors console.
132 */
MaterialEditorPrintConsole(const char * msg)133 void MaterialEditorPrintConsole( const char *msg ) {
134 if(com_editors & EDITOR_MATERIAL)
135 meMainFrame->PrintConsoleMessage(msg);
136 }
137
138 /**
139 * Returns the handle to the main Material Editor Window
140 */
GetMaterialEditorWindow()141 HWND GetMaterialEditorWindow() {
142 return meMainFrame->GetSafeHwnd();
143 }
144
145 /**
146 * Simple about box for the material editor.
147 */
148 class CAboutDlg : public CDialog
149 {
150 public:
151 CAboutDlg();
152
153 enum { IDD = IDD_ME_ABOUTBOX };
154
155 protected:
156 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
157
158 DECLARE_MESSAGE_MAP()
159 };
160
161 /**
162 * Constructor for the about box.
163 */
CAboutDlg()164 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) {
165 }
166
167 /**
168 * Called by the MFC framework to exchange data with the window controls.
169 */
DoDataExchange(CDataExchange * pDX)170 void CAboutDlg::DoDataExchange(CDataExchange* pDX) {
171 CDialog::DoDataExchange(pDX);
172 }
173
174 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
175 END_MESSAGE_MAP()
176