guiFrameSetCtrl.cc 42 KB

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