guiMissionArea.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gui/worldEditor/guiMissionArea.h"
  23. #include "console/consoleTypes.h"
  24. #include "console/engineAPI.h"
  25. #include "gfx/gfxDrawUtil.h"
  26. #include "gfx/primBuilder.h"
  27. #include "gfx/bitmap/gBitmap.h"
  28. #include "gui/3d/guiTSControl.h"
  29. #include "T3D/gameFunctions.h"
  30. #include "terrain/terrData.h"
  31. namespace {
  32. F32 round_local(F32 val)
  33. {
  34. if(val >= 0.f)
  35. {
  36. F32 floor = mFloor(val);
  37. if((val - floor) >= 0.5f)
  38. return(floor + 1.f);
  39. return(floor);
  40. }
  41. else
  42. {
  43. F32 ceil = mCeil(val);
  44. if((val - ceil) <= -0.5f)
  45. return(ceil - 1.f);
  46. return(ceil);
  47. }
  48. }
  49. }
  50. IMPLEMENT_CONOBJECT(GuiMissionAreaCtrl);
  51. ConsoleDocClass( GuiMissionAreaCtrl,
  52. "@brief Visual representation of Mission Area Editor.\n\n"
  53. "@internal"
  54. );
  55. GuiMissionAreaCtrl::GuiMissionAreaCtrl()
  56. {
  57. INIT_ASSET(HandleBitmap);
  58. mHandleTextureSize = Point2I::Zero;
  59. mHandleTextureHalfSize = Point2F::Zero;
  60. mSquareBitmap = true;
  61. mMissionArea = 0;
  62. mTerrainBlock = 0;
  63. mMissionBoundsColor.set(255,0,0);
  64. mCameraColor.set(255,0,0);
  65. mBlendStateBlock = NULL;
  66. mSolidStateBlock = NULL;
  67. mLastHitMode = Handle_None;
  68. mSavedDrag = false;
  69. }
  70. GuiMissionAreaCtrl::~GuiMissionAreaCtrl()
  71. {
  72. }
  73. //------------------------------------------------------------------------------
  74. void GuiMissionAreaCtrl::initPersistFields()
  75. {
  76. docsURL;
  77. addField( "squareBitmap", TypeBool, Offset(mSquareBitmap, GuiMissionAreaCtrl));
  78. INITPERSISTFIELD_IMAGEASSET(HandleBitmap, GuiMissionAreaCtrl, "Bitmap for the mission area handles.\n");
  79. addField( "missionBoundsColor", TypeColorI, Offset(mMissionBoundsColor, GuiMissionAreaCtrl));
  80. addField( "cameraColor", TypeColorI, Offset(mCameraColor, GuiMissionAreaCtrl));
  81. Parent::initPersistFields();
  82. }
  83. //------------------------------------------------------------------------------
  84. bool GuiMissionAreaCtrl::onAdd()
  85. {
  86. if(!Parent::onAdd())
  87. return(false);
  88. GFXStateBlockDesc desc;
  89. desc.setCullMode(GFXCullNone);
  90. desc.setZReadWrite(false);
  91. desc.setBlend(false, GFXBlendOne, GFXBlendZero);
  92. mSolidStateBlock = GFX->createStateBlock( desc );
  93. desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
  94. mBlendStateBlock = GFX->createStateBlock( desc );
  95. if (!mHandleBitmap.isNull())
  96. {
  97. mHandleTextureSize = Point2I(mHandleBitmap->getWidth(), mHandleBitmap->getHeight() );
  98. mHandleTextureHalfSize = Point2F(mHandleTextureSize.x, mHandleTextureSize.y) * 0.5f;
  99. }
  100. else
  101. {
  102. mHandleTextureSize = Point2I::Zero;
  103. mHandleTextureHalfSize = Point2F::Zero;
  104. }
  105. return(true);
  106. }
  107. bool GuiMissionAreaCtrl::onWake()
  108. {
  109. if(!Parent::onWake())
  110. return(false);
  111. //mMissionArea = const_cast<MissionArea*>(MissionArea::getServerObject());
  112. //if(!bool(mMissionArea))
  113. // Con::warnf(ConsoleLogEntry::General, "GuiMissionAreaCtrl::onWake: no MissionArea object.");
  114. //mTerrainBlock = getTerrainObj();
  115. //if(!bool(mTerrainBlock))
  116. // Con::warnf(ConsoleLogEntry::General, "GuiMissionAreaCtrl::onWake: no TerrainBlock object.");
  117. //if ( !bool(mMissionArea) || !bool(mTerrainBlock) )
  118. // return true;
  119. updateTerrainBitmap();
  120. // make sure mission area is clamped
  121. setArea(getArea());
  122. //onUpdate();
  123. setActive(true);
  124. return(true);
  125. }
  126. void GuiMissionAreaCtrl::onSleep()
  127. {
  128. mBitmap = NULL;
  129. mMissionArea = 0;
  130. mTerrainBlock = 0;
  131. Parent::onSleep();
  132. }
  133. //------------------------------------------------------------------------------
  134. void GuiMissionAreaCtrl::onMouseUp(const GuiEvent & event)
  135. {
  136. if(!bool(mMissionArea))
  137. return;
  138. RectI box;
  139. getScreenMissionArea(box);
  140. S32 hit = getHitHandles(event.mousePoint, box);
  141. // set the current cursor
  142. //updateCursor(hit);
  143. mLastHitMode = hit;
  144. if(mSavedDrag)
  145. {
  146. // Let the script get a chance at it.
  147. Con::executef( this, "onMissionAreaModified" );
  148. }
  149. mSavedDrag = false;
  150. }
  151. void GuiMissionAreaCtrl::onMouseDown(const GuiEvent & event)
  152. {
  153. if(!bool(mMissionArea))
  154. return;
  155. RectI box;
  156. getScreenMissionArea(box);
  157. mLastHitMode = getHitHandles(event.mousePoint, box);
  158. //if(mLastHitMode == Handle_Middle)
  159. // setCursor(GrabCursor);
  160. mLastMousePoint = event.mousePoint;
  161. }
  162. void GuiMissionAreaCtrl::onMouseMove(const GuiEvent & event)
  163. {
  164. if(!bool(mMissionArea))
  165. return;
  166. RectI box;
  167. getScreenMissionArea(box);
  168. S32 hit = getHitHandles(event.mousePoint, box);
  169. // set the current cursor...
  170. //updateCursor(hit);
  171. mLastHitMode = hit;
  172. }
  173. void GuiMissionAreaCtrl::onMouseDragged(const GuiEvent & event)
  174. {
  175. if(!bool(mMissionArea))
  176. return;
  177. if(mLastHitMode == Handle_None)
  178. return;
  179. // If we haven't already saved,
  180. // save an undo action to get back to this state,
  181. // before we make any modifications.
  182. if ( !mSavedDrag )
  183. {
  184. submitUndo( "Modify Node" );
  185. mSavedDrag = true;
  186. }
  187. RectI box;
  188. getScreenMissionArea(box);
  189. Point2I mouseDiff(event.mousePoint.x - mLastMousePoint.x,
  190. event.mousePoint.y - mLastMousePoint.y);
  191. // what we drag'n?
  192. RectI area = getArea();
  193. Point2I wp = screenDeltaToWorldDelta(mouseDiff);
  194. if (mLastHitMode == Handle_Middle)
  195. {
  196. area.point += wp;
  197. }
  198. if (mLastHitMode & Handle_Left)
  199. {
  200. if ((area.extent.x - wp.x) >= 1)
  201. {
  202. area.point.x += wp.x;
  203. area.extent.x -= wp.x;
  204. }
  205. }
  206. if (mLastHitMode & Handle_Right)
  207. {
  208. if ((area.extent.x + wp.x) >= 1)
  209. {
  210. area.extent.x += wp.x;
  211. }
  212. }
  213. if (mLastHitMode & Handle_Bottom)
  214. {
  215. if ((area.extent.y - wp.y) >= 1)
  216. {
  217. area.point.y += wp.y;
  218. area.extent.y -= wp.y;
  219. }
  220. }
  221. if (mLastHitMode & Handle_Top)
  222. {
  223. if ((area.extent.y + wp.y) >= 1)
  224. {
  225. area.extent.y += wp.y;
  226. }
  227. }
  228. setArea(area);
  229. mLastMousePoint = event.mousePoint;
  230. }
  231. void GuiMissionAreaCtrl::onMouseEnter(const GuiEvent &)
  232. {
  233. mLastHitMode = Handle_None;
  234. //setCursor(DefaultCursor);
  235. }
  236. void GuiMissionAreaCtrl::onMouseLeave(const GuiEvent &)
  237. {
  238. mLastHitMode = Handle_None;
  239. //setCursor(DefaultCursor);
  240. }
  241. //------------------------------------------------------------------------------
  242. void GuiMissionAreaCtrl::submitUndo( const UTF8 *name )
  243. {
  244. // Grab the mission editor undo manager.
  245. UndoManager *undoMan = NULL;
  246. if ( !Sim::findObject( "EUndoManager", undoMan ) )
  247. {
  248. Con::errorf( "GuiRiverEditorCtrl::submitUndo() - EUndoManager not found!" );
  249. return;
  250. }
  251. // Setup the action.
  252. GuiMissionAreaUndoAction *action = new GuiMissionAreaUndoAction( name );
  253. action->mMissionAreaEditor = this;
  254. action->mObjId = mMissionArea->getId();
  255. action->mArea = mMissionArea->getArea();
  256. undoMan->addAction( action );
  257. }
  258. //------------------------------------------------------------------------------
  259. void GuiMissionAreaCtrl::updateTerrain()
  260. {
  261. mTerrainBlock = getTerrainObj();
  262. updateTerrainBitmap();
  263. }
  264. TerrainBlock * GuiMissionAreaCtrl::getTerrainObj()
  265. {
  266. SimSet * scopeAlwaysSet = Sim::getGhostAlwaysSet();
  267. for(SimSet::iterator itr = scopeAlwaysSet->begin(); itr != scopeAlwaysSet->end(); itr++)
  268. {
  269. TerrainBlock * terrain = dynamic_cast<TerrainBlock*>(*itr);
  270. if(terrain)
  271. return(terrain);
  272. }
  273. return(0);
  274. }
  275. void GuiMissionAreaCtrl::updateTerrainBitmap()
  276. {
  277. GBitmap * bitmap = createTerrainBitmap();
  278. if( bitmap )
  279. setBitmapHandle( GFXTexHandle( bitmap, &GFXDefaultGUIProfile, true, String("Terrain Bitmap Update") ) );
  280. else
  281. setBitmap( "" );
  282. }
  283. GBitmap * GuiMissionAreaCtrl::createTerrainBitmap()
  284. {
  285. if(!mTerrainBlock)
  286. return NULL;
  287. GBitmap * bitmap = new GBitmap(mTerrainBlock->getBlockSize(), mTerrainBlock->getBlockSize(), false, GFXFormatR8G8B8 );
  288. // get the min/max
  289. F32 min, max;
  290. mTerrainBlock->getMinMaxHeight(&min, &max);
  291. F32 diff = max - min;
  292. F32 colRange = 255.0f / diff;
  293. // This method allocates it's bitmap above, and does all assignment
  294. // in the following loop. It is not subject to 24-bit -> 32-bit conversion
  295. // problems, because the texture handle creation is where the conversion would
  296. // occur, if it occurs. Since the data in the texture is never read back, and
  297. // the bitmap is deleted after texture-upload, this is not a problem.
  298. for(S32 y = 0; y < mTerrainBlock->getBlockSize() ; y++)
  299. {
  300. for(S32 x = 0; x < mTerrainBlock->getBlockSize(); x++)
  301. {
  302. F32 height;
  303. height = mTerrainBlock->getHeight(Point2I(x, y));
  304. U8 col = U8((height - min) * colRange);
  305. ColorI color(col, col, col);
  306. bitmap->setColor(x, y, color);
  307. }
  308. }
  309. return(bitmap);
  310. }
  311. //------------------------------------------------------------------------------
  312. void GuiMissionAreaCtrl::setMissionArea( MissionArea* area )
  313. {
  314. mMissionArea = area;
  315. if( mMissionArea )
  316. {
  317. setArea(getArea());
  318. }
  319. }
  320. const RectI & GuiMissionAreaCtrl::getArea()
  321. {
  322. if( !bool(mMissionArea) )
  323. return(MissionArea::smMissionArea);
  324. return(mMissionArea->getArea());
  325. }
  326. void GuiMissionAreaCtrl::setArea(const RectI & area)
  327. {
  328. if( bool(mMissionArea) )
  329. {
  330. mMissionArea->setArea(area);
  331. mMissionArea->inspectPostApply();
  332. //onUpdate();
  333. }
  334. }
  335. //------------------------------------------------------------------------------
  336. void GuiMissionAreaCtrl::drawHandle(const Point2F & pos)
  337. {
  338. Point2F pnt(pos.x-mHandleTextureHalfSize.x, pos.y-mHandleTextureHalfSize.y);
  339. GFX->getDrawUtil()->drawBitmap(mHandleBitmap, pnt);
  340. }
  341. void GuiMissionAreaCtrl::drawHandles(RectI & box)
  342. {
  343. F32 fillOffset = GFX->getFillConventionOffset();
  344. F32 lx = box.point.x + fillOffset, rx = box.point.x + box.extent.x + fillOffset;
  345. F32 cx = (lx + rx) * 0.5f;
  346. F32 by = box.point.y + fillOffset, ty = box.point.y + box.extent.y + fillOffset;
  347. F32 cy = (ty + by) * 0.5f;
  348. GFX->getDrawUtil()->clearBitmapModulation();
  349. drawHandle(Point2F(lx, ty));
  350. drawHandle(Point2F(lx, cy));
  351. drawHandle(Point2F(lx, by));
  352. drawHandle(Point2F(rx, ty));
  353. drawHandle(Point2F(rx, cy));
  354. drawHandle(Point2F(rx, by));
  355. drawHandle(Point2F(cx, ty));
  356. drawHandle(Point2F(cx, by));
  357. }
  358. bool GuiMissionAreaCtrl::testWithinHandle(const Point2I & testPoint, S32 handleX, S32 handleY)
  359. {
  360. S32 dx = testPoint.x - handleX;
  361. S32 dy = testPoint.y - handleY;
  362. return dx <= Handle_Pixel_Size && dx >= -Handle_Pixel_Size && dy <= Handle_Pixel_Size && dy >= -Handle_Pixel_Size;
  363. }
  364. S32 GuiMissionAreaCtrl::getHitHandles(const Point2I & mousePnt, const RectI & box)
  365. {
  366. S32 lx = box.point.x, rx = box.point.x + box.extent.x - 1;
  367. S32 cx = (lx + rx) >> 1;
  368. S32 by = box.point.y, ty = box.point.y + box.extent.y - 1;
  369. S32 cy = (ty + by) >> 1;
  370. if (testWithinHandle(mousePnt, lx, ty))
  371. return Handle_Left | Handle_Top;
  372. if (testWithinHandle(mousePnt, cx, ty))
  373. return Handle_Top;
  374. if (testWithinHandle(mousePnt, rx, ty))
  375. return Handle_Right | Handle_Top;
  376. if (testWithinHandle(mousePnt, lx, by))
  377. return Handle_Left | Handle_Bottom;
  378. if (testWithinHandle(mousePnt, cx, by))
  379. return Handle_Bottom;
  380. if (testWithinHandle(mousePnt, rx, by))
  381. return Handle_Right | Handle_Bottom;
  382. if (testWithinHandle(mousePnt, lx, cy))
  383. return Handle_Left;
  384. if (testWithinHandle(mousePnt, rx, cy))
  385. return Handle_Right;
  386. if(mousePnt.x >= lx && mousePnt.x <= rx &&
  387. mousePnt.y >= ty && mousePnt.y <= by)
  388. return(Handle_Middle);
  389. return Handle_None;
  390. }
  391. //------------------------------------------------------------------------------
  392. Point2F GuiMissionAreaCtrl::worldToScreen(const Point2F & pos)
  393. {
  394. return(Point2F(mCenterPos.x + (pos.x * mScale.x), mCenterPos.y + (pos.y * mScale.y)));
  395. }
  396. Point2I GuiMissionAreaCtrl::worldToScreen(const Point2I &pos)
  397. {
  398. return(Point2I(S32(mCenterPos.x + (pos.x * mScale.x)), S32(mCenterPos.y + (pos.y * mScale.y))));
  399. }
  400. Point2F GuiMissionAreaCtrl::screenToWorld(const Point2F & pos)
  401. {
  402. return(Point2F((pos.x - mCenterPos.x) / mScale.x, (pos.y - mCenterPos.y) / mScale.y));
  403. }
  404. Point2I GuiMissionAreaCtrl::screenToWorld(const Point2I &pos)
  405. {
  406. return(Point2I(S32((pos.x - mCenterPos.x) / mScale.x), S32((pos.y - mCenterPos.y) / mScale.y)));
  407. }
  408. Point2I GuiMissionAreaCtrl::screenDeltaToWorldDelta(const Point2I &screenPoint)
  409. {
  410. return(Point2I(S32(screenPoint.x / mScale.x), S32(screenPoint.y / mScale.y)));
  411. }
  412. void GuiMissionAreaCtrl::setupScreenTransform(const Point2I & offset)
  413. {
  414. const MatrixF & terrMat = mTerrainBlock->getTransform();
  415. Point3F terrPos;
  416. terrMat.getColumn(3, &terrPos);
  417. terrPos.z = 0;
  418. F32 terrDim = mTerrainBlock->getWorldBlockSize();
  419. const Point2I& extenti = getExtent( );
  420. Point2F extent( static_cast<F32>( extenti.x ), static_cast<F32>( extenti.y ) );
  421. if(mSquareBitmap)
  422. extent.x > extent.y ? extent.x = extent.y : extent.y = extent.x;
  423. // We need to negate the y-axis so we are correctly oriented with
  424. // positive y increase up the screen.
  425. mScale.set(extent.x / terrDim, -extent.y / terrDim, 0);
  426. Point3F terrOffset = -terrPos;
  427. terrOffset.convolve(mScale);
  428. // We need to add the y extent so we start from the bottom left of the control
  429. // rather than the top left.
  430. mCenterPos.set(terrOffset.x + F32(offset.x), terrOffset.y + F32(offset.y) + extent.y);
  431. }
  432. void GuiMissionAreaCtrl::getScreenMissionArea(RectI & rect)
  433. {
  434. RectI area = mMissionArea->getArea();
  435. Point2F pos = worldToScreen(Point2F(F32(area.point.x), F32(area.point.y)));
  436. Point2F end = worldToScreen(Point2F(F32(area.point.x + area.extent.x), F32(area.point.y + area.extent.y)));
  437. //
  438. rect.point.x = S32(round_local(pos.x));
  439. rect.point.y = S32(round_local(pos.y));
  440. rect.extent.x = S32(round_local(end.x - pos.x));
  441. rect.extent.y = S32(round_local(end.y - pos.y));
  442. }
  443. void GuiMissionAreaCtrl::getScreenMissionArea(RectF & rect)
  444. {
  445. RectI area = mMissionArea->getArea();
  446. Point2F pos = worldToScreen(Point2F(F32(area.point.x), F32(area.point.y)));
  447. Point2F end = worldToScreen(Point2F(F32(area.point.x + area.extent.x), F32(area.point.y + area.extent.y)));
  448. //
  449. rect.point.x = pos.x;
  450. rect.point.y = pos.y;
  451. rect.extent.x = end.x - pos.x;
  452. rect.extent.y = end.y - pos.y;
  453. }
  454. Point2I GuiMissionAreaCtrl::convertOrigin(const Point2I &pos)
  455. {
  456. // Convert screen point to our bottom left origin
  457. Point2I pnt = globalToLocalCoord(pos);
  458. const Point2I& extent = getExtent( );
  459. pnt.y = extent.y - pnt.y;
  460. Point2I pt = localToGlobalCoord(pnt);
  461. return pt;
  462. }
  463. void GuiMissionAreaCtrl::onRender(Point2I offset, const RectI & updateRect)
  464. {
  465. RectI rect(offset, getExtent());
  466. F32 fillOffset = GFX->getFillConventionOffset();
  467. setUpdate();
  468. // draw an x
  469. if(!bool(mMissionArea) || !bool(mTerrainBlock))
  470. {
  471. GFX->setStateBlock(mSolidStateBlock);
  472. PrimBuild::color3i( 0, 0, 0 );
  473. PrimBuild::begin( GFXLineList, 4 );
  474. PrimBuild::vertex2f( rect.point.x + fillOffset, updateRect.point.y + fillOffset );
  475. PrimBuild::vertex2f( rect.point.x + updateRect.extent.x + fillOffset, updateRect.point.y + updateRect.extent.y + fillOffset );
  476. PrimBuild::vertex2f( rect.point.x + fillOffset, updateRect.point.y + updateRect.extent.y + fillOffset );
  477. PrimBuild::vertex2f( rect.point.x + updateRect.extent.x + fillOffset, updateRect.point.y + fillOffset );
  478. PrimBuild::end();
  479. return;
  480. }
  481. //
  482. setupScreenTransform(offset);
  483. // draw the terrain
  484. if(mSquareBitmap)
  485. rect.extent.x > rect.extent.y ? rect.extent.x = rect.extent.y : rect.extent.y = rect.extent.x;
  486. GFXDrawUtil *drawer = GFX->getDrawUtil();
  487. drawer->clearBitmapModulation();
  488. drawer->drawBitmapStretch(mBitmap, rect, GFXBitmapFlip_Y, GFXTextureFilterLinear, false);
  489. GFX->setStateBlock(mSolidStateBlock);
  490. drawer->clearBitmapModulation();
  491. // draw the reference axis
  492. PrimBuild::begin( GFXLineList, 4 );
  493. PrimBuild::color3i( 255, 0, 0 );
  494. PrimBuild::vertex2f( rect.point.x + 5 + fillOffset, rect.point.y + rect.extent.y - 5 + fillOffset );
  495. PrimBuild::vertex2f( rect.point.x + 25 + fillOffset, rect.point.y + rect.extent.y - 5 + fillOffset );
  496. PrimBuild::color3i( 0, 255, 0 );
  497. PrimBuild::vertex2f( rect.point.x + 5 + fillOffset, rect.point.y + rect.extent.y - 5 + fillOffset );
  498. PrimBuild::vertex2f( rect.point.x + 5 + fillOffset, rect.point.y + rect.extent.y - 25 + fillOffset );
  499. PrimBuild::end();
  500. RectF area;
  501. getScreenMissionArea(area);
  502. // render the mission area box
  503. PrimBuild::color( mMissionBoundsColor );
  504. PrimBuild::begin( GFXLineStrip, 5 );
  505. PrimBuild::vertex2f(area.point.x + fillOffset, area.point.y + fillOffset);
  506. PrimBuild::vertex2f(area.point.x + area.extent.x + fillOffset, area.point.y + fillOffset);
  507. PrimBuild::vertex2f(area.point.x + area.extent.x + fillOffset, area.point.y + area.extent.y + fillOffset);
  508. PrimBuild::vertex2f(area.point.x + fillOffset, area.point.y + area.extent.y + fillOffset);
  509. PrimBuild::vertex2f(area.point.x + fillOffset, area.point.y + fillOffset);
  510. PrimBuild::end();
  511. // render the camera
  512. //if(mRenderCamera)
  513. {
  514. CameraQuery camera;
  515. GameProcessCameraQuery(&camera);
  516. // farplane too far, 90' looks wrong...
  517. camera.fov = mDegToRad(60.f);
  518. camera.farPlane = 500.f;
  519. //
  520. F32 rot = camera.fov / 2;
  521. //
  522. VectorF ray;
  523. VectorF projRayA, projRayB;
  524. ray.set(camera.farPlane * -mSin(rot), camera.farPlane * mCos(rot), 0);
  525. camera.cameraMatrix.mulV(ray, &projRayA);
  526. ray.set(camera.farPlane * -mSin(-rot), camera.farPlane * mCos(-rot), 0);
  527. camera.cameraMatrix.mulV(ray, &projRayB);
  528. Point3F camPos;
  529. camera.cameraMatrix.getColumn(3, &camPos);
  530. Point2F s = worldToScreen(Point2F(camPos.x, camPos.y));
  531. Point2F e1 = worldToScreen(Point2F(camPos.x + projRayA.x, camPos.y + projRayA.y));
  532. Point2F e2 = worldToScreen(Point2F(camPos.x + projRayB.x, camPos.y + projRayB.y));
  533. PrimBuild::color( mCameraColor );
  534. PrimBuild::begin( GFXLineList, 4 );
  535. PrimBuild::vertex2f( s.x + fillOffset, s.y + fillOffset );
  536. PrimBuild::vertex2f( e1.x + fillOffset, e1.y + fillOffset );
  537. PrimBuild::vertex2f( s.x + fillOffset, s.y + fillOffset );
  538. PrimBuild::vertex2f( e2.x + fillOffset, e2.y + fillOffset );
  539. PrimBuild::end();
  540. }
  541. // render the handles
  542. RectI iArea;
  543. getScreenMissionArea(iArea);
  544. drawHandles(iArea);
  545. renderChildControls(offset, updateRect);
  546. }
  547. //------------------------------------------------------------------------------
  548. DefineEngineMethod( GuiMissionAreaCtrl, setMissionArea, void, ( MissionArea* area ),,
  549. "@brief Set the MissionArea to edit.\n\n")
  550. {
  551. object->setMissionArea( area );
  552. }
  553. DefineEngineMethod( GuiMissionAreaCtrl, updateTerrain, void, ( ),,
  554. "@brief Update the terrain bitmap.\n\n")
  555. {
  556. object->updateTerrain();
  557. }
  558. //------------------------------------------------------------------------------
  559. void GuiMissionAreaUndoAction::undo()
  560. {
  561. MissionArea *ma = NULL;
  562. if ( !Sim::findObject( mObjId, ma ) )
  563. return;
  564. // Temporarily save the MissionArea's current data.
  565. RectI area = ma->getArea();
  566. // Restore the MissionArea properties saved in the UndoAction
  567. ma->setArea( mArea );
  568. ma->inspectPostApply();
  569. // Now save the previous Mission data in this UndoAction
  570. // since an undo action must become a redo action and vice-versa
  571. mArea = area;
  572. // Let the script get a chance at it.
  573. Con::executef( mMissionAreaEditor, "onUndo" );
  574. }