guiMissionArea.cpp 21 KB

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