InfoSheet.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. // InfoSheet.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "InfoSheet.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. // CInfoSheet
  24. #define CALLACTIVEPAGE(function, parameter) \
  25. if( pgActivPage == &m_PgGlobal) \
  26. m_PgGlobal.function( parameter); \
  27. if( pgActivPage == &m_PgTerrain) \
  28. m_PgTerrain.function( parameter); \
  29. if( pgActivPage == &m_PgPosition) \
  30. m_PgPosition.function( parameter); \
  31. if( pgActivPage == &m_PgRenderingStatistics) \
  32. m_PgRenderingStatistics.function( parameter); \
  33. if( pgActivPage == &m_PgPolygon) \
  34. m_PgPolygon.function( parameter); \
  35. if( pgActivPage == &m_PgShadow) \
  36. m_PgShadow.function( parameter); \
  37. if( pgActivPage == &m_PgSector) \
  38. m_PgSector.function( parameter); \
  39. if( pgActivPage == &m_PgTexture) \
  40. m_PgTexture.function( parameter); \
  41. if( pgActivPage == &m_PgPrimitive) \
  42. m_PgPrimitive.function( parameter);
  43. IMPLEMENT_DYNAMIC(CInfoSheet, CPropertySheet)
  44. CInfoSheet::CInfoSheet(CWnd* pWndParent)
  45. : CPropertySheet(AFX_IDS_APP_TITLE, pWndParent)
  46. {
  47. // Add all pages so frame could get bounding sizes of all of them
  48. AddPage( &m_PgGlobal);
  49. AddPage( &m_PgTerrain);
  50. AddPage( &m_PgPosition);
  51. AddPage( &m_PgPrimitive);
  52. //AddPage( &m_PgRenderingStatistics);
  53. AddPage( &m_PgPolygon);
  54. AddPage( &m_PgShadow);
  55. AddPage( &m_PgSector);
  56. AddPage( &m_PgTexture);
  57. SoftSetActivePage(0);
  58. // set mode that will be discarded on first OnIdle()
  59. m_ModeID = INFO_MODE_ALL;
  60. }
  61. CInfoSheet::~CInfoSheet()
  62. {
  63. }
  64. // don't take focus
  65. void CInfoSheet::SoftSetActivePage( INDEX iActivePage)
  66. {
  67. // get active view
  68. CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
  69. SetActivePage( iActivePage);
  70. if( pWorldEditorView != NULL)
  71. {
  72. // pWorldEditorView->SetFocus();
  73. }
  74. }
  75. BEGIN_MESSAGE_MAP(CInfoSheet, CPropertySheet)
  76. //{{AFX_MSG_MAP(CInfoSheet)
  77. //}}AFX_MSG_MAP
  78. END_MESSAGE_MAP()
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CInfoSheet message handlers
  81. void CInfoSheet::DoDataExchange(CDataExchange* pDX)
  82. {
  83. CPropertyPage *pgActivPage = GetActivePage();
  84. CALLACTIVEPAGE(UpdateData, pDX->m_bSaveAndValidate);
  85. CPropertySheet::DoDataExchange(pDX);
  86. }
  87. void CInfoSheet::DeleteAllPages()
  88. {
  89. // disable data exchange
  90. theApp.m_bDisableDataExchange = TRUE;
  91. INDEX iPagesCt, i;
  92. iPagesCt = GetPageCount();
  93. for( i=0; i<iPagesCt; i++)
  94. RemovePage( 0);
  95. // enable data exchange
  96. theApp.m_bDisableDataExchange = FALSE;
  97. }
  98. void CInfoSheet::SetInfoModeGlobal(void)
  99. {
  100. m_ModeID = INFO_MODE_GLOBAL;
  101. DeleteAllPages();
  102. AddPage( &m_PgGlobal);
  103. //AddPage( &m_PgRenderingStatistics);
  104. SoftSetActivePage(0);
  105. }
  106. void CInfoSheet::SetInfoModePosition(void)
  107. {
  108. m_ModeID = INFO_MODE_POSITION;
  109. DeleteAllPages();
  110. AddPage( &m_PgGlobal);
  111. //AddPage( &m_PgRenderingStatistics);
  112. AddPage( &m_PgPosition);
  113. SoftSetActivePage(1);
  114. }
  115. void CInfoSheet::SetInfoModePrimitive(void)
  116. {
  117. m_ModeID = INFO_MODE_PRIMITIVE;
  118. DeleteAllPages();
  119. AddPage( &m_PgGlobal);
  120. //AddPage( &m_PgRenderingStatistics);
  121. AddPage( &m_PgPosition);
  122. AddPage( &m_PgPrimitive);
  123. SoftSetActivePage(2);
  124. }
  125. INDEX _iLastActivePgInPolygonMode = 1;
  126. void CInfoSheet::SetInfoModePolygon(void)
  127. {
  128. m_ModeID = INFO_MODE_POLYGON;
  129. DeleteAllPages();
  130. AddPage( &m_PgGlobal);
  131. //AddPage( &m_PgRenderingStatistics);
  132. AddPage( &m_PgPolygon);
  133. AddPage( &m_PgShadow);
  134. AddPage( &m_PgTexture);
  135. SoftSetActivePage( _iLastActivePgInPolygonMode);
  136. }
  137. void CInfoSheet::SetInfoModeSector(void)
  138. {
  139. m_ModeID = INFO_MODE_SECTOR;
  140. DeleteAllPages();
  141. AddPage( &m_PgGlobal);
  142. //AddPage( &m_PgRenderingStatistics);
  143. AddPage( &m_PgSector);
  144. SoftSetActivePage(1);
  145. }
  146. void CInfoSheet::SetInfoModeTerrain(void)
  147. {
  148. m_ModeID = INFO_MODE_TERRAIN;
  149. DeleteAllPages();
  150. AddPage( &m_PgGlobal);
  151. AddPage( &m_PgTerrain);
  152. SoftSetActivePage(1);
  153. }
  154. BOOL CInfoSheet::OnIdle(LONG lCount)
  155. {
  156. // get active view
  157. CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
  158. // get active document
  159. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  160. // if we don't have view
  161. if( pDoc == NULL)
  162. {
  163. // force info mode: INFO_MODE_GLOBAL
  164. if( m_ModeID != INFO_MODE_GLOBAL)
  165. {
  166. SetInfoModeGlobal();
  167. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  168. pMainFrame->SetFocus();
  169. }
  170. }
  171. else
  172. {
  173. // if CSG is on
  174. if( pDoc->m_iMode == CSG_MODE)
  175. {
  176. ASSERT(pDoc->m_pwoSecondLayer != NULL);
  177. // if CSG is done with primitive force info mode: INFO_MODE_PRIMITIVE
  178. if( pDoc->m_bPrimitiveMode)
  179. {
  180. if( m_ModeID != INFO_MODE_PRIMITIVE)
  181. {
  182. // primitive mode includes position page
  183. SetInfoModePrimitive();
  184. }
  185. }
  186. // else force info mode: INFO_MODE_POSITION
  187. else
  188. {
  189. if( m_ModeID != INFO_MODE_POSITION)
  190. {
  191. // no primitive page, only position page
  192. SetInfoModePosition();
  193. }
  194. }
  195. }
  196. // else if we are in entity mode and only one entity is selected,
  197. // force info mode: INFO_MODE_POSITION
  198. else if( (pDoc->m_iMode == ENTITY_MODE) && (pDoc->m_selEntitySelection.Count() == 1) )
  199. {
  200. if( m_ModeID != INFO_MODE_POSITION)
  201. {
  202. SetInfoModePosition();
  203. }
  204. }
  205. // else if we are in polygon mode
  206. else if( pDoc->m_iMode == POLYGON_MODE)
  207. {
  208. if( m_ModeID == INFO_MODE_POLYGON)
  209. {
  210. if( GetActivePage() == &m_PgTexture) _iLastActivePgInPolygonMode = 1;
  211. else if( GetActivePage() == &m_PgShadow)_iLastActivePgInPolygonMode = 2;
  212. else _iLastActivePgInPolygonMode = 3;
  213. }
  214. if( m_ModeID != INFO_MODE_POLYGON)
  215. {
  216. SetInfoModePolygon();
  217. }
  218. }
  219. // else if we are in sector mode
  220. else if( pDoc->m_iMode == SECTOR_MODE)
  221. {
  222. if( m_ModeID != INFO_MODE_SECTOR)
  223. {
  224. SetInfoModeSector();
  225. }
  226. }
  227. // else if we are in terrain mode
  228. else if( pDoc->m_iMode == TERRAIN_MODE)
  229. {
  230. if( m_ModeID != INFO_MODE_TERRAIN)
  231. {
  232. SetInfoModeTerrain();
  233. }
  234. }
  235. // we are not in CSG mode nor in single entity mode, force info mode: INFO_MODE_GLOBAL
  236. else
  237. {
  238. if( m_ModeID != INFO_MODE_GLOBAL)
  239. {
  240. SetInfoModeGlobal();
  241. }
  242. }
  243. }
  244. // call OnIdle() for active page
  245. CPropertyPage *pgActivPage = GetActivePage();
  246. CALLACTIVEPAGE(OnIdle, lCount);
  247. return TRUE;
  248. }
  249. void CInfoSheet::PostNcDestroy()
  250. {
  251. CPropertySheet::PostNcDestroy();
  252. delete this;
  253. }
  254. BOOL CInfoSheet::PreTranslateMessage(MSG* pMsg)
  255. {
  256. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  257. CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  258. BOOL bAlt = (GetKeyState( VK_MENU)&0x8000) != 0;
  259. if(pMsg->message==WM_KEYDOWN)
  260. {
  261. // get active document
  262. BOOL bSectorNameTyping = FALSE;
  263. CPropertyPage *pgActivPage = GetActivePage();
  264. if(pgActivPage == &m_PgSector)
  265. {
  266. bSectorNameTyping = m_PgSector.GetDlgItem( IDC_SECTOR_NAME) == CWnd::GetFocus();
  267. }
  268. if( (pMsg->wParam==VK_SPACE) && !bSectorNameTyping)
  269. {
  270. // don't translate message
  271. return TRUE;
  272. }
  273. // if we have valid document
  274. if( (pDoc != NULL) && !bSectorNameTyping)
  275. {
  276. if( (pMsg->wParam==VK_ADD) ||
  277. (pMsg->wParam==VK_SUBTRACT) ||
  278. (pMsg->wParam=='E') ||
  279. (pMsg->wParam=='S') ||
  280. (pMsg->wParam=='P') ||
  281. (pMsg->wParam=='Z') ||
  282. (pMsg->wParam=='Q') ||
  283. (pMsg->wParam== VK_DECIMAL) )
  284. {
  285. // post this message to main frame
  286. ::PostMessage( pMainFrame->m_hWnd, WM_KEYDOWN, pMsg->wParam, pMsg->lParam);
  287. // don't translate message
  288. return TRUE;
  289. }
  290. }
  291. }
  292. return CPropertySheet::PreTranslateMessage(pMsg);
  293. }