LightMapView.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program 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. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LightMap *
  23. * *
  24. * $Archive:: /Commando/Code/Tool $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 7/17/01 3:17p $*
  29. * *
  30. * $Revision:: 27 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Includes.
  36. #include "StdAfx.h"
  37. #include "LightMap.h"
  38. #include "InsertSolveDialog.h"
  39. #include "LightMapDoc.h"
  40. #include "LightMapView.h"
  41. #include "OptionsDialog.h"
  42. #include "PackingDialog.h"
  43. #include "SelectionDialog.h"
  44. #include "StringBuilder.h"
  45. // The following is maintained by MFC tools.
  46. #ifdef _DEBUG
  47. #define new DEBUG_NEW
  48. #undef THIS_FILE
  49. static char THIS_FILE[] = __FILE__;
  50. #endif
  51. IMPLEMENT_DYNCREATE(LightMapView, CListView)
  52. BEGIN_MESSAGE_MAP(LightMapView, CListView)
  53. //{{AFX_MSG_MAP(LightMapView)
  54. ON_WM_CREATE()
  55. ON_COMMAND(ID_INSERT_SOLVE, OnInsertSolve)
  56. ON_UPDATE_COMMAND_UI(ID_INSERT_SOLVE, OnUpdateInsertSolve)
  57. ON_COMMAND(ID_TOOLS_OPTIONS, OnToolsOptions)
  58. ON_COMMAND(ID_TOOLS_PACKING, OnToolsPacking)
  59. ON_UPDATE_COMMAND_UI(ID_TOOLS_PACKING, OnUpdateToolsPacking)
  60. ON_WM_LBUTTONDOWN()
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. class MeshDialog : public CDialog
  64. {
  65. public:
  66. MeshDialog (UINT nIDTemplate, CWnd* pParentWnd, const char *meshname, const char *anomalies)
  67. : CDialog (nIDTemplate, pParentWnd)
  68. {
  69. MeshName = meshname;
  70. Anomalies = anomalies;
  71. }
  72. protected:
  73. virtual BOOL OnInitDialog();
  74. private:
  75. const char *MeshName;
  76. const char *Anomalies;
  77. };
  78. // Static data.
  79. LightMapDoc *LightMapView::_Document = NULL;
  80. /***********************************************************************************************
  81. * LightMapView::LightMapView -- *
  82. * *
  83. * INPUT: *
  84. * *
  85. * OUTPUT: *
  86. * *
  87. * WARNINGS: *
  88. * *
  89. * HISTORY: *
  90. * 6/1/99 IML : Created. *
  91. *=============================================================================================*/
  92. LightMapView::LightMapView()
  93. {
  94. MeshIndexTable = NULL;
  95. }
  96. /***********************************************************************************************
  97. * LightMapView::~LightMapView -- *
  98. * *
  99. * INPUT: *
  100. * *
  101. * OUTPUT: *
  102. * *
  103. * WARNINGS: *
  104. * *
  105. * HISTORY: *
  106. * 6/1/99 IML : Created. *
  107. *=============================================================================================*/
  108. LightMapView::~LightMapView()
  109. {
  110. if (MeshIndexTable != NULL) delete [] MeshIndexTable;
  111. }
  112. /***********************************************************************************************
  113. * LightMapView::OnInsertSolve -- *
  114. * *
  115. * INPUT: *
  116. * *
  117. * OUTPUT: *
  118. * *
  119. * WARNINGS: *
  120. * *
  121. * HISTORY: *
  122. * 6/1/99 IML : Created. *
  123. *=============================================================================================*/
  124. void LightMapView::OnInsertSolve()
  125. {
  126. // NOTE: Specify initial path to be that of current open document.
  127. InsertSolveDialog insertsolvedialog (GetDocument()->GetPathName());
  128. if (insertsolvedialog.DoModal() == IDOK) {
  129. char *inclusionstring;
  130. if (!insertsolvedialog.Apply_Selective()) {
  131. inclusionstring = NULL;
  132. } else {
  133. inclusionstring = insertsolvedialog.Inclusion_String();
  134. }
  135. GetDocument()->Insert_Solve (insertsolvedialog.Directory_Name(), insertsolvedialog.Filename_List(), inclusionstring, insertsolvedialog.Invert_Selection(), insertsolvedialog.Blend_Noise());
  136. }
  137. }
  138. /***********************************************************************************************
  139. * LightMapView::OnUpdateInsertSolve -- *
  140. * *
  141. * INPUT: *
  142. * *
  143. * OUTPUT: *
  144. * *
  145. * WARNINGS: *
  146. * *
  147. * HISTORY: *
  148. * 6/1/99 IML : Created. *
  149. *=============================================================================================*/
  150. void LightMapView::OnUpdateInsertSolve (CCmdUI *cmdui)
  151. {
  152. cmdui->Enable (GetDocument()->Can_Insert_Solve());
  153. }
  154. /***********************************************************************************************
  155. * LightMapView::OnCreate -- *
  156. * *
  157. * INPUT: *
  158. * *
  159. * OUTPUT: *
  160. * *
  161. * WARNINGS: *
  162. * *
  163. * HISTORY: *
  164. * 6/1/99 IML : Created. *
  165. *=============================================================================================*/
  166. int LightMapView::OnCreate (LPCREATESTRUCT lpCreateStruct)
  167. {
  168. static LV_COLUMN _meshname = {LVCF_TEXT | LVCF_FMT, LVCFMT_LEFT, 0, "Mesh Name", 0, 0};
  169. static LV_COLUMN _meshanomalies = {LVCF_TEXT | LVCF_FMT, LVCFMT_LEFT, 0, "Mesh Anomalies", 0, 0};
  170. static LV_COLUMN _solveanomalies = {LVCF_TEXT | LVCF_FMT, LVCFMT_LEFT, 0, "Solve Anomalies", 0, 0};
  171. static LV_COLUMN _vertexsolve = {LVCF_TEXT | LVCF_FMT, LVCFMT_LEFT, 0, "Vertex Solve", 0, 0};
  172. static LV_COLUMN _lightmapsolve = {LVCF_TEXT | LVCF_FMT, LVCFMT_LEFT, 0, "Lightmap Solve", 0, 0};
  173. CListCtrl &list = GetListCtrl();
  174. long flags = list.GetStyle();
  175. if (CListView::OnCreate(lpCreateStruct) == -1) return (-1);
  176. // Enable report style for the list view.
  177. flags |= LVS_REPORT | LVS_NOSORTHEADER;
  178. SetWindowLong (list.GetSafeHwnd(), GWL_STYLE, flags);
  179. list.SetExtendedStyle (LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT | LVS_EX_GRIDLINES);
  180. list.InsertColumn (0, &_meshname);
  181. list.InsertColumn (1, &_meshanomalies);
  182. list.InsertColumn (2, &_solveanomalies);
  183. list.InsertColumn (3, &_vertexsolve);
  184. list.InsertColumn (4, &_lightmapsolve);
  185. return (0);
  186. }
  187. /***********************************************************************************************
  188. * LightMapView::OnUpdate -- *
  189. * *
  190. * INPUT: *
  191. * *
  192. * OUTPUT: *
  193. * *
  194. * WARNINGS: *
  195. * *
  196. * HISTORY: *
  197. * 6/1/99 IML : Created. *
  198. *=============================================================================================*/
  199. void LightMapView::OnUpdate (CView* pSender, LPARAM lHint, CObject* pHint)
  200. {
  201. static float _widthratio [] = {0.18f, 0.25f, 0.25f, 0.16f, 0.16f};
  202. static LV_COLUMN _column = {LVCF_WIDTH, 0, 0, 0, 0, 0};
  203. unsigned meshindex;
  204. RECT rect;
  205. float w;
  206. CListCtrl &list = GetListCtrl();
  207. LightMapDoc *document;
  208. LVITEM item;
  209. StringBuilder text (256);
  210. document = GetDocument();
  211. // If there are meshes to display...
  212. if (document->Mesh_Count() > 0) {
  213. // Create a mesh index table that will place the mesh indices in alphabetical order of mesh name.
  214. if (MeshIndexTable != NULL) delete [] MeshIndexTable;
  215. MeshIndexTable = new unsigned [document->Mesh_Count()];
  216. ASSERT (MeshIndexTable != NULL);
  217. for (meshindex = 0; meshindex < document->Mesh_Count(); meshindex++) {
  218. MeshIndexTable [meshindex] = meshindex;
  219. }
  220. _Document = document;
  221. qsort (MeshIndexTable, document->Mesh_Count(), sizeof (unsigned), Compare_Names);
  222. _Document = NULL;
  223. list.DeleteAllItems();
  224. item.mask = LVIF_TEXT;
  225. item.iSubItem = 0;
  226. for (meshindex = 0; meshindex < document->Mesh_Count(); meshindex++) {
  227. unsigned remappedmeshindex;
  228. item.iItem = meshindex;
  229. remappedmeshindex = MeshIndexTable [meshindex];
  230. item.pszText = (char*) document->Mesh_Name (remappedmeshindex);
  231. list.InsertItem (&item);
  232. list.SetItemText (meshindex, 1, document->Mesh_Anomalies_String (remappedmeshindex, false, text));
  233. list.SetItemText (meshindex, 2, document->Solve_Anomalies_String (remappedmeshindex, false, text));
  234. list.SetItemText (meshindex, 3, document->Vertex_Solve_Status_String (remappedmeshindex, text));
  235. list.SetItemText (meshindex, 4, document->Lightmap_Solve_Status_String (remappedmeshindex, text));
  236. }
  237. }
  238. // Set the column widths.
  239. GetClientRect (&rect);
  240. w = (float) rect.right;
  241. for (unsigned c = 0; c < sizeof (_widthratio) / sizeof (float); c++) {
  242. float columnwidth;
  243. columnwidth = w * _widthratio [c];
  244. _column.cx = columnwidth;
  245. if (columnwidth - _column.cx > 0.5f) _column.cx++;
  246. list.SetColumn (c, &_column);
  247. }
  248. }
  249. /***********************************************************************************************
  250. * LightMapView::OnToolsOptions -- *
  251. * *
  252. * INPUT: *
  253. * *
  254. * OUTPUT: *
  255. * *
  256. * WARNINGS: *
  257. * *
  258. * HISTORY: *
  259. * 6/1/99 IML : Created. *
  260. *=============================================================================================*/
  261. void LightMapView::OnToolsOptions()
  262. {
  263. OptionsDialog options;
  264. options.DoModal();
  265. }
  266. /***********************************************************************************************
  267. * LightMapView::OnToolsPacking -- *
  268. * *
  269. * INPUT: *
  270. * *
  271. * OUTPUT: *
  272. * *
  273. * WARNINGS: *
  274. * *
  275. * HISTORY: *
  276. * 02/03/00 IML : Created. *
  277. *=============================================================================================*/
  278. void LightMapView::OnToolsPacking()
  279. {
  280. PackingDialog packing;
  281. packing.DoModal();
  282. }
  283. /***********************************************************************************************
  284. * LightMapView::OnToolsPacking -- *
  285. * *
  286. * INPUT: *
  287. * *
  288. * OUTPUT: *
  289. * *
  290. * WARNINGS: *
  291. * *
  292. * HISTORY: *
  293. * 02/03/00 IML : Created. *
  294. *=============================================================================================*/
  295. void LightMapView::OnUpdateToolsPacking (CCmdUI *cmdui)
  296. {
  297. cmdui->Enable (GetDocument()->Solve_Inserted());
  298. }
  299. /***********************************************************************************************
  300. * LightMapView::OnLButtonDown -- *
  301. * *
  302. * INPUT: *
  303. * *
  304. * OUTPUT: *
  305. * *
  306. * WARNINGS: *
  307. * *
  308. * HISTORY: *
  309. * 02/03/00 IML : Created. *
  310. *=============================================================================================*/
  311. void LightMapView::OnLButtonDown (UINT flags, CPoint point)
  312. {
  313. LVHITTESTINFO hittest;
  314. // Call default handler.
  315. CListView::OnLButtonDown (flags, point);
  316. if (MeshIndexTable != NULL) {
  317. hittest.pt = point;
  318. GetListCtrl().SubItemHitTest (&hittest);
  319. if ((hittest.iItem >= 0) && (hittest.iSubItem == 0)) {
  320. unsigned meshindex = MeshIndexTable [hittest.iItem];
  321. LightMapDoc *document = GetDocument();
  322. StringBuilder string (16384), substring (8192);
  323. string.Copy (document->Mesh_Anomalies_String (meshindex, true, substring));
  324. string.Concatenate (document->Solve_Anomalies_String (meshindex, true, substring));
  325. MeshDialog mesh (IDD_MESH_STATUS, this, document->Mesh_Name (meshindex), string.String());
  326. mesh.DoModal();
  327. }
  328. }
  329. }
  330. /***********************************************************************************************
  331. * LightMapView::CompareNames -- *
  332. * *
  333. * INPUT: *
  334. * *
  335. * OUTPUT: *
  336. * *
  337. * WARNINGS: *
  338. * *
  339. * HISTORY: *
  340. * 02/03/00 IML : Created. *
  341. *=============================================================================================*/
  342. int LightMapView::Compare_Names (const void *index0, const void *index1)
  343. {
  344. ASSERT (_Document != NULL);
  345. return (strcmp (_Document->Mesh_Name (*((unsigned*) index0)), _Document->Mesh_Name (*((unsigned*) index1))));
  346. }
  347. /***********************************************************************************************
  348. * MeshDialog::OnInitDialog -- *
  349. * *
  350. * INPUT: *
  351. * *
  352. * OUTPUT: *
  353. * *
  354. * WARNINGS: *
  355. * *
  356. * HISTORY: *
  357. * 02/03/00 IML : Created. *
  358. *=============================================================================================*/
  359. BOOL MeshDialog::OnInitDialog()
  360. {
  361. StringBuilder string (256);
  362. // Allow the base class to process this message.
  363. CDialog::OnInitDialog();
  364. string.Copy (MeshName);
  365. string.Concatenate (" - Anomalies");
  366. SetWindowText (string.String());
  367. GetDlgItem (IDC_MESH_STATUS_TEXT)->SetWindowText (Anomalies);
  368. return (TRUE);
  369. }
  370. // The following is maintained by MFC tools.
  371. BOOL LightMapView::PreCreateWindow(CREATESTRUCT& cs)
  372. {
  373. // TODO: Modify the Window class or styles here by modifying
  374. // the CREATESTRUCT cs
  375. return CListView::PreCreateWindow(cs);
  376. }
  377. #ifdef _DEBUG
  378. void LightMapView::AssertValid() const
  379. {
  380. CListView::AssertValid();
  381. }
  382. void LightMapView::Dump(CDumpContext& dc) const
  383. {
  384. CListView::Dump(dc);
  385. }
  386. LightMapDoc* LightMapView::GetDocument() // non-debug version is inline
  387. {
  388. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(LightMapDoc)));
  389. return (LightMapDoc*)m_pDocument;
  390. }
  391. #endif //_DEBUG