LevelEditView.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  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. // LevelEditView.cpp : implementation of the CLevelEditView class
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "leveleditdoc.h"
  23. #include "leveleditview.h"
  24. #include "camera.h"
  25. #include "cameramgr.h"
  26. #include "mainfrm.h"
  27. #include "ww3d.h"
  28. #include "mousemgr.h"
  29. #include "sceneeditor.h"
  30. #include <process.h>
  31. #include "nodemgr.h"
  32. #include "mmsystem.h"
  33. #include "dynamesh.h"
  34. #include "vertmaterial.h"
  35. #include "win.h"
  36. #include "wwaudio.h"
  37. #include "combat.h"
  38. #include "timemgr.h"
  39. #include "gameobjmanager.h"
  40. #include "gameobjobserver.h"
  41. #include "scripts.h"
  42. #include "backgroundmgr.h"
  43. #include "dazzle.h"
  44. #include "phys.h"
  45. #include "weathermgr.h"
  46. #include "soundenvironment.h"
  47. #include "heightfieldeditor.h"
  48. /////////////////////////////////////////////////////////////////////////
  49. // Local Prototypes
  50. /////////////////////////////////////////////////////////////////////////
  51. void CALLBACK fnTimerCallback (UINT, UINT, DWORD, DWORD, DWORD);
  52. /////////////////////////////////////////////////////////////////////////
  53. // Static member initialization
  54. /////////////////////////////////////////////////////////////////////////
  55. int CLevelEditView::_iPaintingLock = 0;
  56. bool CLevelEditView::_bNeedsRepaint = false;
  57. /////////////////////////////////////////////////////////////////////////
  58. // Globals
  59. /////////////////////////////////////////////////////////////////////////
  60. CRITICAL_SECTION _CriticalSection;
  61. IMPLEMENT_DYNCREATE(CLevelEditView, CView)
  62. BEGIN_MESSAGE_MAP(CLevelEditView, CView)
  63. //{{AFX_MSG_MAP(CLevelEditView)
  64. ON_WM_SIZE()
  65. ON_WM_CREATE()
  66. ON_WM_LBUTTONDOWN()
  67. ON_WM_LBUTTONUP()
  68. ON_WM_RBUTTONDOWN()
  69. ON_WM_RBUTTONUP()
  70. ON_WM_MOUSEMOVE()
  71. ON_WM_DESTROY()
  72. ON_WM_LBUTTONDBLCLK()
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. /////////////////////////////////////////////////////////////////////////
  76. //
  77. // CLevelEditView
  78. //
  79. /////////////////////////////////////////////////////////////////////////
  80. CLevelEditView::CLevelEditView (void)
  81. : m_iDeviceIndex (-1),
  82. m_iBitsPerPixel (16),
  83. m_iWindowed (1),
  84. m_bRenderDeviceInitialized (FALSE),
  85. m_pCameraMgr (NULL),
  86. m_pMouseMgr (NULL),
  87. m_bActive (false),
  88. m_p2DScene (NULL),
  89. m_p2DCamera (NULL),
  90. m_TimerID (0),
  91. m_HorzFOV (0),
  92. m_VertFOV (0),
  93. m_CursorXRatio (1),
  94. m_CursorYRatio (1),
  95. m_hMouseHook (NULL)
  96. {
  97. // Get the windowed mode from the registry
  98. CString string_windowed = theApp.GetProfileString ("Config", "Windowed", "1");
  99. m_iWindowed = ::atoi ((LPCTSTR)string_windowed) || Is_Silent_Mode ();
  100. ::InitializeCriticalSection (&_CriticalSection);
  101. return ;
  102. }
  103. /////////////////////////////////////////////////////////////////////////
  104. //
  105. // ~CLevelEditView
  106. //
  107. /////////////////////////////////////////////////////////////////////////
  108. CLevelEditView::~CLevelEditView (void)
  109. {
  110. // If the camera manager exists, free it.
  111. SAFE_DELETE (m_pCameraMgr);
  112. SAFE_DELETE (m_pMouseMgr);
  113. m_pCursorMesh->Remove ();
  114. MEMBER_RELEASE (m_pCursorMesh);
  115. MEMBER_RELEASE (m_p2DScene);
  116. MEMBER_RELEASE (m_p2DCamera);
  117. // Cache this information in the registry
  118. TCHAR temp_string[10];
  119. ::itoa (m_iWindowed, temp_string, 10);
  120. theApp.WriteProfileString ("Config", "Windowed", temp_string);
  121. ::DeleteCriticalSection (&_CriticalSection);
  122. return ;
  123. }
  124. /////////////////////////////////////////////////////////////////////////
  125. //
  126. // PreCreateWindow
  127. //
  128. /////////////////////////////////////////////////////////////////////////
  129. BOOL
  130. CLevelEditView::PreCreateWindow (CREATESTRUCT& cs)
  131. {
  132. // Allow the base class to process this message
  133. return CView::PreCreateWindow (cs);
  134. }
  135. /////////////////////////////////////////////////////////////////////////
  136. //
  137. // OnDraw
  138. //
  139. void
  140. CLevelEditView::OnDraw (CDC* pDC)
  141. {
  142. CLevelEditDoc* doc = GetDocument();
  143. ASSERT_VALID(doc);
  144. // If we are in fullscreen mode, then erase the window background
  145. if (m_iWindowed == 0) {
  146. // Get the client rectangle of the window
  147. RECT rect;
  148. GetClientRect (&rect);
  149. // Erase the background
  150. ::FillRect (*pDC, &rect, (HBRUSH)(COLOR_WINDOW + 1));
  151. }
  152. // Ask the view to repaint itself.
  153. Repaint_View ();
  154. return ;
  155. }
  156. /////////////////////////////////////////////////////////////////////////
  157. //
  158. // MFC Junk
  159. //
  160. /////////////////////////////////////////////////////////////////////////
  161. #ifdef _DEBUG
  162. void CLevelEditView::AssertValid() const
  163. {
  164. CView::AssertValid();
  165. }
  166. void CLevelEditView::Dump(CDumpContext& dc) const
  167. {
  168. CView::Dump(dc);
  169. }
  170. CLevelEditDoc* CLevelEditView::GetDocument() // non-debug version is inline
  171. {
  172. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLevelEditDoc)));
  173. return (CLevelEditDoc*)m_pDocument;
  174. }
  175. #endif //_DEBUG
  176. /////////////////////////////////////////////////////////////////////////
  177. //
  178. // Initialize_Render_Device
  179. //
  180. /////////////////////////////////////////////////////////////////////////
  181. bool
  182. CLevelEditView::Initialize_Render_Device (void)
  183. {
  184. ::EnterCriticalSection (&_CriticalSection);
  185. // Assume failure
  186. m_bRenderDeviceInitialized = FALSE;
  187. // Initialize the rendering engine with the information from
  188. // this window.
  189. RECT rect;
  190. GetClientRect (&rect);
  191. int cx = rect.right-rect.left;
  192. int cy = rect.bottom-rect.top;
  193. int bpp = m_iBitsPerPixel;
  194. if (m_iWindowed == 0) {
  195. cx = 640;
  196. cy = 480;
  197. bpp = 16;
  198. // Determine what our aspect ratio should be to
  199. // constrain the mouse to the 'window' while in full screen mode.
  200. m_CursorXRatio = cx / ((float)rect.right);
  201. m_CursorYRatio = cy / ((float)rect.bottom);
  202. } else {
  203. m_CursorXRatio = 1.0F;
  204. m_CursorYRatio = 1.0F;
  205. }
  206. // Ask W3D to use this rendering device
  207. m_bRenderDeviceInitialized = (WW3D::Set_Render_Device (m_iDeviceIndex,
  208. cx,
  209. cy,
  210. bpp,
  211. m_iWindowed) == WW3D_ERROR_OK);
  212. ASSERT (m_bRenderDeviceInitialized);
  213. // Create a new camera manager object
  214. if (m_pCameraMgr == NULL) {
  215. m_pCameraMgr = new CameraMgr;
  216. }
  217. // Create a new mouse manager object
  218. if (m_pMouseMgr == NULL) {
  219. m_pMouseMgr = new MouseMgrClass;
  220. }
  221. // Reset the camera's FOV
  222. m_pCameraMgr->Get_Camera ()->Set_View_Plane (m_HorzFOV, m_VertFOV);
  223. if (m_p2DCamera == NULL) {
  224. // Create a new instance of the camera class to use
  225. // when rendering the background BMP
  226. m_p2DCamera = new CameraClass ();
  227. // Were we successful in creating the new instance?
  228. ASSERT (m_p2DCamera != NULL);
  229. if (m_p2DCamera != NULL) {
  230. // Set the default values for the new camera
  231. m_p2DCamera->Set_View_Plane (Vector2 (-1.00F, -1.00F), Vector2 (1.00F, 1.00F));
  232. m_p2DCamera->Set_Position (Vector3 (0.00F, 0.00F, 1.00F));
  233. m_p2DCamera->Set_Clip_Planes (0.1F, 10.0F);
  234. //m_p2DCamera->Set_Position (Vector3 (0.00F, 0.00F, 1.00F));
  235. //m_p2DCamera->Set_Transform (Matrix3D (1));
  236. }
  237. }
  238. if (m_p2DScene == NULL) {
  239. // Instantiate a new scene
  240. m_p2DScene = new SimpleSceneClass;
  241. // Allocate a new mesh we can use to represent the mouse
  242. //.cursor while in full screen mode
  243. m_pCursorMesh = new DynamicScreenMeshClass (2, 6);
  244. //m_pCursorMesh->Set_Force_Visible (true);
  245. VertexMaterialClass *vmat = new VertexMaterialClass;
  246. vmat->Set_Emissive (1,1,1);
  247. vmat->Set_Diffuse (0,0,0);
  248. m_pCursorMesh->Set_Vertex_Material (vmat);
  249. MEMBER_RELEASE (vmat);
  250. m_pCursorMesh->Begin_Tri_Strip();
  251. m_pCursorMesh->Set_Vertex_Color (Vector3 (0, 0.384F, 0.5F));
  252. m_pCursorMesh->Vertex (0.0F, 0.0F, 0, 0, 0);
  253. m_pCursorMesh->Set_Vertex_Color (Vector3 (0, 0, 0.5F));
  254. m_pCursorMesh->Vertex (0.026F,0.028F, 0, 0, 0);
  255. m_pCursorMesh->Set_Vertex_Color (Vector3 (0, 0.5F, 1));
  256. m_pCursorMesh->Vertex (0.010F,0.024F, 0, 0, 0);
  257. m_pCursorMesh->End_Tri_Strip();
  258. m_pCursorMesh->Begin_Tri_Strip();
  259. m_pCursorMesh->Set_Vertex_Color (Vector3 (0, 0.5F, 1));
  260. m_pCursorMesh->Vertex (0.010F,0.024F, 0, 0, 0);
  261. m_pCursorMesh->Set_Vertex_Color (Vector3 (0.53F, 0.76F, 1));
  262. m_pCursorMesh->Vertex (0.0F, 0.041F, 0, 0, 0);
  263. m_pCursorMesh->Set_Vertex_Color (Vector3 (0, 0.5F, 1));
  264. m_pCursorMesh->Vertex (0.0F, 0.0F, 0, 0, 0);
  265. m_pCursorMesh->End_Tri_Strip();
  266. // Add the cursor to the 2D scene
  267. m_pCursorMesh->Add (m_p2DScene);
  268. }
  269. LeaveCriticalSection (&_CriticalSection);
  270. // Return the TRUE/FALSE result code
  271. return m_bRenderDeviceInitialized;
  272. }
  273. /////////////////////////////////////////////////////////////////////////
  274. //
  275. // OnSize
  276. //
  277. void
  278. CLevelEditView::OnSize
  279. (
  280. UINT nType,
  281. int cx,
  282. int cy
  283. )
  284. {
  285. // Allow the base class to process this message
  286. CView::OnSize (nType, cx, cy);
  287. int bpp = m_iBitsPerPixel;
  288. if (m_iWindowed == 0) {
  289. // Determine what our aspect ratio should be to
  290. // constrain the mouse to the 'window' while in full screen mode.
  291. m_CursorXRatio = 640 / ((float)cx);
  292. m_CursorYRatio = 480 / ((float)cy);
  293. cx = 640;
  294. cy = 480;
  295. bpp = 16;
  296. }
  297. // update the camera FOV settings
  298. // take the larger of the two dimensions, give it the
  299. // full desired FOV, then give the other dimension an
  300. // FOV proportional to its relative size
  301. m_HorzFOV = 0.0F;
  302. m_VertFOV = 0.0F;
  303. if (cy > cx) {
  304. m_VertFOV = (float)DEG_TO_RAD(45.0f);
  305. m_HorzFOV = (double)cx / (double)cy * m_VertFOV;
  306. }
  307. else {
  308. m_HorzFOV = (float)DEG_TO_RAD(45.0f);
  309. m_VertFOV = (double)cy / (double)cx * m_HorzFOV;
  310. }
  311. if (m_bRenderDeviceInitialized) {
  312. if (m_iWindowed == 1) {
  313. // Change the resolution of the rendering device to
  314. // match that of the view's current dimensions
  315. WW3D::Set_Device_Resolution (cx, cy, bpp, m_iWindowed);
  316. }
  317. // Reset the field of view
  318. m_pCameraMgr->Get_Camera ()->Set_View_Plane (m_HorzFOV, m_VertFOV);
  319. // Force a repaint of the screen
  320. Repaint_View ();
  321. }
  322. return ;
  323. }
  324. ////////////////////////////////////////////////////////////////////////////
  325. //
  326. // Allow_Repaint
  327. //
  328. ////////////////////////////////////////////////////////////////////////////
  329. void
  330. CLevelEditView::Allow_Repaint (bool active)
  331. {
  332. // Either increment or decrement the lock
  333. _iPaintingLock += (active ? -1 : 1);
  334. //
  335. // Refresh the view if necessary
  336. //
  337. if ((_iPaintingLock == 0) && _bNeedsRepaint) {
  338. ::Refresh_Main_View ();
  339. }
  340. return ;
  341. }
  342. ////////////////////////////////////////////////////////////////////////////
  343. //
  344. // Repaint_View
  345. //
  346. ////////////////////////////////////////////////////////////////////////////
  347. void
  348. CLevelEditView::Repaint_View (void)
  349. {
  350. CLevelEditDoc *doc = (CLevelEditDoc *)GetDocument ();
  351. //
  352. // Make sure separate threads don't try to render at the same time
  353. //
  354. ::EnterCriticalSection (&_CriticalSection);
  355. _bNeedsRepaint = false;
  356. //
  357. // Are we in a valid state?
  358. //
  359. WWASSERT (_iPaintingLock >= 0);
  360. if (m_bRenderDeviceInitialized &&
  361. (_iPaintingLock == 0) &&
  362. (doc != NULL) &&
  363. (doc->Get_Scene () != NULL) &&
  364. (::Is_Silent_Mode () == false))
  365. {
  366. _iPaintingLock ++;
  367. //
  368. // Get access to the scene and current render camera
  369. //
  370. SceneEditorClass *scene = ::Get_Scene_Editor ();
  371. CameraClass *camera = scene->Get_Render_Camera ();
  372. //
  373. // Let the game free up anything it needs
  374. //
  375. NetworkObjectMgrClass::Delete_Pending ();
  376. GameObjObserverManager::Delete_Pending ();
  377. ScriptManager::Destroy_Pending ();
  378. //
  379. // Call updates on some of the subsystems
  380. //
  381. WWAudioClass::Get_Instance ()->On_Frame_Update ();
  382. TimeManager::Update ();
  383. ((CMainFrame *)::AfxGetMainWnd ())->Update_Poly_Count ();
  384. ((CMainFrame *)::AfxGetMainWnd ())->Update_Texture_Mem ();
  385. //
  386. // Let the camera know to update its animation (if any)
  387. //
  388. ::Get_Camera_Mgr ()->On_Frame ();
  389. ::Get_Scene_Editor ()->On_Frame ();
  390. ::Get_Scene_Editor ()->Update_Selection_Boxes ();
  391. // Update some sub-systems.
  392. BackgroundMgrClass::Update (scene, camera);
  393. SoundEnvironmentClass *sound_environment = CombatManager::Get_Sound_Environment ();
  394. if (sound_environment != NULL) sound_environment->Update (scene, camera);
  395. WeatherMgrClass::Update (scene, camera);
  396. //
  397. // Collect visible objects and such...
  398. //
  399. PhysicsSceneClass::Get_Instance ()->Pre_Render_Processing (*camera);
  400. //
  401. // Set-up the rendering process
  402. //
  403. WW3D::Begin_Render (true, true, BackgroundMgrClass::Get_Clear_Color());
  404. //
  405. // Render the background scene from the game (this will give
  406. // us the sky and stuff).
  407. //
  408. WW3D::Render (CombatManager::Get_Background_Scene(), camera);
  409. //
  410. // Now render the main scene
  411. //
  412. WW3D::Render (scene, camera);
  413. //
  414. // Render any heightfield editing gizmos
  415. //
  416. HeightfieldEditorClass::Render ();
  417. //
  418. // Render the dazzle layer (if necessary)
  419. //
  420. DazzleLayerClass *dazzle_layer = CombatManager::Get_Dazzle_Layer ();
  421. if (dazzle_layer != NULL) {
  422. dazzle_layer->Render (camera);
  423. }
  424. //
  425. // Finish out the rendering process
  426. //
  427. WW3D::End_Render ();
  428. //
  429. // Cleanup the rendering processing
  430. //
  431. PhysicsSceneClass::Get_Instance ()->Post_Render_Processing ();
  432. _iPaintingLock --;
  433. } else {
  434. _bNeedsRepaint = true;
  435. }
  436. ::LeaveCriticalSection (&_CriticalSection);
  437. return ;
  438. }
  439. ////////////////////////////////////////////////////////////////////////////
  440. //
  441. // OnFinalRelease
  442. //
  443. void
  444. CLevelEditView::OnFinalRelease (void)
  445. {
  446. // Allow the base class to process this message
  447. CView::OnFinalRelease ();
  448. return;
  449. }
  450. ////////////////////////////////////////////////////////////////////////////
  451. //
  452. // OnInitialUpdate
  453. //
  454. void
  455. CLevelEditView::OnInitialUpdate (void)
  456. {
  457. // Allow the base class to process this message
  458. CView::OnInitialUpdate();
  459. // Initialize the render device before we can update the view
  460. if (m_bRenderDeviceInitialized == false) {
  461. Initialize_Render_Device ();
  462. }
  463. if (m_bRenderDeviceInitialized)
  464. {
  465. Start_Update ();
  466. }
  467. //MainWindow = m_hWnd;
  468. return ;
  469. }
  470. ////////////////////////////////////////////////////////////////////////////
  471. //
  472. // Start_Update
  473. //
  474. void
  475. CLevelEditView::Start_Update (bool bstart)
  476. {
  477. if (bstart && (m_TimerID == 0)) {
  478. // Kick off a timer that we can use to update
  479. // the display (kinda like a game loop iterator)
  480. m_TimerID = (UINT)::timeSetEvent (50,
  481. 50,
  482. fnTimerCallback,
  483. (DWORD)m_hWnd,
  484. TIME_PERIODIC);
  485. } else if ((bstart == false) && (m_TimerID != 0)) {
  486. // Stop the timer
  487. ::timeKillEvent ((UINT)m_TimerID);
  488. // We don't need this anymore
  489. m_TimerID = 0;
  490. }
  491. return ;
  492. }
  493. ////////////////////////////////////////////////////////////////////////////
  494. //
  495. // fnMouseHookProc
  496. //
  497. LRESULT CALLBACK
  498. fnMouseHookProc
  499. (
  500. int nCode,
  501. WPARAM wParam,
  502. LPARAM lParam
  503. )
  504. {
  505. LRESULT result = 0L;
  506. CLevelEditView *pview = ::Get_Main_View ();
  507. if (pview != NULL) {
  508. MOUSEHOOKSTRUCT *pinfo = (MOUSEHOOKSTRUCT *)lParam;
  509. if (pinfo != NULL) {
  510. bool allow_update = pinfo->hwnd == pview->m_hWnd;
  511. if (!allow_update) {
  512. allow_update = (::GetProp (pinfo->hwnd, "ALLOW_UPDATE") != NULL);
  513. if (!allow_update && ::GetParent (pinfo->hwnd)) {
  514. allow_update = (::GetProp (::GetParent (pinfo->hwnd), "ALLOW_UPDATE") != NULL);
  515. }
  516. if ( ::Get_Mouse_Mgr () &&
  517. ::Get_Mouse_Mgr ()->Get_Mouse_Mode () == MouseMgrClass::MODE_CAMERA_WALK) {
  518. allow_update = true;
  519. }
  520. }
  521. // Start or stop updating the view
  522. pview->Start_Update (allow_update);
  523. }
  524. // Call the next hook in our chain
  525. result = ::CallNextHookEx (::Get_Main_View ()->Get_Hook (), nCode, wParam, lParam);
  526. }
  527. return result;
  528. }
  529. ////////////////////////////////////////////////////////////////////////////
  530. //
  531. // OnCreate
  532. //
  533. int
  534. CLevelEditView::OnCreate (LPCREATESTRUCT lpCreateStruct)
  535. {
  536. if (CView::OnCreate(lpCreateStruct) == -1)
  537. return -1;
  538. // Let the main window know we want to be the active view
  539. CMainFrame *pwnd = (CMainFrame *)::AfxGetMainWnd ();
  540. if (pwnd) {
  541. pwnd->SetActiveView (this, FALSE);
  542. }
  543. m_hMouseHook = ::SetWindowsHookEx (WH_MOUSE,
  544. fnMouseHookProc,
  545. ::AfxGetInstanceHandle (),
  546. ::GetCurrentThreadId ());
  547. return 0;
  548. }
  549. ////////////////////////////////////////////////////////////////////////////
  550. //
  551. // OnLButtonDown
  552. //
  553. void
  554. CLevelEditView::OnLButtonDown
  555. (
  556. UINT nFlags,
  557. CPoint point
  558. )
  559. {
  560. // Pass this onto the mouse manager
  561. m_pMouseMgr->Handle_LButton_Down (nFlags, point);
  562. // Allow the base class to process this message
  563. CView::OnLButtonDown(nFlags, point);
  564. return ;
  565. }
  566. ////////////////////////////////////////////////////////////////////////////
  567. //
  568. // OnLButtonDown
  569. //
  570. void
  571. CLevelEditView::OnLButtonUp
  572. (
  573. UINT nFlags,
  574. CPoint point
  575. )
  576. {
  577. // Pass this onto the mouse manager
  578. m_pMouseMgr->Handle_LButton_Up (nFlags, point);
  579. // Allow the base class to process this message
  580. CView::OnLButtonUp(nFlags, point);
  581. return ;
  582. }
  583. ////////////////////////////////////////////////////////////////////////////
  584. //
  585. // OnLButtonDown
  586. //
  587. void
  588. CLevelEditView::OnRButtonDown
  589. (
  590. UINT nFlags,
  591. CPoint point
  592. )
  593. {
  594. // Pass this onto the mouse manager
  595. m_pMouseMgr->Handle_RButton_Down (nFlags, point);
  596. // Allow the base class to process this message
  597. CView::OnRButtonDown (nFlags, point);
  598. return ;
  599. }
  600. ////////////////////////////////////////////////////////////////////////////
  601. //
  602. // OnRButtonUp
  603. //
  604. void
  605. CLevelEditView::OnRButtonUp
  606. (
  607. UINT nFlags,
  608. CPoint point
  609. )
  610. {
  611. // Pass this onto the mouse manager
  612. m_pMouseMgr->Handle_RButton_Up (nFlags, point);
  613. // Allow the base class to process this message
  614. CView::OnRButtonUp (nFlags, point);
  615. return ;
  616. }
  617. ////////////////////////////////////////////////////////////////////////////
  618. //
  619. // OnMouseMove
  620. //
  621. void
  622. CLevelEditView::OnMouseMove
  623. (
  624. UINT nFlags,
  625. CPoint point
  626. )
  627. {
  628. // Pass this onto the mouse manager
  629. m_pMouseMgr->Handle_Mouse_Move (nFlags, point);
  630. SetFocus ();
  631. // Allow the base class to process this message
  632. CView::OnMouseMove (nFlags, point);
  633. return ;
  634. }
  635. ////////////////////////////////////////////////////////////////////////////
  636. //
  637. // WindowProc
  638. //
  639. LRESULT
  640. CLevelEditView::WindowProc
  641. (
  642. UINT message,
  643. WPARAM wParam,
  644. LPARAM lParam
  645. )
  646. {
  647. // Is this the repaint message we are expecting?
  648. if (message == WM_USER+101)
  649. {
  650. Repaint_View ();
  651. ::RemoveProp (m_hWnd, "WaitingToProcess");
  652. }
  653. // Allow the base class to process this message
  654. return CView::WindowProc(message, wParam, lParam);
  655. }
  656. ////////////////////////////////////////////////////////////////////////////
  657. //
  658. // OnDestroy
  659. //
  660. void
  661. CLevelEditView::OnDestroy (void)
  662. {
  663. // Kill the timer
  664. Start_Update (false);
  665. if (m_hMouseHook != NULL) {
  666. ::UnhookWindowsHookEx (m_hMouseHook);
  667. m_hMouseHook = NULL;
  668. }
  669. ::RemoveProp (m_hWnd, "WaitingToProcess");
  670. // Allow the base class to process this message
  671. CView::OnDestroy ();
  672. return ;
  673. }
  674. ////////////////////////////////////////////////////////////////////////////
  675. //
  676. // Reset_View
  677. //
  678. void
  679. CLevelEditView::Reset_View (void)
  680. {
  681. ASSERT (m_pCameraMgr != NULL);
  682. // Re-initialize the camera
  683. m_pCameraMgr->Init_Camera ();
  684. // Reset the mouse mode
  685. m_pMouseMgr->Set_Mouse_Mode (MouseMgrClass::MODE_OBJECT_MANIPULATE);
  686. return ;
  687. }
  688. ////////////////////////////////////////////////////////////////////////////
  689. //
  690. // fnTimerCallback
  691. //
  692. void CALLBACK
  693. fnTimerCallback
  694. (
  695. UINT uID,
  696. UINT uMsg,
  697. DWORD dwUser,
  698. DWORD dw1,
  699. DWORD dw2
  700. )
  701. {
  702. HWND hwnd = (HWND)dwUser;
  703. if (hwnd != NULL) {
  704. // Send this event off to the view to process (hackish, but fine for now)
  705. if ((GetProp (hwnd, "WaitingToProcess") == NULL) &&
  706. (CLevelEditView::_iPaintingLock == 0))
  707. {
  708. SetProp (hwnd, "WaitingToProcess", (HANDLE)1);
  709. // Send the message to the view so it will be in the
  710. // same thread (Surrender doesn't seem to be thread-safe)
  711. ::PostMessage (hwnd, WM_USER+101, 0, 0L);
  712. }
  713. }
  714. return ;
  715. }
  716. ////////////////////////////////////////////////////////////////////////////
  717. //
  718. // OnLButtonDblClk
  719. //
  720. void
  721. CLevelEditView::OnLButtonDblClk
  722. (
  723. UINT nFlags,
  724. CPoint point
  725. )
  726. {
  727. // Pass this onto the mouse manager
  728. m_pMouseMgr->Handle_LButton_Dblclk (nFlags, point);
  729. // Allow the base class to process this message
  730. CView::OnLButtonDown(nFlags, point);
  731. return ;
  732. }