Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
7.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements the 3D options property page.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include "GlobalFunctions.h"
  9. #include "MainFrm.h"
  10. #include "MapDoc.h"
  11. #include "hammer.h"
  12. #include "OPTView3D.h"
  13. #include "Options.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include <tier0/memdbgon.h>
  16. IMPLEMENT_DYNCREATE(COPTView3D, CPropertyPage)
  17. BEGIN_MESSAGE_MAP(COPTView3D, CPropertyPage)
  18. //{{AFX_MSG_MAP(COPTView3D)
  19. ON_WM_HSCROLL()
  20. //}}AFX_MSG_MAP
  21. END_MESSAGE_MAP()
  22. COPTView3D::COPTView3D(void)
  23. : CPropertyPage(COPTView3D::IDD)
  24. {
  25. //{{AFX_DATA_INIT(COPTView3D)
  26. //}}AFX_DATA_INIT
  27. }
  28. COPTView3D::~COPTView3D(void)
  29. {
  30. }
  31. void PASCAL DDV_FOVRange(CDataExchange *pDX, int value)
  32. {
  33. if ( ( value > 100 ) | ( value < 30 ) )
  34. {
  35. AfxMessageBox("FOV must be 30-100.", MB_ICONEXCLAMATION | MB_OK);
  36. pDX->Fail();
  37. }
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. // Input : pDX -
  42. //-----------------------------------------------------------------------------
  43. void COPTView3D::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CPropertyPage::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(COPTView3D)
  47. DDX_Control(pDX, IDC_BACKTEXT, m_cBackText);
  48. DDX_Control(pDX, IDC_BACKPLANE, m_cBackPlane);
  49. DDX_Control(pDX, IDC_MODEL_DISTANCE_TEXT, m_ModelDistanceText);
  50. DDX_Control(pDX, IDC_MODEL_DISTANCE, m_ModelDistance);
  51. DDX_Control(pDX, IDC_DETAIL_DISTANCE_TEXT, m_DetailDistanceText);
  52. DDX_Control(pDX, IDC_DETAIL_DISTANCE, m_DetailDistance);
  53. DDX_Control(pDX, IDC_FORWARD_SPEED_TEXT, m_ForwardSpeedText);
  54. DDX_Control(pDX, IDC_FORWARD_SPEED, m_ForwardSpeedMax);
  55. DDX_Control(pDX, IDC_FORWARD_ACCEL_TEXT, m_TimeToMaxSpeedText);
  56. DDX_Control(pDX, IDC_FORWARD_ACCELERATION, m_TimeToMaxSpeed);
  57. DDX_Check(pDX, IDC_FILTER_TEXTURES, Options.view3d.bFilterTextures);
  58. DDX_Check(pDX, IDC_REVERSEY, Options.view3d.bReverseY);
  59. DDX_Check(pDX, IDC_USEMOUSELOOK, Options.view3d.bUseMouseLook);
  60. DDX_Check(pDX, IDC_ANIMATE_MODELS, Options.view3d.bAnimateModels);
  61. DDX_Check(pDX, IDC_REVERSE_SELECTION, Options.view3d.bReverseSelection);
  62. DDX_Text(pDX, IDC_FOV, Options.view3d.fFOV);
  63. DDX_Text(pDX, IDC_LIGHT_CONE_LENGTH, Options.view3d.fLightConeLength);
  64. DDV_FOVRange(pDX, Options.view3d.fFOV);
  65. //}}AFX_DATA_MAP
  66. m_cBackPlane.SetRange(500, 10000, TRUE);
  67. m_ModelDistance.SetRange(0, 10000, TRUE);
  68. m_DetailDistance.SetRange(0, 10000, TRUE);
  69. m_ForwardSpeedMax.SetRange(100, 10000, TRUE);
  70. m_TimeToMaxSpeed.SetRange(0, 10000, TRUE);
  71. //
  72. // If going from controls to data.
  73. //
  74. if (pDX->m_bSaveAndValidate)
  75. {
  76. Options.view3d.iBackPlane = m_cBackPlane.GetPos();
  77. Options.view3d.nModelDistance = m_ModelDistance.GetPos();
  78. Options.view3d.nDetailDistance = m_DetailDistance.GetPos();
  79. Options.view3d.nForwardSpeedMax = m_ForwardSpeedMax.GetPos();
  80. Options.view3d.nTimeToMaxSpeed = m_TimeToMaxSpeed.GetPos();
  81. }
  82. //
  83. // Else going from data to controls.
  84. //
  85. else
  86. {
  87. CString str;
  88. //
  89. // Back plane distance.
  90. //
  91. m_cBackPlane.SetPos(Options.view3d.iBackPlane);
  92. int iBack = m_cBackPlane.GetPos();
  93. str.Format("%d", iBack);
  94. m_cBackText.SetWindowText(str);
  95. //
  96. // Model render distance.
  97. //
  98. m_ModelDistance.SetPos(Options.view3d.nModelDistance);
  99. int nModelDistance = m_ModelDistance.GetPos();
  100. str.Format("%d", nModelDistance);
  101. m_ModelDistanceText.SetWindowText(str);
  102. //
  103. // Detail render distance.
  104. //
  105. m_DetailDistance.SetPos(Options.view3d.nDetailDistance);
  106. int nDetailDistance = m_DetailDistance.GetPos();
  107. str.Format("%d", nDetailDistance);
  108. m_DetailDistanceText.SetWindowText(str);
  109. //
  110. // Set the max forward speed.
  111. //
  112. m_ForwardSpeedMax.SetPos(Options.view3d.nForwardSpeedMax);
  113. int nSpeed = m_ForwardSpeedMax.GetPos();
  114. str.Format("%d", nSpeed);
  115. m_ForwardSpeedText.SetWindowText(str);
  116. //
  117. // Set the time to max speed.
  118. //
  119. m_TimeToMaxSpeed.SetPos(Options.view3d.nTimeToMaxSpeed);
  120. int nTime = m_TimeToMaxSpeed.GetPos();
  121. str.Format("%.2f sec", (float)nTime / 1000.0f);
  122. m_TimeToMaxSpeedText.SetWindowText(str);
  123. }
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose: Called before the dialog is displayed.
  127. // Output : Returns FALSE when setting focus to a control, TRUE otherwise.
  128. //-----------------------------------------------------------------------------
  129. BOOL COPTView3D::OnInitDialog(void)
  130. {
  131. m_bOldFilterTextures = Options.view3d.bFilterTextures;
  132. CPropertyPage::OnInitDialog();
  133. return TRUE;
  134. }
  135. //-----------------------------------------------------------------------------
  136. // Purpose: Called by the framework when the user chooses the OK or the Apply Now button.
  137. // Output : Nonzero if the changes are accepted; otherwise zero.
  138. //-----------------------------------------------------------------------------
  139. BOOL COPTView3D::OnApply(void)
  140. {
  141. if (Options.view3d.bFilterTextures != m_bOldFilterTextures)
  142. {
  143. AfxMessageBox("The changes to the 'Filter textures' setting will not take effect for any currently visible textures. Close all 3D views and reopen them for the new setting to completely take effect.");
  144. }
  145. Options.PerformChanges(COptions::secView3D);
  146. return CPropertyPage::OnApply();
  147. }
  148. //-----------------------------------------------------------------------------
  149. // Purpose: Handles all the sliders in the property page.
  150. // Input : Per MFC OnHScroll.
  151. //-----------------------------------------------------------------------------
  152. void COPTView3D::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
  153. {
  154. //
  155. // If it is the back plane scroll bar, update the back plane text.
  156. // Also, notify the 3D view so that it can update in realtime.
  157. //
  158. if (pScrollBar->m_hWnd == m_cBackPlane.m_hWnd)
  159. {
  160. int iBack = m_cBackPlane.GetPos();
  161. CString str;
  162. str.Format("%d", iBack);
  163. m_cBackText.SetWindowText(str);
  164. CMainFrame *pMainWnd = GetMainWnd();
  165. if (pMainWnd != NULL)
  166. {
  167. Options.view3d.iBackPlane = m_cBackPlane.GetPos();
  168. pMainWnd->UpdateAllDocViews( MAPVIEW_OPTIONS_CHANGED | MAPVIEW_RENDER_NOW );
  169. }
  170. }
  171. //
  172. // Else if it is the model distance scroll bar, update the model distance text.
  173. // Also, notify the 3D view so that it can update in realtime.
  174. //
  175. else if (pScrollBar->m_hWnd == m_ModelDistance.m_hWnd)
  176. {
  177. int nDistance = m_ModelDistance.GetPos();
  178. CString str;
  179. str.Format("%d", nDistance);
  180. m_ModelDistanceText.SetWindowText(str);
  181. CMainFrame *pMainWnd = GetMainWnd();
  182. if (pMainWnd != NULL)
  183. {
  184. Options.view3d.nModelDistance = m_ModelDistance.GetPos();
  185. pMainWnd->UpdateAllDocViews(MAPVIEW_UPDATE_ONLY_3D | MAPVIEW_OPTIONS_CHANGED | MAPVIEW_RENDER_NOW );
  186. }
  187. }
  188. //
  189. // Else if it is the detail distance scroll bar, update the detail distance text.
  190. // Also, notify the 3D view so that it can update in realtime.
  191. //
  192. else if (pScrollBar->m_hWnd == m_DetailDistance.m_hWnd)
  193. {
  194. int nDistance = m_DetailDistance.GetPos();
  195. CString str;
  196. str.Format("%d", nDistance);
  197. m_DetailDistanceText.SetWindowText(str);
  198. CMainFrame *pMainWnd = GetMainWnd();
  199. if (pMainWnd != NULL)
  200. {
  201. Options.view3d.nDetailDistance = m_DetailDistance.GetPos();
  202. pMainWnd->UpdateAllDocViews(MAPVIEW_UPDATE_ONLY_3D | MAPVIEW_OPTIONS_CHANGED | MAPVIEW_RENDER_NOW );
  203. }
  204. }
  205. //
  206. // Else if it is the maximum forward speed scroll bar, update the maximum forward speed.
  207. //
  208. else if (pScrollBar->m_hWnd == m_ForwardSpeedMax.m_hWnd)
  209. {
  210. int nSpeed = m_ForwardSpeedMax.GetPos();
  211. CString str;
  212. str.Format("%d", nSpeed);
  213. m_ForwardSpeedText.SetWindowText(str);
  214. }
  215. //
  216. // Else if it is the time to max speed scroll bar, update the time to max speed.
  217. //
  218. else if (pScrollBar->m_hWnd == m_TimeToMaxSpeed.m_hWnd)
  219. {
  220. float fTimeSeconds = (float)m_TimeToMaxSpeed.GetPos() / 1000.0f;
  221. CString str;
  222. str.Format("%.2f sec", fTimeSeconds);
  223. m_TimeToMaxSpeedText.SetWindowText(str);
  224. }
  225. CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
  226. }