guiMissionArea.cpp 20 KB

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