doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MaterialEditView.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 "MaterialEditView.h"
32 
33 #ifdef _DEBUG
34 #define new DEBUG_NEW
35 #endif
36 
37 #define EDIT_HEIGHT 25
38 
39 #define EDIT_TAB_CONTROL 0x2006
40 #define NAME_CONTROL 0x2007
41 
43 
44 BEGIN_MESSAGE_MAP(MaterialEditView, CFormView)
45  ON_WM_SIZE()
46  ON_WM_CREATE()
47  ON_NOTIFY(TCN_SELCHANGE, EDIT_TAB_CONTROL, OnTcnSelChange)
48  ON_NOTIFY(EN_CHANGE, IDC_MATERIALEDITOR_EDIT_TEXT, OnEnChangeEdit)
49 END_MESSAGE_MAP()
50 
54 MaterialEditView::MaterialEditView()
55 : CFormView(MaterialEditView::IDD) {
56 
57  initHack = false;
58  sourceInit = false;
59  sourceChanged = false;
60 }
61 
66 }
67 
73 
74  //Apply any text changes that have been made
76 
77  if(pMaterial) {
78  m_nameEdit.SetWindowText(pMaterial->name);
79  m_textView.SetReadOnly(false);
80 
81  //If the edit tab is selected then get the source
82  int sel = m_tabs.GetCurSel();
83  if (sel == 1) {
85  }
86 
87  currentMaterialName = pMaterial->name;
88  } else {
89  m_nameEdit.SetWindowText("");
90 
92  m_textView.SetReadOnly(true);
93 
95  }
96 }
97 
98 void MaterialEditView::MV_OnMaterialNameChanged(MaterialDoc* pMaterial, const char* oldName) {
99  if(!currentMaterialName.Icmp(oldName)) {
100  currentMaterialName = pMaterial->name;
101  }
102 }
103 
108  idStr text;
109  m_textView.GetText(text);
110 
111  text.Replace( "\n", "" );
112  text.Replace( "\r", "\r\n" );
113  text.Replace( "\v", "\r\n" );
114  text.StripLeading( "\r\n" );
115  text.Insert( "\r\n\r\n", 0 );
116  text.StripTrailing( "\r\n" );
117 
118  return text;
119 }
120 
126 
127  //Clear it
128  sourceInit = true;
129  m_textView.SetText("");
130  sourceInit = false;
131 
132  if(materialDocManager) {
134  if(material) {
135  idStr text = material->GetEditSourceText();
136 
137  // clean up new-line crapola
138  text.Replace( "\r", "" );
139  text.Replace( "\n", "\r" );
140  text.Replace( "\v", "\r" );
141  text.StripLeading( '\r' );
142  text.Append( "\r" );
143 
144  sourceInit = true;
145  m_textView.SetText(text);
146  sourceInit = false;
147  }
148  }
149 }
150 
156 
157  if(!sourceChanged)
158  return;
159 
161 
162  if(material) {
163  idStr text = GetSourceText();
164  material->ApplySourceModify(text);
165  }
166 
167  sourceChanged = false;
168 }
169 
173 void MaterialEditView::DoDataExchange(CDataExchange* pDX) {
174 
175  CFormView::DoDataExchange(pDX);
176 
177  DDX_Control(pDX, IDC_MATERIALEDITOR_EDIT_TEXT, m_textView);
178 }
179 
184 
185  CFormView::OnInitialUpdate();
186 
187  if(!initHack) {
188  initHack = true;
189  m_textView.Init();
190  m_textView.LoadKeyWordsFromFile( "editors/material.def" );
191  m_textView.ShowWindow(SW_HIDE);
192 
193  m_textView.SetText("");
194  m_textView.SetReadOnly(true);
195  }
196 }
197 
201 int MaterialEditView::OnCreate(LPCREATESTRUCT lpCreateStruct)
202 {
203  if (CFormView::OnCreate(lpCreateStruct) == -1)
204  return -1;
205 
206  m_nameEdit.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_READONLY, CRect(0,0,0,0), this, NAME_CONTROL);
207 
208  m_editSplitter.CreateStatic(this, 1, 2);
209 
210  if(!m_editSplitter.CreateView(0, 0, RUNTIME_CLASS(StageView), CSize(200, 200), NULL)) {
211  TRACE0("Failed to create stage property pane\n");
212  return -1;
213  }
214 
215  if(!m_editSplitter.CreateView(0, 1, RUNTIME_CLASS(MaterialPropTreeView), CSize(500, 200), NULL)) {
216  TRACE0("Failed to create property pane\n");
217  return -1;
218  }
219 
221 
222  m_stageView = (StageView*)m_editSplitter.GetPane(0, 0);
224 
225  m_tabs.Create(TCS_BOTTOM | TCS_FLATBUTTONS | WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this, EDIT_TAB_CONTROL);
226  m_tabs.InsertItem(0, "Properties");
227  m_tabs.InsertItem(1, "Text");
228 
229  m_tabs.SetFont(materialEditorFont);
230 
231  return 0;
232 }
233 
237 void MaterialEditView::OnSize(UINT nType, int cx, int cy) {
238  CFormView::OnSize(nType, cx, cy);
239 
240  CRect tabRect;
241  m_tabs.GetItemRect(0, tabRect);
242 
243  int tabHeight = tabRect.Height()+5;
244 
245  //Hardcode the edit window height
246  if(m_nameEdit.GetSafeHwnd()) {
247  m_nameEdit.MoveWindow(1,1, cx-2, 20);
248  }
249 
250  if(m_tabs.GetSafeHwnd()) {
251  m_tabs.MoveWindow(0, cy-tabHeight, cx, tabHeight);
252  }
253 
254  if(m_editSplitter.GetSafeHwnd()) {
255  m_editSplitter.MoveWindow(1, 22, cx-2, cy-tabHeight-22);
256  }
257 
258  if(m_textView.GetSafeHwnd()) {
259  m_textView.MoveWindow(1, 22, cx-2, cy-tabHeight-22);
260  }
261 }
262 
267 void MaterialEditView::OnTcnSelChange(NMHDR *pNMHDR, LRESULT *pResult) {
268 
269  int sel = m_tabs.GetCurSel();
270 
271  switch(sel) {
272  case 0:
273  m_editSplitter.ShowWindow(SW_SHOW);
274  m_textView.ShowWindow(SW_HIDE);
275 
277 
279 
280  break;
281  case 1:
282  m_editSplitter.ShowWindow(SW_HIDE);
283  m_textView.ShowWindow(SW_SHOW);
284 
286  m_textView.SetReadOnly(false);
287  }
288 }
289 
293 void MaterialEditView::OnEnChangeEdit( NMHDR *pNMHDR, LRESULT *pResult ) {
296  if(material && !material->IsSourceModified()) {
297  sourceChanged = true;
298  material->SourceModify(this);
299  }
300  }
301 }
302 
303 
304 
305 
306 
307 
308 
View that displays material and stage properties and allows the user to edit the properties.
void StripLeading(const char c)
Definition: Str.cpp:469
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
void GetText(idStr &text) const
afx_msg void OnEnChangeEdit(NMHDR *pNMHDR, LRESULT *pResult)
Called when the user changes text in the edit control.
void SourceModify(SourceModifyOwner *owner)
Called when the editor modifies the source of the material.
void StripTrailing(const char c)
Definition: Str.cpp:515
StageView * m_stageView
CSplitterWnd m_editSplitter
void ApplyMaterialSource()
Takes the source out of the edit control and applies it to the material.
int Icmp(const char *text) const
Definition: Str.h:667
void SetText(const char *text)
const char * GetEditSourceText()
Returns the appropriate source for the editing.
#define IDC_MATERIALEDITOR_EDIT_TEXT
Responsible for managing a single material that is being viewed and/or edited.
Definition: MaterialDoc.h:67
afx_msg void OnTcnSelChange(NMHDR *pNMHDR, LRESULT *pResult)
Called when the user changes the properties/text tab selection.
View that contains the material edit controls.
View that handles managing the material stages.
Definition: StageView.h:41
#define NAME_CONTROL
afx_msg void OnSize(UINT nType, int cx, int cy)
Windows message called when the window is resized.
#define NULL
Definition: Lib.h:88
idStr name
Definition: MaterialDoc.h:71
bool IsSourceModified()
Returns true if the source text of this material has been edited.
MaterialDoc * CreateMaterialDoc(const char *materialName)
Creates a MaterialDoc object for the specified material name.
virtual void MV_OnMaterialNameChanged(MaterialDoc *pMaterial, const char *oldName)
Called when the material name has changed.
void Insert(const char a, int index)
Definition: Str.h:779
virtual void DoDataExchange(CDataExchange *pDX)
Transfers data to and from the controls in the console.
#define EDIT_TAB_CONTROL
void RefreshStageList()
Rebuilds the list of stages based on the currently selected material.
Definition: StageView.cpp:267
IMPLEMENT_DYNCREATE(CCamWnd, CWnd)
void Append(const char a)
Definition: Str.h:729
MaterialDocManager * materialDocManager
Definition: MaterialView.h:143
virtual ~MaterialEditView()
Destructor for MaterialEditView.
Definition: Str.h:116
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct)
Called by the MFC framework when the view is being created.
CFont * materialEditorFont
void ApplySourceModify(idStr &text)
Applies any source changes to the edit representation of the material.
virtual idStr GetSourceText()
Returns the current source text in the source edit control.
virtual void MV_OnMaterialSelectionChange(MaterialDoc *pMaterial)
Called when the selected material has changed.
MaterialPropTreeView * m_materialPropertyView
MaterialDoc * GetCurrentMaterialDoc()
void Replace(const char *old, const char *nw)
Definition: Str.cpp:563
virtual void OnInitialUpdate()
Called by the MFC framework when the view is being created.
bool LoadKeyWordsFromFile(const char *fileName)
CSyntaxRichEditCtrl m_textView
void GetMaterialSource()
Gets the source of the current document and populates the source edit control.