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 ===========================================================================
28 #include "../../idlib/precompiled.h"
32 #include "MaterialPreviewPropView.h"
35 // MaterialPropTreeView
37 IMPLEMENT_DYNCREATE(MaterialPreviewPropView, CPropTreeView)
40 MaterialPreviewPropView::MaterialPreviewPropView() {
42 materialPreview = NULL;
45 MaterialPreviewPropView::~MaterialPreviewPropView() {
48 BEGIN_MESSAGE_MAP(MaterialPreviewPropView, CPropTreeView)
49 ON_NOTIFY( PTN_ITEMCHANGED, IDC_PROPERTYTREE, OnPropertyChangeNotification )
50 ON_NOTIFY( PTN_ITEMBUTTONCLICK, IDC_PROPERTYTREE, OnPropertyButtonClick )
54 void MaterialPreviewPropView::AddLight( void ) {
55 int i, count, lightShaderIndex = 0;
56 const idMaterial *mat;
58 CPropTreeItemButton* pRoot;
59 CPropTreeItemCombo* pCombo;
60 CPropTreeItemColor* pColor;
61 CPropTreeItemCheck* pCheck;
62 CPropTreeItemEdit* pEdit;
64 //Increase the number of lights
67 pRoot = (CPropTreeItemButton*)m_Tree.InsertItem(new CPropTreeItemButton());
68 pRoot->SetLabelText(_T(va("Light #%d", numLights)));
69 pRoot->SetInfoText(_T(va("Parameters for light number %d.", numLights)));
70 pRoot->SetButtonText( "Remove" );
71 pRoot->SetCtrlID( numLights - 1 );
74 pCombo = (CPropTreeItemCombo*)m_Tree.InsertItem(new CPropTreeItemCombo(), pRoot);
75 pCombo->SetLabelText( _T("Shader") );
76 pCombo->SetInfoText( _T("Set the light shader.") );
77 pCombo->SetDropDownHeight( 200 );
78 pCombo->CreateComboBox();
79 // Add all light shaders to the combo box
80 count = declManager->GetNumDecls( DECL_MATERIAL );
81 for (i = 0; i < count; i++) {
82 mat = declManager->MaterialByIndex(i, false);
84 idStr materialName = mat->GetName();
85 materialName.ToLower();
87 if ( materialName.Left(7) == "lights/" || materialName.Left(5) == "fogs/" ) {
88 pCombo->InsertString( lightShaderIndex, materialName );
89 pCombo->SetItemData( lightShaderIndex, lightShaderIndex );
91 if ( materialName == "lights/defaultpointlight" ) {
92 pCombo->SetCurSel( lightShaderIndex );
99 pColor = (CPropTreeItemColor*)m_Tree.InsertItem(new CPropTreeItemColor(), pRoot);
100 pColor->SetLabelText(_T("Color"));
101 pColor->SetInfoText(_T("Color of the light."));
102 pColor->SetItemValue((LPARAM)RGB(0xff, 0xff, 0xff)); // default as color white
104 pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem( new CPropTreeItemEdit(), pRoot);
105 pEdit->SetLabelText(_T("Radius"));
106 pEdit->SetInfoText(_T("Radius of the light."));
107 pEdit->SetItemValue( (LPARAM)_T("300.0") );
109 pCheck = (CPropTreeItemCheck*)m_Tree.InsertItem(new CPropTreeItemCheck(), pRoot);
110 pCheck->SetLabelText(_T("Move light"));
111 pCheck->SetInfoText(_T("When checked, allow light to move."));
112 pCheck->CreateCheckBox();
113 pCheck->SetCheckState( BST_CHECKED );
115 if ( materialPreview ) {
116 materialPreview->OnAddLight();
120 //Create sample data for the preview properties
121 void MaterialPreviewPropView::InitializePropTree( void ) {
123 CPropTreeItem *pRoot;
124 CPropTreeItem *pParmRoot;
125 CPropTreeItemCheck *pCheck;
126 CPropTreeItemEdit *pEdit;
128 pRoot = m_Tree.InsertItem(new CPropTreeItem());
129 pRoot->SetLabelText(_T("Preview Properties"));
130 pRoot->SetInfoText(_T("Properties for the preview window."));
131 pRoot->Expand(); // have this item expanded by default
133 CPropTreeItemCombo* pCombo;
134 pCombo = (CPropTreeItemCombo*)m_Tree.InsertItem(new CPropTreeItemCombo(), pRoot);
135 pCombo->SetLabelText(_T("Model Type"));
136 pCombo->SetInfoText(_T("Select the type of model on which to preview the material."));
137 pCombo->CreateComboBox();
138 pCombo->InsertString( 0, "Cube" );
139 pCombo->InsertString( 1, "Box - 2:1");
140 pCombo->InsertString( 2, "Box - 4:1");
141 pCombo->InsertString( 3, "Box - 1:2");
142 pCombo->InsertString( 4, "Box - 1:4");
143 pCombo->InsertString( 5, "Cylinder - V");
144 pCombo->InsertString( 6, "Cylinder - H");
145 pCombo->InsertString( 7, "Sphere");
146 pCombo->SetItemData( 0, 0 );
147 pCombo->SetItemData( 1, 1 );
148 pCombo->SetItemData( 2, 2 );
149 pCombo->SetItemData( 3, 3 );
150 pCombo->SetItemData( 4, 4 );
151 pCombo->SetItemData( 5, 5 );
152 pCombo->SetItemData( 6, 6 );
153 pCombo->SetItemData( 7, 7 );
155 pCombo->SetCurSel( 0 );
157 // Custom model entry
158 /*pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem( new CPropTreeItemEdit(), pRoot );
159 pEdit->SetLabelText(_T("Custom Model"));
160 pEdit->SetInfoText(_T("Specify any model to display the current material."));
161 pEdit->SetItemValue((LPARAM)_T(""));*/
162 CPropTreeItemEditButton *pCutomButton;
163 pCutomButton = (CPropTreeItemEditButton*)m_Tree.InsertItem(new CPropTreeItemEditButton(), pRoot );
164 pCutomButton->SetButtonText(_T("..."));
165 pCutomButton->SetLabelText(_T("Custom Model"));
166 pCutomButton->SetInfoText(_T("Specify any model to display the current material."));
167 pCutomButton->SetItemValue((LPARAM)_T(""));
169 // Checkbox for showing debug light spheres
170 pCheck = (CPropTreeItemCheck*)m_Tree.InsertItem( new CPropTreeItemCheck(), pRoot );
171 pCheck->SetLabelText(_T("Show Lights"));
172 pCheck->SetInfoText(_T("Show the light origin sphere and number in the preview."));
173 pCheck->CreateCheckBox();
174 pCheck->SetCheckState( BST_CHECKED );
176 // Local and Global shader parms
177 pParmRoot = m_Tree.InsertItem(new CPropTreeItem());
178 pParmRoot->SetLabelText(_T("Local Parms"));
179 pParmRoot->SetInfoText(_T("Local shaderparms for the model being displayed."));
180 pParmRoot->Expand( FALSE ); // have this item NOT expanded by default
182 for( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ ) {
183 pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem( new CPropTreeItemEdit(), pParmRoot );
184 pEdit->SetLabelText(_T(va("parm%d", i)));
185 pEdit->SetInfoText(_T("Set the local shaderparm for the model"));
187 pEdit->SetItemValue((LPARAM)_T("1"));
189 pEdit->SetItemValue((LPARAM)_T("0"));
193 pParmRoot = m_Tree.InsertItem(new CPropTreeItem());
194 pParmRoot->SetLabelText(_T("Global Parms"));
195 pParmRoot->SetInfoText(_T("Global shaderparms for the renderworld being displayed."));
196 pParmRoot->Expand( FALSE ); // have this item NOT expanded by default
198 for( i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ ) {
199 pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem( new CPropTreeItemEdit(), pParmRoot );
200 pEdit->SetLabelText(_T(va("global%d", i)));
201 pEdit->SetInfoText(_T("Set the global shaderparm for the renderworld"));
203 pEdit->SetItemValue((LPARAM)_T("1"));
205 pEdit->SetItemValue((LPARAM)_T("0"));
211 pRoot = m_Tree.InsertItem(new CPropTreeItem());
212 pRoot->SetLabelText(_T(""));
213 pRoot->SetInfoText(_T(""));
215 CPropTreeItemButton *pButton;
216 pButton = (CPropTreeItemButton*)m_Tree.InsertItem(new CPropTreeItemButton());
217 pButton->SetButtonText(_T(" Add Light "));
218 pButton->SetLabelText(_T("Preview Lights"));
219 pButton->SetInfoText(_T("Test the button."));
221 pRoot = m_Tree.InsertItem(new CPropTreeItem());
222 pRoot->SetLabelText(_T(""));
223 pRoot->SetInfoText(_T(""));
228 // MaterialPreviewPropView drawing
230 void MaterialPreviewPropView::OnDraw(CDC* pDC)
232 // TODO: add draw code here
235 // MaterialPreviewPropView diagnostics
238 void MaterialPreviewPropView::AssertValid() const
240 CPropTreeView::AssertValid();
243 void MaterialPreviewPropView::Dump(CDumpContext& dc) const
245 CPropTreeView::Dump(dc);
250 void MaterialPreviewPropView::RegisterPreviewView( MaterialPreviewView *view ) {
251 materialPreview = view;
254 // MaterialPreviewPropView message handlers
256 void MaterialPreviewPropView::OnPropertyChangeNotification( NMHDR *nmhdr, LRESULT *lresult ) {
262 CPropTreeItem *parent;
264 nmProp = (NMPROPTREE *)nmhdr;
265 item = nmProp->pItem;
267 // Determine which light this item modifies
268 parent = item->GetParent();
270 lightId = parent->GetCtrlID();
273 idStr itemLabel = item->GetLabelText();
275 if ( itemLabel == "Model Type" ) {
276 materialPreview->OnModelChange( item->GetItemValue() );
278 } else if ( itemLabel == "Custom Model" ) {
279 materialPreview->OnCustomModelChange( (const char *)item->GetItemValue() );
281 } else if ( itemLabel == "Show Lights" ) {
282 materialPreview->OnShowLightsChange( item->GetItemValue() ? true : false );
284 } else if ( itemLabel == "Shader" ) {
285 CPropTreeItemCombo *combo = (CPropTreeItemCombo *)item;
286 CString materialName;
288 combo->GetLBText( combo->GetCurSel(), materialName );
290 materialPreview->OnLightShaderChange( lightId, materialName.GetBuffer() );
292 } else if ( itemLabel == "Radius" ) {
293 materialPreview->OnLightRadiusChange( lightId, atof( (char *)item->GetItemValue() ) );
295 } else if ( itemLabel == "Color" ) {
296 color = item->GetItemValue();
298 testColor.x = (float)GetRValue( color ) * (float)( 1.f/255.f );
299 testColor.y = (float)GetGValue( color ) * (float)( 1.f/255.f );
300 testColor.z = (float)GetBValue( color ) * (float)( 1.f/255.f );
302 materialPreview->OnLightColorChange( lightId, testColor );
304 } else if ( itemLabel == "Move light" ) {
305 materialPreview->OnLightAllowMoveChange( lightId, item->GetItemValue() ? true : false );
307 } else if ( itemLabel.Left(4) == "parm" ) {
310 itemLabel.Strip( "parm" );
311 index = atoi( itemLabel.c_str() );
313 materialPreview->OnLocalParmChange( index, atof( (char *)item->GetItemValue() ) );
315 } else if ( itemLabel.Left(6) == "global" ) {
318 itemLabel.Strip( "global" );
319 index = atoi( itemLabel.c_str() );
321 materialPreview->OnGlobalParmChange( index, atof( (char *)item->GetItemValue() ) );
325 void MaterialPreviewPropView::OnPropertyButtonClick( NMHDR *nmhdr, LRESULT *lresult ) {
329 nmProp = (NMPROPTREE *)nmhdr;
330 item = nmProp->pItem;
332 idStr itemLabel = item->GetLabelText();
334 if ( itemLabel == "Preview Lights" ) {
337 } else if ( itemLabel.Left(5) == "Light" ) {
338 CPropTreeItem *light;
339 int lightId = item->GetCtrlID();
340 int testLightNum = 0;
342 m_Tree.DeleteItem( item );
344 for( light = m_Tree.GetRootItem()->GetChild(); light != NULL; light = light->GetSibling() ) {
345 idStr label = light->GetLabelText();
347 if ( label.Left(5) == "Light" ) {
349 light->SetLabelText(_T(va("Light #%d", testLightNum)));
350 light->SetInfoText(_T(va("Parameters for light number %d.", testLightNum)));
351 light->SetCtrlID( testLightNum - 1 );
355 materialPreview->OnDeleteLight( lightId );
358 } else if ( itemLabel == "Custom Model" ) {
359 CFileDialog dlg(TRUE);
360 dlg.m_ofn.Flags |= OFN_FILEMUSTEXIST;
362 if( dlg.DoModal()== IDOK) {
364 item->SetItemValue((LPARAM)fileSystem->OSPathToRelativePath(dlg.m_ofn.lpstrFile));
365 m_Tree.SendNotify(PTN_ITEMCHANGED, item);