DlgPreferences.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // DlgPreferences.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "DlgPreferences.h"
  16. #ifdef _DEBUG
  17. #undef new
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDlgPreferences dialog
  24. #define PREF_COMBO_HEIGHT 100
  25. CDlgPreferences::CDlgPreferences( CWnd* pParent /*=NULL*/)
  26. : CDialog(CDlgPreferences::IDD, pParent)
  27. {
  28. //{{AFX_DATA_INIT(CDlgPreferences)
  29. m_PrefsCopy = FALSE;
  30. m_AutoMaximize = FALSE;
  31. m_SetDefaultColors = FALSE;
  32. m_AutomaticInfo = FALSE;
  33. m_UpdateAllways = FALSE;
  34. m_BinaryGrid = FALSE;
  35. m_bSaveUndoForDelete = FALSE;
  36. m_iWndStartupCfg = 0;
  37. m_bAutoColorize = FALSE;
  38. m_strSSProject = _T("");
  39. m_bShowAllOnOpen = FALSE;
  40. m_strCSGPrecission = _T("");
  41. m_bAutoUpdateDisplaceMap = FALSE;
  42. m_fFlyModeSpeed = 0.0f;
  43. m_bHideShadowsOnStart = FALSE;
  44. m_bAutoUpdateTerrainDistribution = FALSE;
  45. m_iMemoryForTerrainUndo = 0;
  46. //}}AFX_DATA_INIT
  47. }
  48. void CDlgPreferences::DoDataExchange(CDataExchange* pDX)
  49. {
  50. CDialog::DoDataExchange(pDX);
  51. // if dialog is recieving data
  52. if( pDX->m_bSaveAndValidate == FALSE)
  53. {
  54. GetDlgItem(IDC_STATIC_SOURCE_SAFE_BORDER)->EnableWindow( FALSE);
  55. GetDlgItem(IDC_STATIC_SOURCE_SAFE_PROJECT)->EnableWindow( FALSE);
  56. GetDlgItem(IDC_EDIT_SS_PROJECT)->EnableWindow( FALSE);
  57. // select current api
  58. if( IsWindow(m_ctrGfxApi.m_hWnd))
  59. {
  60. for(INDEX iItem=0; iItem<m_ctrGfxApi.GetCount(); iItem++)
  61. {
  62. if(theApp.m_iApi==m_ctrGfxApi.GetItemData(iItem))
  63. {
  64. m_ctrGfxApi.SetCurSel(theApp.m_iApi);
  65. break;
  66. }
  67. }
  68. }
  69. m_strSSProject = theApp.m_Preferences.ap_strSourceSafeProject;
  70. m_PrefsCopy = theApp.m_Preferences.ap_CopyExistingWindowPrefs;
  71. m_AutoMaximize = theApp.m_Preferences.ap_AutoMaximizeWindow;
  72. m_SetDefaultColors = theApp.m_Preferences.ap_SetDefaultColors;
  73. m_AutomaticInfo = theApp.m_Preferences.ap_AutomaticInfo;
  74. m_BinaryGrid = theApp.m_Preferences.ap_BinaryGrid;
  75. m_UpdateAllways = theApp.m_Preferences.ap_UpdateAllways;
  76. m_bSaveUndoForDelete = theApp.m_Preferences.ap_bSaveUndoForDelete;
  77. m_bAutoColorize = theApp.m_Preferences.ap_bAutoColorize;
  78. m_bShowAllOnOpen = theApp.m_Preferences.ap_bShowAllOnOpen;
  79. m_bHideShadowsOnStart = theApp.m_Preferences.ap_bHideShadowsOnOpen;
  80. m_bAutoUpdateDisplaceMap = theApp.m_Preferences.ap_bAutoUpdateDisplaceMap;
  81. m_fFlyModeSpeed=theApp.m_Preferences.ap_fDefaultFlyModeSpeed;
  82. if( IsWindow(m_ctrlCSGPrecission.m_hWnd))
  83. {
  84. m_ctrlTerrainSelectionVisible.SetCurSel(theApp.m_Preferences.ap_iTerrainSelectionVisible);
  85. m_ctrlTerrainSelectionHidden.SetCurSel(theApp.m_Preferences.ap_iTerrainSelectionHidden);
  86. m_iMemoryForTerrainUndo=theApp.m_Preferences.ap_iMemoryForTerrainUndo;
  87. m_bAutoUpdateTerrainDistribution=theApp.m_Preferences.ap_bAutoUpdateTerrainDistribution;
  88. INDEX iCSGPrecission=0;
  89. for(INDEX iExp=-5; iExp<=5; iExp+=1)
  90. {
  91. FLOAT fPow=pow(2.0f ,iExp*2);
  92. FLOAT fEpsilon=_pShell->GetFLOAT("mth_fCSGEpsilon");
  93. if( fEpsilon==fPow)
  94. {
  95. iCSGPrecission=iExp;
  96. break;
  97. }
  98. }
  99. m_ctrlCSGPrecission.SetPos( iCSGPrecission+5);
  100. CTString strCSGPrecission;
  101. if( _pShell->GetFLOAT("mth_fCSGEpsilon")==1.0f)
  102. {
  103. strCSGPrecission.PrintF("CSG Precission: 1 (default)");
  104. }
  105. else
  106. {
  107. strCSGPrecission.PrintF("CSG Precission: %g", _pShell->GetFLOAT("mth_fCSGEpsilon"));
  108. }
  109. m_strCSGPrecission=strCSGPrecission;
  110. }
  111. if( IsWindow(m_UndoLevels.m_hWnd))
  112. {
  113. m_UndoLevels.SetPos( theApp.m_Preferences.ap_iUndoLevels);
  114. }
  115. m_iWndStartupCfg = theApp.m_Preferences.ap_iStartupWindowSetup;
  116. }
  117. //{{AFX_DATA_MAP(CDlgPreferences)
  118. DDX_Control(pDX, IDC_TERRAIN_SELECTION_HIDDEN, m_ctrlTerrainSelectionHidden);
  119. DDX_Control(pDX, IDC_TERRAIN_SELECTON_VISIBLE, m_ctrlTerrainSelectionVisible);
  120. DDX_Control(pDX, IDC_API, m_ctrGfxApi);
  121. DDX_Control(pDX, IDC_CSG_PRECISSION, m_ctrlCSGPrecission);
  122. DDX_Control(pDX, IDC_UNDO_LEVELS, m_UndoLevels);
  123. DDX_Control(pDX, IDOK, m_OkButton);
  124. DDX_Check(pDX, IDC_PREFS_COPY, m_PrefsCopy);
  125. DDX_Check(pDX, IDC_PREFS_MAXIMIZE, m_AutoMaximize);
  126. DDX_Check(pDX, IDC_PREFS_SET_DEFAULT_COLORS, m_SetDefaultColors);
  127. DDX_Check(pDX, IDC_PREFS_AUTOMATIC_INFO, m_AutomaticInfo);
  128. DDX_Check(pDX, IDC_PREFS_UPDATE_ALLWAYS, m_UpdateAllways);
  129. DDX_Check(pDX, IDC_PREFS_BINARY_GRID_BY_DEFAULT, m_BinaryGrid);
  130. DDX_Check(pDX, IDC_PREFS_SAVE_UNDO_FOR_DELETE, m_bSaveUndoForDelete);
  131. DDX_Text(pDX, IDC_WND_STARTUP_CFG, m_iWndStartupCfg);
  132. DDV_MinMaxInt(pDX, m_iWndStartupCfg, 0, 9);
  133. DDX_Check(pDX, IDC_PREFS_AUTO_COLORIZE, m_bAutoColorize);
  134. DDX_Text(pDX, IDC_EDIT_SS_PROJECT, m_strSSProject);
  135. DDX_Check(pDX, IDC_PREFS_SHOW_ALL_ON_OPEN, m_bShowAllOnOpen);
  136. DDX_Text(pDX, IDC_CSG_PRECISSION_T, m_strCSGPrecission);
  137. DDX_Check(pDX, IDC_PREFS_AUTO_UPDATE_DISPLACEMAP, m_bAutoUpdateDisplaceMap);
  138. DDX_Text(pDX, IDC_FLY_MODE_SPEED, m_fFlyModeSpeed);
  139. DDV_MinMaxFloat(pDX, m_fFlyModeSpeed, 0.f, 1000.f);
  140. DDX_Check(pDX, IDC_PREFS_HIDE_SHADOWS_ON_START, m_bHideShadowsOnStart);
  141. DDX_Check(pDX, IDC_PREFS_AUTO_GENERATE_TD, m_bAutoUpdateTerrainDistribution);
  142. DDX_Text(pDX, IDC_MEMORY_FOR_UNDO, m_iMemoryForTerrainUndo);
  143. DDV_MinMaxInt(pDX, m_iMemoryForTerrainUndo, -1, 512);
  144. //}}AFX_DATA_MAP
  145. // if dialog is giving data
  146. if( pDX->m_bSaveAndValidate != FALSE)
  147. {
  148. theApp.m_Preferences.ap_iTerrainSelectionVisible=m_ctrlTerrainSelectionVisible.GetCurSel();
  149. theApp.m_Preferences.ap_iTerrainSelectionHidden=m_ctrlTerrainSelectionHidden.GetCurSel();
  150. theApp.m_Preferences.ap_bAutoUpdateTerrainDistribution=m_bAutoUpdateTerrainDistribution;
  151. theApp.m_Preferences.ap_iMemoryForTerrainUndo=m_iMemoryForTerrainUndo;
  152. theApp.m_Preferences.ap_CopyExistingWindowPrefs = m_PrefsCopy;
  153. theApp.m_Preferences.ap_AutoMaximizeWindow = m_AutoMaximize;
  154. theApp.m_Preferences.ap_SetDefaultColors = m_SetDefaultColors;
  155. theApp.m_Preferences.ap_AutomaticInfo = m_AutomaticInfo;
  156. theApp.m_Preferences.ap_BinaryGrid = m_BinaryGrid;
  157. theApp.m_Preferences.ap_UpdateAllways = m_UpdateAllways;
  158. theApp.m_Preferences.ap_bSaveUndoForDelete = m_bSaveUndoForDelete;
  159. theApp.m_Preferences.ap_bAutoColorize = m_bAutoColorize;
  160. theApp.m_Preferences.ap_bShowAllOnOpen = m_bShowAllOnOpen;
  161. theApp.m_Preferences.ap_bHideShadowsOnOpen = m_bHideShadowsOnStart;
  162. theApp.m_Preferences.ap_bAutoUpdateDisplaceMap = m_bAutoUpdateDisplaceMap;
  163. theApp.m_Preferences.ap_iUndoLevels = m_UndoLevels.GetPos();
  164. _pShell->SetFLOAT("mth_fCSGEpsilon", pow(2.0f, (m_ctrlCSGPrecission.GetPos()-5)*2));
  165. theApp.m_Preferences.ap_iStartupWindowSetup = m_iWndStartupCfg;
  166. theApp.m_Preferences.ap_strSourceSafeProject = CStringA(m_strSSProject);
  167. theApp.m_Preferences.ap_fDefaultFlyModeSpeed=m_fFlyModeSpeed;
  168. // and write all data that can be written to INI file multiple times
  169. theApp.WriteToIniFile();
  170. INDEX iCurSel=m_ctrGfxApi.GetCurSel();
  171. INDEX iOldGfxApi=theApp.m_iApi;
  172. if( iCurSel!=CB_ERR)
  173. {
  174. theApp.m_iApi=m_ctrGfxApi.GetItemData(iCurSel);
  175. if( iOldGfxApi!=theApp.m_iApi)
  176. {
  177. _pGfx->ResetDisplayMode((enum GfxAPIType) theApp.m_iApi);
  178. }
  179. }
  180. }
  181. }
  182. BEGIN_MESSAGE_MAP(CDlgPreferences, CDialog)
  183. //{{AFX_MSG_MAP(CDlgPreferences)
  184. ON_BN_CLICKED(ID_SAVE_PREFERENCES, OnSavePreferences)
  185. ON_BN_CLICKED(ID_LOAD_PREFERENCES, OnLoadPreferences)
  186. ON_BN_CLICKED(IDC_CHANGE_FULL_SCREEN_DISPLAY_MODE, OnChangeFullScreenDisplayMode)
  187. ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_CSG_PRECISSION, OnReleasedcaptureCsgPrecission)
  188. //}}AFX_MSG_MAP
  189. ON_COMMAND_RANGE(IDC_RENDERING_PREFS01, IDC_RENDERING_PREFS10, OnChangePreferences)
  190. END_MESSAGE_MAP()
  191. /////////////////////////////////////////////////////////////////////////////
  192. // CDlgPreferences message handlers
  193. BOOL CDlgPreferences::OnInitDialog()
  194. {
  195. CDialog::OnInitDialog();
  196. m_ctrlCSGPrecission.SetRange(0, 10);
  197. m_UndoLevels.SetRange( 0, 10);
  198. m_ctrGfxApi.ResetContent();
  199. if( _pGfx->HasAPI( GAT_OGL))
  200. {
  201. INDEX iAddedAs=m_ctrGfxApi.AddString(L"OpenGL");
  202. m_ctrGfxApi.SetItemData(iAddedAs, GAT_OGL);
  203. }
  204. #ifdef SE1_D3D
  205. if( _pGfx->HasAPI( GAT_D3D))
  206. {
  207. INDEX iAddedAs=m_ctrGfxApi.AddString(L"Direct3D");
  208. m_ctrGfxApi.SetItemData(iAddedAs, GAT_D3D);
  209. }
  210. #endif // SE1_D3D
  211. m_ctrlTerrainSelectionVisible.ResetContent();
  212. m_ctrlTerrainSelectionVisible.AddString(L"Texture");
  213. m_ctrlTerrainSelectionVisible.AddString(L"Wireframe");
  214. m_ctrlTerrainSelectionVisible.AddString(L"Vertices");
  215. m_ctrlTerrainSelectionVisible.AddString(L"None");
  216. m_ctrlTerrainSelectionHidden.ResetContent();
  217. m_ctrlTerrainSelectionHidden.AddString(L"Texture");
  218. m_ctrlTerrainSelectionHidden.AddString(L"Wireframe");
  219. m_ctrlTerrainSelectionHidden.AddString(L"Vertices");
  220. m_ctrlTerrainSelectionHidden.AddString(L"None");
  221. UpdateData( FALSE);
  222. return TRUE;
  223. }
  224. void CDlgPreferences::OnChangePreferences(UINT nID)
  225. {
  226. INDEX iPreferencesBuffer = nID - IDC_RENDERING_PREFS01;
  227. CDlgRenderingPreferences dlg( iPreferencesBuffer);
  228. dlg.DoModal();
  229. }
  230. void CDlgPreferences::OnSavePreferences()
  231. {
  232. UpdateData( TRUE);
  233. // and write all data that can be written to ini file multiple times
  234. theApp.WriteToIniFile();
  235. }
  236. void CDlgPreferences::OnLoadPreferences()
  237. {
  238. // this will load all data that can be readen from ini file multiple times
  239. theApp.ReadFromIniFile();
  240. UpdateData( FALSE);
  241. }
  242. void CDlgPreferences::OnChangeFullScreenDisplayMode()
  243. {
  244. // pass old and get new full screen mode and driver
  245. _EngineGUI.SelectMode( m_dmFullScreen, m_gatFullScreen);
  246. }
  247. void CDlgPreferences::OnReleasedcaptureCsgPrecission(NMHDR* pNMHDR, LRESULT* pResult)
  248. {
  249. *pResult = 0;
  250. /*
  251. CTString strCSGPrecission;
  252. strCSGPrecission.PrintF("CSG Precission: %g", _pShell->GetFLOAT("mth_fCSGEpsilon"));
  253. m_strCSGPrecission=strCSGPrecission;
  254. */
  255. UpdateData(TRUE);
  256. UpdateData(FALSE);
  257. }