MaterialPreviewPropView.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "MaterialPreviewPropView.h"
  23. // MaterialPropTreeView
  24. IMPLEMENT_DYNCREATE(MaterialPreviewPropView, CPropTreeView)
  25. MaterialPreviewPropView::MaterialPreviewPropView() {
  26. numLights = 0;
  27. materialPreview = NULL;
  28. }
  29. MaterialPreviewPropView::~MaterialPreviewPropView() {
  30. }
  31. BEGIN_MESSAGE_MAP(MaterialPreviewPropView, CPropTreeView)
  32. ON_NOTIFY( PTN_ITEMCHANGED, IDC_PROPERTYTREE, OnPropertyChangeNotification )
  33. ON_NOTIFY( PTN_ITEMBUTTONCLICK, IDC_PROPERTYTREE, OnPropertyButtonClick )
  34. END_MESSAGE_MAP()
  35. void MaterialPreviewPropView::AddLight( void ) {
  36. int i, count, lightShaderIndex = 0;
  37. const idMaterial *mat;
  38. CPropTreeItemButton* pRoot;
  39. CPropTreeItemCombo* pCombo;
  40. CPropTreeItemColor* pColor;
  41. CPropTreeItemCheck* pCheck;
  42. CPropTreeItemEdit* pEdit;
  43. //Increase the number of lights
  44. numLights++;
  45. pRoot = (CPropTreeItemButton*)m_Tree.InsertItem(new CPropTreeItemButton());
  46. pRoot->SetLabelText(_T(va("Light #%d", numLights)));
  47. pRoot->SetInfoText(_T(va("Parameters for light number %d.", numLights)));
  48. pRoot->SetButtonText( "Remove" );
  49. pRoot->SetCtrlID( numLights - 1 );
  50. pRoot->Expand();
  51. pCombo = (CPropTreeItemCombo*)m_Tree.InsertItem(new CPropTreeItemCombo(), pRoot);
  52. pCombo->SetLabelText( _T("Shader") );
  53. pCombo->SetInfoText( _T("Set the light shader.") );
  54. pCombo->SetDropDownHeight( 200 );
  55. pCombo->CreateComboBox();
  56. // Add all light shaders to the combo box
  57. count = declManager->GetNumDecls( DECL_MATERIAL );
  58. for (i = 0; i < count; i++) {
  59. mat = declManager->MaterialByIndex(i, false);
  60. idStr materialName = mat->GetName();
  61. materialName.ToLower();
  62. if ( materialName.Left(7) == "lights/" || materialName.Left(5) == "fogs/" ) {
  63. pCombo->InsertString( lightShaderIndex, materialName );
  64. pCombo->SetItemData( lightShaderIndex, lightShaderIndex );
  65. if ( materialName == "lights/defaultpointlight" ) {
  66. pCombo->SetCurSel( lightShaderIndex );
  67. }
  68. lightShaderIndex++;
  69. }
  70. }
  71. pColor = (CPropTreeItemColor*)m_Tree.InsertItem(new CPropTreeItemColor(), pRoot);
  72. pColor->SetLabelText(_T("Color"));
  73. pColor->SetInfoText(_T("Color of the light."));
  74. pColor->SetItemValue((LPARAM)RGB(0xff, 0xff, 0xff)); // default as color white
  75. pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem( new CPropTreeItemEdit(), pRoot);
  76. pEdit->SetLabelText(_T("Radius"));
  77. pEdit->SetInfoText(_T("Radius of the light."));
  78. pEdit->SetItemValue( (LPARAM)_T("300.0") );
  79. pCheck = (CPropTreeItemCheck*)m_Tree.InsertItem(new CPropTreeItemCheck(), pRoot);
  80. pCheck->SetLabelText(_T("Move light"));
  81. pCheck->SetInfoText(_T("When checked, allow light to move."));
  82. pCheck->CreateCheckBox();
  83. pCheck->SetCheckState( BST_CHECKED );
  84. if ( materialPreview ) {
  85. materialPreview->OnAddLight();
  86. }
  87. }
  88. //Create sample data for the preview properties
  89. void MaterialPreviewPropView::InitializePropTree( void ) {
  90. int i;
  91. CPropTreeItem *pRoot;
  92. CPropTreeItem *pParmRoot;
  93. CPropTreeItemCheck *pCheck;
  94. CPropTreeItemEdit *pEdit;
  95. pRoot = m_Tree.InsertItem(new CPropTreeItem());
  96. pRoot->SetLabelText(_T("Preview Properties"));
  97. pRoot->SetInfoText(_T("Properties for the preview window."));
  98. pRoot->Expand(); // have this item expanded by default
  99. CPropTreeItemCombo* pCombo;
  100. pCombo = (CPropTreeItemCombo*)m_Tree.InsertItem(new CPropTreeItemCombo(), pRoot);
  101. pCombo->SetLabelText(_T("Model Type"));
  102. pCombo->SetInfoText(_T("Select the type of model on which to preview the material."));
  103. pCombo->CreateComboBox();
  104. pCombo->InsertString( 0, "Cube" );
  105. pCombo->InsertString( 1, "Box - 2:1");
  106. pCombo->InsertString( 2, "Box - 4:1");
  107. pCombo->InsertString( 3, "Box - 1:2");
  108. pCombo->InsertString( 4, "Box - 1:4");
  109. pCombo->InsertString( 5, "Cylinder - V");
  110. pCombo->InsertString( 6, "Cylinder - H");
  111. pCombo->InsertString( 7, "Sphere");
  112. pCombo->SetItemData( 0, 0 );
  113. pCombo->SetItemData( 1, 1 );
  114. pCombo->SetItemData( 2, 2 );
  115. pCombo->SetItemData( 3, 3 );
  116. pCombo->SetItemData( 4, 4 );
  117. pCombo->SetItemData( 5, 5 );
  118. pCombo->SetItemData( 6, 6 );
  119. pCombo->SetItemData( 7, 7 );
  120. pCombo->SetCurSel( 0 );
  121. // Custom model entry
  122. /*pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem( new CPropTreeItemEdit(), pRoot );
  123. pEdit->SetLabelText(_T("Custom Model"));
  124. pEdit->SetInfoText(_T("Specify any model to display the current material."));
  125. pEdit->SetItemValue((LPARAM)_T(""));*/
  126. CPropTreeItemEditButton *pCutomButton;
  127. pCutomButton = (CPropTreeItemEditButton*)m_Tree.InsertItem(new CPropTreeItemEditButton(), pRoot );
  128. pCutomButton->SetButtonText(_T("..."));
  129. pCutomButton->SetLabelText(_T("Custom Model"));
  130. pCutomButton->SetInfoText(_T("Specify any model to display the current material."));
  131. pCutomButton->SetItemValue((LPARAM)_T(""));
  132. // Checkbox for showing debug light spheres
  133. pCheck = (CPropTreeItemCheck*)m_Tree.InsertItem( new CPropTreeItemCheck(), pRoot );
  134. pCheck->SetLabelText(_T("Show Lights"));
  135. pCheck->SetInfoText(_T("Show the light origin sphere and number in the preview."));
  136. pCheck->CreateCheckBox();
  137. pCheck->SetCheckState( BST_CHECKED );
  138. // Local and Global shader parms
  139. pParmRoot = m_Tree.InsertItem(new CPropTreeItem());
  140. pParmRoot->SetLabelText(_T("Local Parms"));
  141. pParmRoot->SetInfoText(_T("Local shaderparms for the model being displayed."));
  142. pParmRoot->Expand( FALSE ); // have this item NOT expanded by default
  143. for( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ ) {
  144. pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem( new CPropTreeItemEdit(), pParmRoot );
  145. pEdit->SetLabelText(_T(va("parm%d", i)));
  146. pEdit->SetInfoText(_T("Set the local shaderparm for the model"));
  147. if ( i < 4 ) {
  148. pEdit->SetItemValue((LPARAM)_T("1"));
  149. } else {
  150. pEdit->SetItemValue((LPARAM)_T("0"));
  151. }
  152. }
  153. pParmRoot = m_Tree.InsertItem(new CPropTreeItem());
  154. pParmRoot->SetLabelText(_T("Global Parms"));
  155. pParmRoot->SetInfoText(_T("Global shaderparms for the renderworld being displayed."));
  156. pParmRoot->Expand( FALSE ); // have this item NOT expanded by default
  157. for( i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ ) {
  158. pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem( new CPropTreeItemEdit(), pParmRoot );
  159. pEdit->SetLabelText(_T(va("global%d", i)));
  160. pEdit->SetInfoText(_T("Set the global shaderparm for the renderworld"));
  161. if ( i < 4 ) {
  162. pEdit->SetItemValue((LPARAM)_T("1"));
  163. } else {
  164. pEdit->SetItemValue((LPARAM)_T("0"));
  165. }
  166. }
  167. // Lights
  168. pRoot = m_Tree.InsertItem(new CPropTreeItem());
  169. pRoot->SetLabelText(_T(""));
  170. pRoot->SetInfoText(_T(""));
  171. CPropTreeItemButton *pButton;
  172. pButton = (CPropTreeItemButton*)m_Tree.InsertItem(new CPropTreeItemButton());
  173. pButton->SetButtonText(_T(" Add Light "));
  174. pButton->SetLabelText(_T("Preview Lights"));
  175. pButton->SetInfoText(_T("Test the button."));
  176. pRoot = m_Tree.InsertItem(new CPropTreeItem());
  177. pRoot->SetLabelText(_T(""));
  178. pRoot->SetInfoText(_T(""));
  179. AddLight();
  180. }
  181. // MaterialPreviewPropView drawing
  182. void MaterialPreviewPropView::OnDraw(CDC* pDC)
  183. {
  184. // TODO: add draw code here
  185. }
  186. // MaterialPreviewPropView diagnostics
  187. #ifdef _DEBUG
  188. void MaterialPreviewPropView::AssertValid() const
  189. {
  190. CPropTreeView::AssertValid();
  191. }
  192. void MaterialPreviewPropView::Dump(CDumpContext& dc) const
  193. {
  194. CPropTreeView::Dump(dc);
  195. }
  196. #endif //_DEBUG
  197. void MaterialPreviewPropView::RegisterPreviewView( MaterialPreviewView *view ) {
  198. materialPreview = view;
  199. }
  200. // MaterialPreviewPropView message handlers
  201. void MaterialPreviewPropView::OnPropertyChangeNotification( NMHDR *nmhdr, LRESULT *lresult ) {
  202. idVec3 testColor;
  203. int lightId = 0;
  204. COLORREF color;
  205. NMPROPTREE *nmProp;
  206. CPropTreeItem *item;
  207. CPropTreeItem *parent;
  208. nmProp = (NMPROPTREE *)nmhdr;
  209. item = nmProp->pItem;
  210. // Determine which light this item modifies
  211. parent = item->GetParent();
  212. if ( parent ) {
  213. lightId = parent->GetCtrlID();
  214. }
  215. idStr itemLabel = item->GetLabelText();
  216. if ( itemLabel == "Model Type" ) {
  217. materialPreview->OnModelChange( item->GetItemValue() );
  218. } else if ( itemLabel == "Custom Model" ) {
  219. materialPreview->OnCustomModelChange( (const char *)item->GetItemValue() );
  220. } else if ( itemLabel == "Show Lights" ) {
  221. materialPreview->OnShowLightsChange( item->GetItemValue() ? true : false );
  222. } else if ( itemLabel == "Shader" ) {
  223. CPropTreeItemCombo *combo = (CPropTreeItemCombo *)item;
  224. CString materialName;
  225. combo->GetLBText( combo->GetCurSel(), materialName );
  226. materialPreview->OnLightShaderChange( lightId, materialName.GetBuffer() );
  227. } else if ( itemLabel == "Radius" ) {
  228. materialPreview->OnLightRadiusChange( lightId, atof( (char *)item->GetItemValue() ) );
  229. } else if ( itemLabel == "Color" ) {
  230. color = item->GetItemValue();
  231. testColor.x = (float)GetRValue( color ) * (float)( 1.f/255.f );
  232. testColor.y = (float)GetGValue( color ) * (float)( 1.f/255.f );
  233. testColor.z = (float)GetBValue( color ) * (float)( 1.f/255.f );
  234. materialPreview->OnLightColorChange( lightId, testColor );
  235. } else if ( itemLabel == "Move light" ) {
  236. materialPreview->OnLightAllowMoveChange( lightId, item->GetItemValue() ? true : false );
  237. } else if ( itemLabel.Left(4) == "parm" ) {
  238. int index;
  239. itemLabel.Strip( "parm" );
  240. index = atoi( itemLabel.c_str() );
  241. materialPreview->OnLocalParmChange( index, atof( (char *)item->GetItemValue() ) );
  242. } else if ( itemLabel.Left(6) == "global" ) {
  243. int index;
  244. itemLabel.Strip( "global" );
  245. index = atoi( itemLabel.c_str() );
  246. materialPreview->OnGlobalParmChange( index, atof( (char *)item->GetItemValue() ) );
  247. }
  248. }
  249. void MaterialPreviewPropView::OnPropertyButtonClick( NMHDR *nmhdr, LRESULT *lresult ) {
  250. NMPROPTREE *nmProp;
  251. CPropTreeItem *item;
  252. nmProp = (NMPROPTREE *)nmhdr;
  253. item = nmProp->pItem;
  254. idStr itemLabel = item->GetLabelText();
  255. if ( itemLabel == "Preview Lights" ) {
  256. AddLight();
  257. } else if ( itemLabel.Left(5) == "Light" ) {
  258. CPropTreeItem *light;
  259. int lightId = item->GetCtrlID();
  260. int testLightNum = 0;
  261. m_Tree.DeleteItem( item );
  262. for( light = m_Tree.GetRootItem()->GetChild(); light != NULL; light = light->GetSibling() ) {
  263. idStr label = light->GetLabelText();
  264. if ( label.Left(5) == "Light" ) {
  265. testLightNum++;
  266. light->SetLabelText(_T(va("Light #%d", testLightNum)));
  267. light->SetInfoText(_T(va("Parameters for light number %d.", testLightNum)));
  268. light->SetCtrlID( testLightNum - 1 );
  269. }
  270. }
  271. materialPreview->OnDeleteLight( lightId );
  272. numLights--;
  273. } else if ( itemLabel == "Custom Model" ) {
  274. CFileDialog dlg(TRUE);
  275. dlg.m_ofn.Flags |= OFN_FILEMUSTEXIST;
  276. item->Check(FALSE);
  277. if( dlg.DoModal()== IDOK) {
  278. item->Check(FALSE);
  279. item->SetItemValue((LPARAM)fileSystem->OSPathToRelativePath(dlg.m_ofn.lpstrFile));
  280. m_Tree.SendNotify(PTN_ITEMCHANGED, item);
  281. }
  282. }
  283. }