NewHeightfieldDialog.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. // NewHeightfieldDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "newheightfielddialog.h"
  23. #include "heightfieldmgr.h"
  24. #include "utils.h"
  25. #include "refcount.h"
  26. #include "wwstring.h"
  27. #include "heightfieldeditor.h"
  28. #include "editableheightfield.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. /////////////////////////////////////////////////////////////////////////////
  35. // NewHeightfieldDialogClass dialog
  36. NewHeightfieldDialogClass::NewHeightfieldDialogClass(CWnd* pParent /*=NULL*/)
  37. : CDialog(NewHeightfieldDialogClass::IDD, pParent)
  38. {
  39. //{{AFX_DATA_INIT(NewHeightfieldDialogClass)
  40. // NOTE: the ClassWizard will add member initialization here
  41. //}}AFX_DATA_INIT
  42. }
  43. void NewHeightfieldDialogClass::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CDialog::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(NewHeightfieldDialogClass)
  47. // NOTE: the ClassWizard will add DDX and DDV calls here
  48. //}}AFX_DATA_MAP
  49. }
  50. BEGIN_MESSAGE_MAP(NewHeightfieldDialogClass, CDialog)
  51. //{{AFX_MSG_MAP(NewHeightfieldDialogClass)
  52. ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. //
  57. // OnOK
  58. //
  59. /////////////////////////////////////////////////////////////////////////////
  60. void
  61. NewHeightfieldDialogClass::OnOK (void)
  62. {
  63. int width = GetDlgItemInt (IDC_WIDTH_EDIT);
  64. int height = GetDlgItemInt (IDC_HEIGHT_EDIT);
  65. float density = ::GetDlgItemFloat (m_hWnd, IDC_DENSITY_EDIT, false);
  66. //
  67. // Is the user attempting to initialize the heightfield from a grayscale bitmap?
  68. //
  69. CString bmp_filename;
  70. GetDlgItemText (IDC_BMP_FILENAME_EDIT, bmp_filename);
  71. if (bmp_filename.GetLength () >= 0 && ::GetFileAttributes (bmp_filename) != 0xFFFFFFFF) {
  72. //
  73. // Create the initial heightfield from these values
  74. //
  75. float scale = ::GetDlgItemFloat (m_hWnd, IDC_HEIGHT_SCALE_EDIT, false);
  76. HeightfieldMgrClass::Create_Heightfield (bmp_filename, width, height, density, scale);
  77. } else {
  78. //
  79. // Create the initial heightfield from these values
  80. //
  81. HeightfieldMgrClass::Create_Heightfield (width, height, density);
  82. }
  83. CDialog::OnOK ();
  84. return ;
  85. }
  86. /////////////////////////////////////////////////////////////////////////////
  87. //
  88. // OnInitDialog
  89. //
  90. /////////////////////////////////////////////////////////////////////////////
  91. BOOL
  92. NewHeightfieldDialogClass::OnInitDialog (void)
  93. {
  94. CDialog::OnInitDialog ();
  95. //
  96. // Generate a name for this heightfield
  97. //
  98. StringClass new_name;
  99. new_name.Format ("Heightfield %d", HeightfieldMgrClass::Get_Heightfield_Count () + 1);
  100. SetDlgItemText (IDC_NAME_EDIT, new_name);
  101. //
  102. // Set some default values...
  103. //
  104. SetDlgItemInt (IDC_WIDTH_EDIT, 500);
  105. SetDlgItemInt (IDC_HEIGHT_EDIT, 500);
  106. ::SetDlgItemFloat (m_hWnd, IDC_DENSITY_EDIT, 2.0F);
  107. ::SetDlgItemFloat (m_hWnd, IDC_HEIGHT_SCALE_EDIT, 75.0F);
  108. return TRUE;
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. //
  112. // OnBrowse
  113. //
  114. /////////////////////////////////////////////////////////////////////////////
  115. void
  116. NewHeightfieldDialogClass::OnBrowse (void)
  117. {
  118. //
  119. // Get the current texture path
  120. //
  121. CString filename;
  122. GetDlgItemText (IDC_BMP_FILENAME_EDIT, filename);
  123. CFileDialog dialog (TRUE, ".bmp", filename,
  124. OFN_HIDEREADONLY | OFN_EXPLORER,
  125. "Windows Bitmap Files (*.bmp)|*.bmp||", ::AfxGetMainWnd ());
  126. //
  127. // Ask the user what bitmap they wish to use
  128. //
  129. if (dialog.DoModal () == IDOK) {
  130. SetDlgItemText (IDC_BMP_FILENAME_EDIT, dialog.GetPathName ());
  131. }
  132. return ;
  133. }