guiMissionArea.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. if(!bitmap)
  292. return NULL;
  293. // get the min/max
  294. F32 min, max;
  295. mTerrainBlock->getMinMaxHeight(&min, &max);
  296. F32 diff = max - min;
  297. F32 colRange = 255.0f / diff;
  298. // This method allocates it's bitmap above, and does all assignment
  299. // in the following loop. It is not subject to 24-bit -> 32-bit conversion
  300. // problems, because the texture handle creation is where the conversion would
  301. // occur, if it occurs. Since the data in the texture is never read back, and
  302. // the bitmap is deleted after texture-upload, this is not a problem.
  303. for(S32 y = 0; y < mTerrainBlock->getBlockSize() ; y++)
  304. {
  305. for(S32 x = 0; x < mTerrainBlock->getBlockSize(); x++)
  306. {
  307. F32 height;
  308. height = mTerrainBlock->getHeight(Point2I(x, y));
  309. U8 col = U8((height - min) * colRange);
  310. ColorI color(col, col, col);
  311. bitmap->setColor(x, y, color);
  312. }
  313. }
  314. return(bitmap);
  315. }
  316. //------------------------------------------------------------------------------
  317. void GuiMissionAreaCtrl::setMissionArea( MissionArea* area )
  318. {
  319. mMissionArea = area;
  320. if( mMissionArea )
  321. {
  322. setArea(getArea());
  323. }
  324. }
  325. const RectI & GuiMissionAreaCtrl::getArea()
  326. {
  327. if( !bool(mMissionArea) )
  328. return(MissionArea::smMissionArea);
  329. return(mMissionArea->getArea());
  330. }
  331. void GuiMissionAreaCtrl::setArea(const RectI & area)
  332. {
  333. if( bool(mMissionArea) )
  334. {
  335. mMissionArea->setArea(area);
  336. mMissionArea->inspectPostApply();
  337. //onUpdate();
  338. }
  339. }
  340. //------------------------------------------------------------------------------
  341. void GuiMissionAreaCtrl::drawHandle(const Point2F & pos)
  342. {
  343. Point2F pnt(pos.x-mHandleTextureHalfSize.x, pos.y-mHandleTextureHalfSize.y);
  344. GFX->getDrawUtil()->drawBitmap(mHandleTexture, pnt);
  345. }
  346. void GuiMissionAreaCtrl::drawHandles(RectI & box)
  347. {
  348. F32 fillOffset = GFX->getFillConventionOffset();
  349. F32 lx = box.point.x + fillOffset, rx = box.point.x + box.extent.x + fillOffset;
  350. F32 cx = (lx + rx) * 0.5f;
  351. F32 by = box.point.y + fillOffset, ty = box.point.y + box.extent.y + fillOffset;
  352. F32 cy = (ty + by) * 0.5f;
  353. GFX->getDrawUtil()->clearBitmapModulation();
  354. drawHandle(Point2F(lx, ty));
  355. drawHandle(Point2F(lx, cy));
  356. drawHandle(Point2F(lx, by));
  357. drawHandle(Point2F(rx, ty));
  358. drawHandle(Point2F(rx, cy));
  359. drawHandle(Point2F(rx, by));
  360. drawHandle(Point2F(cx, ty));
  361. drawHandle(Point2F(cx, by));
  362. }
  363. bool GuiMissionAreaCtrl::testWithinHandle(const Point2I & testPoint, S32 handleX, S32 handleY)
  364. {
  365. S32 dx = testPoint.x - handleX;
  366. S32 dy = testPoint.y - handleY;
  367. return dx <= Handle_Pixel_Size && dx >= -Handle_Pixel_Size && dy <= Handle_Pixel_Size && dy >= -Handle_Pixel_Size;
  368. }
  369. S32 GuiMissionAreaCtrl::getHitHandles(const Point2I & mousePnt, const RectI & box)
  370. {
  371. S32 lx = box.point.x, rx = box.point.x + box.extent.x - 1;
  372. S32 cx = (lx + rx) >> 1;
  373. S32 by = box.point.y, ty = box.point.y + box.extent.y - 1;
  374. S32 cy = (ty + by) >> 1;
  375. if (testWithinHandle(mousePnt, lx, ty))
  376. return Handle_Left | Handle_Top;
  377. if (testWithinHandle(mousePnt, cx, ty))
  378. return Handle_Top;
  379. if (testWithinHandle(mousePnt, rx, ty))
  380. return Handle_Right | Handle_Top;
  381. if (testWithinHandle(mousePnt, lx, by))
  382. return Handle_Left | Handle_Bottom;
  383. if (testWithinHandle(mousePnt, cx, by))
  384. return Handle_Bottom;
  385. if (testWithinHandle(mousePnt, rx, by))
  386. return Handle_Right | Handle_Bottom;
  387. if (testWithinHandle(mousePnt, lx, cy))
  388. return Handle_Left;
  389. if (testWithinHandle(mousePnt, rx, cy))
  390. return Handle_Right;
  391. if(mousePnt.x >= lx && mousePnt.x <= rx &&
  392. mousePnt.y >= ty && mousePnt.y <= by)
  393. return(Handle_Middle);
  394. return Handle_None;
  395. }
  396. //------------------------------------------------------------------------------
  397. Point2F GuiMissionAreaCtrl::worldToScreen(const Point2F & pos)
  398. {
  399. return(Point2F(mCenterPos.x + (pos.x * mScale.x), mCenterPos.y + (pos.y * mScale.y)));
  400. }
  401. Point2I GuiMissionAreaCtrl::worldToScreen(const Point2I &pos)
  402. {
  403. return(Point2I(S32(mCenterPos.x + (pos.x * mScale.x)), S32(mCenterPos.y + (pos.y * mScale.y))));
  404. }
  405. Point2F GuiMissionAreaCtrl::screenToWorld(const Point2F & pos)
  406. {
  407. return(Point2F((pos.x - mCenterPos.x) / mScale.x, (pos.y - mCenterPos.y) / mScale.y));
  408. }
  409. Point2I GuiMissionAreaCtrl::screenToWorld(const Point2I &pos)
  410. {
  411. return(Point2I(S32((pos.x - mCenterPos.x) / mScale.x), S32((pos.y - mCenterPos.y) / mScale.y)));
  412. }
  413. Point2I GuiMissionAreaCtrl::screenDeltaToWorldDelta(const Point2I &screenPoint)
  414. {
  415. return(Point2I(S32(screenPoint.x / mScale.x), S32(screenPoint.y / mScale.y)));
  416. }
  417. void GuiMissionAreaCtrl::setupScreenTransform(const Point2I & offset)
  418. {
  419. const MatrixF & terrMat = mTerrainBlock->getTransform();
  420. Point3F terrPos;
  421. terrMat.getColumn(3, &terrPos);
  422. terrPos.z = 0;
  423. F32 terrDim = mTerrainBlock->getWorldBlockSize();
  424. const Point2I& extenti = getExtent( );
  425. Point2F extent( static_cast<F32>( extenti.x ), static_cast<F32>( extenti.y ) );
  426. if(mSquareBitmap)
  427. extent.x > extent.y ? extent.x = extent.y : extent.y = extent.x;
  428. // We need to negate the y-axis so we are correctly oriented with
  429. // positive y increase up the screen.
  430. mScale.set(extent.x / terrDim, -extent.y / terrDim, 0);
  431. Point3F terrOffset = -terrPos;
  432. terrOffset.convolve(mScale);
  433. // We need to add the y extent so we start from the bottom left of the control
  434. // rather than the top left.
  435. mCenterPos.set(terrOffset.x + F32(offset.x), terrOffset.y + F32(offset.y) + extent.y);
  436. }
  437. void GuiMissionAreaCtrl::getScreenMissionArea(RectI & rect)
  438. {
  439. RectI area = mMissionArea->getArea();
  440. Point2F pos = worldToScreen(Point2F(F32(area.point.x), F32(area.point.y)));
  441. Point2F end = worldToScreen(Point2F(F32(area.point.x + area.extent.x), F32(area.point.y + area.extent.y)));
  442. //
  443. rect.point.x = S32(round_local(pos.x));
  444. rect.point.y = S32(round_local(pos.y));
  445. rect.extent.x = S32(round_local(end.x - pos.x));
  446. rect.extent.y = S32(round_local(end.y - pos.y));
  447. }
  448. void GuiMissionAreaCtrl::getScreenMissionArea(RectF & rect)
  449. {
  450. RectI area = mMissionArea->getArea();
  451. Point2F pos = worldToScreen(Point2F(F32(area.point.x), F32(area.point.y)));
  452. Point2F end = worldToScreen(Point2F(F32(area.point.x + area.extent.x), F32(area.point.y + area.extent.y)));
  453. //
  454. rect.point.x = pos.x;
  455. rect.point.y = pos.y;
  456. rect.extent.x = end.x - pos.x;
  457. rect.extent.y = end.y - pos.y;
  458. }
  459. Point2I GuiMissionAreaCtrl::convertOrigin(const Point2I &pos)
  460. {
  461. // Convert screen point to our bottom left origin
  462. Point2I pnt = globalToLocalCoord(pos);
  463. const Point2I& extent = getExtent( );
  464. pnt.y = extent.y - pnt.y;
  465. Point2I pt = localToGlobalCoord(pnt);
  466. return pt;
  467. }
  468. void GuiMissionAreaCtrl::onRender(Point2I offset, const RectI & updateRect)
  469. {
  470. RectI rect(offset, getExtent());
  471. F32 fillOffset = GFX->getFillConventionOffset();
  472. setUpdate();
  473. // draw an x
  474. if(!bool(mMissionArea) || !bool(mTerrainBlock))
  475. {
  476. GFX->setStateBlock(mSolidStateBlock);
  477. PrimBuild::color3i( 0, 0, 0 );
  478. PrimBuild::begin( GFXLineList, 4 );
  479. PrimBuild::vertex2f( rect.point.x + fillOffset, updateRect.point.y + fillOffset );
  480. PrimBuild::vertex2f( rect.point.x + updateRect.extent.x + fillOffset, updateRect.point.y + updateRect.extent.y + fillOffset );
  481. PrimBuild::vertex2f( rect.point.x + fillOffset, updateRect.point.y + updateRect.extent.y + fillOffset );
  482. PrimBuild::vertex2f( rect.point.x + updateRect.extent.x + fillOffset, updateRect.point.y + fillOffset );
  483. PrimBuild::end();
  484. return;
  485. }
  486. //
  487. setupScreenTransform(offset);
  488. // draw the terrain
  489. if(mSquareBitmap)
  490. rect.extent.x > rect.extent.y ? rect.extent.x = rect.extent.y : rect.extent.y = rect.extent.x;
  491. GFXDrawUtil *drawer = GFX->getDrawUtil();
  492. drawer->clearBitmapModulation();
  493. drawer->drawBitmapStretch(mTextureObject, rect, GFXBitmapFlip_Y, GFXTextureFilterLinear, false);
  494. GFX->setStateBlock(mSolidStateBlock);
  495. drawer->clearBitmapModulation();
  496. // draw the reference axis
  497. PrimBuild::begin( GFXLineList, 4 );
  498. PrimBuild::color3i( 255, 0, 0 );
  499. PrimBuild::vertex2f( rect.point.x + 5 + fillOffset, rect.point.y + rect.extent.y - 5 + fillOffset );
  500. PrimBuild::vertex2f( rect.point.x + 25 + fillOffset, rect.point.y + rect.extent.y - 5 + fillOffset );
  501. PrimBuild::color3i( 0, 255, 0 );
  502. PrimBuild::vertex2f( rect.point.x + 5 + fillOffset, rect.point.y + rect.extent.y - 5 + fillOffset );
  503. PrimBuild::vertex2f( rect.point.x + 5 + fillOffset, rect.point.y + rect.extent.y - 25 + fillOffset );
  504. PrimBuild::end();
  505. RectF area;
  506. getScreenMissionArea(area);
  507. // render the mission area box
  508. PrimBuild::color( mMissionBoundsColor );
  509. PrimBuild::begin( GFXLineStrip, 5 );
  510. PrimBuild::vertex2f(area.point.x + fillOffset, area.point.y + fillOffset);
  511. PrimBuild::vertex2f(area.point.x + area.extent.x + fillOffset, area.point.y + fillOffset);
  512. PrimBuild::vertex2f(area.point.x + area.extent.x + fillOffset, area.point.y + area.extent.y + fillOffset);
  513. PrimBuild::vertex2f(area.point.x + fillOffset, area.point.y + area.extent.y + fillOffset);
  514. PrimBuild::vertex2f(area.point.x + fillOffset, area.point.y + fillOffset);
  515. PrimBuild::end();
  516. // render the camera
  517. //if(mRenderCamera)
  518. {
  519. CameraQuery camera;
  520. GameProcessCameraQuery(&camera);
  521. // farplane too far, 90' looks wrong...
  522. camera.fov = mDegToRad(60.f);
  523. camera.farPlane = 500.f;
  524. //
  525. F32 rot = camera.fov / 2;
  526. //
  527. VectorF ray;
  528. VectorF projRayA, projRayB;
  529. ray.set(camera.farPlane * -mSin(rot), camera.farPlane * mCos(rot), 0);
  530. camera.cameraMatrix.mulV(ray, &projRayA);
  531. ray.set(camera.farPlane * -mSin(-rot), camera.farPlane * mCos(-rot), 0);
  532. camera.cameraMatrix.mulV(ray, &projRayB);
  533. Point3F camPos;
  534. camera.cameraMatrix.getColumn(3, &camPos);
  535. Point2F s = worldToScreen(Point2F(camPos.x, camPos.y));
  536. Point2F e1 = worldToScreen(Point2F(camPos.x + projRayA.x, camPos.y + projRayA.y));
  537. Point2F e2 = worldToScreen(Point2F(camPos.x + projRayB.x, camPos.y + projRayB.y));
  538. PrimBuild::color( mCameraColor );
  539. PrimBuild::begin( GFXLineList, 4 );
  540. PrimBuild::vertex2f( s.x + fillOffset, s.y + fillOffset );
  541. PrimBuild::vertex2f( e1.x + fillOffset, e1.y + fillOffset );
  542. PrimBuild::vertex2f( s.x + fillOffset, s.y + fillOffset );
  543. PrimBuild::vertex2f( e2.x + fillOffset, e2.y + fillOffset );
  544. PrimBuild::end();
  545. }
  546. // render the handles
  547. RectI iArea;
  548. getScreenMissionArea(iArea);
  549. drawHandles(iArea);
  550. renderChildControls(offset, updateRect);
  551. }
  552. //------------------------------------------------------------------------------
  553. DefineEngineMethod( GuiMissionAreaCtrl, setMissionArea, void, ( MissionArea* area ),,
  554. "@brief Set the MissionArea to edit.\n\n")
  555. {
  556. object->setMissionArea( area );
  557. }
  558. DefineEngineMethod( GuiMissionAreaCtrl, updateTerrain, void, ( ),,
  559. "@brief Update the terrain bitmap.\n\n")
  560. {
  561. object->updateTerrain();
  562. }
  563. //------------------------------------------------------------------------------
  564. void GuiMissionAreaUndoAction::undo()
  565. {
  566. MissionArea *ma = NULL;
  567. if ( !Sim::findObject( mObjId, ma ) )
  568. return;
  569. // Temporarily save the MissionArea's current data.
  570. RectI area = ma->getArea();
  571. // Restore the MissionArea properties saved in the UndoAction
  572. ma->setArea( mArea );
  573. ma->inspectPostApply();
  574. // Now save the previous Mission data in this UndoAction
  575. // since an undo action must become a redo action and vice-versa
  576. mArea = area;
  577. // Let the script get a chance at it.
  578. Con::executef( mMissionAreaEditor, "onUndo" );
  579. }