doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaterialPropTreeView.cpp
Go to the documentation of this file.
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 "../../idlib/precompiled.h"
29 #pragma hdrstop
30 
31 #include "MaterialPropTreeView.h"
32 
33 #define PROP_TREE_VIEW "PropTreeView"
34 
35 
37 
38 BEGIN_MESSAGE_MAP(MaterialPropTreeView, CPropTreeView)
39  ON_NOTIFY( PTN_ITEMCHANGED, IDC_PROPERTYTREE, OnPropertyChangeNotification )
40  ON_NOTIFY( PTN_ITEMEXPANDING, IDC_PROPERTYTREE, OnPropertyItemExpanding )
41 END_MESSAGE_MAP()
42 
43 
47 MaterialPropTreeView::MaterialPropTreeView() {
48  registry.Init("Software\\id Software\\DOOM3\\Tools\\MaterialEditor\\PropertySettings");
49  internalChange = false;
50 }
51 
56 }
57 
63 void MaterialPropTreeView::SetPropertyListType(int listType, int stageNum) {
64 
65  currentListType = listType;
66  currentStage = stageNum;
67 
69 
70  //idList<MaterialProp_t*>* propList = NULL;
72  currentPropDefs = propList;
73 
74  if(!propList)
75  return;
76 
77  CPropTreeItem* pCurrentGroup = NULL;
78  CPropTreeItem* pCurrentNode = NULL;
79 
80  for(int i = 0; i < propList->Num(); i++) {
81  switch((*propList)[i]->type) {
83  {
84  pCurrentGroup = m_Tree.InsertItem(new CPropTreeItem());
85  pCurrentNode = pCurrentGroup;
86 
87  if(!registry.GetBool(va("Expand%d%s", currentListType, (*propList)[i]->displayName.c_str())))
88  pCurrentGroup->Expand();
89  }
90  break;
92  {
93  CPropTreeItemCheck* pCheck;
94  pCheck = (CPropTreeItemCheck*)m_Tree.InsertItem(new CPropTreeItemCheck(), pCurrentGroup);
95  pCheck->CreateCheckBox();
96  pCurrentNode = pCheck;
97  }
98  break;
100  {
101  //pCurrentNode = m_Tree.InsertItem(new CPropTreeItemEdit(), pCurrentGroup);
102  pCurrentNode = m_Tree.InsertItem(new CPropTreeItemFileEdit(), pCurrentGroup);
103 
104  }
105  break;
106  }
107 
108  if(pCurrentNode) {
109  (*propList)[i]->SetViewData(PROP_TREE_VIEW, pCurrentNode->GetCtrlID());
110  pCurrentNode->SetLabelText((*propList)[i]->displayName);
111  pCurrentNode->SetInfoText((*propList)[i]->displayInfo);
112  }
113  }
114 
116 }
117 
122  registry.Load();
123 }
124 
129  registry.Save();
130 }
131 
137 
140  if(!internalChange && !pMaterial->name.Icmp(currentName)) {
142  }
143  }
144 }
145 
149 void MaterialPropTreeView::OnPropertyChangeNotification( NMHDR *nmhdr, LRESULT *lresult ) {
150 
151  NMPROPTREE *nmProp = (NMPROPTREE *)nmhdr;
152  CPropTreeItem *item = nmProp->pItem;
153 
154  internalChange = true;
155 
156  MaterialDef* propItem = FindDefForTreeID(item->GetCtrlID());
157  if(propItem) {
159 
160  switch(propItem->type) {
162  {
163  BOOL val = item->GetItemValue();
164  materialDoc->SetAttributeBool(currentStage, propItem->dictName, val ? true : false);
165  }
166  break;
168  {
169  idStr val = (LPCTSTR)item->GetItemValue();
170  materialDoc->SetAttribute(currentStage, propItem->dictName, val);
171  }
172  break;
173  }
174  }
175 
176  internalChange = false;
177 
178  *lresult = 0;
179 }
180 
184 void MaterialPropTreeView::OnPropertyItemExpanding( NMHDR *nmhdr, LRESULT *lresult ) {
185 
186  NMPROPTREE *nmProp = (NMPROPTREE *)nmhdr;
187  CPropTreeItem *item = nmProp->pItem;
188 
189  //The item isn't toggled till after this returns so use the opposite of the current state.
190  registry.SetBool(va("Expand%d%s", currentListType, item->GetLabelText()), item->IsExpanded() ? true : false);
191  registry.Save();
192 
193  *lresult = 0;
194 }
195 
201 
202  int c = currentPropDefs->Num();
203  for(int i = 0; i < c; i++) {
204  if((*currentPropDefs)[i]->GetViewData(PROP_TREE_VIEW) == treeID)
205  return (*currentPropDefs)[i];
206  }
207 
208  return NULL;
209 }
210 
215 
217 
218  if(!propList)
219  return;
220 
222 
223  for(int i = 0; i < propList->Num(); i++) {
224  switch((*propList)[i]->type) {
226  {
227  bool val = materialDoc->GetAttributeBool(currentStage, (*propList)[i]->dictName);
228  CPropTreeItemCheck* item = (CPropTreeItemCheck*)m_Tree.FindItem((*propList)[i]->GetViewData(PROP_TREE_VIEW));
229  item->SetCheckState(val ? TRUE:FALSE);
230  }
231  break;
233  {
234  idStr val = materialDoc->GetAttribute(currentStage, (*propList)[i]->dictName);
235  CPropTreeItemEdit* item = (CPropTreeItemEdit*)m_Tree.FindItem((*propList)[i]->GetViewData(PROP_TREE_VIEW));
236  item->SetItemValue((LPARAM)val.c_str());
237  }
238  break;
239  }
240  }
241 
242  Invalidate();
243 }
244 
245 
246 
247 
248 
View that displays material and stage properties and allows the user to edit the properties.
virtual ~MaterialPropTreeView()
Destructor for MaterialPropTreeView.
idStr dictName
Definition: MaterialDef.h:51
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
MaterialDefList * currentPropDefs
#define IDC_PROPERTYTREE
Definition: PropTreeView.h:6
void SetPropertyListType(int listType, int stageNum=-1)
Initializes the list of properties based on the type (material, stage, special stage).
void DeleteAllItems()
Definition: PropTree.cpp:376
LPCTSTR GetLabelText()
#define PTN_ITEMCHANGED
Definition: PropTree.h:100
rvRegistryOptions registry
void SaveSettings()
Saves the property view settings to the registry.
#define PROP_TREE_VIEW
afx_msg void OnPropertyItemExpanding(NMHDR *nmhdr, LRESULT *lresult)
Changes the property setting of a group when is expanding.
void SetLabelText(LPCTSTR sLabel)
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
MaterialDef * FindDefForTreeID(UINT treeID)
Returns the MeterialDef for a given property tree item.
int Icmp(const char *text) const
Definition: Str.h:667
virtual LPARAM GetItemValue()
Represents a single attribute in a material.
Definition: MaterialDef.h:36
void LoadSettings()
Loads the property view settings from the registry.
void SetAttribute(int stage, const char *attribName, const char *value, bool addUndo=true)
Sets an attribute string in the material or a stage.
Responsible for managing a single material that is being viewed and/or edited.
Definition: MaterialDoc.h:67
const GLubyte * c
Definition: glext.h:4677
#define NULL
Definition: Lib.h:88
idStr name
Definition: MaterialDoc.h:71
void SetBool(const char *name, bool v)
virtual void SetItemValue(LPARAM lParam)
CPropTree m_Tree
Definition: PropTreeView.h:13
CPropTreeItem * pItem
Definition: PropTree.h:91
#define PTN_ITEMEXPANDING
Definition: PropTree.h:103
void Expand(BOOL bExpand=TRUE)
void SetAttributeBool(int stage, const char *attribName, bool value, bool addUndo=true)
Sets an attribute bool in the material or a stage.
const char * GetAttribute(int stage, const char *attribName, const char *defaultString="")
Returns an attribute string from the material or a stage.
afx_msg void OnPropertyChangeNotification(NMHDR *nmhdr, LRESULT *lresult)
Updated the material when an attribute has been changed.
void SetInfoText(LPCTSTR sInfo)
virtual void MV_OnMaterialChange(MaterialDoc *pMaterial)
Called when the material has changed but not applied.
IMPLEMENT_DYNCREATE(CCamWnd, CWnd)
bool GetAttributeBool(int stage, const char *attribName, const char *defaultString="0")
Returns an attribute bool from the material or a stage.
int Num(void) const
Definition: List.h:265
MaterialDocManager * materialDocManager
Definition: MaterialView.h:143
bool GetBool(const char *name)
Definition: Str.h:116
const char * c_str(void) const
Definition: Str.h:487
#define FALSE
Definition: mprintf.c:70
CPropTreeItem * FindItem(const POINT &pt)
Definition: PropTree.cpp:620
CPropTreeItem * InsertItem(CPropTreeItem *pItem, CPropTreeItem *pParent=NULL)
Definition: PropTree.cpp:549
#define TRUE
Definition: mprintf.c:69
static MaterialDefList * GetMaterialDefs(int type)
Returns the MaterialDefList for the specified attribute grouping.
void RefreshProperties()
Initializes the property tree with the data from the currently selected material. ...
char * va(const char *fmt,...)
Definition: Str.cpp:1568
MaterialDoc * GetCurrentMaterialDoc()
Definition: List.h:84
void SetCheckState(BOOL state)