MemLogDialog.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. // MemLogDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "memlogdialog.h"
  23. #include "wwmemlog.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Constants
  31. /////////////////////////////////////////////////////////////////////////////
  32. enum
  33. {
  34. COL_NAME = 0,
  35. COL_CURRENT,
  36. COL_PEAK,
  37. };
  38. /////////////////////////////////////////////////////////////////////////////
  39. //
  40. // MemLogDialogClass
  41. //
  42. /////////////////////////////////////////////////////////////////////////////
  43. MemLogDialogClass::MemLogDialogClass(CWnd* pParent /*=NULL*/)
  44. : CDialog(MemLogDialogClass::IDD, pParent)
  45. {
  46. //{{AFX_DATA_INIT(MemLogDialogClass)
  47. // NOTE: the ClassWizard will add member initialization here
  48. //}}AFX_DATA_INIT
  49. return ;
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. //
  53. // DoDataExchange
  54. //
  55. /////////////////////////////////////////////////////////////////////////////
  56. void
  57. MemLogDialogClass::DoDataExchange (CDataExchange *pDX)
  58. {
  59. CDialog::DoDataExchange(pDX);
  60. //{{AFX_DATA_MAP(MemLogDialogClass)
  61. DDX_Control(pDX, IDC_MEM_USAGE_LIST, m_ListCtrl);
  62. //}}AFX_DATA_MAP
  63. return ;
  64. }
  65. BEGIN_MESSAGE_MAP(MemLogDialogClass, CDialog)
  66. //{{AFX_MSG_MAP(MemLogDialogClass)
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. //
  71. // OnInitDialog
  72. //
  73. /////////////////////////////////////////////////////////////////////////////
  74. BOOL
  75. MemLogDialogClass::OnInitDialog (void)
  76. {
  77. CDialog::OnInitDialog ();
  78. //
  79. // Configure the columns
  80. //
  81. m_ListCtrl.InsertColumn (COL_NAME, "Name");
  82. m_ListCtrl.InsertColumn (COL_CURRENT, "Current Usage");
  83. m_ListCtrl.InsertColumn (COL_PEAK, "Peak Usage");
  84. m_ListCtrl.SetExtendedStyle (m_ListCtrl.GetExtendedStyle () | LVS_EX_FULLROWSELECT);
  85. //
  86. // Choose an appropriate size for the columns
  87. //
  88. CRect rect;
  89. m_ListCtrl.GetClientRect (&rect);
  90. rect.right -= ::GetSystemMetrics (SM_CXVSCROLL) + 2;
  91. m_ListCtrl.SetColumnWidth (COL_NAME, (rect.Width () * 3) / 5);
  92. m_ListCtrl.SetColumnWidth (COL_CURRENT, rect.Width () / 5);
  93. m_ListCtrl.SetColumnWidth (COL_PEAK, rect.Width () / 5);
  94. //
  95. // Loop over all the categories in the logger
  96. //
  97. int count = WWMemoryLogClass::Get_Category_Count ();
  98. for (int index = 0; index < count; index ++) {
  99. const char *name = WWMemoryLogClass::Get_Category_Name (index);
  100. int current_mem = WWMemoryLogClass::Get_Current_Allocated_Memory (index);
  101. int peak_mem = WWMemoryLogClass::Get_Peak_Allocated_Memory (index);
  102. //
  103. // Insert this category in the list
  104. //
  105. int item_index = m_ListCtrl.InsertItem (index, name);
  106. if (item_index >= 0) {
  107. CString current_mem_string;
  108. CString peak_mem_string;
  109. current_mem_string.Format ("%.2f KB", (float)current_mem / 1024.0F);
  110. peak_mem_string.Format ("%.2f KB", (float)peak_mem / 1024.0F);
  111. m_ListCtrl.SetItemText (item_index, COL_CURRENT, current_mem_string);
  112. m_ListCtrl.SetItemText (item_index, COL_PEAK, peak_mem_string);
  113. }
  114. }
  115. return TRUE;
  116. }