EditorToySceneWindow.cc 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  1. #include "2d/editorToy/EditorToySceneWindow.h"
  2. #include "console/console.h"
  3. #include "console/consoleTypes.h"
  4. #include "graphics/dgl.h"
  5. #include "platform/event.h"
  6. #include "2d/editorToy/EditorToyTool.h"
  7. #include "2d/editorToy/EditorToySceneWindow_ScriptBinding.h"
  8. //-----------------------------------------------------------------------
  9. IMPLEMENT_CONOBJECT(EditorToySceneWindow);
  10. //-----------------------------------------------------------------------
  11. bool EditorToySceneWindow::inNut(const Point2I &pt, S32 x, S32 y)
  12. {
  13. //S32 checkSize = mNutSize << 1;
  14. // check area relative to nut size.
  15. Point2I cTL(-(mNutSize *2), -(mNutSize * 2));
  16. Point2I cBR((mNutSize * 2), (mNutSize * 2));
  17. S32 dx = pt.x - x;
  18. S32 dy = pt.y - y;
  19. return dx <= cBR.x && dx >= cTL.x && dy <= cBR.y && dy >= cTL.y;
  20. }
  21. //-----------------------------------------------------------------------
  22. void EditorToySceneWindow::updatedSelection()
  23. {
  24. mSelSet.clear();
  25. Vector<SceneObject*>::iterator i;
  26. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  27. {
  28. mSelSet.addObject(*i);
  29. }
  30. }
  31. EditorToySceneWindow::EditorToySceneWindow()
  32. : mGridSnap(1.0f,1.0f),
  33. mSnapThreshold(0.2f),
  34. mSceneCamPos(0.0f, 0.0f),
  35. mSceneCamSize(16.0f, 9.0f),
  36. mDragBegin(0,0)
  37. {
  38. VECTOR_SET_ASSOCIATION(mSelectedObjs);
  39. VECTOR_SET_ASSOCIATION(mDragBeginPoints);
  40. mActive = true;
  41. mDragBeginPoints.clear();
  42. mSelectedObjs.clear();
  43. mMouseMode = Selecting;
  44. mSizeMode = SizingNone;
  45. mDropType = DropAtScreenCenter;
  46. mActiveTool = nullptr;
  47. mNutSize = 5;
  48. mDefaultCursor = NULL;
  49. mLeftRightCursor = NULL;
  50. mUpDownCursor = NULL;
  51. mMoveCursor = NULL;
  52. mAllCam = true;
  53. mDrawCam = true;
  54. mDrawAspectSafety = true;
  55. mDrawSaftey = true;
  56. }
  57. bool EditorToySceneWindow::onAdd()
  58. {
  59. if (!Parent::onAdd())
  60. return false;
  61. mTrash.registerObject();
  62. mSelSet.registerObject();
  63. mUndoManager.registerObject();
  64. return true;
  65. }
  66. void EditorToySceneWindow::onRemove()
  67. {
  68. Parent::onRemove();
  69. mTrash.unregisterObject();
  70. mSelSet.unregisterObject();
  71. mUndoManager.unregisterObject();
  72. }
  73. //-----------------------------------------------------------------------
  74. EditorToySceneWindow::~EditorToySceneWindow()
  75. {
  76. }
  77. //-----------------------------------------------------------------------
  78. void EditorToySceneWindow::setEditScene(Scene* pScene)
  79. {
  80. Parent::setScene(pScene);
  81. if (getScene())
  82. getScene()->setIsEditorScene(true);
  83. mCurrentScene = pScene;
  84. // find out if these vars are set.
  85. const char* pos = mCurrentScene->getDataField("CamPos", NULL);
  86. // if not load some defaults.
  87. if (Utility::mGetStringElementCount(pos) != 2)
  88. {
  89. mCurrentScene->setDataField("CamPos", NULL, "0.0 0.0");
  90. pos = "0.0 0.0";
  91. }
  92. const char* size = mCurrentScene->getDataField("CamSize", NULL);
  93. if (Utility::mGetStringElementCount(size) != 2)
  94. {
  95. mCurrentScene->setDataField("CamSize", NULL, "16.0 9.0");
  96. size = "16.0 9.0";
  97. }
  98. mSceneCamPos = Utility::mGetStringElementVector(pos);
  99. mSceneCamSize = Utility::mGetStringElementVector(size);
  100. mSceneCamRect = updateSceneCamera();
  101. }
  102. //-----------------------------------------------------------------------
  103. RectI EditorToySceneWindow::updateSceneCamera()
  104. {
  105. Vector2 uppLeft = mSceneCamPos - (mSceneCamSize * 0.5f);
  106. Vector2 lowRight = mSceneCamPos + (mSceneCamSize * 0.5f);
  107. sceneToWindowPoint(uppLeft, uppLeft);
  108. sceneToWindowPoint(lowRight, lowRight);
  109. Point2I winUppLeft = localToGlobalCoord(Point2I(uppLeft.x, uppLeft.y));
  110. Point2I winLowRight = localToGlobalCoord(Point2I(lowRight.x, lowRight.y));
  111. return RectI((S32)winUppLeft.x, (S32)winUppLeft.y,
  112. S32(winLowRight.x - winUppLeft.x),
  113. S32(winLowRight.y - winUppLeft.y));
  114. }
  115. //-----------------------------------------------------------------------
  116. void EditorToySceneWindow::resetEditScene()
  117. {
  118. if (getScene())
  119. getScene()->setIsEditorScene(false);
  120. Parent::resetScene();
  121. }
  122. //-----------------------------------------------------------------------
  123. S32 EditorToySceneWindow::getNutHit(const Point2I &pt, const RectI &box)
  124. {
  125. S32 lx = box.point.x, rx = box.point.x + box.extent.x - 1;
  126. S32 cx = (lx + rx) >> 1;
  127. S32 ty = box.point.y, by = box.point.y + box.extent.y - 1;
  128. S32 cy = (ty + by) >> 1;
  129. if (inNut(pt, lx, ty))
  130. return SizingLeft | SizingTop;
  131. if (inNut(pt, rx, ty))
  132. return SizingRight | SizingTop;
  133. if (inNut(pt, lx, by))
  134. return SizingLeft | SizingBottom;
  135. if (inNut(pt, rx, by))
  136. return SizingRight | SizingBottom;
  137. return SizingNone;
  138. }
  139. S32 EditorToySceneWindow::getDirNutHit(const Point2I & pt, SceneObject * obj)
  140. {
  141. // vars
  142. Vector2 pos = obj->getPosition();
  143. Vector2 size = obj->getSize();
  144. F32 ang = obj->getAngle();
  145. // right
  146. Vector2 right = right.getVecFromAng(pos, ang, (size.x*0.5f));
  147. // top
  148. Vector2 top = top.getVecFromAng(pos, ang + mDegToRad(90.0f), (size.y*0.5f));
  149. // left
  150. Vector2 left = left.getVecFromAng(pos, ang - mDegToRad(180.0f), (size.x*0.5f));
  151. // bottom
  152. Vector2 bottom = bottom.getVecFromAng(pos, ang - mDegToRad(90.0f), (size.y*0.5f));
  153. // cardinal
  154. Vector2 r;
  155. Vector2 l;
  156. Vector2 t;
  157. Vector2 b;
  158. // cardinal
  159. sceneToWindowPoint(right, r);
  160. sceneToWindowPoint(left, l);
  161. sceneToWindowPoint(top, t);
  162. sceneToWindowPoint(bottom, b);
  163. F32 deg = mRadToDeg(ang);
  164. if (deg == 90.0f)
  165. {
  166. if (inNut(pt, (S32)(l.x), (S32)(l.y)))
  167. return SizingBottom;
  168. if (inNut(pt, (S32)(r.x), (S32)(r.y)))
  169. return SizingTop;
  170. if (inNut(pt, (S32)(b.x), (S32)(b.y)))
  171. return SizingRight;
  172. if (inNut(pt, (S32)(t.x), (S32)(t.y)))
  173. return SizingLeft;
  174. }
  175. else if (deg == 180.0f || deg == -180.0f)
  176. {
  177. if (inNut(pt, (S32)(l.x), (S32)(l.y)))
  178. return SizingRight;
  179. if (inNut(pt, (S32)(r.x), (S32)(r.y)))
  180. return SizingLeft;
  181. if (inNut(pt, (S32)(b.x), (S32)(b.y)))
  182. return SizingTop;
  183. if (inNut(pt, (S32)(t.x), (S32)(t.y)))
  184. return SizingBottom;
  185. }
  186. else if (deg == -90.0f)
  187. {
  188. if (inNut(pt, (S32)(l.x), (S32)(l.y)))
  189. return SizingTop;
  190. if (inNut(pt, (S32)(r.x), (S32)(r.y)))
  191. return SizingBottom;
  192. if (inNut(pt, (S32)(b.x), (S32)(b.y)))
  193. return SizingLeft;
  194. if (inNut(pt, (S32)(t.x), (S32)(t.y)))
  195. return SizingRight;
  196. }
  197. else
  198. {
  199. if (inNut(pt, (S32)(l.x), (S32)(l.y)))
  200. return SizingLeft;
  201. if (inNut(pt, (S32)(r.x), (S32)(r.y)))
  202. return SizingRight;
  203. if (inNut(pt, (S32)(b.x), (S32)(b.y)))
  204. return SizingBottom;
  205. if (inNut(pt, (S32)(t.x), (S32)(t.y)))
  206. return SizingTop;
  207. }
  208. return SizingNone;
  209. }
  210. //-----------------------------------------------------------------------
  211. void EditorToySceneWindow::drawNut(const Point2I & nut, ColorI & outlineColor, ColorI & nutColor)
  212. {
  213. dglDrawCircleFill(nut,(F32)mNutSize, nutColor);
  214. dglDrawCircle(nut, (F32)mNutSize, outlineColor);
  215. }
  216. //-----------------------------------------------------------------------
  217. void EditorToySceneWindow::drawSizingNuts(SceneObject* obj, ColorI &outlineColor, ColorI &nutColor)
  218. {
  219. // vars
  220. // there has to be a better way...
  221. Vector2 pos = obj->getPosition();
  222. Vector2 size = obj->getSize();
  223. F32 ang = obj->getAngle();
  224. // right
  225. Vector2 right = right.getVecFromAng(pos, ang, (size.x*0.5f));
  226. Vector2 topRight = topRight.getVecFromAng(right, (ang + 1.5708f), (size.y*0.5f));
  227. // top
  228. Vector2 top = top.getVecFromAng(pos, (ang + 1.5708f), (size.y*0.5f));
  229. Vector2 topLeft = topLeft.getVecFromAng(top, ((ang + 1.5708f) + 1.5708f), (size.x*0.5f));
  230. // left
  231. Vector2 left = left.getVecFromAng(pos, ang + 3.14159f, (size.x*0.5f));
  232. Vector2 bottomLeft = bottomLeft.getVecFromAng(left, (ang - 1.5708f), (size.y*0.5f));
  233. // bottom
  234. Vector2 bottom = bottom.getVecFromAng(pos, ang - 1.5708f, (size.y*0.5f));
  235. Vector2 bottomRight = bottomRight.getVecFromAng(bottom, ang, (size.x*0.5f));
  236. // cardinal
  237. Vector2 r;
  238. Vector2 l;
  239. Vector2 t;
  240. Vector2 b;
  241. // corners
  242. Vector2 tr;
  243. Vector2 tl;
  244. Vector2 bl;
  245. Vector2 br;
  246. // cardinal
  247. sceneToWindowPoint(right, r);
  248. sceneToWindowPoint(left, l);
  249. sceneToWindowPoint(top, t);
  250. sceneToWindowPoint(bottom, b);
  251. // corners
  252. sceneToWindowPoint(topRight, tr);
  253. sceneToWindowPoint(topLeft, tl);
  254. sceneToWindowPoint(bottomLeft, bl);
  255. sceneToWindowPoint(bottomRight, br);
  256. // draw lines
  257. dglDrawLine((S32)(tr.x), (S32)(tr.y), (S32)(tl.x), (S32)(tl.y), outlineColor );
  258. dglDrawLine((S32)(tl.x), (S32)(tl.y), (S32)(bl.x), (S32)(bl.y),outlineColor );
  259. dglDrawLine((S32)(bl.x), (S32)(bl.y), (S32)(br.x), (S32)(br.y),outlineColor );
  260. dglDrawLine((S32)(br.x), (S32)(br.y), (S32)(tr.x), (S32)(tr.y), outlineColor );
  261. drawNut(Point2I((S32)(r.x), (S32)r.y), outlineColor, nutColor);
  262. drawNut(Point2I((S32)(l.x), (S32)l.y), outlineColor, nutColor);
  263. drawNut(Point2I((S32)(t.x), (S32)(t.y)), outlineColor, nutColor);
  264. drawNut(Point2I((S32)(b.x), (S32)(b.y)), outlineColor, nutColor);
  265. }
  266. bool EditorToySceneWindow::getRotateNutHit(const Point2I & pt, SceneObject* obj)
  267. {
  268. // vars
  269. Vector2 pos = obj->getPosition();
  270. Vector2 size = obj->getSize();
  271. F32 ang = obj->getAngle();
  272. // right
  273. Vector2 edge = edge.getVecFromAng(pos, ang, (size.x*0.5f));
  274. Vector2 rotate = rotate.getVecFromAng(edge, ang, (size.x*0.5f));
  275. Vector2 r;
  276. sceneToWindowPoint(rotate, r);
  277. return inNut(pt, (S32)(r.x), (S32)(r.y));
  278. }
  279. void EditorToySceneWindow::drawRotateNuts(SceneObject* obj, ColorI &outlineColor, ColorI &nutColor)
  280. {
  281. // vars
  282. Vector2 pos = obj->getPosition();
  283. Vector2 size = obj->getSize();
  284. F32 ang = obj->getAngle();
  285. // right
  286. Vector2 edge = edge.getVecFromAng(pos,ang,(size.x*0.5f));
  287. Vector2 rotate = rotate.getVecFromAng(edge,ang,(size.x*0.5f));
  288. Vector2 e;
  289. Vector2 r;
  290. sceneToWindowPoint(edge, e);
  291. sceneToWindowPoint(rotate, r);
  292. // draw lines
  293. dglDrawLine((S32)(e.x), (S32)(e.y), (S32)(r.x), (S32)(r.y), outlineColor);
  294. drawNut(Point2I((S32)(r.x), (S32)r.y), outlineColor, nutColor);
  295. }
  296. //-----------------------------------------------------------------------
  297. // Sizing Cursors
  298. bool EditorToySceneWindow::initCursors()
  299. {
  300. if (mMoveCursor == NULL || mUpDownCursor == NULL || mLeftRightCursor == NULL || mDefaultCursor == NULL)
  301. {
  302. SimObject *obj;
  303. obj = Sim::findObject("MoveCursor");
  304. mMoveCursor = dynamic_cast<GuiCursor*>(obj);
  305. obj = Sim::findObject("UpDownCursor");
  306. mUpDownCursor = dynamic_cast<GuiCursor*>(obj);
  307. obj = Sim::findObject("LeftRightCursor");
  308. mLeftRightCursor = dynamic_cast<GuiCursor*>(obj);
  309. obj = Sim::findObject("DefaultCursor");
  310. mDefaultCursor = dynamic_cast<GuiCursor*>(obj);
  311. obj = Sim::findObject("MoveCursor");
  312. mMoveCursor = dynamic_cast<GuiCursor*>(obj);
  313. return(mMoveCursor != NULL && mUpDownCursor != NULL && mLeftRightCursor != NULL && mDefaultCursor != NULL && mMoveCursor != NULL);
  314. }
  315. else
  316. return(true);
  317. }
  318. void EditorToySceneWindow::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &gEvt)
  319. {
  320. showCursor = true;
  321. SceneObject *obj;
  322. Point2I mousePos = globalToLocalCoord(gEvt.mousePoint);
  323. // first see if we hit a sizing knob on the currently selected control...
  324. if (mSelectedObjs.size() == 1 && initCursors() == true)
  325. {
  326. obj = mSelectedObjs.first();
  327. F32 deg = mRadToDeg(obj->getAngle());
  328. EditorToySceneWindow::SizingMode sizeMode = (EditorToySceneWindow::SizingMode)getDirNutHit(mousePos, obj);
  329. if (mMouseMode == SizingSelection)
  330. {
  331. if (mSizeMode == SizingLeft || mSizeMode == SizingRight)
  332. cursor = mLeftRightCursor;
  333. else if (mSizeMode == SizingTop || mSizeMode == SizingBottom)
  334. cursor = mUpDownCursor;
  335. else
  336. cursor = NULL;
  337. }
  338. else
  339. {
  340. // Check for current mouse position after checking for actual sizing mode
  341. if (sizeMode == SizingLeft || sizeMode == SizingRight)
  342. cursor = mLeftRightCursor;
  343. else if (sizeMode == SizingTop || sizeMode == SizingBottom)
  344. cursor = mUpDownCursor;
  345. else
  346. cursor = NULL;
  347. }
  348. }
  349. if (mMouseMode == MovingSelection && cursor == NULL)
  350. cursor = mMoveCursor;
  351. }
  352. //-----------------------------------------------------------------------
  353. void EditorToySceneWindow::getDragRect(RectI &box)
  354. {
  355. // draw the box in gui space. worldQuery to convert to scene.
  356. box.point.x = getMin(mLastMousePt.x, mSelectionAnchor.x);
  357. box.extent.x = getMax(mLastMousePt.x, mSelectionAnchor.x) - box.point.x + 1;
  358. box.point.y = getMin(mLastMousePt.y, mSelectionAnchor.y);
  359. box.extent.y = getMax(mLastMousePt.y, mSelectionAnchor.y) - box.point.y + 1;
  360. }
  361. //-----------------------------------------------------------------------
  362. RectI EditorToySceneWindow::objWindowBounds(const SceneObject* obj)
  363. {
  364. const RectF objAABBRect = obj->getAABBRectangle();
  365. Vector2 upLeft = Vector2(objAABBRect.point.x, objAABBRect.point.y + objAABBRect.extent.y);
  366. Vector2 lowRight = Vector2(objAABBRect.point.x + objAABBRect.extent.x, objAABBRect.point.y);
  367. Vector2 winUpLeft;
  368. Vector2 winLowRight;
  369. sceneToWindowPoint(upLeft, winUpLeft);
  370. sceneToWindowPoint(lowRight, winLowRight);
  371. return RectI(S32(winUpLeft.x), S32(winUpLeft.y),
  372. S32(winLowRight.x - winUpLeft.x),
  373. S32(winLowRight.y - winUpLeft.y));
  374. }
  375. //-----------------------------------------------------------------------
  376. Point2I EditorToySceneWindow::objWindowPos(const SceneObject * obj)
  377. {
  378. Vector2 pos = obj->getPosition();
  379. Vector2 winPos;
  380. sceneToWindowPoint(pos, winPos);
  381. return Point2I((S32)winPos.x,(S32)winPos.y);
  382. }
  383. //-----------------------------------------------------------------------
  384. bool EditorToySceneWindow::selectionContains(SceneObject *obj)
  385. {
  386. Vector<SceneObject*>::iterator i;
  387. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  388. {
  389. if (obj == *i)
  390. return true;
  391. }
  392. return false;
  393. }
  394. //-----------------------------------------------------------------------
  395. void EditorToySceneWindow::onTouchDown(const GuiEvent& gEvt)
  396. {
  397. if (!mCurrentScene)
  398. {
  399. //no scene, pass to parent and do nothing!
  400. Parent::onTouchDown(gEvt);
  401. return;
  402. }
  403. if (mActiveTool)
  404. {
  405. // if we have an active tool, give it the touch event.
  406. mActiveTool->onTouchDown(gEvt);
  407. return;
  408. }
  409. mouseLock();
  410. setFirstResponder();
  411. Point2I ctOff;
  412. Point2I oExt;
  413. SceneObject* obj;
  414. mLastMousePt = globalToLocalCoord(gEvt.mousePoint);
  415. Vector2 sceneMousePt;
  416. windowToScenePoint(mLastMousePt, sceneMousePt);
  417. WorldQuery* mWQ = mCurrentScene->getWorldQuery(true);
  418. WorldQueryFilter mQF(MASK_ALL, MASK_ALL, true, false, true, true);
  419. mWQ->setQueryFilter(mQF);
  420. mWQ->anyQueryPoint(sceneMousePt);
  421. U32 resCount = mWQ->getQueryResultsCount();
  422. typeWorldQueryResultVector& queryResults = mWQ->getQueryResults();
  423. // only apply the obj if we actually clicked something.
  424. if (resCount > 0)
  425. {
  426. obj = queryResults[0].mpSceneObject;
  427. }
  428. // If we have an object selected already, test sizing.
  429. if (mSelectedObjs.size() == 1)
  430. {
  431. SceneObject* obj = mSelectedObjs.first();
  432. RectI objBox = objWindowBounds(obj);
  433. RectI box(objBox.point.x, objBox.point.y, objBox.extent.x, objBox.extent.y);
  434. mSizeMode = (EditorToySceneWindow::SizingMode)getDirNutHit(mLastMousePt, obj);
  435. if (mSizeMode != SizingNone)
  436. {
  437. mMouseMode = SizingSelection;
  438. // for the undo
  439. Con::executef(this, 2, "onPreEdit", Con::getIntArg(getSelectionSet().getId()));
  440. return;
  441. }
  442. else if (getRotateNutHit(mLastMousePt,obj))
  443. {
  444. mMouseMode = RotateSelection;
  445. mStartAngle = obj->getAngle();
  446. mStartVector = sceneMousePt - obj->getPosition();
  447. // for the undo
  448. Con::executef(this, 2, "onPreEdit", Con::getIntArg(getSelectionSet().getId()));
  449. return;
  450. }
  451. }
  452. // handle movement for objs in selection.
  453. if (resCount > 0)
  454. {
  455. if (selectionContains(obj))
  456. {
  457. if (gEvt.modifier & SI_SHIFT)
  458. {
  459. Vector<SceneObject*>::iterator i;
  460. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  461. {
  462. if (*i == obj)
  463. {
  464. Con::executef(this, 2, "onRemoveSelected", Con::getIntArg(obj->getId()));
  465. mSelectedObjs.erase(i);
  466. break;
  467. }
  468. }
  469. mMouseMode = Selecting;
  470. }
  471. else
  472. {
  473. mDragBegin = gEvt.mousePoint;
  474. mDragBeginPoints.reserve(mSelectedObjs.size());
  475. // do this whether its 1 object or 100
  476. Vector<SceneObject*>::iterator i;
  477. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  478. {
  479. mDragBeginPoints.push_back((*i)->getPosition());
  480. }
  481. Vector2 pos = obj->getPosition();
  482. if(mSelectedObjs.size() > 1)
  483. mOffset = mSelCenter - sceneMousePt;
  484. else
  485. mOffset = pos - sceneMousePt;
  486. mMouseMode = MovingSelection;
  487. //undo
  488. Con::executef(this, 2, "onPreEdit", Con::getIntArg(getSelectionSet().getId()));
  489. }
  490. }
  491. else if(gEvt.modifier & SI_SHIFT)
  492. {
  493. mSelectedObjs.push_back(obj);
  494. Con::executef(this, 2, "onAddSelected", Con::getIntArg(obj->getId()));
  495. // update bounds.
  496. updateSelectionBounds();
  497. }
  498. else
  499. {
  500. //clear and select the object clicked
  501. mSelectedObjs.clear();
  502. mSelectedObjs.push_back(obj);
  503. }
  504. }
  505. else
  506. {
  507. // if no modifier clear the selection.
  508. if (!(gEvt.modifier & SI_SHIFT))
  509. {
  510. Con::executef(this, 1, "onClearSelected");
  511. mSelectedObjs.clear();
  512. }
  513. // start drgging
  514. // save this, we need it later.
  515. mSelectionAnchor = mLastMousePt;
  516. mMouseMode = DragSelection;
  517. }
  518. }
  519. //-----------------------------------------------------------------------
  520. void EditorToySceneWindow::onTouchUp(const GuiEvent& gEvt)
  521. {
  522. if (!mCurrentScene)
  523. {
  524. //no scene do nothing!
  525. Parent::onTouchUp(gEvt);
  526. return;
  527. }
  528. if (mActiveTool)
  529. {
  530. // if we have an active tool, give it the touch event.
  531. mActiveTool->onTouchUp(gEvt);
  532. return;
  533. }
  534. mouseUnlock();
  535. // house keeping
  536. mDragBegin.set(0, 0);
  537. mDragBeginPoints.clear();
  538. mLastMousePt = globalToLocalCoord(gEvt.mousePoint);
  539. if (mMouseMode == DragSelection)
  540. {
  541. RectI drag;
  542. getDragRect(drag);
  543. Vector2 dragPoint = drag.point;
  544. Vector2 dragUp;
  545. dragUp.x = dragPoint.x + drag.extent.x;
  546. dragUp.y = dragPoint.y + drag.extent.y;
  547. Vector2 sPt;
  548. Vector2 sUp;
  549. windowToScenePoint(dragPoint, sPt);
  550. windowToScenePoint(dragUp, sUp);
  551. // Build our area query
  552. WorldQuery* mWQ = mCurrentScene->getWorldQuery(true);
  553. WorldQueryFilter mQF(MASK_ALL, MASK_ALL, true, false, true, true);
  554. mWQ->setQueryFilter(mQF);
  555. mWQ->anyQueryArea(sPt,sUp);
  556. for (U32 i = 0; i < mWQ->getQueryResultsCount(); i++)
  557. {
  558. SceneObject *obj = mWQ->getQueryResults().at(i).mpSceneObject;;
  559. mSelectedObjs.push_back(obj);
  560. }
  561. updateSelectionBounds();
  562. }
  563. // we selected 1 item
  564. if(mSelectedObjs.size() == 1)
  565. Con::executef(this, 2, "onSelect", Con::getIntArg(mSelectedObjs[0]->getId()));
  566. // undo manager for move, size and rotate
  567. if(mMouseMode == SizingSelection || mMouseMode == MovingSelection || mMouseMode == RotateSelection)
  568. Con::executef(this, 2, "onPostEdit", Con::getIntArg(getSelectionSet().getId()));
  569. setFirstResponder();
  570. mMouseMode = Selecting;
  571. }
  572. //-----------------------------------------------------------------------
  573. void EditorToySceneWindow::onTouchDragged(const GuiEvent& gEvt)
  574. {
  575. if (!mCurrentScene)
  576. {
  577. //no scene do nothing!
  578. Parent::onTouchDragged(gEvt);
  579. return;
  580. }
  581. if (mActiveTool)
  582. {
  583. // if we have an active tool, give it the touch event.
  584. mActiveTool->onTouchDragged(gEvt);
  585. return;
  586. }
  587. // some vars
  588. Point2I curPoint = this->globalToLocalCoord(gEvt.mousePoint);
  589. Vector2 sceneMousePt;
  590. windowToScenePoint(curPoint, sceneMousePt);
  591. SceneObject *obj;
  592. if (mSelectedObjs.size() > 0)
  593. {
  594. obj = mSelectedObjs.first();
  595. // if our obj is locked, don't do anything!
  596. if (obj->isLocked())
  597. return;
  598. }
  599. if (mMouseMode == SizingSelection)
  600. {
  601. Vector2 objPos = obj->getRenderPosition();
  602. Vector2 objSize = obj->getSize();
  603. bool ar = true;
  604. bool fP = false;
  605. // if shift, no ar kept.
  606. if ((gEvt.modifier & SI_SHIFT))
  607. ar = false;
  608. // if ctrl, scale from center, no pos change, size axis.
  609. if ((gEvt.modifier & SI_LCTRL))
  610. {
  611. fP = true;
  612. ar = false;
  613. }
  614. // if alt, scale from center, no pos change.
  615. if ((gEvt.modifier & SI_LALT))
  616. {
  617. fP = true;
  618. ar = true;
  619. }
  620. scaleObject(objSize, objPos, sceneMousePt, ar, fP);
  621. }
  622. else if (mMouseMode == MovingSelection && mSelectedObjs.size())
  623. {
  624. moveObject(sceneMousePt + mOffset);
  625. }
  626. else if (mMouseMode == RotateSelection)
  627. {
  628. rotateObject(sceneMousePt - obj->getPosition(), mStartVector,mStartAngle);
  629. }
  630. else
  631. {
  632. mLastMousePt = curPoint;
  633. }
  634. }
  635. void EditorToySceneWindow::rotateObject(Vector2 mousePos, Vector2 origVec, F32 origAngle)
  636. {
  637. // init vars
  638. SceneObject* obj = mSelectedObjs.first();
  639. // some snapping
  640. F32 snapThresh = mDegToRad(10.0f);
  641. F32 snapDegrees = mDegToRad(90.0f);
  642. F32 oldAng = mAtan(origVec.x, origVec.y) + mDegToRad(origAngle);
  643. F32 ang = mAtan(mousePos.x, mousePos.y);
  644. F32 closeAng = mFloor((ang / snapDegrees) + 0.5f) * snapDegrees;
  645. if (mFabs(ang - closeAng) < snapThresh)
  646. {
  647. ang = closeAng;
  648. }
  649. if (ang > mDegToRad(359.0f))
  650. {
  651. ang = 0.0f;
  652. }
  653. obj->setAngle(ang);
  654. }
  655. void EditorToySceneWindow::moveObject(Vector2 newPos)
  656. {
  657. if (mGridSnap.x)
  658. {
  659. F32 closeX = mFloor((newPos.x / mGridSnap.x) + 0.5f) * mGridSnap.x;
  660. if (mFabs(newPos.x - closeX) < mSnapThreshold)
  661. newPos.x = closeX;
  662. }
  663. if (mGridSnap.y)
  664. {
  665. F32 closeY = mFloor((newPos.y / mGridSnap.y) + 0.5f) * mGridSnap.y;
  666. if (mFabs(newPos.y - closeY) < mSnapThreshold)
  667. newPos.y = closeY;
  668. }
  669. // moving multiple objects needs to be offset from center.
  670. if (mSelectedObjs.size() > 1)
  671. {
  672. Vector<SceneObject*>::iterator i;
  673. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  674. {
  675. (*i)->setPosition(((*i)->getPosition() - mSelCenter) + newPos);
  676. }
  677. }
  678. else
  679. {
  680. Vector<SceneObject*>::iterator i = mSelectedObjs.begin();
  681. (*i)->setPosition(newPos);
  682. }
  683. }
  684. void EditorToySceneWindow::scaleObject(Vector2 size, Vector2 pos, Vector2 mousePos, bool maintainAr, bool fixedPos)
  685. {
  686. // init vars
  687. SceneObject* obj = mSelectedObjs.first();
  688. Vector2 sizeDelt = Vector2(0.0, 0.0);
  689. Vector2 newPos = pos;
  690. Vector2 newSize = size;
  691. bool flipX = false;
  692. bool flipY = false;
  693. F32 ang = mRadToDeg(obj->getAngle());
  694. if (ang != 90.0f && ang != -180.0f && ang != 0.0f && ang != 180.0f && ang != -90.0f)
  695. {
  696. //maintainAr = true;
  697. fixedPos = true;
  698. }
  699. if (mGridSnap.x)
  700. {
  701. F32 closeX = mFloor((mousePos.x / mGridSnap.x) + 0.5f) * mGridSnap.x;
  702. if (mFabs(mousePos.x - closeX) < mSnapThreshold)
  703. mousePos.x = closeX;
  704. }
  705. if (mGridSnap.y)
  706. {
  707. F32 closeY = mFloor((mousePos.y / mGridSnap.y) + 0.5f) * mGridSnap.y;
  708. if (mFabs(mousePos.y - closeY) < mSnapThreshold)
  709. mousePos.y = closeY;
  710. }
  711. if (ang == 90.0f || ang == -90.0f)
  712. {
  713. if (mSizeMode == SizingLeft)
  714. {
  715. sizeDelt.x = mousePos.x - (pos.x - (size.y * 0.5f));
  716. newSize.y -= sizeDelt.x;
  717. newPos.x += sizeDelt.x * 0.5f;
  718. }
  719. else if (mSizeMode == SizingRight)
  720. {
  721. sizeDelt.x = mousePos.x - (pos.x + (size.y * 0.5f));
  722. newSize.y += sizeDelt.x;
  723. newPos.x += sizeDelt.x * 0.5f;
  724. }
  725. if (mSizeMode == SizingTop)
  726. {
  727. sizeDelt.y = mousePos.y - (pos.y + (size.x * 0.5f));
  728. newSize.x += sizeDelt.y;
  729. newPos.y += sizeDelt.y * 0.5f;
  730. }
  731. else if (mSizeMode == SizingBottom)
  732. {
  733. sizeDelt.y = mousePos.y - (pos.y - (size.x * 0.5f));
  734. newSize.x -= sizeDelt.y;
  735. newPos.y += sizeDelt.y * 0.5f;
  736. }
  737. // flip the sizing calcs.
  738. if (newSize.y < 0.0f)
  739. {
  740. if (mSizeMode == SizingLeft)
  741. {
  742. mSizeMode = SizingRight;
  743. }
  744. else if (mSizeMode == SizingRight)
  745. {
  746. mSizeMode = SizingLeft;
  747. }
  748. flipX = true;
  749. newSize.y = -newSize.y;
  750. }
  751. if (newSize.x < 0.0f)
  752. {
  753. if (mSizeMode == SizingTop)
  754. {
  755. mSizeMode = SizingBottom;
  756. }
  757. else if (mSizeMode == SizingBottom)
  758. {
  759. mSizeMode = SizingTop;
  760. }
  761. flipY = true;
  762. newSize.x = -newSize.x;
  763. }
  764. }
  765. else
  766. {
  767. if (mSizeMode == SizingLeft)
  768. {
  769. sizeDelt.x = mousePos.x - (pos.x - (size.x * 0.5f));
  770. newSize.x -= sizeDelt.x;
  771. newPos.x += sizeDelt.x * 0.5f;
  772. }
  773. else if (mSizeMode == SizingRight)
  774. {
  775. sizeDelt.x = mousePos.x - (pos.x + (size.x * 0.5f));
  776. newSize.x += sizeDelt.x;
  777. newPos.x += sizeDelt.x * 0.5f;
  778. }
  779. if (mSizeMode == SizingTop)
  780. {
  781. sizeDelt.y = mousePos.y - (pos.y + (size.y * 0.5f));
  782. newSize.y += sizeDelt.y;
  783. newPos.y += sizeDelt.y * 0.5f;
  784. }
  785. else if (mSizeMode == SizingBottom)
  786. {
  787. sizeDelt.y = mousePos.y - (pos.y - (size.y * 0.5f));
  788. newSize.y -= sizeDelt.y;
  789. newPos.y += sizeDelt.y * 0.5f;
  790. }
  791. // flip the sizing calcs.
  792. if (newSize.x < 0.0f)
  793. {
  794. if (mSizeMode == SizingLeft)
  795. {
  796. mSizeMode = SizingRight;
  797. }
  798. else if (mSizeMode == SizingRight)
  799. {
  800. mSizeMode = SizingLeft;
  801. }
  802. flipX = true;
  803. newSize.x = -newSize.x;
  804. }
  805. if (newSize.y < 0.0f)
  806. {
  807. if (mSizeMode == SizingTop)
  808. {
  809. mSizeMode = SizingBottom;
  810. }
  811. else if (mSizeMode == SizingBottom)
  812. {
  813. mSizeMode = SizingTop;
  814. }
  815. flipY = true;
  816. newSize.y = -newSize.y;
  817. }
  818. }
  819. //-----------------------
  820. if (maintainAr)
  821. {
  822. F32 oldAr = size.x / size.y;
  823. F32 newAr = newSize.x / newSize.y;
  824. Vector2 prevResize = newSize;
  825. if (newAr < oldAr)
  826. {
  827. if ((newSize.x < size.x))
  828. {
  829. newSize.y *= newAr / oldAr;
  830. }
  831. else
  832. {
  833. newSize.x *= oldAr / newAr;
  834. }
  835. }
  836. else
  837. {
  838. if ((newSize.y < size.y) )
  839. {
  840. newSize.x *= oldAr / newAr;
  841. }
  842. else
  843. {
  844. newSize.y *= newAr / oldAr;
  845. }
  846. }
  847. if (ang == 90.0f || ang == -90.0f)
  848. {
  849. if (mSizeMode == SizingLeft)
  850. {
  851. newPos.x -= (newSize.y - prevResize.y) * 0.5f;
  852. }
  853. else if (mSizeMode == SizingRight)
  854. {
  855. newPos.x += (newSize.y - prevResize.y) * 0.5f;
  856. }
  857. if (mSizeMode == SizingTop)
  858. {
  859. newPos.y -= (newSize.x - prevResize.x) * 0.5f;
  860. }
  861. else if (mSizeMode == SizingBottom)
  862. {
  863. newPos.y += (newSize.x - prevResize.x) * 0.5f;
  864. }
  865. }
  866. else
  867. {
  868. if (mSizeMode == SizingLeft)
  869. {
  870. newPos.x -= (newSize.x - prevResize.x) * 0.5f;
  871. }
  872. else if (mSizeMode == SizingRight)
  873. {
  874. newPos.x += (newSize.x - prevResize.x) * 0.5f;
  875. }
  876. if (mSizeMode == SizingTop)
  877. {
  878. newPos.y += (newSize.y - prevResize.y) * 0.5f;
  879. }
  880. else if (mSizeMode == SizingBottom)
  881. {
  882. newPos.y -= (newSize.y - prevResize.y) * 0.5f;
  883. }
  884. }
  885. }
  886. if (fixedPos)
  887. {
  888. obj->setPosition(pos);
  889. }
  890. else
  891. {
  892. obj->setPosition(newPos);
  893. }
  894. if (newSize != size)
  895. {
  896. obj->setSize(newSize);
  897. }
  898. }
  899. //-----------------------------------------------------------------------
  900. void EditorToySceneWindow::onTouchMove(const GuiEvent& gEvt)
  901. {
  902. }
  903. //-----------------------------------------------------------------------
  904. void EditorToySceneWindow::onRightMouseUp(const GuiEvent& gEvt)
  905. {
  906. if (!mCurrentScene)
  907. {
  908. //no scene do nothing!
  909. Parent::onRightMouseUp(gEvt);
  910. return;
  911. }
  912. if (mActiveTool)
  913. {
  914. // if we have an active tool, give it the touch event.
  915. mActiveTool->onRightMouseUp(gEvt);
  916. return;
  917. }
  918. }
  919. //-----------------------------------------------------------------------
  920. void EditorToySceneWindow::onRightMouseDown(const GuiEvent& gEvt)
  921. {
  922. if (!mCurrentScene)
  923. {
  924. //no scene do nothing!
  925. Parent::onRightMouseDown(gEvt);
  926. return;
  927. }
  928. if (mActiveTool)
  929. {
  930. // if we have an active tool, give it the touch event.
  931. mActiveTool->onRightMouseDown(gEvt);
  932. return;
  933. }
  934. // some vars
  935. Point2I curPoint = this->globalToLocalCoord(gEvt.mousePoint);
  936. windowToScenePoint(curPoint, mMouseCamDown);
  937. }
  938. //-----------------------------------------------------------------------
  939. void EditorToySceneWindow::onRightMouseDragged(const GuiEvent& gEvt)
  940. {
  941. if (!mCurrentScene)
  942. {
  943. //no scene do nothing!
  944. Parent::onRightMouseDragged(gEvt);
  945. return;
  946. }
  947. if (mActiveTool)
  948. {
  949. // if we have an active tool, give it the touch event.
  950. mActiveTool->onRightMouseDragged(gEvt);
  951. return;
  952. }
  953. // some vars
  954. Point2I curPoint = this->globalToLocalCoord(gEvt.mousePoint);
  955. Vector2 sceneMousePt;
  956. windowToScenePoint(curPoint, sceneMousePt);
  957. Vector2 move = mMouseCamDown - sceneMousePt;
  958. Vector2 newPos = getCameraPosition() + move;
  959. setCameraPosition(newPos);
  960. }
  961. bool EditorToySceneWindow::onMouseWheelDown(const GuiEvent & gEvt)
  962. {
  963. // Call Parent.
  964. Parent::onMouseWheelDown(gEvt);
  965. F32 zoom = getCameraZoom();
  966. if (zoom < 0.1f)
  967. return false;
  968. F32 amt = -10 * 0.005f * zoom;
  969. setCameraZoom(zoom + amt);
  970. return true;
  971. }
  972. bool EditorToySceneWindow::onMouseWheelUp(const GuiEvent & gEvt)
  973. {
  974. // Call Parent.
  975. Parent::onMouseWheelUp(gEvt);
  976. F32 zoom = getCameraZoom();
  977. F32 amt = 10 * 0.005f * zoom;
  978. setCameraZoom(zoom + amt);
  979. return true;
  980. }
  981. //-----------------------------------------------------------------------
  982. void EditorToySceneWindow::updateSelectionBounds()
  983. {
  984. // we want everything to be smaller.
  985. Point2I point(S32_MAX, S32_MAX);
  986. // we want everything to be bigger.
  987. Point2I extentPos(S32_MIN, S32_MIN);
  988. Vector<SceneObject*>::iterator i;
  989. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  990. {
  991. RectI bounds = objWindowBounds((*i));
  992. //bottom right
  993. Point2I bottomRight((bounds.point.x + bounds.extent.x), (bounds.point.y + bounds.extent.y));
  994. if (bounds.point.x < point.x)
  995. point.x = bounds.point.x;
  996. if (bounds.point.y < point.y)
  997. point.y = bounds.point.y;
  998. if (bottomRight.x > extentPos.x)
  999. extentPos.x = bottomRight.x;
  1000. if (bottomRight.y > extentPos.y)
  1001. extentPos.y = bottomRight.y;
  1002. }
  1003. Point2I extent = extentPos - point;
  1004. mSelBox = RectI(point.x, point.y, extent.x, extent.y);
  1005. mSelCenter = getSelectionCenter();
  1006. }
  1007. Vector2 EditorToySceneWindow::getSelectionCenter()
  1008. {
  1009. Vector2 center(mSelBox.point.x + (mSelBox.extent.x * 0.5f), mSelBox.point.y + (mSelBox.extent.y * 0.5f));
  1010. Vector2 sceneCenter;
  1011. windowToScenePoint(center, sceneCenter);
  1012. return sceneCenter;
  1013. }
  1014. void EditorToySceneWindow::onRender(Point2I offset, const RectI &updateRect)
  1015. {
  1016. // let parent do its thing or you wont see anything
  1017. Parent::onRender(offset, updateRect);
  1018. if (mCurrentScene)
  1019. {
  1020. if (mAllCam)
  1021. {
  1022. // render camera.
  1023. RectI c;
  1024. c = updateSceneCamera();
  1025. Point2I inset(c.extent.x * 0.1, c.extent.y * 0.1);
  1026. if (mDrawAspectSafety)
  1027. {
  1028. // Aspect ratio percent
  1029. c.inset(-inset.x, -inset.y);
  1030. dglDrawRect(c, ColorI(255, 0, 0, 100));
  1031. // ordinary cam
  1032. c.inset(inset.x, inset.y);
  1033. }
  1034. if (mDrawCam)
  1035. {
  1036. dglDrawRect(c, ColorI(255, 255, 255, 255));
  1037. }
  1038. if (mDrawSaftey)
  1039. {
  1040. // 90% inside safety
  1041. c.inset(inset.x, inset.y);
  1042. dglDrawRect(c, ColorI(0, 255, 0, 100));
  1043. }
  1044. }
  1045. bool multi = mSelectedObjs.size() > 1;
  1046. if (multi)
  1047. {
  1048. //RectI b = windowSelectionBounds();
  1049. updateSelectionBounds();
  1050. mSelBox.point += offset;
  1051. dglDrawRect(mSelBox, ColorI(255, 255, 255, 255));
  1052. }
  1053. Vector<SceneObject*>::iterator i;
  1054. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  1055. {
  1056. SceneObject* obj = (*i);
  1057. ColorI nutColor = multi ? ColorI(255, 255, 255) : ColorI(100, 100, 200);
  1058. ColorI outlineColor = ColorI(255, 255, 255);
  1059. // only draw rotate when we are not in multi
  1060. // draw rotate first so its under other nuts.
  1061. if (!multi)
  1062. {
  1063. drawRotateNuts(obj, outlineColor, nutColor);
  1064. }
  1065. drawSizingNuts(obj, outlineColor, nutColor);
  1066. }
  1067. if (mMouseMode == DragSelection)
  1068. {
  1069. RectI b;
  1070. getDragRect(b);
  1071. mSelBox.point += offset;
  1072. dglDrawRect(b, ColorI(255, 255, 255, 255));
  1073. }
  1074. }
  1075. if (mCurrentScene && (mGridSnap.x && mGridSnap.y) &&
  1076. (mMouseMode == MovingSelection || mMouseMode == SizingSelection))
  1077. {
  1078. RectF area = getCameraRenderArea();
  1079. U32 maxdot = (U32)(area.extent.x / mGridSnap.x) * (U32)(area.extent.y / mGridSnap.y);
  1080. Vector2 curDot;
  1081. Point2F areaEnd(area.point.x + area.extent.x, area.point.y + area.extent.y);
  1082. area.point.x = mGridSnap.x * ((S32)(area.point.x / mGridSnap.x));
  1083. area.point.y = mGridSnap.y * ((S32)(area.point.y / mGridSnap.y));
  1084. //vector<F32> verts;
  1085. for (F32 ix = area.point.x; ix < areaEnd.x; ix += mGridSnap.x)
  1086. {
  1087. for (F32 iy = area.point.y; iy < areaEnd.y; iy += mGridSnap.y)
  1088. {
  1089. curDot.Set(ix, iy);
  1090. sceneToWindowPoint(curDot, curDot);
  1091. curDot = (Vector2)localToGlobalCoord(Point2I(S32(curDot.x), S32(curDot.y)));
  1092. //verts.push_back(curDot.x);
  1093. //verts.push_back(curDot.y);
  1094. // the commented out method for doing this is a lot faster
  1095. // but it crashes if there are too many, slow is better than
  1096. // crashing, especially just in an editor.
  1097. dglDrawDot((Point2F)curDot, ColorI(255, 255, 255, 128));
  1098. }
  1099. }
  1100. //U32 num = verts.size();
  1101. //glEnableClientState(GL_VERTEX_ARRAY);
  1102. //glVertexPointer(2, GL_FLOAT, 0, verts.data());
  1103. //glDrawArrays(GL_POINTS, 0, num);
  1104. //glDisableClientState(GL_VERTEX_ARRAY);
  1105. }
  1106. }
  1107. void EditorToySceneWindow::resize(const Point2I &newPosition, const Point2I &newExtent)
  1108. {
  1109. Point2F extent = getCameraArea().extent;
  1110. F32 aR = (F32)newExtent.x / (F32)newExtent.y;
  1111. F32 localAr = extent.x / extent.y;
  1112. extent.x = extent.y * aR;
  1113. Parent::resize(newPosition, newExtent);
  1114. Parent::setCameraPosition(getCameraPosition());
  1115. Parent::setCameraSize(Vector2(extent.x, extent.y));
  1116. }
  1117. //-----------------------------------------------------------------------
  1118. void EditorToySceneWindow::setTool(EditorToyTool * tool)
  1119. {
  1120. if (mActiveTool)
  1121. mActiveTool->onDeactivate();
  1122. mActiveTool = tool;
  1123. if (mActiveTool)
  1124. mActiveTool->onActivate(this);
  1125. }
  1126. //-----------------------------------------------------------------------
  1127. // Required so editor can re-handle ontouch
  1128. void EditorToySceneWindow::deactivateTool()
  1129. {
  1130. mActiveTool->onDeactivate();
  1131. mActiveTool = nullptr;
  1132. }
  1133. //-----------------------------------------------------------------------