guiFrameSetCtrl.cc 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 "console/consoleTypes.h"
  23. #include "console/console.h"
  24. #include "gui/containers/guiFrameSetCtrl.h"
  25. #include "gui/guiDefaultControlRender.h"
  26. #include "gui/guiCanvas.h"
  27. #include "gui/containers/guiWindowCtrl.h"
  28. #include "graphics/dgl.h"
  29. #include "gui/containers/guiTabBookCtrl.h"
  30. #include "gui/containers/guiTabPageCtrl.h"
  31. #include "gui/editor/guiEditCtrl.h"
  32. #include "collection/vector.h"
  33. #include "guiFrameSetCtrl_ScriptBinding.h"
  34. void GuiFrameSetCtrl::Frame::deleteChildren()
  35. {
  36. if (child1)
  37. {
  38. child1->deleteChildren();
  39. delete child1;
  40. }
  41. if (child2)
  42. {
  43. child2->deleteChildren();
  44. delete child2;
  45. }
  46. }
  47. void GuiFrameSetCtrl::Frame::resize(const Point2I& newPosition, const Point2I& newExtent)
  48. {
  49. const S32 minSize = owner->minSize;
  50. extent.set(newExtent.x, newExtent.y);
  51. localPosition.set(newPosition.x, newPosition.y);
  52. sizeInsertButtons(newPosition, newExtent);
  53. if (control)
  54. {
  55. control->resize(newPosition, newExtent);
  56. }
  57. if (!child1 && !child2 && owner->isEditMode())
  58. {
  59. if (extent.x > (3 * owner->minSize))
  60. {
  61. spliterRect1.set(localPosition.x + ((extent.x - owner->mDividerThickness) / 2), localPosition.y, owner->mDividerThickness, extent.y);
  62. }
  63. else
  64. {
  65. spliterRect1.set(0, 0, 0, 0);
  66. }
  67. if (extent.y > (3 * owner->minSize))
  68. {
  69. spliterRect2.set(localPosition.x, localPosition.y + ((extent.y - owner->mDividerThickness) / 2), extent.x, owner->mDividerThickness);
  70. }
  71. else
  72. {
  73. spliterRect2.set(0, 0, 0, 0);
  74. }
  75. }
  76. else if (child1 && child2)
  77. {
  78. S32 spaceX = isVertical ? newExtent.x : newExtent.x - owner->mDividerThickness;
  79. S32 spaceY = !isVertical ? newExtent.y : newExtent.y - owner->mDividerThickness;
  80. S32 x1 = newExtent.x;
  81. S32 x2 = newExtent.x;
  82. if(!isVertical)
  83. {
  84. if (child1->isAnchored)
  85. {
  86. x1 = getMin(child1->extent.x, spaceX - minSize);
  87. x2 = spaceX - x1;
  88. }
  89. else
  90. {
  91. x2 = getMin(child2->extent.x, spaceX - minSize);
  92. x1 = spaceX - x2;
  93. }
  94. }
  95. S32 y1 = newExtent.y;
  96. S32 y2 = newExtent.y;
  97. if (isVertical)
  98. {
  99. if (child1->isAnchored)
  100. {
  101. y1 = getMin(child1->extent.y, spaceY - minSize);
  102. y2 = spaceY - y1;
  103. }
  104. else
  105. {
  106. y2 = getMin(child2->extent.y, spaceY - minSize);
  107. y1 = spaceY - y2;
  108. }
  109. }
  110. Point2I ext1 = Point2I(x1, y1);
  111. Point2I ext2 = Point2I(x2, y2);
  112. Point2I pos2 = isVertical ? Point2I(newPosition.x, newPosition.y + y1 + owner->mDividerThickness) : Point2I(newPosition.x + x1 + owner->mDividerThickness, newPosition.y);
  113. if(isVertical)
  114. {
  115. dividerRect.set(newPosition.x, newPosition.y + y1, x1, owner->mDividerThickness);
  116. }
  117. else
  118. {
  119. dividerRect.set(newPosition.x + x1, newPosition.y, owner->mDividerThickness, y1);
  120. }
  121. child1->resize(newPosition, ext1);
  122. child2->resize(pos2, ext2);
  123. }
  124. }
  125. void GuiFrameSetCtrl::Frame::sizeInsertButtons(const Point2I& newPosition, const Point2I& newExtent)
  126. {
  127. const U32 size = 40;
  128. const U32 gutter = 10;
  129. hasLeftRightButtons = false;
  130. hasTopBottomButtons = false;
  131. if (newExtent.x > (4 * (size + gutter)))
  132. {
  133. hasLeftRightButtons = true;
  134. mLeftButtonRect = RectI(newPosition.x + gutter, newPosition.y + ((newExtent.y - size) / 2), size, size);
  135. mRightButtonRect = RectI(newPosition.x + newExtent.x - (gutter + size), newPosition.y + ((newExtent.y - size) / 2), size, size);
  136. }
  137. if (newExtent.y > (4 * (size + gutter)))
  138. {
  139. hasTopBottomButtons = true;
  140. mTopButtonRect = RectI(newPosition.x + ((newExtent.x - size) / 2), newPosition.y + gutter, size, size);
  141. mBottomButtonRect = RectI(newPosition.x + ((newExtent.x - size) / 2), newPosition.y + newExtent.y - (gutter + size), size, size);
  142. }
  143. mCenterButtonRect = RectI(newPosition.x + ((newExtent.x - size) / 2), newPosition.y + ((newExtent.y - size) / 2), size, size);
  144. }
  145. GuiFrameSetCtrl::Frame* GuiFrameSetCtrl::Frame::findFrame(const S32 frameID)
  146. {
  147. if (id == frameID)
  148. {
  149. return this;
  150. }
  151. if (child1 && child2)
  152. {
  153. Frame* attempt = child1->findFrame(frameID);
  154. return attempt ? attempt : child2->findFrame(frameID);
  155. }
  156. return nullptr;
  157. }
  158. GuiFrameSetCtrl::Frame* GuiFrameSetCtrl::Frame::findEmptyFrame()
  159. {
  160. if (!control && !child1 && !child2)
  161. {
  162. return this;
  163. }
  164. else if (child1 && child2)
  165. {
  166. Frame* attempt = child1->findEmptyFrame();
  167. return attempt ? attempt : child2->findEmptyFrame();
  168. }
  169. return nullptr;
  170. }
  171. GuiFrameSetCtrl::Frame* GuiFrameSetCtrl::Frame::findEmptyFrameAtLocation(const RectI& location)
  172. {
  173. if (!control && !child1 && !child2 && localPosition == location.point && extent == location.extent)
  174. {
  175. return this;
  176. }
  177. else if (child1 && child2)
  178. {
  179. Frame* attempt = child1->findEmptyFrameAtLocation(location);
  180. return attempt ? attempt : child2->findEmptyFrameAtLocation(location);
  181. }
  182. return nullptr;
  183. }
  184. GuiFrameSetCtrl::Frame* GuiFrameSetCtrl::Frame::twin()
  185. {
  186. if (parent)
  187. {
  188. if (parent->child1 == this)
  189. {
  190. return parent->child2;
  191. }
  192. else
  193. {
  194. return parent->child1;
  195. }
  196. }
  197. return this;
  198. }
  199. GuiFrameSetCtrl::Frame* GuiFrameSetCtrl::Frame::findHitDivider(const Point2I& position)
  200. {
  201. S32 x = position.x;
  202. S32 y = position.y;
  203. if (child1 && child2)
  204. {
  205. if (x >= dividerRect.point.x && x <= (dividerRect.point.x + dividerRect.extent.x) &&
  206. y >= dividerRect.point.y && y <= (dividerRect.point.y + dividerRect.extent.y))
  207. {
  208. return this;
  209. }
  210. Frame* attempt = child1->findHitDivider(position);
  211. return attempt ? attempt : child2->findHitDivider(position);
  212. }
  213. return nullptr;
  214. }
  215. GuiFrameSetCtrl::Frame* GuiFrameSetCtrl::Frame::findFrameWithCtrl(GuiControl* ctrl)
  216. {
  217. if (ctrl == control)
  218. {
  219. return this;
  220. }
  221. else if(child1 && child2)
  222. {
  223. Frame* attempt = child1->findFrameWithCtrl(ctrl);
  224. return attempt ? attempt : child2->findFrameWithCtrl(ctrl);
  225. }
  226. return nullptr;
  227. }
  228. GuiFrameSetCtrl::Frame* GuiFrameSetCtrl::Frame::findFrameWithPoint(const Point2I& point)
  229. {
  230. //Point is local to the frame.
  231. if (!child1 && !child2)
  232. {
  233. return this;
  234. }
  235. if (child1 && child2)
  236. {
  237. S32 x = point.x;
  238. S32 y = point.y;
  239. Point2I pos2 = isVertical ? Point2I(x, child1->extent.y + owner->mDividerThickness) : Point2I(child1->extent.x + owner->mDividerThickness, y);
  240. if ((isVertical && y < child1->extent.y) || (!isVertical && x < child1->extent.x))
  241. {
  242. return child1->findFrameWithPoint(point);
  243. }
  244. else if ((isVertical && y > pos2.y && y < (pos2.y + child2->extent.y)) || (!isVertical && x > pos2.x && x < (pos2.x + child2->extent.x)))
  245. {
  246. Point2I pt = isVertical ? Point2I(x, y - pos2.y) : Point2I(x - pos2.x, y);
  247. return child2->findFrameWithPoint(pt);
  248. }
  249. }
  250. return nullptr;//This will happen if the mouse is over a divider.
  251. }
  252. void GuiFrameSetCtrl::Frame::editRender(const Point2I& cursorPt, const F32 fade)
  253. {
  254. //cursorPt is local to owner
  255. if (!child1 && !child2)
  256. {
  257. //Show the frame
  258. RectI localRect = RectI(localPosition, extent);
  259. Point2I pos = localPosition;
  260. RectI rect = RectI(owner->localToGlobalCoord(pos), extent);
  261. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  262. ColorI border = edit->getEditorColor();
  263. if (!localRect.pointInRect(cursorPt))
  264. {
  265. border.alpha = (150 * fade);
  266. }
  267. dglDrawRect(rect, border);
  268. ColorI fill = ColorI(border);
  269. fill.alpha = (40 * fade);
  270. dglDrawRectFill(rect, fill);
  271. U8 divThickness = owner->mDividerThickness;
  272. fill.alpha = (10 * fade);
  273. if(spliterRect1.pointInRect(cursorPt))
  274. {
  275. fill.alpha = (200 * fade);
  276. }
  277. RectI globalSpliter1 = RectI(owner->localToGlobalCoord(spliterRect1.point), spliterRect1.extent);
  278. dglDrawRectFill(globalSpliter1, fill);
  279. fill.alpha = (10 * fade);
  280. if (spliterRect2.pointInRect(cursorPt) && !spliterRect1.pointInRect(cursorPt))
  281. {
  282. fill.alpha = (200 * fade);
  283. }
  284. RectI globalSpliter2 = RectI(owner->localToGlobalCoord(spliterRect2.point), spliterRect2.extent);
  285. dglDrawRectFill(globalSpliter2, fill);
  286. }
  287. if (child1)
  288. {
  289. child1->editRender(cursorPt, fade);
  290. }
  291. if (child2)
  292. {
  293. child2->editRender(cursorPt, fade);
  294. }
  295. }
  296. //------------------------------------------------------------------------------
  297. IMPLEMENT_CONOBJECT(GuiFrameSetCtrl);
  298. //------------------------------------------------------------------------------
  299. GuiFrameSetCtrl::GuiFrameSetCtrl()
  300. {
  301. mIsContainer = true;
  302. setField("profile", "GuiDefaultProfile");
  303. mRootFrame = Frame(this, nullptr);
  304. mHitDivider = nullptr;
  305. mDividerThickness = 8;
  306. mNextFrameID = 1;
  307. mResizeGuard = false;
  308. mDepressed = false;
  309. mActive = true;
  310. mFrameDragAnchor = 0;
  311. mEaseFillColorHL = EasingFunction::EaseInOut;
  312. mEaseFillColorSL = EasingFunction::EaseOut;
  313. mEaseTimeFillColorHL = 500;
  314. mEaseTimeFillColorSL = 1000;
  315. mDropButtonProfile = NULL;
  316. setField("dropButtonProfile", "GuiButtonProfile");
  317. mTabBookProfile = NULL;
  318. mTabProfile = NULL;
  319. mTabPageProfile = NULL;
  320. setField("tabBookProfile", "GuiDefaultProfile");
  321. setField("tabProfile", "GuiTabProfile");
  322. setField("tabPageProfile", "GuiDefaultProfile");
  323. mLeftRightCursor = NULL;
  324. mUpDownCursor = NULL;
  325. }
  326. GuiFrameSetCtrl::~GuiFrameSetCtrl()
  327. {
  328. mRootFrame.deleteChildren();
  329. }
  330. //------------------------------------------------------------------------------
  331. void GuiFrameSetCtrl::initPersistFields()
  332. {
  333. Parent::initPersistFields();
  334. addField("DividerThickness", TypeS8, Offset(mDividerThickness, GuiFrameSetCtrl));
  335. addField("dropButtonProfile", TypeGuiProfile, Offset(mDropButtonProfile, GuiFrameSetCtrl));
  336. addField("leftRightCursor", TypeGuiCursor, Offset(mLeftRightCursor, GuiFrameSetCtrl));
  337. addField("upDownCursor", TypeGuiCursor, Offset(mUpDownCursor, GuiFrameSetCtrl));
  338. addProtectedField("TabBookProfile", TypeGuiProfile, Offset(mTabBookProfile, GuiFrameSetCtrl), &setBookProfileFn, &defaultProtectedGetFn, &defaultProtectedWriteFn, "");
  339. addProtectedField("TabProfile", TypeGuiProfile, Offset(mTabProfile, GuiFrameSetCtrl), &setTabProfileFn, &defaultProtectedGetFn, &defaultProtectedWriteFn, "");
  340. addProtectedField("TabPageProfile", TypeGuiProfile, Offset(mTabPageProfile, GuiFrameSetCtrl), &setPageProfileFn, &defaultProtectedGetFn, &defaultProtectedWriteFn, "");
  341. }
  342. //------------------------------------------------------------------------------
  343. bool GuiFrameSetCtrl::onWake()
  344. {
  345. if (!Parent::onWake())
  346. return false;
  347. if (mDropButtonProfile != NULL)
  348. mDropButtonProfile->incRefCount();
  349. if (mTabBookProfile != NULL)
  350. mTabBookProfile->incRefCount();
  351. if (mTabProfile != NULL)
  352. mTabProfile->incRefCount();
  353. if (mTabPageProfile != NULL)
  354. mTabPageProfile->incRefCount();
  355. return true;
  356. }
  357. //------------------------------------------------------------------------------
  358. void GuiFrameSetCtrl::onSleep()
  359. {
  360. Parent::onSleep();
  361. if (mDropButtonProfile != NULL)
  362. mDropButtonProfile->decRefCount();
  363. if (mTabBookProfile != NULL)
  364. mTabBookProfile->decRefCount();
  365. if (mTabProfile != NULL)
  366. mTabProfile->decRefCount();
  367. if (mTabPageProfile != NULL)
  368. mTabPageProfile->decRefCount();
  369. }
  370. //------------------------------------------------------------------------------
  371. void GuiFrameSetCtrl::inspectPostApply()
  372. {
  373. resize(getPosition(), getExtent());
  374. Parent::inspectPostApply();
  375. }
  376. //------------------------------------------------------------------------------
  377. void GuiFrameSetCtrl::resize(const Point2I& newPosition, const Point2I& newExtent)
  378. {
  379. if(!mResizeGuard)//Prevent circular resizing
  380. {
  381. mResizeGuard = true;
  382. Point2I actualNewExtent = Point2I(getMax(mMinExtent.x, newExtent.x),
  383. getMax(mMinExtent.y, newExtent.y));
  384. //call set update both before and after
  385. setUpdate();
  386. Point2I origin = Point2I::Zero;
  387. mRootFrame.resize(origin, actualNewExtent);
  388. mBounds.set(newPosition, actualNewExtent);
  389. GuiControl* parent = getParent();
  390. if (parent)
  391. parent->childResized(this);
  392. setUpdate();
  393. mResizeGuard = false;
  394. }
  395. }
  396. bool GuiFrameSetCtrl::onAdd()
  397. {
  398. // Let Parent Do Work.
  399. if (!Parent::onAdd())
  400. return false;
  401. // Always expand to fill the parent (we just ignore the points passed in).
  402. parentResized(Point2I(), Point2I());
  403. Frame* frame = &mRootFrame;
  404. loadFrame(frame, 1);
  405. clearDynamicFields();
  406. //resize one last time for the frames
  407. resize(getPosition(), getExtent());
  408. // Return Success.
  409. return true;
  410. }
  411. void GuiFrameSetCtrl::parentResized(const Point2I& oldParentExtent, const Point2I& newParentExtent)
  412. {
  413. //In the case of centering, we want to make doubly sure we are using the inner rect.
  414. GuiControl* parent = getParent();
  415. if(parent)
  416. {
  417. Point2I origin = Point2I::Zero;
  418. Point2I parentInnerExt = parent->getInnerRect().extent;
  419. resize(origin, parentInnerExt);
  420. }
  421. }
  422. void GuiFrameSetCtrl::loadFrame(GuiFrameSetCtrl::Frame* frame, const U32 frameID)
  423. {
  424. frame->id = frameID;
  425. U32 child1ID = dAtoi(getDataField("child1ID", frameID));
  426. U32 child2ID = dAtoi(getDataField("child2ID", frameID));
  427. frame->isVertical = dAtob(getDataField("isVertical", frameID));
  428. U32 frameExtentX = dAtoi(getDataField("frameExtentX", frameID));
  429. U32 frameExtentY = dAtoi(getDataField("frameExtentY", frameID));
  430. frame->isAnchored = dAtob(getDataField("isAnchored", frameID));
  431. frame->extent.set(frameExtentX, frameExtentY);
  432. if (child1ID && child2ID)
  433. {
  434. splitFrame(frame, frame->isVertical ? GuiDirection::Up : GuiDirection::Left);
  435. loadFrame(frame->child1, child1ID);
  436. loadFrame(frame->child2, child2ID);
  437. }
  438. }
  439. void GuiFrameSetCtrl::onChildAdded(GuiControl* child)
  440. {
  441. //Ensure the child isn't positioned to the center
  442. if (child->getHorizSizing() == horizResizeCenter)
  443. {
  444. child->setHorizSizing(horizResizeLeft);
  445. }
  446. if (child->getVertSizing() == vertResizeCenter)
  447. {
  448. child->setVertSizing(vertResizeTop);
  449. }
  450. Parent::onChildAdded(child);
  451. assignChildToFrame(child);
  452. }
  453. void GuiFrameSetCtrl::assignChildToFrame(GuiControl* child)
  454. {
  455. Frame* frame = mRootFrame.findFrameWithCtrl(child);
  456. if(!frame)
  457. {
  458. Frame* emptyFrame = mRootFrame.findEmptyFrameAtLocation(child->getBounds());
  459. if(emptyFrame)
  460. {
  461. emptyFrame->control = child;
  462. }
  463. else
  464. {
  465. Frame* emptyFrame = mRootFrame.findEmptyFrame();
  466. if (emptyFrame)
  467. {
  468. emptyFrame->control = child;
  469. }
  470. }
  471. }
  472. }
  473. void GuiFrameSetCtrl::onChildRemoved(GuiControl* child)
  474. {
  475. Frame* frame = mRootFrame.findFrameWithCtrl(child);
  476. if (frame && frame == &mRootFrame)
  477. {
  478. mRootFrame.control = nullptr;
  479. }
  480. else if(frame)
  481. {
  482. //Remove the frame from the heirarchy
  483. Frame* frameParent = frame->parent;
  484. Frame* frameTwin = frame->twin();
  485. frameParent->control = frameTwin->control;
  486. frameParent->child1 = frameTwin->child1;
  487. frameParent->child2 = frameTwin->child2;
  488. if (frameParent->child1)
  489. {
  490. frameParent->child1->parent = frameParent;
  491. }
  492. if (frameParent->child2)
  493. {
  494. frameParent->child2->parent = frameParent;
  495. }
  496. frameParent->isVertical = frameTwin->isVertical;
  497. delete frame;
  498. delete frameTwin;
  499. }
  500. resize(getPosition(), getExtent());
  501. }
  502. void GuiFrameSetCtrl::childResized(GuiControl* child)
  503. {
  504. Parent::childResized(child);
  505. resize(getPosition(), getExtent());
  506. }
  507. void GuiFrameSetCtrl::childMoved(GuiControl* child)
  508. {
  509. Parent::childMoved(child);
  510. resize(getPosition(), getExtent());
  511. }
  512. void GuiFrameSetCtrl::childrenReordered()
  513. {
  514. resize(getPosition(), getExtent());
  515. Parent::childrenReordered();
  516. }
  517. Point2I GuiFrameSetCtrl::splitFrame(S32 frameID, bool isVertical)
  518. {
  519. Frame* frame = mRootFrame.findFrame(frameID);
  520. if(frame)
  521. {
  522. splitFrame(frame, isVertical ? GuiDirection::Up : GuiDirection::Left);
  523. return Point2I(frame->child1 ? static_cast<S32>(frame->child1->id) : 0, frame->child2 ? static_cast<S32>(frame->child2->id) : 0);
  524. }
  525. return Point2I::Zero;
  526. }
  527. void GuiFrameSetCtrl::splitFrame(GuiFrameSetCtrl::Frame* frame, GuiDirection direction)
  528. {
  529. //The existing control, if any, is moved to the new frame in the direction and anchored. The frame oposite is left empty.
  530. if (!frame->child1 && !frame->child2)
  531. {
  532. GuiControl* ctrl = frame->control;
  533. frame->child1 = new GuiFrameSetCtrl::Frame(this, frame);
  534. frame->child2 = new GuiFrameSetCtrl::Frame(this, frame);
  535. frame->control = nullptr;
  536. frame->child1->control = direction == GuiDirection::Left || direction == GuiDirection::Up ? ctrl : nullptr;
  537. frame->child2->control = direction == GuiDirection::Right || direction == GuiDirection::Down ? ctrl : nullptr;
  538. frame->child1->id = ++mNextFrameID;
  539. frame->child2->id = ++mNextFrameID;
  540. frame->child1->isAnchored = direction == GuiDirection::Left || direction == GuiDirection::Up;
  541. frame->child2->isAnchored = direction == GuiDirection::Right || direction == GuiDirection::Down;
  542. }
  543. frame->isVertical = direction == GuiDirection::Up || direction == GuiDirection::Down;
  544. }
  545. void GuiFrameSetCtrl::anchorFrame(S32 frameID)
  546. {
  547. Frame* frame = mRootFrame.findFrame(frameID);
  548. anchorFrame(frame);
  549. }
  550. void GuiFrameSetCtrl::anchorFrame(GuiFrameSetCtrl::Frame* frame)
  551. {
  552. if (frame && frame != &mRootFrame)//The root frame has no twin and can't be anchored.
  553. {
  554. frame->isAnchored = true;
  555. frame->twin()->isAnchored = false;
  556. }
  557. }
  558. void GuiFrameSetCtrl::setFrameSize(S32 frameID, S32 size)
  559. {
  560. Frame* frame = mRootFrame.findFrame(frameID);
  561. if (frame && frame != &mRootFrame)//The root frame must be the size of the control.
  562. {
  563. if (frame->parent->isVertical)
  564. {
  565. frame->extent.y = size;
  566. frame->twin()->extent.y = getMax(frame->parent->extent.y - (size + mDividerThickness), minSize);
  567. }
  568. else
  569. {
  570. frame->extent.x = size;
  571. frame->twin()->extent.x = getMax(frame->parent->extent.x - (size + mDividerThickness), minSize);
  572. }
  573. //Pass this down to the other frames and then to the child controls
  574. resize(getPosition(), getExtent());
  575. }
  576. }
  577. void GuiFrameSetCtrl::onPreRender()
  578. {
  579. SimSet::iterator i;
  580. for(i = begin(); i < end(); i++)
  581. {
  582. GuiTabBookCtrl* book = dynamic_cast<GuiTabBookCtrl*>(*i);
  583. if (book && book->mIsFrameSetGenerated && book->size() == 0)
  584. {
  585. book->deleteObject();
  586. }
  587. }
  588. if (isEditMode())
  589. {
  590. GuiCanvas* root = getRoot();
  591. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  592. if (root && edit)
  593. {
  594. Point2I cursorPt = globalToLocalCoord(root->getCursorPos());
  595. if (mBounds.pointInRect(cursorPt))
  596. {
  597. mHitDivider = mRootFrame.findHitDivider(cursorPt);
  598. }
  599. }
  600. }
  601. }
  602. void GuiFrameSetCtrl::onRender(Point2I offset, const RectI& updateRect)
  603. {
  604. Parent::onRender(offset, updateRect);
  605. if (mHitDivider)
  606. {
  607. GuiControlState currentState = mDepressed ? SelectedState : HighlightState;
  608. mOldHitDivider = mHitDivider;
  609. RectI contentRect = RectI(localToGlobalCoord(mHitDivider->dividerRect.point), mHitDivider->dividerRect.extent);
  610. renderUniversalRect(contentRect, mProfile, currentState, getFillColor(currentState), true);
  611. }
  612. else if (mOldHitDivider && (mCurrentState == HighlightState || mFluidFillColor.isAnimating()))
  613. {
  614. RectI contentRect = RectI(localToGlobalCoord(mOldHitDivider->dividerRect.point), mOldHitDivider->dividerRect.extent);
  615. renderUniversalRect(contentRect, mProfile, NormalState, getFillColor(NormalState), true);
  616. }
  617. else if (mOldHitDivider)
  618. {
  619. mOldHitDivider = nullptr;
  620. }
  621. if (isEditMode())
  622. {
  623. GuiCanvas* root = getRoot();
  624. GuiEditCtrl* edit = GuiControl::smEditorHandle;
  625. if(root && edit)
  626. {
  627. Point2I cursorPt = globalToLocalCoord(root->getCursorPos());
  628. RectI visBounds = RectI(mBounds);
  629. const S32 fadeDist = 140;
  630. visBounds.inset(-fadeDist, -fadeDist);
  631. if (visBounds.pointInRect(cursorPt) && isEditSelected())
  632. {
  633. visBounds.inset(fadeDist, fadeDist);
  634. F32 fade = getMin(1.0, getMax(0.0, 1.0 - ((F32)visBounds.distanceToRect(cursorPt) / (F32)fadeDist)));
  635. mRootFrame.editRender(cursorPt, fade);
  636. }
  637. }
  638. }
  639. }
  640. void GuiFrameSetCtrl::onTouchMove(const GuiEvent& event)
  641. {
  642. if (!mVisible || !mAwake)
  643. return;
  644. if(!mDepressed)
  645. {
  646. Point2I localPoint = globalToLocalCoord(event.mousePoint);
  647. mHitDivider = mRootFrame.findHitDivider(localPoint);
  648. }
  649. if (!mHitDivider)
  650. {
  651. Parent::onTouchMove(event);
  652. }
  653. }
  654. void GuiFrameSetCtrl::onTouchDragged(const GuiEvent& event)
  655. {
  656. if (mDepressed && mHitDivider && mHitDivider->child1 && mHitDivider->child2)
  657. {
  658. S32 offset = (mHitDivider->isVertical ? event.mousePoint.y : event.mousePoint.x) - mFrameDragAnchor;
  659. if(offset != 0)
  660. {
  661. if (mHitDivider->isVertical)
  662. {
  663. mHitDivider->child1->extent.y = getMax(minSize, mHitDivider->child1->extent.y + offset);
  664. mHitDivider->child2->extent.y = getMax(minSize, mHitDivider->child2->extent.y - offset);
  665. }
  666. else
  667. {
  668. mHitDivider->child1->extent.x = getMax(minSize, mHitDivider->child1->extent.x + offset);
  669. mHitDivider->child2->extent.x = getMax(minSize, mHitDivider->child2->extent.x - offset);
  670. }
  671. resize(getPosition(), getExtent());
  672. mFrameDragAnchor = mHitDivider->isVertical ? event.mousePoint.y : event.mousePoint.x;
  673. }
  674. }
  675. }
  676. void GuiFrameSetCtrl::onTouchDown(const GuiEvent& event)
  677. {
  678. if (!mActive)
  679. return;
  680. if(mHitDivider)
  681. {
  682. mDepressed = true;
  683. mFrameDragAnchor = mHitDivider->isVertical ? event.mousePoint.y : event.mousePoint.x;
  684. //lock the mouse
  685. mouseLock();
  686. //update
  687. setUpdate();
  688. }
  689. }
  690. void GuiFrameSetCtrl::onTouchUp(const GuiEvent& event)
  691. {
  692. if (!mActive)
  693. return;
  694. if(mHitDivider)
  695. {
  696. mouseUnlock();
  697. mDepressed = false;
  698. //update
  699. setUpdate();
  700. }
  701. }
  702. void GuiFrameSetCtrl::getCursor(GuiCursor*& cursor, bool& showCursor, const GuiEvent& lastGuiEvent)
  703. {
  704. GuiControl* parent = getParent();
  705. if (!parent)
  706. {
  707. return;
  708. }
  709. if (mHitDivider && mHitDivider->isVertical)
  710. {
  711. if (mUpDownCursor == NULL)
  712. {
  713. SimObject* obj;
  714. obj = Sim::findObject("UpDownCursor");
  715. mUpDownCursor = dynamic_cast<GuiCursor*>(obj);
  716. }
  717. if (mUpDownCursor != NULL)
  718. {
  719. cursor = mUpDownCursor;
  720. }
  721. }
  722. else if (mHitDivider && !mHitDivider->isVertical)
  723. {
  724. if (mLeftRightCursor == NULL)
  725. {
  726. SimObject* obj;
  727. obj = Sim::findObject("LeftRightCursor");
  728. mLeftRightCursor = dynamic_cast<GuiCursor*>(obj);
  729. }
  730. if (mLeftRightCursor != NULL)
  731. {
  732. cursor = mLeftRightCursor;
  733. }
  734. }
  735. }
  736. bool GuiFrameSetCtrl::onMouseDownEditor(const GuiEvent& event, const Point2I& offset)
  737. {
  738. Point2I cursorPt = globalToLocalCoord(event.mousePoint);
  739. Frame* frame = mRootFrame.findFrameWithPoint(cursorPt);
  740. if(frame && isEditSelected())
  741. {
  742. if (frame->spliterRect1.pointInRect(cursorPt))
  743. {
  744. splitFrame(frame, GuiDirection::Left);
  745. setFrameSize(frame->child1->id, (frame->extent.x - mDividerThickness) / 2);
  746. return true;
  747. }
  748. else if (frame->spliterRect2.pointInRect(cursorPt))
  749. {
  750. splitFrame(frame, GuiDirection::Up);
  751. setFrameSize(frame->child1->id, (frame->extent.y - mDividerThickness) / 2);
  752. return true;
  753. }
  754. }
  755. frame = mRootFrame.findHitDivider(cursorPt);
  756. if (frame)
  757. {
  758. onTouchDown(event);
  759. return true;
  760. }
  761. return Parent::onMouseDownEditor(event, offset);
  762. }
  763. bool GuiFrameSetCtrl::onMouseUpEditor(const GuiEvent& event, const Point2I& offset)
  764. {
  765. if (mDepressed)
  766. {
  767. onTouchUp(event);
  768. return true;
  769. }
  770. return false;
  771. }
  772. bool GuiFrameSetCtrl::onMouseDraggedEditor(const GuiEvent& event, const Point2I& offset)
  773. {
  774. if (mDepressed)
  775. {
  776. onTouchDragged(event);
  777. return true;
  778. }
  779. return false;
  780. }
  781. void GuiFrameSetCtrl::renderDropOptions(GuiWindowCtrl* window)
  782. {
  783. Point2I cursorPt = Point2I(0, 0);
  784. GuiCanvas* root = getRoot();
  785. if (root)
  786. {
  787. cursorPt = globalToLocalCoord(root->getCursorPos());
  788. cursorPt.x = getMin(getMax(0, cursorPt.x), mRootFrame.extent.x);
  789. cursorPt.y = getMin(getMax(0, cursorPt.y), mRootFrame.extent.y);
  790. }
  791. Frame* frame = mRootFrame.findFrameWithPoint(cursorPt);
  792. if (frame)
  793. {
  794. ColorI fillColor = mProfile->getFillColor(SelectedState);
  795. fillColor.alpha = 50;
  796. const U32 width = getMax(minSize, getMin(frame->extent.x / 2, window->mBounds.extent.x));
  797. const U32 height = getMax(minSize, getMin(frame->extent.y / 2, window->mBounds.extent.y));
  798. if (frame->hasLeftRightButtons)
  799. {
  800. Point2I fillExt = Point2I(width, frame->extent.y);
  801. renderDropButton(frame, frame->mLeftButtonRect, cursorPt, frame->localPosition, fillExt, GuiDirection::Left);
  802. renderDropButton(frame, frame->mRightButtonRect, cursorPt, Point2I(frame->localPosition.x + frame->extent.x - width, frame->localPosition.y), fillExt, GuiDirection::Right);
  803. }
  804. if (frame->hasTopBottomButtons)
  805. {
  806. Point2I fillExt = Point2I(frame->extent.x, height);
  807. renderDropButton(frame, frame->mTopButtonRect, cursorPt, frame->localPosition, fillExt, GuiDirection::Up);
  808. renderDropButton(frame, frame->mBottomButtonRect, cursorPt, Point2I(frame->localPosition.x, frame->localPosition.y + frame->extent.y - height), fillExt, GuiDirection::Down);
  809. }
  810. if (hasCenterButton(frame))
  811. {
  812. renderDropButton(frame, frame->mCenterButtonRect, cursorPt, frame->localPosition, frame->extent, GuiDirection::Center);
  813. }
  814. }
  815. }
  816. bool GuiFrameSetCtrl::hasCenterButton(GuiFrameSetCtrl::Frame* frame)
  817. {
  818. if (!frame->control)
  819. {
  820. return false;
  821. }
  822. GuiWindowCtrl* window = dynamic_cast<GuiWindowCtrl*>(frame->control);
  823. GuiTabBookCtrl* book = dynamic_cast<GuiTabBookCtrl*>(frame->control);
  824. return frame != &mRootFrame && (window || book);
  825. }
  826. void GuiFrameSetCtrl::renderDropButton(const GuiFrameSetCtrl::Frame* frame, const RectI& buttonRect, const Point2I& cursorPt, const Point2I& fillPos, const Point2I& fillExt, GuiDirection direction)
  827. {
  828. GuiControlState state = NormalState;
  829. if (buttonRect.pointInRect(cursorPt))
  830. {
  831. state = HighlightState;
  832. RectI rect = RectI(fillPos, fillExt);
  833. rect.point = localToGlobalCoord(rect.point);
  834. setUpdateRegion(rect.point, rect.extent);
  835. renderUniversalRect(rect, mDropButtonProfile, SelectedState);
  836. }
  837. RectI globalButtonRect = RectI(localToGlobalCoord(buttonRect.point), buttonRect.extent);
  838. renderUniversalRect(globalButtonRect, mDropButtonProfile, state);
  839. ColorI triColor = getFontColor(mDropButtonProfile, state);
  840. if(direction != GuiDirection::Center)
  841. {
  842. renderTriangleIcon(globalButtonRect, triColor, direction, 10);
  843. }
  844. else
  845. {
  846. RectI iconRect = RectI(buttonRect);
  847. iconRect.inset(15, 15);
  848. RectI lineH = RectI(localToGlobalCoord(Point2I(iconRect.point.x, iconRect.point.y + 4)), Point2I(iconRect.extent.x, 2));
  849. RectI lineV = RectI(localToGlobalCoord(Point2I(iconRect.point.x + 4, iconRect.point.y)), Point2I(2, iconRect.extent.y));
  850. dglDrawRectFill(lineH, triColor);
  851. dglDrawRectFill(lineV, triColor);
  852. }
  853. }
  854. void GuiFrameSetCtrl::handleDropButtons(GuiWindowCtrl* window)
  855. {
  856. Point2I cursorPt = Point2I(0, 0);
  857. GuiCanvas* root = getRoot();
  858. if (root)
  859. {
  860. cursorPt = globalToLocalCoord(root->getCursorPos());
  861. cursorPt.x = getMin(getMax(0, cursorPt.x), mRootFrame.extent.x);
  862. cursorPt.y = getMin(getMax(0, cursorPt.y), mRootFrame.extent.y);
  863. }
  864. Frame* frame = mRootFrame.findFrameWithPoint(cursorPt);
  865. if (frame)
  866. {
  867. const U32 width = getMax(minSize, getMin(frame->extent.x / 2, window->mBounds.extent.x));
  868. const U32 height = getMax(minSize, getMin(frame->extent.y / 2, window->mBounds.extent.y));
  869. bool hitButton = false;
  870. if (frame->hasLeftRightButtons && frame->mLeftButtonRect.pointInRect(cursorPt))
  871. {
  872. splitFrame(frame, GuiDirection::Right);//This existing control goes right, the new window will go left.
  873. anchorFrame(frame->child1);
  874. frame->child1->control = window;
  875. frame->child1->extent = Point2I(width, frame->extent.y);
  876. hitButton = true;
  877. }
  878. else if (frame->hasLeftRightButtons && frame->mRightButtonRect.pointInRect(cursorPt))
  879. {
  880. splitFrame(frame, GuiDirection::Left);
  881. anchorFrame(frame->child2);
  882. frame->child2->control = window;
  883. frame->child2->extent = Point2I(width, frame->extent.y);
  884. hitButton = true;
  885. }
  886. else if (frame->hasTopBottomButtons && frame->mTopButtonRect.pointInRect(cursorPt))
  887. {
  888. splitFrame(frame, GuiDirection::Down);
  889. anchorFrame(frame->child1);
  890. frame->child1->control = window;
  891. frame->child1->extent = Point2I(frame->extent.x, height);
  892. hitButton = true;
  893. }
  894. else if (frame->hasTopBottomButtons && frame->mBottomButtonRect.pointInRect(cursorPt))
  895. {
  896. splitFrame(frame, GuiDirection::Up);
  897. anchorFrame(frame->child2);
  898. frame->child2->control = window;
  899. frame->child2->extent = Point2I(frame->extent.x, height);
  900. hitButton = true;
  901. }
  902. else if (hasCenterButton(frame) && frame->mCenterButtonRect.pointInRect(cursorPt))
  903. {
  904. if (!frame->control)
  905. {
  906. frame->control = window;
  907. hitButton = true;
  908. }
  909. else
  910. {
  911. GuiTabBookCtrl* book = dynamic_cast<GuiTabBookCtrl*>(frame->control);
  912. GuiTabPageCtrl* page = nullptr;
  913. if (!book)
  914. {
  915. book = new GuiTabBookCtrl();
  916. book->setControlProfile(mTabBookProfile);
  917. book->setControlTabProfile(mTabProfile);
  918. book->mBounds.set(frame->localPosition, frame->extent);
  919. book->mIsFrameSetGenerated = true;
  920. book->registerObject();
  921. book->addNewPage();
  922. page = dynamic_cast<GuiTabPageCtrl*>((*book)[0]);
  923. page->setControlProfile(mTabPageProfile);
  924. GuiWindowCtrl* windowChild = dynamic_cast<GuiWindowCtrl*>(frame->control);
  925. GuiControl* child = dynamic_cast<GuiControl*>(frame->control);
  926. if (windowChild)
  927. {
  928. windowChild->dockToPage();
  929. }
  930. page->setText(child->getText());
  931. frame->control = book;
  932. page->addObject(child);
  933. addObject(book);
  934. }
  935. window->dockToPage();
  936. book->addNewPage();
  937. page = dynamic_cast<GuiTabPageCtrl*>((*book)[book->size() - 1]);
  938. page->setControlProfile(mTabPageProfile);
  939. page->setText(window->getText());
  940. page->addObject(window);
  941. book->selectPage(window->getText());
  942. window->resize(window->getPosition(), window->getExtent());
  943. }
  944. }
  945. if (hitButton)
  946. {
  947. addObject(window);
  948. resize(mBounds.point, mBounds.extent);
  949. }
  950. }
  951. }
  952. void GuiFrameSetCtrl::undockWindowFromBook(GuiWindowCtrl* window, GuiTabBookCtrl* book, GuiTabPageCtrl* page)
  953. {
  954. GuiControl* parent = getParent();
  955. GuiCanvas* root = getRoot();
  956. if (parent && window && book && page && window->mPageDocked && root)
  957. {
  958. parent->addObject(window);
  959. parent->pushObjectToBack(window);
  960. Point2I cursorPt = globalToLocalCoord(root->getCursorPos());
  961. window->undockFromPage();
  962. window->restore();
  963. Point2I newPosition = Point2I(cursorPt.x - (window->getExtent().x / 2), cursorPt.y - (window->getTitleHeight() / 2));
  964. Point2I pos = parent->localToGlobalCoord(newPosition);
  965. root->addUpdateRegion(pos, window->getExtent());
  966. window->resize(newPosition, window->getExtent());
  967. GuiEvent event = GuiEvent();
  968. event.mousePoint = Point2I(root->getCursorPos());
  969. event.mouseClickCount = 1;
  970. root->rootScreenTouchUp(event);
  971. root->rootScreenTouchDown(event);
  972. book->removeObject(page);
  973. page->deleteObject();
  974. if (book->size() > 0)
  975. {
  976. book->calculatePageTabs();
  977. book->selectPage(0);
  978. }
  979. if (book->mIsFrameSetGenerated && book->size() == 1)
  980. {
  981. GuiTabPageCtrl* lastPage = dynamic_cast<GuiTabPageCtrl*>((*book)[0]);
  982. GuiWindowCtrl* lastWindow = dynamic_cast<GuiWindowCtrl*>((*lastPage)[0]);
  983. GuiFrameSetCtrl::Frame* frame = mRootFrame.findFrameWithCtrl(book);
  984. frame->control = lastWindow;
  985. addObject(lastWindow);
  986. lastPage->deleteObject();
  987. lastWindow->undockFromPage();
  988. }
  989. }
  990. }
  991. void GuiFrameSetCtrl::renderChild(GuiControl* ctrl, const Point2I& offset, const RectI& content, const RectI& clipRect)
  992. {
  993. RectI clip = RectI(clipRect);
  994. Frame* frame = mRootFrame.findFrameWithCtrl(ctrl);
  995. if (frame)
  996. {
  997. Point2I framePos = localToGlobalCoord(frame->localPosition);
  998. RectI area(framePos, frame->extent);
  999. clip.intersect(area);
  1000. }
  1001. Parent::renderChild(ctrl, offset, content, clip);
  1002. }
  1003. GuiControl* GuiFrameSetCtrl::findHitControl(const Point2I& pt, S32 initialLayer)
  1004. {
  1005. iterator i = end(); // find in z order (last to first)
  1006. while (i != begin())
  1007. {
  1008. i--;
  1009. GuiControl* ctrl = static_cast<GuiControl*>(*i);
  1010. RectI ctrlRect = RectI(localToGlobalCoord(ctrl->getPosition()), ctrl->getExtent());
  1011. Frame* frame = mRootFrame.findFrameWithCtrl(ctrl);
  1012. if (frame)
  1013. {
  1014. Point2I framePos = localToGlobalCoord(frame->localPosition);
  1015. RectI area(framePos, frame->extent);
  1016. ctrlRect.intersect(area);
  1017. }
  1018. Point2I globalPoint = localToGlobalCoord(pt);
  1019. if (initialLayer >= 0 && ctrl->mLayer > initialLayer)
  1020. {
  1021. continue;
  1022. }
  1023. else if (ctrl->mVisible && ctrl->pointInControl(pt - ctrl->mRenderInsetLT) && ctrl->mUseInput && ctrlRect.pointInRect(globalPoint))
  1024. {
  1025. Point2I ptemp = pt - (ctrl->mBounds.point + ctrl->mRenderInsetLT);
  1026. GuiControl* hitCtrl = ctrl->findHitControl(ptemp);
  1027. if (hitCtrl->mUseInput)
  1028. return hitCtrl;
  1029. }
  1030. }
  1031. return this;
  1032. }
  1033. void GuiFrameSetCtrl::setDropButtonProfile(GuiControlProfile* prof)
  1034. {
  1035. AssertFatal(prof, "GuiFrameSetCtrl::setDropButtonProfile: invalid content profile");
  1036. if (prof == mDropButtonProfile)
  1037. return;
  1038. if (mAwake)
  1039. mDropButtonProfile->decRefCount();
  1040. mDropButtonProfile = prof;
  1041. if (mAwake)
  1042. mDropButtonProfile->incRefCount();
  1043. }
  1044. void GuiFrameSetCtrl::setTabBookProfile(GuiControlProfile* prof)
  1045. {
  1046. AssertFatal(prof, "GuiFrameSetCtrl::setTabBookProfile: invalid content profile");
  1047. if (prof == mTabBookProfile)
  1048. return;
  1049. if (mAwake)
  1050. mTabBookProfile->decRefCount();
  1051. mTabBookProfile = prof;
  1052. if (mAwake)
  1053. mTabBookProfile->incRefCount();
  1054. //Cycle through all children and replace the profiles of frameSetGenerated books.
  1055. SimSet::iterator i;
  1056. for (i = begin(); i != end(); i++)
  1057. {
  1058. GuiTabBookCtrl* book = dynamic_cast<GuiTabBookCtrl*>(*i);
  1059. if (book && book->mIsFrameSetGenerated)
  1060. {
  1061. book->setControlProfile(prof);
  1062. }
  1063. }
  1064. }
  1065. void GuiFrameSetCtrl::setTabProfile(GuiControlProfile* prof)
  1066. {
  1067. AssertFatal(prof, "GuiFrameSetCtrl::setTabProfile: invalid content profile");
  1068. if (prof == mTabProfile)
  1069. return;
  1070. if (mAwake)
  1071. mTabProfile->decRefCount();
  1072. mTabProfile = prof;
  1073. if (mAwake)
  1074. mTabProfile->incRefCount();
  1075. SimSet::iterator i;
  1076. for (i = begin(); i != end(); i++)
  1077. {
  1078. GuiTabBookCtrl* book = dynamic_cast<GuiTabBookCtrl*>(*i);
  1079. if (book && book->mIsFrameSetGenerated)
  1080. {
  1081. book->setControlTabProfile(prof);
  1082. }
  1083. }
  1084. }
  1085. void GuiFrameSetCtrl::setTabPageProfile(GuiControlProfile* prof)
  1086. {
  1087. AssertFatal(prof, "GuiFrameSetCtrl::setTabPageProfile: invalid content profile");
  1088. if (prof == mTabPageProfile)
  1089. return;
  1090. if (mAwake)
  1091. mTabPageProfile->decRefCount();
  1092. mTabPageProfile = prof;
  1093. if (mAwake)
  1094. mTabPageProfile->incRefCount();
  1095. SimSet::iterator i;
  1096. for (i = begin(); i != end(); i++)
  1097. {
  1098. GuiTabBookCtrl* book = dynamic_cast<GuiTabBookCtrl*>(*i);
  1099. if (book && book->mIsFrameSetGenerated)
  1100. {
  1101. SimSet::iterator j;
  1102. for (j = begin(); j != end(); j++)
  1103. {
  1104. GuiTabPageCtrl* page = dynamic_cast<GuiTabPageCtrl*>(*i);
  1105. if (page)
  1106. {
  1107. page->setControlProfile(prof);
  1108. }
  1109. }
  1110. }
  1111. }
  1112. }
  1113. void GuiFrameSetCtrl::setControlLeftRightCursor(GuiCursor* cursor)
  1114. {
  1115. AssertFatal(cursor, "GuiFrameSetCtrl::setControlLeftRightCursor: invalid cursor");
  1116. if (cursor == mLeftRightCursor)
  1117. return;
  1118. mLeftRightCursor = cursor;
  1119. }
  1120. void GuiFrameSetCtrl::setControlUpDownCursor(GuiCursor* cursor)
  1121. {
  1122. AssertFatal(cursor, "GuiFrameSetCtrl::setControlUpDownCursor: invalid cursor");
  1123. if (cursor == mUpDownCursor)
  1124. return;
  1125. mUpDownCursor = cursor;
  1126. }
  1127. void GuiFrameSetCtrl::writeFields(Stream& stream, U32 tabStop)
  1128. {
  1129. if (mRootFrame.child1 && mRootFrame.child2)
  1130. {
  1131. setModDynamicFields(true);
  1132. setCanSaveDynamicFields(true);
  1133. Frame* frame = &mRootFrame;
  1134. generateFrameFields(frame);
  1135. Parent::writeFields(stream, tabStop);
  1136. clearDynamicFields();
  1137. setModDynamicFields(false);
  1138. setCanSaveDynamicFields(false);
  1139. }
  1140. else
  1141. {
  1142. Parent::writeFields(stream, tabStop);
  1143. }
  1144. }
  1145. void GuiFrameSetCtrl::generateFrameFields(GuiFrameSetCtrl::Frame* frame)
  1146. {
  1147. U32 id = frame->id;
  1148. U32 child1ID = frame->child1 ? frame->child1->id : 0;
  1149. U32 child2ID = frame->child2 ? frame->child2->id : 0;
  1150. setDataField("child1ID", id, child1ID);
  1151. setDataField("child2ID", id, child2ID);
  1152. setDataField("isVertical", id, frame->isVertical);
  1153. setDataField("frameExtentX", id, frame->extent.x);
  1154. setDataField("frameExtentY", id, frame->extent.y);
  1155. setDataField("isAnchored", id, frame->isAnchored);
  1156. if (frame->child1)
  1157. {
  1158. generateFrameFields(frame->child1);
  1159. }
  1160. if (frame->child2)
  1161. {
  1162. generateFrameFields(frame->child2);
  1163. }
  1164. }
  1165. void GuiFrameSetCtrl::setDataField(const char* tag, const U32 id, const U32 value)
  1166. {
  1167. char idBuffer[16];
  1168. char valueBuffer[16];
  1169. StringTableEntry tagFieldName = StringTable->insert(tag);
  1170. dSprintf(idBuffer, 16, "%d", id);
  1171. dSprintf(valueBuffer, 16, "%d", value);
  1172. SimObject::setDataField(tagFieldName, idBuffer, valueBuffer);
  1173. }
  1174. const char* GuiFrameSetCtrl::getDataField(const char* tag, const U32 id)
  1175. {
  1176. char idBuffer[16];
  1177. StringTableEntry tagFieldName = StringTable->insert(tag);
  1178. dSprintf(idBuffer, 16, "%d", id);
  1179. return SimObject::getDataField(tagFieldName, idBuffer);
  1180. }
  1181. static StringTableEntry frameNodeSectionName = StringTable->insert("Frames", true);
  1182. static StringTableEntry frameNodeName = StringTable->insert("Frame", true);
  1183. static StringTableEntry frameIDName = StringTable->insert("ID", true);
  1184. static StringTableEntry frameChild1Name = StringTable->insert("Child1ID", true);
  1185. static StringTableEntry frameChild2Name = StringTable->insert("Child2ID", true);
  1186. static StringTableEntry frameIsVerticalName = StringTable->insert("IsVertical", true);
  1187. static StringTableEntry frameExtentXName = StringTable->insert("ExtentX", true);
  1188. static StringTableEntry frameExtentYName = StringTable->insert("ExtentY", true);
  1189. static StringTableEntry frameIsAnchoredName = StringTable->insert("IsAnchored", true);
  1190. static StringTableEntry frameChildMapName = StringTable->insert("ChildMap", true);
  1191. void GuiFrameSetCtrl::onTamlCustomWrite(TamlCustomNodes& customNodes)
  1192. {
  1193. // Debug Profiling.
  1194. PROFILE_SCOPE(GuiFrameSetCtrl_OnTamlCustomWrite);
  1195. // Call parent.
  1196. Parent::onTamlCustomWrite(customNodes);
  1197. if (mRootFrame.child1 && mRootFrame.child2)
  1198. {
  1199. TamlCustomNode* pCustomFrameSection = customNodes.addNode(frameNodeSectionName);
  1200. Frame* frame = &mRootFrame;
  1201. writeFrameCustomTaml(pCustomFrameSection, frame);
  1202. }
  1203. }
  1204. void GuiFrameSetCtrl::writeFrameCustomTaml(TamlCustomNode* pParentNode, GuiFrameSetCtrl::Frame* frame)
  1205. {
  1206. TamlCustomNode* pFrameNode = pParentNode->addNode(frameNodeName);
  1207. U32 child1ID = frame->child1 ? frame->child1->id : 0;
  1208. U32 child2ID = frame->child2 ? frame->child2->id : 0;
  1209. pFrameNode->addField(frameIDName, frame->id);
  1210. pFrameNode->addField(frameChild1Name, child1ID);
  1211. pFrameNode->addField(frameChild2Name, child2ID);
  1212. pFrameNode->addField(frameIsVerticalName, frame->isVertical);
  1213. pFrameNode->addField(frameExtentXName, frame->extent.x);
  1214. pFrameNode->addField(frameExtentYName, frame->extent.y);
  1215. pFrameNode->addField(frameIsAnchoredName, frame->isAnchored);
  1216. if (frame->control)
  1217. {
  1218. U32 childMap = 0;
  1219. for (SimSet::iterator itr = begin(); itr != end(); itr++, childMap++)
  1220. {
  1221. GuiControl* ctrl = dynamic_cast<GuiControl*>(*itr);
  1222. if (ctrl && ctrl == frame->control)
  1223. {
  1224. break;
  1225. }
  1226. }
  1227. pFrameNode->addField(frameChildMapName, childMap);
  1228. }
  1229. if (frame->child1)
  1230. {
  1231. writeFrameCustomTaml(pFrameNode, frame->child1);
  1232. }
  1233. if (frame->child2)
  1234. {
  1235. writeFrameCustomTaml(pFrameNode, frame->child2);
  1236. }
  1237. }
  1238. void GuiFrameSetCtrl::onTamlCustomRead(const TamlCustomNodes& customNodes)
  1239. {
  1240. // Debug Profiling.
  1241. PROFILE_SCOPE(GuiFrameSetCtrl_OnTamlCustomRead);
  1242. // Call parent.
  1243. Parent::onTamlCustomRead(customNodes);
  1244. // Load the frames
  1245. loadTamlFrames(customNodes);
  1246. }
  1247. void GuiFrameSetCtrl::loadTamlFrames(const TamlCustomNodes& customNodes)
  1248. {
  1249. const TamlCustomNode* pCustomFrameSection = customNodes.findNode(frameNodeSectionName);
  1250. if (pCustomFrameSection != NULL)
  1251. {
  1252. const TamlCustomNodeVector& childList = pCustomFrameSection->getChildren();
  1253. if (childList.size() == 0)
  1254. {
  1255. //not really an error so let's move on.
  1256. return;
  1257. }
  1258. else if (childList.size() != 1)
  1259. {
  1260. Con::warnf("GuiFrameSetCtrl::loadTamlFrames() - Only a single root frame should be defined.");
  1261. return;
  1262. }
  1263. TamlCustomNode* rootNode = *childList.begin();
  1264. Frame* frame = &mRootFrame;
  1265. loadTamlFrame(*rootNode, frame);
  1266. mRootFrame.resize(getPosition(), getExtent());
  1267. }
  1268. }
  1269. void GuiFrameSetCtrl::loadTamlFrame(const TamlCustomNode& node, GuiFrameSetCtrl::Frame* frame)
  1270. {
  1271. StringTableEntry frameName = node.getNodeName();
  1272. if (frameName != frameNodeName)
  1273. {
  1274. Con::warnf("GuiFrameSetCtrl::loadTamlFrame() - Unknown tag name of '%s'. Only '%s' is valid.", frameName, frameNodeName);
  1275. return;
  1276. }
  1277. U32 child1ID = 0;
  1278. U32 child2ID = 0;
  1279. U32 childMap = 0;
  1280. const TamlCustomFieldVector& fields = node.getFields();
  1281. for (TamlCustomFieldVector::const_iterator fieldItr = fields.begin(); fieldItr != fields.end(); ++fieldItr)
  1282. {
  1283. const TamlCustomField* pField = *fieldItr;
  1284. StringTableEntry fieldName = pField->getFieldName();
  1285. if (fieldName == frameIDName)
  1286. {
  1287. pField->getFieldValue(frame->id);
  1288. }
  1289. else if (fieldName == frameChild1Name)
  1290. {
  1291. pField->getFieldValue(child1ID);
  1292. }
  1293. else if (fieldName == frameChild2Name)
  1294. {
  1295. pField->getFieldValue(child2ID);
  1296. }
  1297. else if (fieldName == frameIsVerticalName)
  1298. {
  1299. pField->getFieldValue(frame->isVertical);
  1300. }
  1301. else if (fieldName == frameExtentXName)
  1302. {
  1303. pField->getFieldValue(frame->extent.x);
  1304. }
  1305. else if (fieldName == frameExtentYName)
  1306. {
  1307. pField->getFieldValue(frame->extent.y);
  1308. }
  1309. else if (fieldName == frameIsAnchoredName)
  1310. {
  1311. pField->getFieldValue(frame->isAnchored);
  1312. }
  1313. else if (fieldName == frameChildMapName)
  1314. {
  1315. pField->getFieldValue(childMap);
  1316. }
  1317. else
  1318. {
  1319. Con::warnf("GuiFrameSetCtrl::loadTamlFrame() - Encountered an unknown field name of '%s'.", fieldName);
  1320. continue;
  1321. }
  1322. }
  1323. if (frame->extent.x <= 0 || frame->extent.y <= 0)
  1324. {
  1325. Con::warnf("GuiFrameSetCtrl::loadTamlFrame() - Frame extent of '(%d,%d)' is invalid or was not set.", frame->extent.x, frame->extent.y);
  1326. frame->extent.set(1, 1);
  1327. }
  1328. const TamlCustomNodeVector& childList = node.getChildren();
  1329. if ((child1ID != 0 || child2ID != 0) && childList.size() < 2)
  1330. {
  1331. Con::warnf("GuiFrameSetCtrl::loadTamlFrame() - Frame %d shows child IDs but child nodes don't exist. Frames may have no children or exactly 2.", frame->id);
  1332. return;
  1333. }
  1334. else if (childList.size() != 0 && childList.size() != 2)
  1335. {
  1336. Con::warnf("GuiFrameSetCtrl::loadTamlFrame() - Frame %d has %d child nodes. Frames may have no children or exactly 2.", frame->id, childList.size());
  1337. return;
  1338. }
  1339. if (childList.size() == 2 && child1ID && child2ID)
  1340. {
  1341. splitFrame(frame, frame->isVertical ? GuiDirection::Up : GuiDirection::Left);
  1342. TamlCustomNode* child1Node = *childList.begin();
  1343. loadTamlFrame(*child1Node, frame->child1);
  1344. TamlCustomNode* child2Node = *(childList.begin() + 1);
  1345. loadTamlFrame(*child2Node, frame->child2);
  1346. }
  1347. else
  1348. {
  1349. GuiControl* child = dynamic_cast<GuiControl*>(at(childMap));
  1350. frame->control = child;
  1351. }
  1352. }