EditorToySceneWindow.cc 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  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. return(mMoveCursor != NULL && mUpDownCursor != NULL && mLeftRightCursor != NULL && mDefaultCursor != NULL);
  312. }
  313. else
  314. return(true);
  315. }
  316. void EditorToySceneWindow::getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &gEvt)
  317. {
  318. showCursor = true;
  319. SceneObject *obj;
  320. Point2I mousePos = globalToLocalCoord(gEvt.mousePoint);
  321. // first see if we hit a sizing knob on the currently selected control...
  322. if (mSelectedObjs.size() == 1 && initCursors() == true)
  323. {
  324. obj = mSelectedObjs.first();
  325. F32 deg = mRadToDeg(obj->getAngle());
  326. EditorToySceneWindow::SizingMode sizeMode = (EditorToySceneWindow::SizingMode)getDirNutHit(mousePos, obj);
  327. if (mMouseMode == SizingSelection)
  328. {
  329. if (mSizeMode == SizingLeft || mSizeMode == SizingRight)
  330. cursor = mLeftRightCursor;
  331. else if (mSizeMode == SizingTop || mSizeMode == SizingBottom)
  332. cursor = mUpDownCursor;
  333. else
  334. cursor = NULL;
  335. }
  336. else
  337. {
  338. // Check for current mouse position after checking for actual sizing mode
  339. if (sizeMode == SizingLeft || sizeMode == SizingRight)
  340. cursor = mLeftRightCursor;
  341. else if (sizeMode == SizingTop || sizeMode == SizingBottom)
  342. cursor = mUpDownCursor;
  343. else
  344. cursor = NULL;
  345. }
  346. }
  347. if (mMouseMode == MovingSelection && cursor == NULL)
  348. cursor = mMoveCursor;
  349. }
  350. //-----------------------------------------------------------------------
  351. void EditorToySceneWindow::getDragRect(RectI &box)
  352. {
  353. // draw the box in gui space. worldQuery to convert to scene.
  354. box.point.x = getMin(mLastMousePt.x, mSelectionAnchor.x);
  355. box.extent.x = getMax(mLastMousePt.x, mSelectionAnchor.x) - box.point.x + 1;
  356. box.point.y = getMin(mLastMousePt.y, mSelectionAnchor.y);
  357. box.extent.y = getMax(mLastMousePt.y, mSelectionAnchor.y) - box.point.y + 1;
  358. }
  359. //-----------------------------------------------------------------------
  360. RectI EditorToySceneWindow::objWindowBounds(const SceneObject* obj)
  361. {
  362. const RectF objAABBRect = obj->getAABBRectangle();
  363. Vector2 upLeft = Vector2(objAABBRect.point.x, objAABBRect.point.y + objAABBRect.extent.y);
  364. Vector2 lowRight = Vector2(objAABBRect.point.x + objAABBRect.extent.x, objAABBRect.point.y);
  365. Vector2 winUpLeft;
  366. Vector2 winLowRight;
  367. sceneToWindowPoint(upLeft, winUpLeft);
  368. sceneToWindowPoint(lowRight, winLowRight);
  369. return RectI(S32(winUpLeft.x), S32(winUpLeft.y),
  370. S32(winLowRight.x - winUpLeft.x),
  371. S32(winLowRight.y - winUpLeft.y));
  372. }
  373. //-----------------------------------------------------------------------
  374. Point2I EditorToySceneWindow::objWindowPos(const SceneObject * obj)
  375. {
  376. Vector2 pos = obj->getPosition();
  377. Vector2 winPos;
  378. sceneToWindowPoint(pos, winPos);
  379. return Point2I((S32)winPos.x,(S32)winPos.y);
  380. }
  381. //-----------------------------------------------------------------------
  382. bool EditorToySceneWindow::selectionContains(SceneObject *obj)
  383. {
  384. Vector<SceneObject*>::iterator i;
  385. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  386. {
  387. if (obj == *i)
  388. return true;
  389. }
  390. return false;
  391. }
  392. //-----------------------------------------------------------------------
  393. void EditorToySceneWindow::onTouchDown(const GuiEvent& gEvt)
  394. {
  395. if (!mCurrentScene)
  396. {
  397. //no scene, pass to parent and do nothing!
  398. Parent::onTouchDown(gEvt);
  399. return;
  400. }
  401. if (mActiveTool)
  402. {
  403. // if we have an active tool, give it the touch event.
  404. mActiveTool->onTouchDown(gEvt);
  405. return;
  406. }
  407. mouseLock();
  408. setFirstResponder();
  409. Point2I ctOff;
  410. Point2I oExt;
  411. SceneObject* obj;
  412. mLastMousePt = globalToLocalCoord(gEvt.mousePoint);
  413. Vector2 sceneMousePt;
  414. windowToScenePoint(mLastMousePt, sceneMousePt);
  415. WorldQuery* mWQ = mCurrentScene->getWorldQuery(true);
  416. WorldQueryFilter mQF(MASK_ALL, MASK_ALL, true, false, true, true);
  417. mWQ->setQueryFilter(mQF);
  418. mWQ->anyQueryPoint(sceneMousePt);
  419. U32 resCount = mWQ->getQueryResultsCount();
  420. typeWorldQueryResultVector& queryResults = mWQ->getQueryResults();
  421. // only apply the obj if we actually clicked something.
  422. if (resCount > 0)
  423. {
  424. obj = queryResults[0].mpSceneObject;
  425. }
  426. // If we have an object selected already, test sizing.
  427. if (mSelectedObjs.size() == 1)
  428. {
  429. SceneObject* obj = mSelectedObjs.first();
  430. RectI objBox = objWindowBounds(obj);
  431. RectI box(objBox.point.x, objBox.point.y, objBox.extent.x, objBox.extent.y);
  432. mSizeMode = (EditorToySceneWindow::SizingMode)getDirNutHit(mLastMousePt, obj);
  433. if (mSizeMode != SizingNone)
  434. {
  435. mMouseMode = SizingSelection;
  436. // for the undo
  437. Con::executef(this, 2, "onPreEdit", Con::getIntArg(getSelectionSet().getId()));
  438. return;
  439. }
  440. else if (getRotateNutHit(mLastMousePt,obj))
  441. {
  442. mMouseMode = RotateSelection;
  443. mStartAngle = obj->getAngle();
  444. mStartVector = sceneMousePt - obj->getPosition();
  445. // for the undo
  446. Con::executef(this, 2, "onPreEdit", Con::getIntArg(getSelectionSet().getId()));
  447. return;
  448. }
  449. }
  450. // handle movement for objs in selection.
  451. if (resCount > 0)
  452. {
  453. if (selectionContains(obj))
  454. {
  455. if (gEvt.modifier & SI_SHIFT)
  456. {
  457. Vector<SceneObject*>::iterator i;
  458. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  459. {
  460. if (*i == obj)
  461. {
  462. Con::executef(this, 2, "onRemoveSelected", Con::getIntArg(obj->getId()));
  463. mSelectedObjs.erase(i);
  464. break;
  465. }
  466. }
  467. mMouseMode = Selecting;
  468. }
  469. else
  470. {
  471. mDragBegin = gEvt.mousePoint;
  472. mDragBeginPoints.reserve(mSelectedObjs.size());
  473. // do this whether its 1 object or 100
  474. Vector<SceneObject*>::iterator i;
  475. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  476. {
  477. mDragBeginPoints.push_back((*i)->getPosition());
  478. }
  479. Vector2 pos = obj->getPosition();
  480. if(mSelectedObjs.size() > 1)
  481. mOffset = mSelCenter - sceneMousePt;
  482. else
  483. mOffset = pos - sceneMousePt;
  484. mMouseMode = MovingSelection;
  485. //undo
  486. Con::executef(this, 2, "onPreEdit", Con::getIntArg(getSelectionSet().getId()));
  487. }
  488. }
  489. else if(gEvt.modifier & SI_SHIFT)
  490. {
  491. mSelectedObjs.push_back(obj);
  492. Con::executef(this, 2, "onAddSelected", Con::getIntArg(obj->getId()));
  493. // update bounds.
  494. updateSelectionBounds();
  495. }
  496. else
  497. {
  498. //clear and select the object clicked
  499. mSelectedObjs.clear();
  500. mSelectedObjs.push_back(obj);
  501. }
  502. }
  503. else
  504. {
  505. // if no modifier clear the selection.
  506. if (!(gEvt.modifier & SI_SHIFT))
  507. {
  508. Con::executef(this, 1, "onClearSelected");
  509. mSelectedObjs.clear();
  510. }
  511. // start drgging
  512. // save this, we need it later.
  513. mSelectionAnchor = mLastMousePt;
  514. mMouseMode = DragSelection;
  515. }
  516. }
  517. //-----------------------------------------------------------------------
  518. void EditorToySceneWindow::onTouchUp(const GuiEvent& gEvt)
  519. {
  520. if (!mCurrentScene)
  521. {
  522. //no scene do nothing!
  523. Parent::onTouchUp(gEvt);
  524. return;
  525. }
  526. if (mActiveTool)
  527. {
  528. // if we have an active tool, give it the touch event.
  529. mActiveTool->onTouchUp(gEvt);
  530. return;
  531. }
  532. mouseUnlock();
  533. // house keeping
  534. mDragBegin.set(0, 0);
  535. mDragBeginPoints.clear();
  536. mLastMousePt = globalToLocalCoord(gEvt.mousePoint);
  537. if (mMouseMode == DragSelection)
  538. {
  539. RectI drag;
  540. getDragRect(drag);
  541. Vector2 dragPoint = drag.point;
  542. Vector2 dragUp;
  543. dragUp.x = dragPoint.x + drag.extent.x;
  544. dragUp.y = dragPoint.y + drag.extent.y;
  545. Vector2 sPt;
  546. Vector2 sUp;
  547. windowToScenePoint(dragPoint, sPt);
  548. windowToScenePoint(dragUp, sUp);
  549. // Build our area query
  550. WorldQuery* mWQ = mCurrentScene->getWorldQuery(true);
  551. WorldQueryFilter mQF(MASK_ALL, MASK_ALL, true, false, true, true);
  552. mWQ->setQueryFilter(mQF);
  553. mWQ->anyQueryArea(sPt,sUp);
  554. for (U32 i = 0; i < mWQ->getQueryResultsCount(); i++)
  555. {
  556. SceneObject *obj = mWQ->getQueryResults().at(i).mpSceneObject;;
  557. mSelectedObjs.push_back(obj);
  558. }
  559. updateSelectionBounds();
  560. }
  561. // we selected 1 item
  562. if(mSelectedObjs.size() == 1)
  563. Con::executef(this, 2, "onSelect", Con::getIntArg(mSelectedObjs[0]->getId()));
  564. // undo manager for move, size and rotate
  565. if(mMouseMode == SizingSelection || mMouseMode == MovingSelection || mMouseMode == RotateSelection)
  566. Con::executef(this, 2, "onPostEdit", Con::getIntArg(getSelectionSet().getId()));
  567. setFirstResponder();
  568. mMouseMode = Selecting;
  569. }
  570. //-----------------------------------------------------------------------
  571. void EditorToySceneWindow::onTouchDragged(const GuiEvent& gEvt)
  572. {
  573. if (!mCurrentScene)
  574. {
  575. //no scene do nothing!
  576. Parent::onTouchDragged(gEvt);
  577. return;
  578. }
  579. if (mActiveTool)
  580. {
  581. // if we have an active tool, give it the touch event.
  582. mActiveTool->onTouchDragged(gEvt);
  583. return;
  584. }
  585. // some vars
  586. Point2I curPoint = this->globalToLocalCoord(gEvt.mousePoint);
  587. Vector2 sceneMousePt;
  588. windowToScenePoint(curPoint, sceneMousePt);
  589. SceneObject *obj;
  590. if (mSelectedObjs.size() > 0)
  591. {
  592. obj = mSelectedObjs.first();
  593. // if our obj is locked, don't do anything!
  594. if (obj->isLocked())
  595. return;
  596. }
  597. if (mMouseMode == SizingSelection)
  598. {
  599. Vector2 objPos = obj->getRenderPosition();
  600. Vector2 objSize = obj->getSize();
  601. bool ar = true;
  602. bool fP = false;
  603. // if shift, no ar kept.
  604. if ((gEvt.modifier & SI_SHIFT))
  605. ar = false;
  606. // if ctrl, scale from center, no pos change, size axis.
  607. if ((gEvt.modifier & SI_LCTRL))
  608. {
  609. fP = true;
  610. ar = false;
  611. }
  612. // if alt, scale from center, no pos change.
  613. if ((gEvt.modifier & SI_LALT))
  614. {
  615. fP = true;
  616. ar = true;
  617. }
  618. scaleObject(objSize, objPos, sceneMousePt, ar, fP);
  619. }
  620. else if (mMouseMode == MovingSelection && mSelectedObjs.size())
  621. {
  622. moveObject(sceneMousePt + mOffset);
  623. }
  624. else if (mMouseMode == RotateSelection)
  625. {
  626. rotateObject(sceneMousePt - obj->getPosition(), mStartVector,mStartAngle);
  627. }
  628. else
  629. {
  630. mLastMousePt = curPoint;
  631. }
  632. }
  633. void EditorToySceneWindow::rotateObject(Vector2 mousePos, Vector2 origVec, F32 origAngle)
  634. {
  635. // init vars
  636. SceneObject* obj = mSelectedObjs.first();
  637. // some snapping
  638. F32 snapThresh = mDegToRad(10.0f);
  639. F32 snapDegrees = mDegToRad(90.0f);
  640. F32 oldAng = mAtan(origVec.x, origVec.y) + mDegToRad(origAngle);
  641. F32 ang = mAtan(mousePos.x, mousePos.y);
  642. F32 closeAng = mFloor((ang / snapDegrees) + 0.5f) * snapDegrees;
  643. if (mFabs(ang - closeAng) < snapThresh)
  644. {
  645. ang = closeAng;
  646. }
  647. if (ang > mDegToRad(359.0f))
  648. {
  649. ang = 0.0f;
  650. }
  651. obj->setAngle(ang);
  652. }
  653. void EditorToySceneWindow::moveObject(Vector2 newPos)
  654. {
  655. if (mGridSnap.x)
  656. {
  657. F32 closeX = mFloor((newPos.x / mGridSnap.x) + 0.5f) * mGridSnap.x;
  658. if (mFabs(newPos.x - closeX) < mSnapThreshold)
  659. newPos.x = closeX;
  660. }
  661. if (mGridSnap.y)
  662. {
  663. F32 closeY = mFloor((newPos.y / mGridSnap.y) + 0.5f) * mGridSnap.y;
  664. if (mFabs(newPos.y - closeY) < mSnapThreshold)
  665. newPos.y = closeY;
  666. }
  667. // moving multiple objects needs to be offset from center.
  668. if (mSelectedObjs.size() > 1)
  669. {
  670. Vector<SceneObject*>::iterator i;
  671. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  672. {
  673. (*i)->setPosition(((*i)->getPosition() - mSelCenter) + newPos);
  674. }
  675. }
  676. else
  677. {
  678. Vector<SceneObject*>::iterator i = mSelectedObjs.begin();
  679. (*i)->setPosition(newPos);
  680. }
  681. }
  682. void EditorToySceneWindow::scaleObject(Vector2 size, Vector2 pos, Vector2 mousePos, bool maintainAr, bool fixedPos)
  683. {
  684. // init vars
  685. SceneObject* obj = mSelectedObjs.first();
  686. Vector2 sizeDelt = Vector2(0.0, 0.0);
  687. Vector2 newPos = pos;
  688. Vector2 newSize = size;
  689. bool flipX = false;
  690. bool flipY = false;
  691. F32 ang = mRadToDeg(obj->getAngle());
  692. if (ang != 90.0f && ang != -180.0f && ang != 0.0f && ang != 180.0f && ang != -90.0f)
  693. {
  694. //maintainAr = true;
  695. fixedPos = true;
  696. }
  697. if (mGridSnap.x)
  698. {
  699. F32 closeX = mFloor((mousePos.x / mGridSnap.x) + 0.5f) * mGridSnap.x;
  700. if (mFabs(mousePos.x - closeX) < mSnapThreshold)
  701. mousePos.x = closeX;
  702. }
  703. if (mGridSnap.y)
  704. {
  705. F32 closeY = mFloor((mousePos.y / mGridSnap.y) + 0.5f) * mGridSnap.y;
  706. if (mFabs(mousePos.y - closeY) < mSnapThreshold)
  707. mousePos.y = closeY;
  708. }
  709. if (ang == 90.0f || ang == -90.0f)
  710. {
  711. if (mSizeMode == SizingLeft)
  712. {
  713. sizeDelt.x = mousePos.x - (pos.x - (size.y * 0.5f));
  714. newSize.y -= sizeDelt.x;
  715. newPos.x += sizeDelt.x * 0.5f;
  716. }
  717. else if (mSizeMode == SizingRight)
  718. {
  719. sizeDelt.x = mousePos.x - (pos.x + (size.y * 0.5f));
  720. newSize.y += sizeDelt.x;
  721. newPos.x += sizeDelt.x * 0.5f;
  722. }
  723. if (mSizeMode == SizingTop)
  724. {
  725. sizeDelt.y = mousePos.y - (pos.y + (size.x * 0.5f));
  726. newSize.x += sizeDelt.y;
  727. newPos.y += sizeDelt.y * 0.5f;
  728. }
  729. else if (mSizeMode == SizingBottom)
  730. {
  731. sizeDelt.y = mousePos.y - (pos.y - (size.x * 0.5f));
  732. newSize.x -= sizeDelt.y;
  733. newPos.y += sizeDelt.y * 0.5f;
  734. }
  735. // flip the sizing calcs.
  736. if (newSize.y < 0.0f)
  737. {
  738. if (mSizeMode == SizingLeft)
  739. {
  740. mSizeMode = SizingRight;
  741. }
  742. else if (mSizeMode == SizingRight)
  743. {
  744. mSizeMode = SizingLeft;
  745. }
  746. flipX = true;
  747. newSize.y = -newSize.y;
  748. }
  749. if (newSize.x < 0.0f)
  750. {
  751. if (mSizeMode == SizingTop)
  752. {
  753. mSizeMode = SizingBottom;
  754. }
  755. else if (mSizeMode == SizingBottom)
  756. {
  757. mSizeMode = SizingTop;
  758. }
  759. flipY = true;
  760. newSize.x = -newSize.x;
  761. }
  762. }
  763. else
  764. {
  765. if (mSizeMode == SizingLeft)
  766. {
  767. sizeDelt.x = mousePos.x - (pos.x - (size.x * 0.5f));
  768. newSize.x -= sizeDelt.x;
  769. newPos.x += sizeDelt.x * 0.5f;
  770. }
  771. else if (mSizeMode == SizingRight)
  772. {
  773. sizeDelt.x = mousePos.x - (pos.x + (size.x * 0.5f));
  774. newSize.x += sizeDelt.x;
  775. newPos.x += sizeDelt.x * 0.5f;
  776. }
  777. if (mSizeMode == SizingTop)
  778. {
  779. sizeDelt.y = mousePos.y - (pos.y + (size.y * 0.5f));
  780. newSize.y += sizeDelt.y;
  781. newPos.y += sizeDelt.y * 0.5f;
  782. }
  783. else if (mSizeMode == SizingBottom)
  784. {
  785. sizeDelt.y = mousePos.y - (pos.y - (size.y * 0.5f));
  786. newSize.y -= sizeDelt.y;
  787. newPos.y += sizeDelt.y * 0.5f;
  788. }
  789. // flip the sizing calcs.
  790. if (newSize.x < 0.0f)
  791. {
  792. if (mSizeMode == SizingLeft)
  793. {
  794. mSizeMode = SizingRight;
  795. }
  796. else if (mSizeMode == SizingRight)
  797. {
  798. mSizeMode = SizingLeft;
  799. }
  800. flipX = true;
  801. newSize.x = -newSize.x;
  802. }
  803. if (newSize.y < 0.0f)
  804. {
  805. if (mSizeMode == SizingTop)
  806. {
  807. mSizeMode = SizingBottom;
  808. }
  809. else if (mSizeMode == SizingBottom)
  810. {
  811. mSizeMode = SizingTop;
  812. }
  813. flipY = true;
  814. newSize.y = -newSize.y;
  815. }
  816. }
  817. //-----------------------
  818. if (maintainAr)
  819. {
  820. F32 oldAr = size.x / size.y;
  821. F32 newAr = newSize.x / newSize.y;
  822. Vector2 prevResize = newSize;
  823. if (newAr < oldAr)
  824. {
  825. if ((newSize.x < size.x))
  826. {
  827. newSize.y *= newAr / oldAr;
  828. }
  829. else
  830. {
  831. newSize.x *= oldAr / newAr;
  832. }
  833. }
  834. else
  835. {
  836. if ((newSize.y < size.y) )
  837. {
  838. newSize.x *= oldAr / newAr;
  839. }
  840. else
  841. {
  842. newSize.y *= newAr / oldAr;
  843. }
  844. }
  845. if (ang == 90.0f || ang == -90.0f)
  846. {
  847. if (mSizeMode == SizingLeft)
  848. {
  849. newPos.x -= (newSize.y - prevResize.y) * 0.5f;
  850. }
  851. else if (mSizeMode == SizingRight)
  852. {
  853. newPos.x += (newSize.y - prevResize.y) * 0.5f;
  854. }
  855. if (mSizeMode == SizingTop)
  856. {
  857. newPos.y -= (newSize.x - prevResize.x) * 0.5f;
  858. }
  859. else if (mSizeMode == SizingBottom)
  860. {
  861. newPos.y += (newSize.x - prevResize.x) * 0.5f;
  862. }
  863. }
  864. else
  865. {
  866. if (mSizeMode == SizingLeft)
  867. {
  868. newPos.x -= (newSize.x - prevResize.x) * 0.5f;
  869. }
  870. else if (mSizeMode == SizingRight)
  871. {
  872. newPos.x += (newSize.x - prevResize.x) * 0.5f;
  873. }
  874. if (mSizeMode == SizingTop)
  875. {
  876. newPos.y += (newSize.y - prevResize.y) * 0.5f;
  877. }
  878. else if (mSizeMode == SizingBottom)
  879. {
  880. newPos.y -= (newSize.y - prevResize.y) * 0.5f;
  881. }
  882. }
  883. }
  884. if (fixedPos)
  885. {
  886. obj->setPosition(pos);
  887. }
  888. else
  889. {
  890. obj->setPosition(newPos);
  891. }
  892. if (newSize != size)
  893. {
  894. obj->setSize(newSize);
  895. }
  896. }
  897. //-----------------------------------------------------------------------
  898. void EditorToySceneWindow::onTouchMove(const GuiEvent& gEvt)
  899. {
  900. }
  901. //-----------------------------------------------------------------------
  902. void EditorToySceneWindow::onRightMouseUp(const GuiEvent& gEvt)
  903. {
  904. if (!mCurrentScene)
  905. {
  906. //no scene do nothing!
  907. Parent::onRightMouseUp(gEvt);
  908. return;
  909. }
  910. if (mActiveTool)
  911. {
  912. // if we have an active tool, give it the touch event.
  913. mActiveTool->onRightMouseUp(gEvt);
  914. return;
  915. }
  916. }
  917. //-----------------------------------------------------------------------
  918. void EditorToySceneWindow::onRightMouseDown(const GuiEvent& gEvt)
  919. {
  920. if (!mCurrentScene)
  921. {
  922. //no scene do nothing!
  923. Parent::onRightMouseDown(gEvt);
  924. return;
  925. }
  926. if (mActiveTool)
  927. {
  928. // if we have an active tool, give it the touch event.
  929. mActiveTool->onRightMouseDown(gEvt);
  930. return;
  931. }
  932. // some vars
  933. Point2I curPoint = this->globalToLocalCoord(gEvt.mousePoint);
  934. windowToScenePoint(curPoint, mMouseCamDown);
  935. }
  936. //-----------------------------------------------------------------------
  937. void EditorToySceneWindow::onRightMouseDragged(const GuiEvent& gEvt)
  938. {
  939. if (!mCurrentScene)
  940. {
  941. //no scene do nothing!
  942. Parent::onRightMouseDragged(gEvt);
  943. return;
  944. }
  945. if (mActiveTool)
  946. {
  947. // if we have an active tool, give it the touch event.
  948. mActiveTool->onRightMouseDragged(gEvt);
  949. return;
  950. }
  951. // some vars
  952. Point2I curPoint = this->globalToLocalCoord(gEvt.mousePoint);
  953. Vector2 sceneMousePt;
  954. windowToScenePoint(curPoint, sceneMousePt);
  955. Vector2 move = mMouseCamDown - sceneMousePt;
  956. Vector2 newPos = getCameraPosition() + move;
  957. setCameraPosition(newPos);
  958. }
  959. void EditorToySceneWindow::onMouseWheelDown(const GuiEvent & gEvt)
  960. {
  961. // Call Parent.
  962. Parent::onMouseWheelDown(gEvt);
  963. F32 zoom = getCameraZoom();
  964. if (zoom < 0.1f)
  965. return;
  966. F32 amt = -10 * 0.005f * zoom;
  967. setCameraZoom(zoom + amt);
  968. return;
  969. }
  970. void EditorToySceneWindow::onMouseWheelUp(const GuiEvent & gEvt)
  971. {
  972. // Call Parent.
  973. Parent::onMouseWheelUp(gEvt);
  974. F32 zoom = getCameraZoom();
  975. F32 amt = 10 * 0.005f * zoom;
  976. setCameraZoom(zoom + amt);
  977. return;
  978. }
  979. //-----------------------------------------------------------------------
  980. void EditorToySceneWindow::updateSelectionBounds()
  981. {
  982. // we want everything to be smaller.
  983. Point2I point(S32_MAX, S32_MAX);
  984. // we want everything to be bigger.
  985. Point2I extentPos(S32_MIN, S32_MIN);
  986. Vector<SceneObject*>::iterator i;
  987. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  988. {
  989. RectI bounds = objWindowBounds((*i));
  990. //bottom right
  991. Point2I bottomRight((bounds.point.x + bounds.extent.x), (bounds.point.y + bounds.extent.y));
  992. if (bounds.point.x < point.x)
  993. point.x = bounds.point.x;
  994. if (bounds.point.y < point.y)
  995. point.y = bounds.point.y;
  996. if (bottomRight.x > extentPos.x)
  997. extentPos.x = bottomRight.x;
  998. if (bottomRight.y > extentPos.y)
  999. extentPos.y = bottomRight.y;
  1000. }
  1001. Point2I extent = extentPos - point;
  1002. mSelBox = RectI(point.x, point.y, extent.x, extent.y);
  1003. mSelCenter = getSelectionCenter();
  1004. }
  1005. Vector2 EditorToySceneWindow::getSelectionCenter()
  1006. {
  1007. Vector2 center(mSelBox.point.x + (mSelBox.extent.x * 0.5f), mSelBox.point.y + (mSelBox.extent.y * 0.5f));
  1008. Vector2 sceneCenter;
  1009. windowToScenePoint(center, sceneCenter);
  1010. return sceneCenter;
  1011. }
  1012. void EditorToySceneWindow::onRender(Point2I offset, const RectI &updateRect)
  1013. {
  1014. // let parent do its thing or you wont see anything
  1015. Parent::onRender(offset, updateRect);
  1016. if (mCurrentScene)
  1017. {
  1018. if (mAllCam)
  1019. {
  1020. // render camera.
  1021. RectI c;
  1022. c = updateSceneCamera();
  1023. Point2I inset(c.extent.x * 0.1, c.extent.y * 0.1);
  1024. if (mDrawAspectSafety)
  1025. {
  1026. // Aspect ratio percent
  1027. c.inset(-inset.x, -inset.y);
  1028. dglDrawRect(c, ColorI(255, 0, 0, 100));
  1029. // ordinary cam
  1030. c.inset(inset.x, inset.y);
  1031. }
  1032. if (mDrawCam)
  1033. {
  1034. dglDrawRect(c, ColorI(255, 255, 255, 255));
  1035. }
  1036. if (mDrawSaftey)
  1037. {
  1038. // 90% inside safety
  1039. c.inset(inset.x, inset.y);
  1040. dglDrawRect(c, ColorI(0, 255, 0, 100));
  1041. }
  1042. }
  1043. bool multi = mSelectedObjs.size() > 1;
  1044. if (multi)
  1045. {
  1046. //RectI b = windowSelectionBounds();
  1047. updateSelectionBounds();
  1048. mSelBox.point += offset;
  1049. dglDrawRect(mSelBox, ColorI(255, 255, 255, 255));
  1050. }
  1051. Vector<SceneObject*>::iterator i;
  1052. for (i = mSelectedObjs.begin(); i != mSelectedObjs.end(); i++)
  1053. {
  1054. SceneObject* obj = (*i);
  1055. ColorI nutColor = multi ? ColorI(255, 255, 255) : ColorI(100, 100, 200);
  1056. ColorI outlineColor = ColorI(255, 255, 255);
  1057. // only draw rotate when we are not in multi
  1058. // draw rotate first so its under other nuts.
  1059. if (!multi)
  1060. {
  1061. drawRotateNuts(obj, outlineColor, nutColor);
  1062. }
  1063. drawSizingNuts(obj, outlineColor, nutColor);
  1064. }
  1065. if (mMouseMode == DragSelection)
  1066. {
  1067. RectI b;
  1068. getDragRect(b);
  1069. mSelBox.point += offset;
  1070. dglDrawRect(b, ColorI(255, 255, 255, 255));
  1071. }
  1072. }
  1073. if (mCurrentScene && (mGridSnap.x && mGridSnap.y) &&
  1074. (mMouseMode == MovingSelection || mMouseMode == SizingSelection))
  1075. {
  1076. RectF area = getCameraRenderArea();
  1077. U32 maxdot = (U32)(area.extent.x / mGridSnap.x) * (U32)(area.extent.y / mGridSnap.y);
  1078. Vector2 curDot;
  1079. Point2F areaEnd(area.point.x + area.extent.x, area.point.y + area.extent.y);
  1080. area.point.x = mGridSnap.x * ((S32)(area.point.x / mGridSnap.x));
  1081. area.point.y = mGridSnap.y * ((S32)(area.point.y / mGridSnap.y));
  1082. //vector<F32> verts;
  1083. for (F32 ix = area.point.x; ix < areaEnd.x; ix += mGridSnap.x)
  1084. {
  1085. for (F32 iy = area.point.y; iy < areaEnd.y; iy += mGridSnap.y)
  1086. {
  1087. curDot.Set(ix, iy);
  1088. sceneToWindowPoint(curDot, curDot);
  1089. curDot = (Vector2)localToGlobalCoord(Point2I(S32(curDot.x), S32(curDot.y)));
  1090. //verts.push_back(curDot.x);
  1091. //verts.push_back(curDot.y);
  1092. // the commented out method for doing this is a lot faster
  1093. // but it crashes if there are too many, slow is better than
  1094. // crashing, especially just in an editor.
  1095. dglDrawDot((Point2F)curDot, ColorI(255, 255, 255, 128));
  1096. }
  1097. }
  1098. //U32 num = verts.size();
  1099. //glEnableClientState(GL_VERTEX_ARRAY);
  1100. //glVertexPointer(2, GL_FLOAT, 0, verts.data());
  1101. //glDrawArrays(GL_POINTS, 0, num);
  1102. //glDisableClientState(GL_VERTEX_ARRAY);
  1103. }
  1104. }
  1105. void EditorToySceneWindow::resize(const Point2I &newPosition, const Point2I &newExtent)
  1106. {
  1107. Point2F extent = getCameraArea().extent;
  1108. F32 aR = (F32)newExtent.x / (F32)newExtent.y;
  1109. F32 localAr = extent.x / extent.y;
  1110. extent.x = extent.y * aR;
  1111. Parent::resize(newPosition, newExtent);
  1112. Parent::setCameraPosition(getCameraPosition());
  1113. Parent::setCameraSize(Vector2(extent.x, extent.y));
  1114. }
  1115. //-----------------------------------------------------------------------
  1116. void EditorToySceneWindow::setTool(EditorToyTool * tool)
  1117. {
  1118. if (mActiveTool)
  1119. mActiveTool->onDeactivate();
  1120. mActiveTool = tool;
  1121. if (mActiveTool)
  1122. mActiveTool->onActivate(this);
  1123. }
  1124. //-----------------------------------------------------------------------
  1125. // Required so editor can re-handle ontouch
  1126. void EditorToySceneWindow::deactivateTool()
  1127. {
  1128. mActiveTool->onDeactivate();
  1129. mActiveTool = nullptr;
  1130. }
  1131. //-----------------------------------------------------------------------