WheeledVehicleDialog.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // WheeledVehicleDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "phystest.h"
  22. #include "WheeledVehicleDialog.h"
  23. #include "wheelvehicle.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. const float MIN_KS = 0.01f;
  30. const float MAX_KS = 1000.0f;
  31. const float MIN_KD = 0.01f;
  32. const float MAX_KD = 1000.0f;
  33. const float MIN_LENGTH = 0.1f;
  34. const float MAX_LENGTH = 32.0f;
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CWheeledVehicleDialog dialog
  37. CWheeledVehicleDialog::CWheeledVehicleDialog(CWnd* pParent,WheeledVehicleClass * obj)
  38. : CDialog(CWheeledVehicleDialog::IDD, pParent),
  39. EditedObject(obj)
  40. {
  41. //{{AFX_DATA_INIT(CWheeledVehicleDialog)
  42. // NOTE: the ClassWizard will add member initialization here
  43. //}}AFX_DATA_INIT
  44. }
  45. void CWheeledVehicleDialog::DoDataExchange(CDataExchange* pDX)
  46. {
  47. CDialog::DoDataExchange(pDX);
  48. //{{AFX_DATA_MAP(CWheeledVehicleDialog)
  49. DDX_Control(pDX, IDC_WVEHICLE_LENGTH_SPIN, m_LengthSpin);
  50. DDX_Control(pDX, IDC_WVEHICLE_KS_SPIN, m_KSSpin);
  51. DDX_Control(pDX, IDC_WVEHICLE_KD_SPIN, m_KDSpin);
  52. //}}AFX_DATA_MAP
  53. }
  54. BEGIN_MESSAGE_MAP(CWheeledVehicleDialog, CDialog)
  55. //{{AFX_MSG_MAP(CWheeledVehicleDialog)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CWheeledVehicleDialog message handlers
  60. BOOL CWheeledVehicleDialog::OnInitDialog()
  61. {
  62. CDialog::OnInitDialog();
  63. m_KSSpin.SetRange(MIN_KS * 100,MAX_KS * 100);
  64. m_KDSpin.SetRange(MIN_KD * 100,MAX_KD * 100);
  65. m_LengthSpin.SetRange(MIN_LENGTH * 100,MAX_LENGTH * 100);
  66. float ks,kd,len;
  67. EditedObject->Get_Suspension_Parameters(&ks,&kd,&len);
  68. m_KSSpin.SetPos(ks * 100);
  69. m_KDSpin.SetPos(kd * 100);
  70. m_LengthSpin.SetPos(len * 100);
  71. SetDlgItemFloat(IDC_WVEHICLE_KS_EDIT,ks);
  72. SetDlgItemFloat(IDC_WVEHICLE_KD_EDIT,kd);
  73. SetDlgItemFloat(IDC_WVEHICLE_LENGTH_EDIT,len);
  74. return TRUE;
  75. }
  76. BOOL CWheeledVehicleDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  77. {
  78. // make the spin controls work...
  79. switch(wParam)
  80. {
  81. case IDC_WVEHICLE_KS_SPIN:
  82. case IDC_WVEHICLE_KD_SPIN:
  83. case IDC_WVEHICLE_LENGTH_SPIN:
  84. LPNMUPDOWN lpnmud = (LPNMUPDOWN) lParam;
  85. if (lpnmud->hdr.code == UDN_DELTAPOS) {
  86. HWND hwnd = (HWND)SendDlgItemMessage(LOWORD(wParam),UDM_GETBUDDY);
  87. float curval = GetDlgItemFloat(GetWindowLong(hwnd,GWL_ID));
  88. curval += (float)lpnmud->iDelta / 100.0f;
  89. SetDlgItemFloat(GetWindowLong(hwnd,GWL_ID), curval);
  90. }
  91. break;
  92. }
  93. return CDialog::OnNotify(wParam, lParam, pResult);
  94. }
  95. void CWheeledVehicleDialog::OnOK()
  96. {
  97. float ks,kd,len;
  98. ks = GetDlgItemFloat(IDC_WVEHICLE_KS_EDIT);
  99. kd = GetDlgItemFloat(IDC_WVEHICLE_KD_EDIT);
  100. len = GetDlgItemFloat(IDC_WVEHICLE_LENGTH_EDIT);
  101. EditedObject->Set_Suspension_Parameters(ks,kd,len);
  102. CDialog::OnOK();
  103. }
  104. float CWheeledVehicleDialog::GetDlgItemFloat(int controlid)
  105. {
  106. CString string;
  107. GetDlgItemText(controlid,string);
  108. return atof(string);
  109. }
  110. void CWheeledVehicleDialog::SetDlgItemFloat(int controlid,float val)
  111. {
  112. CString string;
  113. string.Format("%.2f",val);
  114. SetDlgItemText(controlid,string);
  115. }